Skip to content

Commit

Permalink
Issue #1116 - flag to license process - The process skips already
Browse files Browse the repository at this point in the history
licensed works.
  • Loading branch information
pavel-stastny committed Feb 4, 2025
1 parent de99101 commit d786057
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,15 @@ public static void main(String[] args) throws IOException, SolrServerException,
// IResourceIndex resourceIndex = new ResourceIndexImplByKrameriusNewApis(repository, ProcessUtils.getCoreBaseUrl());
ProcessingIndex processingIndex = new ProcessingIndexImplByKrameriusNewApis(repository, ProcessUtils.getCoreBaseUrl());

List<String> brokenPids = new ArrayList<>();
switch (action) {
case ADD:
ProcessStarter.updateName(String.format("Přidání licence '%s' pro %s", license, target));
for (String pid : extractPids(target)) {
try {
addLicense(license, pid, repository, processingIndex, searchIndex, indexerAccess);
} catch (Exception ex) {
brokenPids.add(pid);
LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
LOGGER.log(Level.SEVERE, String.format("Skipping object %s", pid));
}
Expand All @@ -129,12 +131,18 @@ public static void main(String[] args) throws IOException, SolrServerException,
try {
removeLicense(license, pid, repository, processingIndex, searchIndex, indexerAccess, authToken);
} catch (Exception ex) {
brokenPids.add(pid);
LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
LOGGER.log(Level.SEVERE, String.format("Skipping object %s", pid));
}
}
break;
}

if (!brokenPids.isEmpty()) {
throw new RuntimeException("All problematic pids:"+brokenPids);
}

}

private static List<String> extractPids(String target) {
Expand Down Expand Up @@ -209,15 +217,21 @@ private static void addLicense(String license, String targetPid, KrameriusReposi
}
}

private static List<String> getPidsOfOwnAncestors(String targetPid, ProcessingIndex processingIndex) throws ResourceIndexException {
List<String> result = new ArrayList<>();
String pidOfCurrentNode = targetPid;
String pidOfCurrentNodesOwnParent;
while ((pidOfCurrentNodesOwnParent = processingIndex.getPidsOfParents(pidOfCurrentNode).getFirst()) != null) {
result.add(pidOfCurrentNodesOwnParent);
pidOfCurrentNode = pidOfCurrentNodesOwnParent;
private static List<String> getPidsOfOwnAncestors(String targetPid, ProcessingIndex processingIndex) {

try {
List<String> result = new ArrayList<>();
String pidOfCurrentNode = targetPid;
String pidOfCurrentNodesOwnParent;
while ((pidOfCurrentNodesOwnParent = processingIndex.getPidsOfParents(pidOfCurrentNode).getFirst()) != null) {
result.add(pidOfCurrentNodesOwnParent);
pidOfCurrentNode = pidOfCurrentNodesOwnParent;
}
return result;
} catch (ResourceIndexException e) {
// trhow runtime exception = FAILED state
throw new RuntimeException(e);
}
return result;
}

/* private static List<String> getPidsOfAllAncestors(String targetPid, SolrAccess searchIndex) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,14 @@ public static void main(String[] args) throws ParserConfigurationException, SAXE
Map<String, String> topLevelModelsMap = new HashMap<>();
Map<String, List<Pair<String,String>>> subLevelModelsMap = new HashMap<>();
Map<String, Triple<String, String, String>> details = new HashMap<>();


List<String> alreadyLicensedPids = new ArrayList<>();

List<String> publicPids = new ArrayList<>();
List<String> privatePids = new ArrayList<>();


IterationUtils.cursorIteration(new IterationUtils.FieldsProvider(getSortField(), "pid","root.pid","accessibility","model"), Endpoint.select, client, KConfiguration.getInstance().getSolrSearchHost() , encodedQ, (elm, iter)-> {
IterationUtils.cursorIteration(new IterationUtils.FieldsProvider(getSortField(), "pid","root.pid","accessibility","model","licenses"), Endpoint.select, client, KConfiguration.getInstance().getSolrSearchHost() , encodedQ, (elm, iter)-> {
try {
List<Element> docs = XMLUtils.getElementsRecursive(elm, new XMLUtils.ElementsFilter() {

Expand All @@ -143,7 +145,9 @@ public boolean acceptElement(Element element) {
AtomicReference<String> model = new AtomicReference<>();
AtomicReference<String> pid = new AtomicReference<>();
AtomicReference<String> rootPid = new AtomicReference<>();


AtomicReference<List<String>> lics = new AtomicReference<>();

XMLUtils.getElements(doc).forEach(e-> {
String name = e.getAttribute("name");
switch(name) {
Expand All @@ -159,6 +163,11 @@ public boolean acceptElement(Element element) {
case "root.pid":
rootPid.set(e.getTextContent());
break;
case "licenses":
List<Element> elements = XMLUtils.getElements(e);
List<String> collectedLicenses = elements.stream().map(Element::getTextContent).collect(Collectors.toList());
lics.set(collectedLicenses);
break;
}
});

Expand All @@ -175,6 +184,11 @@ public boolean acceptElement(Element element) {
list.add( Pair.of(pid.get(), accessibility.get()) );
}
details.put(pid.get(), Triple.of(model.get(), accessibility.get(), pid.get()));


if (lics.get() != null && (lics.get().contains(CzechEmbeddedLicenses.PUBLIC_LICENSE.getName()) || lics.get().contains(CzechEmbeddedLicenses.ONSITE_LICENSE.getName()))) {
alreadyLicensedPids.add(pid.get());
}
});

} catch (Exception e) {
Expand All @@ -200,9 +214,18 @@ public boolean acceptElement(Element element) {
});
}
});


// public batches

// remove from public list & private list
alreadyLicensedPids.forEach(pid-> {
publicPids.remove(pid);
privatePids.remove(pid);
});

LOGGER.info(String.format("Number of already licensed pids: %d", alreadyLicensedPids.size()));
LOGGER.info(String.format("To public license: %d", publicPids.size()));
LOGGER.info(String.format("To onsite license: %d", privatePids.size()));

// public batches
scheduleSetLicenses(publicPids, CzechEmbeddedLicenses.PUBLIC_LICENSE.getName(), authToken);

// private batches
Expand Down

0 comments on commit d786057

Please sign in to comment.