use of org.hisp.dhis.feedback.ErrorCode.E5005 in project dhis2-core by dhis2.
the class UniqueMultiPropertiesCheck method check.
@Override
public <T extends IdentifiableObject> void check(ObjectBundle bundle, Class<T> klass, List<T> persistedObjects, List<T> nonPersistedObjects, ImportStrategy importStrategy, ValidationContext context, Consumer<ObjectReport> addReports) {
Schema schema = context.getSchemaService().getSchema(klass);
Map<List<String>, List<IdentifiableObject>> propertyValuesToObjects = new HashMap<>();
for (T identifiableObject : nonPersistedObjects) {
for (Map.Entry<Collection<String>, Collection<Function<IdentifiableObject, String>>> entry : schema.getUniqueMultiPropertiesExctractors().entrySet()) {
List<String> propertyValues = entry.getValue().stream().map(valueExtractor -> valueExtractor.apply(identifiableObject)).collect(Collectors.toList());
propertyValuesToObjects.computeIfAbsent(propertyValues, key -> new ArrayList<>()).add(identifiableObject);
}
}
for (Map.Entry<List<String>, List<IdentifiableObject>> entry : propertyValuesToObjects.entrySet()) {
List<IdentifiableObject> objects = entry.getValue();
if (objects.size() > 1) {
for (IdentifiableObject object : objects) {
ErrorReport errorReport = new ErrorReport(klass, E5005, String.join(", ", entry.getKey()), objects.stream().map(IdentifiableObject::getUid).collect(joining(", ")));
addReports.accept(ValidationUtils.createObjectReport(errorReport, object, bundle));
context.markForRemoval(object);
}
}
}
}
Aggregations