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);
}
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);
}
}
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);
}
}
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);
}
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);
}
Aggregations