Skip to content

Commit

Permalink
CSW Harvester / Avoid increment 2 metrics for a single metadata in ce…
Browse files Browse the repository at this point in the history
…rtain conditions (#8069)

* CSW Harvester / Avoid increment 2 metrics for a single metadata in certain conditions.

Retrieve metadata method increments metrics under certain conditions and returns null. Methods calling the retrieve metadata method increments additionally the unretrievable metric if null is returned. Sonarlint fixeas are already applied. Fixes #8039

* CSW Harvester / Use primitive boolean for 'force' parameter
  • Loading branch information
josegar74 authored Sep 5, 2024
1 parent ee23e54 commit 05b2e43
Showing 1 changed file with 14 additions and 13 deletions.
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 @@ -404,7 +403,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 @@ -424,7 +423,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 @@ -443,11 +442,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 @@ -500,8 +498,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 @@ -524,6 +525,7 @@ private Element retrieveMetadata(String uuid) {
//--- maybe the metadata has been removed

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

Expand All @@ -544,11 +546,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 @@ -612,7 +613,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

0 comments on commit 05b2e43

Please sign in to comment.