Search in sources :

Example 1 with UpdateResource

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
    }
}
Also used : UpdateResource(io.lumeer.engine.api.event.UpdateResource) Collection(io.lumeer.api.model.Collection)

Example 2 with UpdateResource

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);
    }
}
Also used : Project(io.lumeer.api.model.Project) MongoException(com.mongodb.MongoException) UpdateResource(io.lumeer.engine.api.event.UpdateResource) FindOneAndUpdateOptions(com.mongodb.client.model.FindOneAndUpdateOptions) Document(org.bson.Document) ReturnDocument(com.mongodb.client.model.ReturnDocument) StorageException(io.lumeer.storage.api.exception.StorageException) Bson(org.bson.conversions.Bson)

Example 3 with UpdateResource

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);
    }
}
Also used : Organization(io.lumeer.api.model.Organization) MongoException(com.mongodb.MongoException) UpdateResource(io.lumeer.engine.api.event.UpdateResource) FindOneAndUpdateOptions(com.mongodb.client.model.FindOneAndUpdateOptions) Document(org.bson.Document) ReturnDocument(com.mongodb.client.model.ReturnDocument) StorageException(io.lumeer.storage.api.exception.StorageException) Bson(org.bson.conversions.Bson)

Example 4 with UpdateResource

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));
    }
}
Also used : UpdateResource(io.lumeer.engine.api.event.UpdateResource) Collection(io.lumeer.api.model.Collection) RemoveResource(io.lumeer.engine.api.event.RemoveResource)

Example 5 with UpdateResource

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);
    }
}
Also used : MongoException(com.mongodb.MongoException) UpdateResource(io.lumeer.engine.api.event.UpdateResource) FindOneAndUpdateOptions(com.mongodb.client.model.FindOneAndUpdateOptions) Document(org.bson.Document) ReturnDocument(com.mongodb.client.model.ReturnDocument) View(io.lumeer.api.model.View) StorageException(io.lumeer.storage.api.exception.StorageException) Bson(org.bson.conversions.Bson)

Aggregations

UpdateResource (io.lumeer.engine.api.event.UpdateResource)6 MongoException (com.mongodb.MongoException)4 FindOneAndUpdateOptions (com.mongodb.client.model.FindOneAndUpdateOptions)4 ReturnDocument (com.mongodb.client.model.ReturnDocument)4 StorageException (io.lumeer.storage.api.exception.StorageException)4 Document (org.bson.Document)4 Bson (org.bson.conversions.Bson)4 Collection (io.lumeer.api.model.Collection)3 MongoCollection (com.mongodb.client.MongoCollection)1 Organization (io.lumeer.api.model.Organization)1 Project (io.lumeer.api.model.Project)1 View (io.lumeer.api.model.View)1 RemoveResource (io.lumeer.engine.api.event.RemoveResource)1