use of org.hisp.dhis.feedback.ObjectReport in project dhis2-core by dhis2.
the class ReferencesCheck method check.
@Override
public <T extends IdentifiableObject> TypeReport check(ObjectBundle bundle, Class<T> klass, List<T> persistedObjects, List<T> nonPersistedObjects, ImportStrategy importStrategy, ValidationContext ctx) {
if (persistedObjects.isEmpty() && nonPersistedObjects.isEmpty()) {
return TypeReport.empty(klass);
}
TypeReport typeReport = new TypeReport(klass);
for (IdentifiableObject object : joinObjects(persistedObjects, nonPersistedObjects)) {
List<PreheatErrorReport> errorReports = checkReferences(object, bundle.getPreheat(), bundle.getPreheatIdentifier(), bundle.isSkipSharing(), ctx);
if (!errorReports.isEmpty() && object != null) {
ObjectReport objectReport = new ObjectReport(object, bundle);
objectReport.addErrorReports(errorReports);
typeReport.addObjectReport(objectReport);
}
}
if (typeReport.hasErrorReports() && AtomicMode.ALL == bundle.getAtomicMode()) {
typeReport.getStats().incIgnored();
}
return typeReport;
}
use of org.hisp.dhis.feedback.ObjectReport in project dhis2-core by dhis2.
the class DefaultObjectBundleService method handleUpdates.
private <T extends IdentifiableObject> TypeReport handleUpdates(Session session, Class<T> klass, List<T> 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.hasJobId()) {
notifier.notify(bundle.getJobId(), message);
}
objects.forEach(object -> {
T persistedObject = bundle.getPreheat().get(bundle.getPreheatIdentifier(), object);
objectBundleHooks.getObjectHooks(object).forEach(hook -> hook.preUpdate(object, persistedObject, bundle));
});
session.flush();
for (T object : objects) {
T persistedObject = bundle.getPreheat().get(bundle.getPreheatIdentifier(), object);
ObjectReport objectReport = new ObjectReport(object, bundle);
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()).setSkipTranslation(bundle.isSkipTranslation()));
}
if (bundle.getOverrideUser() != null) {
persistedObject.setCreatedBy(bundle.getOverrideUser());
if (object instanceof User) {
(object).setCreatedBy(bundle.getOverrideUser());
}
}
session.update(persistedObject);
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();
}
}
session.flush();
objects.forEach(object -> {
T persistedObject = bundle.getPreheat().get(bundle.getPreheatIdentifier(), object);
objectBundleHooks.getObjectHooks(object).forEach(hook -> hook.postUpdate(persistedObject, bundle));
});
return typeReport;
}
use of org.hisp.dhis.feedback.ObjectReport in project dhis2-core by dhis2.
the class DefaultObjectBundleService method handleCreates.
// -----------------------------------------------------------------------------------
// Utility Methods
// -----------------------------------------------------------------------------------
private <T extends IdentifiableObject> TypeReport handleCreates(Session session, Class<T> klass, List<T> objects, ObjectBundle bundle) {
TypeReport typeReport = new TypeReport(klass);
handleDeprecationIfEventReport(klass, objects);
if (objects.isEmpty()) {
return typeReport;
}
String message = "(" + bundle.getUsername() + ") Creating " + objects.size() + " object(s) of type " + objects.get(0).getClass().getSimpleName();
log.info(message);
if (bundle.hasJobId()) {
notifier.notify(bundle.getJobId(), message);
}
objects.forEach(object -> objectBundleHooks.getObjectHooks(object).forEach(hook -> hook.preCreate(object, bundle)));
session.flush();
for (T object : objects) {
ObjectReport objectReport = new ObjectReport(object, bundle);
objectReport.setDisplayName(IdentifiableObjectUtils.getDisplayName(object));
typeReport.addObjectReport(objectReport);
preheatService.connectReferences(object, bundle.getPreheat(), bundle.getPreheatIdentifier());
if (bundle.getOverrideUser() != null) {
object.setCreatedBy(bundle.getOverrideUser());
if (object instanceof User) {
(object).setCreatedBy(bundle.getOverrideUser());
}
}
session.save(object);
bundle.getPreheat().replace(bundle.getPreheatIdentifier(), object);
if (log.isDebugEnabled()) {
String msg = "(" + bundle.getUsername() + ") Created object '" + bundle.getPreheatIdentifier().getIdentifiersWithName(object) + "'";
log.debug(msg);
}
if (FlushMode.OBJECT == bundle.getFlushMode()) {
session.flush();
}
}
session.flush();
objects.forEach(object -> objectBundleHooks.getObjectHooks(object).forEach(hook -> hook.postCreate(object, bundle)));
return typeReport;
}
use of org.hisp.dhis.feedback.ObjectReport in project dhis2-core by dhis2.
the class UniqueMultiPropertiesCheck method check.
@Override
public <T extends IdentifiableObject> void check(ObjectBundle bundle, Class<T> klass, List<T> persistedObjects, List<T> nonPersistedObjects, ImportStrategy importStrategy, ValidationContext context, Consumer<ObjectReport> addReports) {
Schema schema = context.getSchemaService().getSchema(klass);
Map<List<String>, List<IdentifiableObject>> propertyValuesToObjects = new HashMap<>();
for (T identifiableObject : nonPersistedObjects) {
for (Map.Entry<Collection<String>, Collection<Function<IdentifiableObject, String>>> entry : schema.getUniqueMultiPropertiesExctractors().entrySet()) {
List<String> propertyValues = entry.getValue().stream().map(valueExtractor -> valueExtractor.apply(identifiableObject)).collect(Collectors.toList());
propertyValuesToObjects.computeIfAbsent(propertyValues, key -> new ArrayList<>()).add(identifiableObject);
}
}
for (Map.Entry<List<String>, List<IdentifiableObject>> entry : propertyValuesToObjects.entrySet()) {
List<IdentifiableObject> objects = entry.getValue();
if (objects.size() > 1) {
for (IdentifiableObject object : objects) {
ErrorReport errorReport = new ErrorReport(klass, E5005, String.join(", ", entry.getKey()), objects.stream().map(IdentifiableObject::getUid).collect(joining(", ")));
addReports.accept(ValidationUtils.createObjectReport(errorReport, object, bundle));
context.markForRemoval(object);
}
}
}
}
use of org.hisp.dhis.feedback.ObjectReport in project dhis2-core by dhis2.
the class ValidationUtils method createObjectReport.
public static ObjectReport createObjectReport(List<ErrorReport> reports, IdentifiableObject object, ObjectBundle bundle) {
ObjectReport objectReport = new ObjectReport(object, bundle);
objectReport.setDisplayName(IdentifiableObjectUtils.getDisplayName(object));
objectReport.addErrorReports(reports);
return objectReport;
}
Aggregations