Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSW Harvester / Avoid increment 2 metrics for a single metadata in certain conditions #8069

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//=============================================================================
//=== Copyright (C) 2001-2007 Food and Agriculture Organization of the
//=== Copyright (C) 2001-2024 Food and Agriculture Organization of the
//=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
//=== and United Nations Environment Programme (UNEP)
//===
Expand Down Expand Up @@ -232,7 +232,7 @@ private void insertOrUpdate(Collection<RecordInfo> records, Collection<HarvestEr
}

result.totalMetadata++;
} catch (Throwable t) {
} catch (Exception t) {
errors.add(new HarvestError(this.context, t));
log.error("Unable to process record from csw (" + this.params.getName() + ")");
log.error(" Record failed: " + ri.uuid + ". Error is: " + t.getMessage());
Expand Down Expand Up @@ -285,7 +285,6 @@ private void addMetadata(RecordInfo ri, String uuidToAssign) throws Exception {
Element md = retrieveMetadata(ri.uuid);

if (md == null) {
result.unretrievable++;
return;
}

Expand Down Expand Up @@ -399,7 +398,7 @@ public static void applyBatchEdits(
if (StringUtils.isNotEmpty(batchEditParameter.getCondition())) {
applyEdit = false;
final Object node = Xml.selectSingle(md, batchEditParameter.getCondition(), metadataSchema.getNamespaces());
if (node != null && node instanceof Boolean && (Boolean)node == true) {
if (node instanceof Boolean && Boolean.TRUE.equals(node)) {
applyEdit = true;
}
}
Expand All @@ -419,7 +418,7 @@ public static void applyBatchEdits(
}
}
}
private void updateMetadata(RecordInfo ri, String id, Boolean force) throws Exception {
private void updateMetadata(RecordInfo ri, String id, boolean force) throws Exception {
String date = localUuids.getChangeDate(ri.uuid);

if (date == null && !force) {
Expand All @@ -438,11 +437,10 @@ private void updateMetadata(RecordInfo ri, String id, Boolean force) throws Exce
}
}
@Transactional(value = TxType.REQUIRES_NEW)
boolean updatingLocalMetadata(RecordInfo ri, String id, Boolean force) throws Exception {
boolean updatingLocalMetadata(RecordInfo ri, String id, boolean force) throws Exception {
Element md = retrieveMetadata(ri.uuid);

if (md == null) {
result.unchangedMetadata++;
return false;
}

Expand Down Expand Up @@ -495,8 +493,11 @@ boolean updatingLocalMetadata(RecordInfo ri, String id, Boolean force) throws Ex
}

/**
* Does CSW GetRecordById request. If validation is requested and the metadata does not
* validate, null is returned.
* Does CSW GetRecordById request. Returns null on error conditions:
* - If validation is requested and the metadata does not validate.
* - No metadata is retrieved.
* - If metadata resource is duplicated.
* - An exception occurs retrieving the metadata.
*
* @param uuid uuid of metadata to request
* @return metadata the metadata
Expand All @@ -519,6 +520,7 @@ private Element retrieveMetadata(String uuid) {
//--- maybe the metadata has been removed

if (list.isEmpty()) {
result.unretrievable++;
return null;
}

Expand All @@ -539,11 +541,10 @@ private Element retrieveMetadata(String uuid) {
return null;
}

if (params.rejectDuplicateResource) {
if (foundDuplicateForResource(uuid, response)) {
if (params.rejectDuplicateResource && (foundDuplicateForResource(uuid, response))) {
result.unchangedMetadata++;
return null;
}

}

return response;
Expand Down Expand Up @@ -607,7 +608,7 @@ private boolean foundDuplicateForResource(String uuid, Element response) {
}
}
}
} catch (Throwable e) {
} catch (Exception e) {
log.warning(" - Error when searching for resource duplicate " + uuid + ". Error is: " + e.getMessage());
}
}
Expand Down
Loading