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);
}
}
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;
}
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));
}
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());
}
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());
}
Aggregations