use of org.hisp.dhis.feedback.TypeReport in project dhis2-core by dhis2.
the class DefaultObjectBundleValidationService method checkUniqueness.
private TypeReport checkUniqueness(Class<? extends IdentifiableObject> klass, List<IdentifiableObject> objects, Preheat preheat, PreheatIdentifier identifier) {
TypeReport typeReport = new TypeReport(klass);
if (objects.isEmpty()) {
return typeReport;
}
Iterator<IdentifiableObject> iterator = objects.iterator();
int idx = 0;
while (iterator.hasNext()) {
IdentifiableObject object = iterator.next();
List<ErrorReport> errorReports = new ArrayList<>();
if (User.class.isInstance(object)) {
User user = (User) object;
errorReports.addAll(checkUniqueness(User.class, user, preheat, identifier));
errorReports.addAll(checkUniqueness(UserCredentials.class, user.getUserCredentials(), preheat, identifier));
} else {
errorReports = checkUniqueness(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 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.TypeReport in project dhis2-core by dhis2.
the class DefaultCollectionService method addCollectionItems.
@Override
@Transactional
public TypeReport addCollectionItems(IdentifiableObject object, String propertyName, Collection<? extends IdentifiableObject> objects) throws Exception {
Property property = validateUpdate(object, propertyName, "Only identifiable object collections can be added to.");
Collection<String> itemCodes = getItemCodes(objects);
if (itemCodes.isEmpty()) {
return TypeReport.empty(property.getItemKlass());
}
TypeReport report = new TypeReport(property.getItemKlass());
manager.refresh(object);
if (property.isOwner()) {
addOwnedCollectionItems(object, property, itemCodes, report);
} else {
addNonOwnedCollectionItems(object, property, itemCodes, report);
}
dbmsManager.clearSession();
cacheManager.clearCache();
return report;
}
use of org.hisp.dhis.feedback.TypeReport 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.TypeReport 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;
}
Aggregations