use of org.devgateway.ocds.persistence.mongo.merge.MergeStrategy in project ocvn by devgateway.
the class ReleaseCompilerService method mergeFieldFromOcdsBeans.
/**
* Computes the output of an atomic merging operation on a specific field
*
* @param field the field to perform the merge on
* @param leftBean the left bean
* @param rightBean the right bean
* @return the merged result
* @throws IllegalAccessException
* @throws InvocationTargetException
* @throws NoSuchMethodException
*/
protected <S> Object mergeFieldFromOcdsBeans(final Field field, final S leftBean, final S rightBean) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
Object rightFieldValue = PropertyUtils.getProperty(rightBean, field.getName());
Object leftFieldValue = PropertyUtils.getProperty(leftBean, field.getName());
if (fieldsAnnotatedWithMerge.contains(field)) {
MergeStrategy mergeStrategy = field.getDeclaredAnnotation(Merge.class).value();
switch(mergeStrategy) {
case overwrite:
return mergeFieldStrategyOverwrite(leftFieldValue, rightFieldValue);
case ocdsOmit:
return mergeFieldStrategyOcdsOmit(leftFieldValue, rightFieldValue);
case ocdsVersion:
return mergeFieldStrategyOcdsVersion(leftFieldValue, rightFieldValue);
case arrayMergeById:
return mergeFieldStrategyArrayMergeById((Collection<Identifiable>) leftFieldValue, (Collection<Identifiable>) rightFieldValue);
default:
throw new RuntimeException("Unknown or unimplemented merge strategy!");
}
} else {
// recursively invoke the method on the field value
return mergeOcdsBeans(leftFieldValue, rightFieldValue);
}
}
use of org.devgateway.ocds.persistence.mongo.merge.MergeStrategy in project oc-explorer by devgateway.
the class ReleaseCompilerService method mergeFieldFromOcdsBeans.
/**
* Computes the output of an atomic merging operation on a specific field
*
* @param field the field to perform the merge on
* @param leftBean the left bean
* @param rightBean the right bean
* @return the merged result
* @throws IllegalAccessException
* @throws InvocationTargetException
* @throws NoSuchMethodException
*/
protected <S> Object mergeFieldFromOcdsBeans(final Field field, final S leftBean, final S rightBean) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
Object rightFieldValue = PropertyUtils.getProperty(rightBean, field.getName());
Object leftFieldValue = PropertyUtils.getProperty(leftBean, field.getName());
if (fieldsAnnotatedWithMerge.contains(field)) {
MergeStrategy mergeStrategy = field.getDeclaredAnnotation(Merge.class).value();
switch(mergeStrategy) {
case overwrite:
return mergeFieldStrategyOverwrite(leftFieldValue, rightFieldValue);
case ocdsOmit:
return mergeFieldStrategyOcdsOmit(leftFieldValue, rightFieldValue);
case ocdsVersion:
return mergeFieldStrategyOcdsVersion(leftFieldValue, rightFieldValue);
case arrayMergeById:
return mergeFieldStrategyArrayMergeById((Collection<Identifiable>) leftFieldValue, (Collection<Identifiable>) rightFieldValue);
default:
throw new RuntimeException("Unknown or unimplemented merge strategy!");
}
} else {
// recursively invoke the method on the field value
return mergeOcdsBeans(leftFieldValue, rightFieldValue);
}
}
Aggregations