Search in sources :

Example 26 with ErrorReport

use of org.hisp.dhis.feedback.ErrorReport in project dhis2-core by dhis2.

the class DefaultObjectBundleValidationService method checkMandatoryAttributes.

private TypeReport checkMandatoryAttributes(Class<? extends IdentifiableObject> klass, List<IdentifiableObject> objects, Preheat preheat, PreheatIdentifier identifier) {
    TypeReport typeReport = new TypeReport(klass);
    Schema schema = schemaService.getDynamicSchema(klass);
    if (objects.isEmpty() || !schema.havePersistedProperty("attributeValues")) {
        return typeReport;
    }
    Iterator<IdentifiableObject> iterator = objects.iterator();
    int idx = 0;
    while (iterator.hasNext()) {
        IdentifiableObject object = iterator.next();
        List<ErrorReport> errorReports = checkMandatoryAttributes(klass, object, preheat, identifier);
        if (!errorReports.isEmpty()) {
            ObjectReport objectReport = new ObjectReport(object.getClass(), idx);
            objectReport.setDisplayName(IdentifiableObjectUtils.getDisplayName(object));
            objectReport.addErrorReports(errorReports);
            typeReport.addObjectReport(objectReport);
            typeReport.getStats().incIgnored();
            iterator.remove();
        }
        idx++;
    }
    return typeReport;
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) PreheatErrorReport(org.hisp.dhis.preheat.PreheatErrorReport) TypeReport(org.hisp.dhis.feedback.TypeReport) Schema(org.hisp.dhis.schema.Schema) ObjectReport(org.hisp.dhis.feedback.ObjectReport) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 27 with ErrorReport

use of org.hisp.dhis.feedback.ErrorReport in project dhis2-core by dhis2.

the class ObjectBundleValidationReport method getErrorReportsByCode.

//-----------------------------------------------------------------------------------
// Utility Methods
//-----------------------------------------------------------------------------------
public List<ErrorReport> getErrorReportsByCode(Class<?> klass, ErrorCode errorCode) {
    List<ErrorReport> errorReports = new ArrayList<>();
    if (!typeReportMap.containsKey(klass)) {
        return errorReports;
    }
    List<ObjectReport> objectReports = typeReportMap.get(klass).getObjectReports();
    for (ObjectReport objectReport : objectReports) {
        List<ErrorReport> byCode = objectReport.getErrorReportsByCode().get(errorCode);
        if (byCode != null) {
            errorReports.addAll(byCode);
        }
    }
    return errorReports;
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) ArrayList(java.util.ArrayList) ObjectReport(org.hisp.dhis.feedback.ObjectReport)

Example 28 with ErrorReport

use of org.hisp.dhis.feedback.ErrorReport in project dhis2-core by dhis2.

the class DefaultObjectBundleValidationService method validateForUpdate.

private TypeReport validateForUpdate(Class<? extends IdentifiableObject> klass, List<IdentifiableObject> objects, ObjectBundle bundle) {
    TypeReport typeReport = new TypeReport(klass);
    if (objects == null || objects.isEmpty()) {
        return typeReport;
    }
    Iterator<IdentifiableObject> iterator = objects.iterator();
    int idx = 0;
    while (iterator.hasNext()) {
        IdentifiableObject identifiableObject = iterator.next();
        IdentifiableObject object = bundle.getPreheat().get(bundle.getPreheatIdentifier(), identifiableObject);
        if (object == null || object.getId() == 0) {
            if (Preheat.isDefaultClass(identifiableObject.getClass()))
                continue;
            ObjectReport objectReport = new ObjectReport(klass, idx, object != null ? object.getUid() : null);
            objectReport.setDisplayName(IdentifiableObjectUtils.getDisplayName(object));
            objectReport.addErrorReport(new ErrorReport(klass, ErrorCode.E5001, bundle.getPreheatIdentifier(), bundle.getPreheatIdentifier().getIdentifiersWithName(identifiableObject)).setErrorProperty("id").setMainId(identifiableObject.getUid()));
            typeReport.addObjectReport(objectReport);
            typeReport.getStats().incIgnored();
            iterator.remove();
        }
        idx++;
    }
    return typeReport;
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) PreheatErrorReport(org.hisp.dhis.preheat.PreheatErrorReport) TypeReport(org.hisp.dhis.feedback.TypeReport) ObjectReport(org.hisp.dhis.feedback.ObjectReport) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 29 with ErrorReport

