Skip to content

Commit

Permalink
implement deepMode in MapConverterValueEnhancer
Browse files Browse the repository at this point in the history
  • Loading branch information
floriangantner committed Feb 20, 2024
1 parent 9c46991 commit 5ab97e4
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public boolean canEnhance(Context context, Item item) {
}

@Override
public void enhance(Context context, Item item) {
public boolean enhance(Context context, Item item, boolean deepMode) {
try {
if (StringUtils.isBlank(sourceItemMetadataField) || Objects.isNull(converter) ||
StringUtils.isBlank(targetItemMetadataField)) {
return;
return false;
}
String sourceval;
String targetval;
Expand All @@ -78,18 +78,28 @@ public void enhance(Context context, Item item) {
// replace mdv if it's different
removeTargetMetadata(context, item);
addTargetMetadata(context, item, calculatedval);
return true;
} else if (StringUtils.isBlank(targetval)) {
// set new value
addTargetMetadata(context, item, calculatedval);
return true;
} else if (StringUtils.isNotBlank(sourceval) && StringUtils.isNotBlank(targetval)
&& sourceval.contentEquals(targetval) && deepMode) {
//When both values are equal and deepMode is active, recalculate the value
removeTargetMetadata(context, item);
addTargetMetadata(context, item, calculatedval);
return true;
}
} else if (StringUtils.isBlank(sourceval) && StringUtils.isNotBlank(targetval)) {
// remove value
removeTargetMetadata(context, item);
return true;
}
} catch (Exception e) {
LOGGER.error("An error occurs enhancing item with id {}: {}", item.getID(), e.getMessage(), e);
//throw new SQLRuntimeException(e);
}
return false;
}
private void addTargetMetadata(Context context, Item item, String value) throws Exception {
MetadataField targetmd = metadatafieldService.findByString(context, targetItemMetadataField, '.');
Expand Down

0 comments on commit 5ab97e4

Please sign in to comment.