Skip to content

Commit

Permalink
Issue #1065
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-stastny committed May 30, 2024
1 parent f94e5b8 commit 5ee866d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import javax.xml.xpath.XPathExpressionException;

import java.io.*;
import java.util.Arrays;
import java.util.logging.Level;


Expand Down Expand Up @@ -74,6 +75,10 @@ public static void main(String[] args) throws InterruptedException, JAXBExceptio
/*for (int i = 0; i < args.length; i++) {
System.out.println("arg " + i + ": " + args[i]);
}*/

log.info(String.format("Arguments :%s", Arrays.asList(args).toString()));


if (args.length < 2 || args[0].equalsIgnoreCase("true") || args[0].equalsIgnoreCase("false")) { //through CLI with 0-3 args
System.out.println("ANL METS to FOXML conversion tool.\n");
System.out.println("Usage: conversion-tool policyPublic <input-folder> <output-folder>");
Expand All @@ -89,9 +94,12 @@ public static void main(String[] args) throws InterruptedException, JAXBExceptio
if (args.length < 2) {
throw new RuntimeException("Not enough arguments.");
}

int argsIndex = 0;
//token for keeping possible following processes in same batch
String authToken = args[argsIndex++]; //auth token always second, but still suboptimal solution, best would be if it was outside the scope of this as if ProcessHelper.scheduleProcess() similarly to changing name (ProcessStarter)


//process params
String policy = args[argsIndex++];
boolean policyPublic = "PUBLIC".equals(policy);
Expand All @@ -107,7 +115,7 @@ public static void main(String[] args) throws InterruptedException, JAXBExceptio
}

String license = null;
if (startIndexer) { license = args.length > argsIndex ? args[argsIndex++] : null; }
license = args.length > argsIndex ? args[argsIndex++] : null;

try {
ProcessStarter.updateName(String.format("Import NDK METS z %s ", importRoot));
Expand Down Expand Up @@ -149,7 +157,7 @@ private void run(String importRoot, String exportRoot, boolean policyPublic, boo
FOXMLAppendLicenseService foxmlService = injector.getInstance(FOXMLAppendLicenseService.class);


if (license != null && startIndexer) {
if (license != null) {
log.info(String.format("Applying license to %s", license));
try {
foxmlService.appendLicense(exportRoot, license);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
Expand Down Expand Up @@ -167,6 +168,7 @@ public void onFinished(int processed) {
nowIndexed++;
} catch (Throwable e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE,e.getMessage(),e);
nowErrors++;
}
}
Expand All @@ -183,7 +185,7 @@ public void onFinished(int processed) {
report(" Total objects processed: " + totalObjectProcessed[0]);
report("===========================================");

if (nowErrors > 0) {
if (nowErrors > 0 || nowIgnored >0) {
throw new IllegalStateException("Indexation finished with errors; see error log");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,16 @@ public void indexByObjectPid(String pid, IndexationType type, ProgressListener p
report(" records processing duration: " + formatTime(System.currentTimeMillis() - start));
report("=======================================");
report("");

if (counters.getErrors() > 0 || counters.getIgnored() >0) {
throw new IllegalStateException("Indexation finished with errors; see error log");
}

if (progressListener != null) {
progressListener.onFinished(counters.getProcessed());
}


}
}

Expand Down Expand Up @@ -194,12 +200,12 @@ private void indexObjectWithCounters(String pid, RepositoryNode repositoryNode,
// Replaced ingoremissingFromRepository by ingore inconsistent object
//boolean ignoreObjectsMissingFromRepository = true;
if (this.ignoreInconsistentObjects) { //ignore missing objects
report("object not found in repository (or found in inconsistent state), ignoring: " + pid);
System.err.println("object not found in repository (or found in inconsistent state), ignoring: " + pid);
reportError("object not found in repository (or found in inconsistent state), ignoring: " + pid);
//System.err.println("object not found in repository (or found in inconsistent state), ignoring: " + pid);
counters.incrementIgnored();
} else { //remove missing objects from index
report("object not found in repository (or found in inconsistent state), removing from index: " + pid);
System.err.println("object not found in repository (or found in inconsistent state), removing from index: " + pid);
reportError("object not found in repository (or found in inconsistent state), removing from index: " + pid);
//System.err.println("object not found in repository (or found in inconsistent state), removing from index: " + pid);
solrIndexer.deleteById(pid);
counters.incrementRemoved();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx
.getList(LICENSE_RULES, Arrays.asList("monograph->monographunit", "periodical->periodicalvolume"))
.stream().map(Object::toString).collect(Collectors.toList());
for (String rule : rules) {
String[] split = rule.split("=>");
if (split.length > 0) {
String[] split = rule.split("->");
if (split.length > 1) {
String leftSide = split[0];
String rightSide = split[1];
if (modelsMapping.containsKey(leftSide) && modelsMapping.containsKey(rightSide)) {
Expand Down

0 comments on commit 5ee866d

Please sign in to comment.