Search in sources :

Example 36 with ObjectReport

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

the class TranslationsCheck method run.

private <T extends IdentifiableObject> void run(IdentifiableObject object, Class<T> klass, Consumer<ObjectReport> addReports, Schema schema, int index) {
    Set<Translation> translations = object.getTranslations();
    if (CollectionUtils.isEmpty(translations)) {
        return;
    }
    ObjectReport objectReport = new ObjectReport(klass, index);
    if (!schema.isTranslatable()) {
        objectReport.addErrorReport(new ErrorReport(Translation.class, ErrorCode.E1107, klass.getSimpleName()).setErrorKlass(klass));
        addReports.accept(objectReport);
        return;
    }
    Set<String> setPropertyLocales = new HashSet<>();
    for (Translation translation : translations) {
        String key = String.join("_", translation.getProperty(), translation.getLocale());
        if (setPropertyLocales.contains(key)) {
            objectReport.addErrorReport(new ErrorReport(Translation.class, ErrorCode.E1106, translation.getProperty(), translation.getLocale()).setErrorKlass(klass));
        } else {
            setPropertyLocales.add(key);
        }
        if (translation.getLocale() == null) {
            objectReport.addErrorReport(new ErrorReport(Translation.class, ErrorCode.E4000, "locale").setErrorKlass(klass));
        }
        if (translation.getProperty() == null) {
            objectReport.addErrorReport(new ErrorReport(Translation.class, ErrorCode.E4000, "property").setErrorKlass(klass));
        }
        if (translation.getValue() == null) {
            objectReport.addErrorReport(new ErrorReport(Translation.class, ErrorCode.E4000, "value").setErrorKlass(klass));
        }
    }
    if (objectReport.hasErrorReports()) {
        addReports.accept(objectReport);
    }
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) Translation(org.hisp.dhis.translation.Translation) ObjectReport(org.hisp.dhis.feedback.ObjectReport) HashSet(java.util.HashSet)

Example 37 with ObjectReport

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

the class WebMessageUtils method typeReport.

public static TypeReport typeReport(Class clazz, List<ErrorReport> errorReports) {
    ObjectReport objectReport = new ObjectReport(clazz, 0);
    objectReport.addErrorReports(errorReports);
    TypeReport typeReport = new TypeReport(clazz);
    typeReport.addObjectReport(objectReport);
    return typeReport;
}
Also used : TypeReport(org.hisp.dhis.feedback.TypeReport) ObjectReport(org.hisp.dhis.feedback.ObjectReport)

Example 38 with ObjectReport

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

the class GeoJsonAttributesCheckTest method testValidPolygon.

@Test
public void testValidPolygon() {
    organisationUnit.getAttributeValues().add(new AttributeValue(attribute, " {\n" + "         \"type\": \"Polygon\",\n" + "         \"coordinates\": [\n" + "             [\n" + "                 [100.0, 0.0],\n" + "                 [101.0, 0.0],\n" + "                 [101.0, 1.0],\n" + "                 [100.0, 1.0],\n" + "                 [100.0, 0.0]\n" + "             ]\n" + "         ]\n" + "     }"));
    List<ObjectReport> objectReportList = new ArrayList<>();
    geoJsonAttributesCheck.check(objectBundle, OrganisationUnit.class, Lists.newArrayList(organisationUnit), Collections.emptyList(), ImportStrategy.CREATE_AND_UPDATE, validationContext, objectReport -> objectReportList.add(objectReport));
    assertTrue(CollectionUtils.isEmpty(objectReportList));
}
Also used : AttributeValue(org.hisp.dhis.attribute.AttributeValue) ArrayList(java.util.ArrayList) ObjectReport(org.hisp.dhis.feedback.ObjectReport) Test(org.junit.jupiter.api.Test)

Example 39 with ObjectReport

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

the class GeoJsonAttributesCheckTest method testInValidPolygonType.

@Test
public void testInValidPolygonType() {
    organisationUnit.getAttributeValues().add(new AttributeValue(attribute, " {\n" + "         \"type\": \"PolygonNew\"     }"));
    List<ObjectReport> objectReportList = new ArrayList<>();
    geoJsonAttributesCheck.check(objectBundle, OrganisationUnit.class, Lists.newArrayList(organisationUnit), Collections.emptyList(), ImportStrategy.CREATE_AND_UPDATE, validationContext, objectReport -> objectReportList.add(objectReport));
    assertFalse(CollectionUtils.isEmpty(objectReportList));
    assertEquals(ErrorCode.E6004, objectReportList.get(0).getErrorReports().get(0).getErrorCode());
}
Also used : AttributeValue(org.hisp.dhis.attribute.AttributeValue) ArrayList(java.util.ArrayList) ObjectReport(org.hisp.dhis.feedback.ObjectReport) Test(org.junit.jupiter.api.Test)

Example 40 with ObjectReport

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

the class GeoJsonAttributesCheckTest method testInvalidPolygonCoordinatesValue.

@Test
public void testInvalidPolygonCoordinatesValue() {
    organisationUnit.getAttributeValues().add(new AttributeValue(attribute, " {" + "         \"type\": \"Polygon\"," + "         \"coordinates\": [100.0, 0.0]" + "     }"));
    List<ObjectReport> objectReportList = new ArrayList<>();
    geoJsonAttributesCheck.check(objectBundle, OrganisationUnit.class, Lists.newArrayList(organisationUnit), Collections.emptyList(), ImportStrategy.CREATE_AND_UPDATE, validationContext, objectReport -> objectReportList.add(objectReport));
    assertFalse(CollectionUtils.isEmpty(objectReportList));
    assertEquals(ErrorCode.E6004, objectReportList.get(0).getErrorReports().get(0).getErrorCode());
}
Also used : AttributeValue(org.hisp.dhis.attribute.AttributeValue) ArrayList(java.util.ArrayList) ObjectReport(org.hisp.dhis.feedback.ObjectReport) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectReport (org.hisp.dhis.feedback.ObjectReport)46 TypeReport (org.hisp.dhis.feedback.TypeReport)29 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)22 ErrorReport (org.hisp.dhis.feedback.ErrorReport)22 ArrayList (java.util.ArrayList)15 PreheatErrorReport (org.hisp.dhis.preheat.PreheatErrorReport)13 User (org.hisp.dhis.user.User)9 Schema (org.hisp.dhis.schema.Schema)7 List (java.util.List)6 AttributeValue (org.hisp.dhis.attribute.AttributeValue)6 Test (org.junit.jupiter.api.Test)6 IdentifiableObjectManager (org.hisp.dhis.common.IdentifiableObjectManager)5 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)5 SchemaService (org.hisp.dhis.schema.SchemaService)5 Service (org.springframework.stereotype.Service)5 HashMap (java.util.HashMap)4 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)4 WebMessage (org.hisp.dhis.dxf2.webmessage.WebMessage)4 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3