Search in sources :

Example 1 with ErrorCode

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);
}
Also used : IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) ErrorCode(org.hisp.dhis.feedback.ErrorCode) LinkedHashMap(java.util.LinkedHashMap) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 ErrorCode (org.hisp.dhis.feedback.ErrorCode)1