Search in sources :

Example 1 with Merge

use of org.devgateway.ocds.persistence.mongo.merge.Merge 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);
    }
}
Also used : Merge(org.devgateway.ocds.persistence.mongo.merge.Merge) MergeStrategy(org.devgateway.ocds.persistence.mongo.merge.MergeStrategy) Identifiable(org.devgateway.ocds.persistence.mongo.Identifiable)

Example 2 with Merge

use of org.devgateway.ocds.persistence.mongo.merge.Merge 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);
    }
}
Also used : Merge(org.devgateway.ocds.persistence.mongo.merge.Merge) MergeStrategy(org.devgateway.ocds.persistence.mongo.merge.MergeStrategy) Identifiable(org.devgateway.ocds.persistence.mongo.Identifiable)

Aggregations

Identifiable (org.devgateway.ocds.persistence.mongo.Identifiable)2 Merge (org.devgateway.ocds.persistence.mongo.merge.Merge)2 MergeStrategy (org.devgateway.ocds.persistence.mongo.merge.MergeStrategy)2