use of org.hisp.dhis.feedback.ErrorReport in project dhis2-core by dhis2.

the class DefaultObjectBundleValidationService method validateBySchemas.

private TypeReport validateBySchemas(Class<? extends IdentifiableObject> klass, List<IdentifiableObject> objects, ObjectBundle bundle) {
    TypeReport typeReport = new TypeReport(klass);
    if (objects == null || objects.isEmpty()) {
        return typeReport;
    }
    Iterator<IdentifiableObject> iterator = objects.iterator();
    int idx = 0;
    while (iterator.hasNext()) {
        IdentifiableObject object = iterator.next();
        List<ErrorReport> validationErrorReports = schemaValidator.validate(object);
        if (!validationErrorReports.isEmpty()) {
            ObjectReport objectReport = new ObjectReport(klass, idx, object.getUid());
            objectReport.setDisplayName(IdentifiableObjectUtils.getDisplayName(object));
            objectReport.addErrorReports(validationErrorReports);
            typeReport.addObjectReport(objectReport);
            typeReport.getStats().incIgnored();
            iterator.remove();
        }
        idx++;
    }
    return typeReport;
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) PreheatErrorReport(org.hisp.dhis.preheat.PreheatErrorReport) TypeReport(org.hisp.dhis.feedback.TypeReport) ObjectReport(org.hisp.dhis.feedback.ObjectReport) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 30 with ErrorReport

use of org.hisp.dhis.feedback.ErrorReport in project dhis2-core by dhis2.

the class DefaultObjectBundleValidationService method checkUniqueness.

private TypeReport checkUniqueness(Class<? extends IdentifiableObject> klass, List<IdentifiableObject> objects, Preheat preheat, PreheatIdentifier identifier) {
    TypeReport typeReport = new TypeReport(klass);
    if (objects.isEmpty()) {
        return typeReport;
    }
    Iterator<IdentifiableObject> iterator = objects.iterator();
    int idx = 0;
    while (iterator.hasNext()) {
        IdentifiableObject object = iterator.next();
        List<ErrorReport> errorReports = new ArrayList<>();
        if (User.class.isInstance(object)) {
            User user = (User) object;
            errorReports.addAll(checkUniqueness(User.class, user, preheat, identifier));
            errorReports.addAll(checkUniqueness(UserCredentials.class, user.getUserCredentials(), preheat, identifier));
        } else {
            errorReports = checkUniqueness(klass, object, preheat, identifier);
        }
        if (!errorReports.isEmpty()) {
            ObjectReport objectReport = new ObjectReport(object.getClass(), idx);
            objectReport.setDisplayName(IdentifiableObjectUtils.getDisplayName(object));
            objectReport.addErrorReports(errorReports);
            typeReport.addObjectReport(objectReport);
            typeReport.getStats().incIgnored();
            iterator.remove();
        }
        idx++;
    }
    return typeReport;
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) PreheatErrorReport(org.hisp.dhis.preheat.PreheatErrorReport) User(org.hisp.dhis.user.User) TypeReport(org.hisp.dhis.feedback.TypeReport) ArrayList(java.util.ArrayList) UserCredentials(org.hisp.dhis.user.UserCredentials) ObjectReport(org.hisp.dhis.feedback.ObjectReport) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Aggregations

ErrorReport (org.hisp.dhis.feedback.ErrorReport)30 ObjectReport (org.hisp.dhis.feedback.ObjectReport)17 ArrayList (java.util.ArrayList)15 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)14 PreheatErrorReport (org.hisp.dhis.preheat.PreheatErrorReport)14 TypeReport (org.hisp.dhis.feedback.TypeReport)13 User (org.hisp.dhis.user.User)8 Schema (org.hisp.dhis.schema.Schema)5 List (java.util.List)4 ErrorCode (org.hisp.dhis.feedback.ErrorCode)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 DhisSpringTest (org.hisp.dhis.DhisSpringTest)3 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)3 Test (org.junit.Test)3 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2