This commit is contained in:
Michele Artini 2024-01-19 15:59:04 +01:00
parent 821f038fe1
commit cea27b4612
3 changed files with 31 additions and 23 deletions

View File

@ -1,4 +1,4 @@
<h1 mat-dialog-title>Process {{wf.processId}} - {{wf.status}
<h1 mat-dialog-title>Process {{wf.processId}}
<span class="badge-label" [ngClass]="{
'badge-success' : wf.status === 'success',
'badge-failure' : wf.status === 'failure',

View File

@ -10,6 +10,8 @@ import java.util.Queue;
import java.util.concurrent.PriorityBlockingQueue;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Node;
@ -34,6 +36,8 @@ class OaiIterator implements Iterator<String> {
private String token;
private boolean started;
private static final Log log = LogFactory.getLog(OaiIterator.class);
public OaiIterator(final String baseUrl,
final String mdFormat,
final String set,
@ -44,14 +48,14 @@ class OaiIterator implements Iterator<String> {
this.set = set;
this.fromDate = fromDate;
this.untilDate = untilDate;
started = false;
this.started = false;
}
private void verifyStarted() {
if (!started) {
started = true;
if (!this.started) {
this.started = true;
try {
token = firstPage();
this.token = firstPage();
} catch (final CollectorException e) {
throw new RuntimeException(e);
}
@ -60,20 +64,20 @@ class OaiIterator implements Iterator<String> {
@Override
public boolean hasNext() {
synchronized (queue) {
synchronized (this.queue) {
verifyStarted();
return !queue.isEmpty();
return !this.queue.isEmpty();
}
}
@Override
public String next() {
synchronized (queue) {
synchronized (this.queue) {
verifyStarted();
final String res = queue.poll();
while (queue.isEmpty() && (token != null) && !token.isEmpty()) {
final String res = this.queue.poll();
while (this.queue.isEmpty() && (this.token != null) && !this.token.isEmpty()) {
try {
token = otherPages(token);
this.token = otherPages(this.token);
} catch (final CollectorException e) {
throw new RuntimeException(e);
}
@ -87,24 +91,24 @@ class OaiIterator implements Iterator<String> {
private String firstPage() throws CollectorException {
final StringBuilder url = new StringBuilder()
.append(baseUrl)
.append(this.baseUrl)
.append("?verb=ListRecords&metadataPrefix=")
.append(URLEncoder.encode(mdFormat, StandardCharsets.UTF_8));
.append(URLEncoder.encode(this.mdFormat, StandardCharsets.UTF_8));
if (StringUtils.isNotBlank(set)) {
url.append("&set=").append(URLEncoder.encode(set, StandardCharsets.UTF_8));
if (StringUtils.isNotBlank(this.set)) {
url.append("&set=").append(URLEncoder.encode(this.set, StandardCharsets.UTF_8));
}
if (fromDate != null) {
url.append("&from=").append(URLEncoder.encode(fromDate.format(oaiDateFormatter), StandardCharsets.UTF_8));
if (this.fromDate != null) {
url.append("&from=").append(URLEncoder.encode(this.fromDate.format(oaiDateFormatter), StandardCharsets.UTF_8));
}
if (untilDate != null) {
url.append("&until=").append(URLEncoder.encode(untilDate.format(oaiDateFormatter), StandardCharsets.UTF_8));
if (this.untilDate != null) {
url.append("&until=").append(URLEncoder.encode(this.untilDate.format(oaiDateFormatter), StandardCharsets.UTF_8));
}
return downloadPage(url.toString());
}
private String otherPages(final String resumptionToken) throws CollectorException {
return downloadPage(baseUrl + "?verb=ListRecords&resumptionToken=" + URLEncoder.encode(resumptionToken, StandardCharsets.UTF_8));
return downloadPage(this.baseUrl + "?verb=ListRecords&resumptionToken=" + URLEncoder.encode(resumptionToken, StandardCharsets.UTF_8));
}
private String extractResumptionToken(final String xml) {
@ -119,14 +123,17 @@ class OaiIterator implements Iterator<String> {
}
private String downloadPage(final String url) throws CollectorException {
log.debug("Invoking url: " + url);
final String xml = new RestTemplate().getForObject(url, String.class);
Document doc;
try {
doc = reader.read(new StringReader(xml));
doc = this.reader.read(new StringReader(xml));
} catch (final DocumentException e) {
final String cleaned = XmlCleaner.cleanAllEntities(xml);
try {
doc = reader.read(new StringReader(cleaned));
doc = this.reader.read(new StringReader(cleaned));
} catch (final DocumentException e1) {
final String resumptionToken = extractResumptionToken(xml);
if (resumptionToken == null) { throw new CollectorException("Error parsing cleaned document:" + cleaned, e1); }
@ -142,7 +149,7 @@ class OaiIterator implements Iterator<String> {
}
for (final Object o : doc.selectNodes("//*[local-name()='ListRecords']/*[local-name()='record']")) {
queue.add(((Node) o).asXML());
this.queue.add(((Node) o).asXML());
}
return doc.valueOf("//*[local-name()='resumptionToken']");

View File

@ -264,6 +264,7 @@ public abstract class ProcessNode implements BeanNameAware {
}
protected void updateProgressMessage(final String message) {
log.debug("* PROGRESS MESSAGE: " + message);
this.graphNode.setProgressMessage(message);
this.engine.updateRunningJob(this.process);
}