use of io.lumeer.engine.api.event.UpdateResource in project engine by Lumeer.
the class AttributePurposeChangeDetector method detectChanges.
@Override
public void detectChanges(final ResourceEvent resourceEvent) {
if (resourceEvent instanceof UpdateResource) {
final Collection originalCollection = (Collection) ((UpdateResource) resourceEvent).getOriginalResource();
final Collection updatedCollection = (Collection) resourceEvent.getResource();
if (originalCollection != null) {
final List<String> removedIds = AttributeUtil.checkAttributesDiff(originalCollection.getAttributes(), updatedCollection.getAttributes()).getRemovedIds();
final String dueDateAttributeId = originalCollection.getPurpose().getDueDateAttributeId();
if (removedIds.contains(dueDateAttributeId)) {
delayedActionDao.deleteAllScheduledActions(getResourcePath(resourceEvent), Set.of(NotificationType.DUE_DATE_SOON, NotificationType.PAST_DUE_DATE));
}
}
// other types are sent immediately and we do not want to eradicate history just because someone deleted an attribute
}
}
use of io.lumeer.engine.api.event.UpdateResource in project engine by Lumeer.
the class MongoProjectDao method updateProject.
@Override
public Project updateProject(final String projectId, final Project project, final Project originalProject) {
FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER);
try {
Bson update = new Document("$set", project).append("$inc", new Document(ProjectCodec.VERSION, 1L));
Project updatedProject = databaseCollection().findOneAndUpdate(idFilter(projectId), update, options);
if (updatedProject == null) {
throw new StorageException("Project '" + projectId + "' has not been updated.");
}
if (updateResourceEvent != null) {
updateResourceEvent.fire(new UpdateResource(updatedProject, originalProject));
}
return updatedProject;
} catch (MongoException ex) {
throw new StorageException("Cannot update project: " + project, ex);
}
}
use of io.lumeer.engine.api.event.UpdateResource in project engine by Lumeer.
the class MongoOrganizationDao method updateOrganization.
@Override
public Organization updateOrganization(final String organizationId, final Organization organization, final Organization originalOrganization) {
FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER);
try {
Bson update = new Document("$set", organization).append("$inc", new Document(OrganizationCodec.VERSION, 1L));
Organization updatedOrganization = databaseCollection().findOneAndUpdate(idFilter(organizationId), update, options);
if (updatedOrganization == null) {
throw new StorageException("Organization '" + organizationId + "' has not been updated.");
}
if (updateResourceEvent != null) {
updateResourceEvent.fire(new UpdateResource(updatedOrganization, originalOrganization));
}
return updatedOrganization;
} catch (MongoException ex) {
throw new StorageException("Cannot update organization: " + organization, ex);
}
}
use of io.lumeer.engine.api.event.UpdateResource in project engine by Lumeer.
the class CollectionPurposeChangeDetector method detectChanges.
@Override
public void detectChanges(final ResourceEvent resourceEvent) {
if (resourceEvent instanceof UpdateResource) {
final Collection originalCollection = (Collection) ((UpdateResource) resourceEvent).getOriginalResource();
final Collection updatedCollection = (Collection) resourceEvent.getResource();
if (originalCollection != null && updatedCollection != null) {
if (originalCollection.getPurposeType() != updatedCollection.getPurposeType() && originalCollection.getPurposeType() == CollectionPurposeType.Tasks) {
delayedActionDao.deleteAllScheduledActions(getResourcePath(resourceEvent));
}
}
}
if (resourceEvent instanceof RemoveResource) {
delayedActionDao.deleteAllScheduledActions(getResourcePath(resourceEvent));
}
}
use of io.lumeer.engine.api.event.UpdateResource in project engine by Lumeer.
the class MongoViewDao method updateView.
@Override
public View updateView(final String id, final View view, final View originalView) {
FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER);
try {
Bson update = new Document("$set", view).append("$inc", new Document(ViewCodec.VERSION, 1L));
View updatedView = databaseCollection().findOneAndUpdate(idFilter(id), update, options);
if (updatedView == null) {
throw new StorageException("View '" + id + "' has not been updated.");
}
if (updateResourceEvent != null) {
updateResourceEvent.fire(new UpdateResource(updatedView, originalView));
}
return updatedView;
} catch (MongoException ex) {
throw new StorageException("Cannot update view: " + view, ex);
}
}
Aggregations