use of org.hisp.dhis.feedback.TypeReport in project dhis2-core by dhis2.
the class DefaultObjectBundleService method handleUpdates.
private TypeReport handleUpdates(Session session, Class<? extends IdentifiableObject> klass, List<IdentifiableObject> objects, ObjectBundle bundle) {
TypeReport typeReport = new TypeReport(klass);
if (objects.isEmpty()) {
return typeReport;
}
String message = "(" + bundle.getUsername() + ") Updating " + objects.size() + " object(s) of type " + objects.get(0).getClass().getSimpleName();
log.info(message);
if (bundle.hasTaskId()) {
notifier.notify(bundle.getTaskId(), message);
}
objects.forEach(object -> {
IdentifiableObject persistedObject = bundle.getPreheat().get(bundle.getPreheatIdentifier(), object);
objectBundleHooks.forEach(hook -> hook.preUpdate(object, persistedObject, bundle));
});
for (int idx = 0; idx < objects.size(); idx++) {
IdentifiableObject object = objects.get(idx);
IdentifiableObject persistedObject = bundle.getPreheat().get(bundle.getPreheatIdentifier(), object);
if (Preheat.isDefault(object))
continue;
ObjectReport objectReport = new ObjectReport(klass, idx, object.getUid());
objectReport.setDisplayName(IdentifiableObjectUtils.getDisplayName(object));
typeReport.addObjectReport(objectReport);
preheatService.connectReferences(object, bundle.getPreheat(), bundle.getPreheatIdentifier());
if (bundle.getMergeMode() != MergeMode.NONE) {
mergeService.merge(new MergeParams<>(object, persistedObject).setMergeMode(bundle.getMergeMode()).setSkipSharing(bundle.isSkipSharing()));
}
session.update(persistedObject);
if (MetadataObject.class.isInstance(object)) {
deletedObjectService.deleteDeletedObjects(new DeletedObjectQuery(object));
}
objectBundleHooks.forEach(hook -> hook.postUpdate(persistedObject, bundle));
bundle.getPreheat().replace(bundle.getPreheatIdentifier(), persistedObject);
if (log.isDebugEnabled()) {
String msg = "(" + bundle.getUsername() + ") Updated object '" + bundle.getPreheatIdentifier().getIdentifiersWithName(persistedObject) + "'";
log.debug(msg);
}
if (FlushMode.OBJECT == bundle.getFlushMode())
session.flush();
}
return typeReport;
}
use of org.hisp.dhis.feedback.TypeReport in project dhis2-core by dhis2.
the class DefaultObjectBundleValidationService method checkDuplicateIds.
private TypeReport checkDuplicateIds(Class<? extends IdentifiableObject> klass, List<IdentifiableObject> persistedObjects, List<IdentifiableObject> nonPersistedObjects, Preheat preheat, PreheatIdentifier identifier) {
TypeReport typeReport = new TypeReport(klass);
if (persistedObjects.isEmpty() && nonPersistedObjects.isEmpty()) {
return typeReport;
}
Map<Class<?>, String> idMap = new HashMap<>();
Iterator<IdentifiableObject> iterator = persistedObjects.iterator();
int idx = 0;
while (iterator.hasNext()) {
IdentifiableObject object = iterator.next();
if (idMap.containsKey(object.getClass()) && idMap.get(object.getClass()).equals(object.getUid())) {
ErrorReport errorReport = new ErrorReport(object.getClass(), ErrorCode.E5004, object.getUid(), object.getClass()).setMainId(object.getUid()).setErrorProperty("id");
ObjectReport objectReport = new ObjectReport(object.getClass(), idx);
objectReport.setDisplayName(IdentifiableObjectUtils.getDisplayName(object));
objectReport.addErrorReport(errorReport);
typeReport.addObjectReport(objectReport);
typeReport.getStats().incIgnored();
iterator.remove();
} else {
idMap.put(object.getClass(), object.getUid());
}
idx++;
}
iterator = nonPersistedObjects.iterator();
idx = 0;
while (iterator.hasNext()) {
IdentifiableObject object = iterator.next();
if (idMap.containsKey(object.getClass()) && idMap.get(object.getClass()).equals(object.getUid())) {
ErrorReport errorReport = new ErrorReport(object.getClass(), ErrorCode.E5004, object.getUid(), object.getClass()).setMainId(object.getUid()).setErrorProperty("id");
ObjectReport objectReport = new ObjectReport(object.getClass(), idx);
objectReport.setDisplayName(IdentifiableObjectUtils.getDisplayName(object));
objectReport.addErrorReport(errorReport);
typeReport.addObjectReport(objectReport);
typeReport.getStats().incIgnored();
iterator.remove();
} else {
idMap.put(object.getClass(), object.getUid());
}
idx++;
}
return typeReport;
}
use of org.hisp.dhis.feedback.TypeReport 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.TypeReport in project dhis2-core by dhis2.
the class ObjectBundleCommitReport method addTypeReport.
public void addTypeReport(TypeReport report) {
if (report == null) {
return;
}
if (!typeReportMap.containsKey(report.getKlass())) {
typeReportMap.put(report.getKlass(), report);
return;
}
TypeReport typeReport = typeReportMap.get(report.getKlass());
typeReport.merge(typeReport);
}
use of org.hisp.dhis.feedback.TypeReport 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;
}
Aggregations