use of org.hisp.dhis.deletedobject.DeletedObjectQuery in project dhis2-core by dhis2.
the class HibernateGenericStore method save.
@Override
public void save(T object, User user, boolean clearSharing) {
String username = user != null ? user.getUsername() : "system-process";
if (IdentifiableObject.class.isAssignableFrom(object.getClass())) {
BaseIdentifiableObject identifiableObject = (BaseIdentifiableObject) object;
identifiableObject.setAutoFields();
identifiableObject.setLastUpdatedBy(user);
if (clearSharing) {
identifiableObject.setPublicAccess(AccessStringHelper.DEFAULT);
if (identifiableObject.getUserGroupAccesses() != null) {
identifiableObject.getUserGroupAccesses().clear();
}
if (identifiableObject.getUserAccesses() != null) {
identifiableObject.getUserAccesses().clear();
}
}
if (identifiableObject.getUser() == null) {
identifiableObject.setUser(user);
}
}
if (user != null && aclService.isShareable(clazz)) {
BaseIdentifiableObject identifiableObject = (BaseIdentifiableObject) object;
if (clearSharing) {
if (aclService.canMakePublic(user, identifiableObject.getClass())) {
if (aclService.defaultPublic(identifiableObject.getClass())) {
identifiableObject.setPublicAccess(AccessStringHelper.READ_WRITE);
}
} else if (aclService.canMakePrivate(user, identifiableObject.getClass())) {
identifiableObject.setPublicAccess(AccessStringHelper.newInstance().build());
}
}
if (!checkPublicAccess(user, identifiableObject)) {
AuditLogUtil.infoWrapper(log, username, object, AuditLogUtil.ACTION_CREATE_DENIED);
throw new CreateAccessDeniedException(object.toString());
}
}
AuditLogUtil.infoWrapper(log, username, object, AuditLogUtil.ACTION_CREATE);
getSession().save(object);
if (MetadataObject.class.isInstance(object)) {
deletedObjectService.deleteDeletedObjects(new DeletedObjectQuery((IdentifiableObject) object));
}
}
use of org.hisp.dhis.deletedobject.DeletedObjectQuery in project dhis2-core by dhis2.
the class HibernateDeletedObjectStore method getByKlass.
@Override
public List<DeletedObject> getByKlass(String klass) {
DeletedObjectQuery query = new DeletedObjectQuery();
query.getKlass().add(klass);
return query(query);
}
use of org.hisp.dhis.deletedobject.DeletedObjectQuery in project dhis2-core by dhis2.
the class HibernateGenericStore method update.
@Override
public void update(T object, User user) {
String username = user != null ? user.getUsername() : "system-process";
if (IdentifiableObject.class.isInstance(object)) {
BaseIdentifiableObject identifiableObject = (BaseIdentifiableObject) object;
identifiableObject.setAutoFields();
identifiableObject.setLastUpdatedBy(user);
if (identifiableObject.getUser() == null) {
identifiableObject.setUser(user);
}
}
if (!isUpdateAllowed(object, user)) {
AuditLogUtil.infoWrapper(log, username, object, AuditLogUtil.ACTION_UPDATE_DENIED);
throw new UpdateAccessDeniedException(object.toString());
}
AuditLogUtil.infoWrapper(log, username, object, AuditLogUtil.ACTION_UPDATE);
if (object != null) {
getSession().update(object);
}
if (MetadataObject.class.isInstance(object)) {
deletedObjectService.deleteDeletedObjects(new DeletedObjectQuery((IdentifiableObject) object));
}
}
use of org.hisp.dhis.deletedobject.DeletedObjectQuery in project dhis2-core by dhis2.
the class DefaultObjectBundleService method handleCreates.
//-----------------------------------------------------------------------------------
// Utility Methods
//-----------------------------------------------------------------------------------
private TypeReport handleCreates(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() + ") Creating " + 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 -> objectBundleHooks.forEach(hook -> hook.preCreate(object, bundle)));
for (int idx = 0; idx < objects.size(); idx++) {
IdentifiableObject object = objects.get(idx);
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());
session.save(object);
if (MetadataObject.class.isInstance(object)) {
deletedObjectService.deleteDeletedObjects(new DeletedObjectQuery(object));
}
bundle.getPreheat().replace(bundle.getPreheatIdentifier(), object);
objectBundleHooks.forEach(hook -> hook.postCreate(object, bundle));
if (log.isDebugEnabled()) {
String msg = "(" + bundle.getUsername() + ") Created object '" + bundle.getPreheatIdentifier().getIdentifiersWithName(object) + "'";
log.debug(msg);
}
if (FlushMode.OBJECT == bundle.getFlushMode())
session.flush();
}
return typeReport;
}
use of org.hisp.dhis.deletedobject.DeletedObjectQuery 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;
}
Aggregations