use of org.hisp.dhis.feedback.ObjectReport 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;
}
use of org.hisp.dhis.feedback.ObjectReport 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;
}
use of org.hisp.dhis.feedback.ObjectReport 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;
}
use of org.hisp.dhis.feedback.ObjectReport 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;
}
use of org.hisp.dhis.feedback.ObjectReport in project dhis2-core by dhis2.
the class DefaultObjectBundleValidationService method checkReferences.
private TypeReport checkReferences(Class<? extends IdentifiableObject> klass, List<IdentifiableObject> objects, Preheat preheat, PreheatIdentifier identifier, boolean skipSharing) {
TypeReport typeReport = new TypeReport(klass);
if (objects.isEmpty()) {
return typeReport;
}
for (int idx = 0; idx < objects.size(); idx++) {
IdentifiableObject object = objects.get(idx);
List<PreheatErrorReport> errorReports = checkReferences(object, preheat, identifier, skipSharing);
if (errorReports.isEmpty())
continue;
ObjectReport objectReport = new ObjectReport(object.getClass(), idx);
objectReport.addErrorReports(errorReports);
typeReport.addObjectReport(objectReport);
}
return typeReport;
}
Aggregations