use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.
the class DefaultObjectBundleValidationService method checkUniqueAttributes.
private TypeReport checkUniqueAttributes(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 = checkUniqueAttributes(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.common.IdentifiableObject in project dhis2-core by dhis2.
the class DefaultObjectBundleValidationService method runValidationHooks.
private TypeReport runValidationHooks(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> errorReports = new ArrayList<>();
objectBundleHooks.forEach(hook -> errorReports.addAll(hook.validate(object, bundle)));
if (!errorReports.isEmpty()) {
ObjectReport objectReport = new ObjectReport(klass, idx, object.getUid());
objectReport.setDisplayName(IdentifiableObjectUtils.getDisplayName(object));
objectReport.addErrorReports(errorReports);
typeReport.addObjectReport(objectReport);
typeReport.getStats().incIgnored();
iterator.remove();
continue;
}
idx++;
}
return typeReport;
}
use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.
the class DefaultObjectBundleValidationService method validateForCreate.
private TypeReport validateForCreate(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) {
ObjectReport objectReport = new ObjectReport(klass, idx, object.getUid());
objectReport.setDisplayName(IdentifiableObjectUtils.getDisplayName(object));
objectReport.addErrorReport(new ErrorReport(klass, ErrorCode.E5000, bundle.getPreheatIdentifier(), bundle.getPreheatIdentifier().getIdentifiersWithName(identifiableObject)).setMainId(identifiableObject.getUid()));
typeReport.addObjectReport(objectReport);
typeReport.getStats().incIgnored();
iterator.remove();
}
idx++;
}
return typeReport;
}
use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.
the class EmbeddedObjectObjectBundleHook method handleEmbeddedObjects.
private <T extends IdentifiableObject> void handleEmbeddedObjects(T object, ObjectBundle bundle, Collection<Property> properties) {
for (Property property : properties) {
if (property.isCollection()) {
Collection<?> objects = ReflectionUtils.invokeMethod(object, property.getGetterMethod());
objects.forEach(o -> {
if (property.isIdentifiableObject()) {
((BaseIdentifiableObject) o).setAutoFields();
}
preheatService.connectReferences(o, bundle.getPreheat(), bundle.getPreheatIdentifier());
});
} else {
Object o = ReflectionUtils.invokeMethod(object, property.getGetterMethod());
if (property.isIdentifiableObject()) {
((BaseIdentifiableObject) o).setAutoFields();
}
preheatService.connectReferences(o, bundle.getPreheat(), bundle.getPreheatIdentifier());
}
}
}
use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.
the class OrganisationUnitObjectBundleHook method sortOrganisationUnits.
private void sortOrganisationUnits(ObjectBundle bundle) {
List<IdentifiableObject> nonPersistedObjects = bundle.getObjects(OrganisationUnit.class, false);
List<IdentifiableObject> persistedObjects = bundle.getObjects(OrganisationUnit.class, true);
nonPersistedObjects.sort(new OrganisationUnitParentCountComparator());
persistedObjects.sort(new OrganisationUnitParentCountComparator());
}
Aggregations