use of org.hisp.dhis.feedback.ErrorCode in project dhis2-core by dhis2.
the class ImportConflict method createConflict.
public static ImportConflict createConflict(I18n i18n, Function<Class<? extends IdentifiableObject>, String> singularNameForType, int index, ImportConflictDescriptor descriptor, String... objects) {
Class<?>[] objectTypes = descriptor.getObjectTypes();
Map<String, String> objectsMap = new LinkedHashMap<>();
String property = descriptor.getProperty();
for (int i = 0; i < objectTypes.length; i++) {
Class<?> objectType = objectTypes[i];
String object = objects[i];
if (objectType == I18n.class) {
if (property != null) {
objectsMap.putIfAbsent(property, object);
}
objects[i] = i18n.getString(object);
} else if (IdentifiableObject.class.isAssignableFrom(objectType)) {
@SuppressWarnings("unchecked") Class<? extends IdentifiableObject> type = (Class<? extends IdentifiableObject>) objectType;
objectsMap.put(singularNameForType.apply(type), object);
} else if (property != null) {
objectsMap.put(property, object);
}
}
ErrorCode errorCode = descriptor.getErrorCode();
String message = MessageFormat.format(errorCode.getMessage(), (Object[]) objects);
return new ImportConflict(objectsMap, message, errorCode, property, index);
}
Aggregations