Search in sources :

Example 1 with ResourceComment

use of io.lumeer.api.model.ResourceComment in project engine by Lumeer.

the class ResourceCommentFacade method deleteComment.

public void deleteComment(final ResourceComment comment) {
    checkPermissions(comment.getResourceType(), comment.getResourceId());
    final ResourceComment dbComment = getCommentForUpdate(comment);
    resourceCommentDao.deleteComment(dbComment);
}
Also used : ResourceComment(io.lumeer.api.model.ResourceComment)

Example 2 with ResourceComment

use of io.lumeer.api.model.ResourceComment in project engine by Lumeer.

the class MongoResourceCommentDao method updateComment.

@Override
public ResourceComment updateComment(final ResourceComment comment) {
    FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER);
    try {
        Bson update = new org.bson.Document("$set", comment);
        ResourceComment updatedComment = databaseCollection().findOneAndUpdate(idFilter(comment.getId()), update, options);
        if (updatedComment == null) {
            throw new StorageException("Comment '" + comment.getId() + "' has not been updated.");
        }
        if (updateResourceCommentEvent != null) {
            updateResourceCommentEvent.fire(new UpdateResourceComment(comment));
        }
        return updatedComment;
    } catch (MongoException ex) {
        throw new StorageException("Cannot update comment: " + comment, ex);
    }
}
Also used : UpdateResourceComment(io.lumeer.engine.api.event.UpdateResourceComment) RemoveResourceComment(io.lumeer.engine.api.event.RemoveResourceComment) ResourceComment(io.lumeer.api.model.ResourceComment) CreateResourceComment(io.lumeer.engine.api.event.CreateResourceComment) MongoException(com.mongodb.MongoException) FindOneAndUpdateOptions(com.mongodb.client.model.FindOneAndUpdateOptions) UpdateResourceComment(io.lumeer.engine.api.event.UpdateResourceComment) 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 ResourceComment

use of io.lumeer.api.model.ResourceComment in project engine by Lumeer.

the class ResourceCommentCreator method createComments.

private void createComments() {
    final JSONArray comments = (JSONArray) templateParser.template.get("comments");
    if (comments != null) {
        final List<ResourceComment> result = new ArrayList<>();
        comments.forEach(commentObj -> {
            try {
                var commentJson = (JSONObject) commentObj;
                var resourceComment = mapper.readValue(commentJson.toJSONString(), ResourceCommentWrapper.class);
                var translatedParentId = templateParser.translateString(resourceComment.getParentId(), constraintManager);
                resourceComment.setParentId(translatedParentId != null ? translatedParentId.toString() : null);
                var translatedResourceId = templateParser.translateString(resourceComment.getResourceId(), constraintManager);
                resourceComment.setResourceId(translatedResourceId != null ? translatedResourceId.toString() : null);
                resourceComment.setId(null);
                result.add(resourceComment.getResourceComment());
            } catch (IOException e) {
                throw new TemplateNotAvailableException(e);
            }
        });
        resourceCommentFacade.storeResourceComments(result);
    }
}
Also used : ResourceComment(io.lumeer.api.model.ResourceComment) TemplateNotAvailableException(io.lumeer.core.exception.TemplateNotAvailableException) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 4 with ResourceComment

use of io.lumeer.api.model.ResourceComment in project engine by Lumeer.

the class ResourceCommentService method deleteComment.

@DELETE
@Path("{commentId:[0-9a-fA-F]{24}}")
public void deleteComment(@PathParam("commentId") final String commentId) {
    final ResourceComment comment = new ResourceComment(null, null);
    comment.setId(commentId);
    comment.setResourceType(type);
    comment.setResourceId(resourceId);
    resourceCommentFacade.deleteComment(comment);
}
Also used : ResourceComment(io.lumeer.api.model.ResourceComment) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 5 with ResourceComment

use of io.lumeer.api.model.ResourceComment in project engine by Lumeer.

the class ResourceCommentFacade method updateResourceComment.

public ResourceComment updateResourceComment(final ResourceComment comment) {
    checkPermissions(comment.getResourceType(), comment.getResourceId());
    final ResourceComment dbComment = getCommentForUpdate(comment);
    dbComment.setUpdateDate(ZonedDateTime.now());
    dbComment.setComment(comment.getComment());
    dbComment.setMetaData(comment.getMetaData());
    return resourceCommentDao.updateComment(dbComment);
}
Also used : ResourceComment(io.lumeer.api.model.ResourceComment)

Aggregations

ResourceComment (io.lumeer.api.model.ResourceComment)9 Document (org.bson.Document)3 MongoException (com.mongodb.MongoException)2 FindOneAndUpdateOptions (com.mongodb.client.model.FindOneAndUpdateOptions)2 ReturnDocument (com.mongodb.client.model.ReturnDocument)2 DataDocument (io.lumeer.engine.api.data.DataDocument)2 CreateResourceComment (io.lumeer.engine.api.event.CreateResourceComment)2 RemoveResourceComment (io.lumeer.engine.api.event.RemoveResourceComment)2 UpdateResourceComment (io.lumeer.engine.api.event.UpdateResourceComment)2 StorageException (io.lumeer.storage.api.exception.StorageException)2 Date (java.util.Date)2 Bson (org.bson.conversions.Bson)2 Document (io.lumeer.api.model.Document)1 Role (io.lumeer.api.model.Role)1 TemplateNotAvailableException (io.lumeer.core.exception.TemplateNotAvailableException)1 RemoveDocument (io.lumeer.engine.api.event.RemoveDocument)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 DELETE (javax.ws.rs.DELETE)1 Path (javax.ws.rs.Path)1