Codota Logo
Comment
Code IndexAdd Codota to your IDE (free)

How to use
Comment
in
org.nuxeo.ecm.platform.comment.api

Best Java code snippets using org.nuxeo.ecm.platform.comment.api.Comment (Showing top 13 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
StringBuilder s =
  • Codota Iconnew StringBuilder()
  • Codota Iconnew StringBuilder(32)
  • Codota IconString str;new StringBuilder(str)
  • Smart code suggestions by Codota
}
origin: org.nuxeo.ecm.platform/nuxeo-platform-comment

protected static void writeCommentEntity(Comment entity, JsonGenerator jg) throws IOException {
  jg.writeStringField(COMMENT_ID_FIELD, entity.getId());
  jg.writeStringField(COMMENT_PARENT_ID_FIELD, entity.getParentId());
  jg.writeArrayFieldStart(COMMENT_ANCESTOR_IDS_FIELD);
  for (String ancestorId : entity.getAncestorIds()) {
    jg.writeString(ancestorId);
  }
  jg.writeEndArray();
  jg.writeStringField(COMMENT_AUTHOR_FIELD, entity.getAuthor());
  jg.writeStringField(COMMENT_TEXT_FIELD, entity.getText());
  String creationDate = entity.getCreationDate() != null ? entity.getCreationDate().toString() : null;
  jg.writeStringField(COMMENT_CREATION_DATE_FIELD, creationDate);
  String modificationDate = entity.getModificationDate() != null ? entity.getModificationDate().toString() : null;
  jg.writeStringField(COMMENT_MODIFICATION_DATE_FIELD, modificationDate);
  if (entity instanceof ExternalEntity) {
    jg.writeStringField(EXTERNAL_ENTITY_ID, ((ExternalEntity) entity).getEntityId());
    jg.writeStringField(EXTERNAL_ENTITY_ORIGIN, ((ExternalEntity) entity).getOrigin());
    jg.writeStringField(EXTERNAL_ENTITY, ((ExternalEntity) entity).getEntity());
  }
}
origin: org.nuxeo.ecm.platform/nuxeo-platform-comment

  protected static Comment fillCommentEntity(JsonNode jn, Comment comment) {
    // don't read id from given JsonNode, if needed it is read from path
    comment.setParentId(jn.get(COMMENT_PARENT_ID_FIELD).textValue());
    comment.setAuthor(jn.get(COMMENT_AUTHOR_FIELD).textValue());
    comment.setText(jn.get(COMMENT_TEXT_FIELD).textValue());

    JsonNode creationDateNode = jn.get(COMMENT_CREATION_DATE_FIELD);
    Instant creationDate = creationDateNode != null && !creationDateNode.isNull()
        ? Instant.parse(creationDateNode.textValue())
        : null;
    comment.setCreationDate(creationDate);

    JsonNode modificationDateNode = jn.get(COMMENT_MODIFICATION_DATE_FIELD);
    Instant modificationDate = modificationDateNode != null && !modificationDateNode.isNull()
        ? Instant.parse(modificationDateNode.textValue())
        : null;
    comment.setModificationDate(modificationDate);

    if (jn.has(EXTERNAL_ENTITY_ID)) {
      ExternalEntity externalEntity = (ExternalEntity) comment;
      externalEntity.setEntityId(jn.get(EXTERNAL_ENTITY_ID).textValue());
      externalEntity.setOrigin(jn.get(EXTERNAL_ENTITY_ORIGIN).textValue());
      externalEntity.setEntity(jn.get(EXTERNAL_ENTITY).textValue());
    }
    return comment;
  }
}
origin: org.nuxeo.ecm.platform/nuxeo-platform-comment-api

public static void commentToDocumentModel(Comment comment, DocumentModel documentModel) {
  // Do not set ancestor ids as it is computed at document creation
  documentModel.setPropertyValue(COMMENT_AUTHOR, comment.getAuthor());
  documentModel.setPropertyValue(COMMENT_TEXT, comment.getText());
  documentModel.setPropertyValue(COMMENT_PARENT_ID, comment.getParentId());
  Instant creationDate = comment.getCreationDate();
  if (creationDate != null) {
    documentModel.setPropertyValue(COMMENT_CREATION_DATE,
        GregorianCalendar.from(ZonedDateTime.ofInstant(creationDate, ZoneId.systemDefault())));
  }
  Instant modificationDate = comment.getModificationDate();
  if (modificationDate != null) {
    documentModel.setPropertyValue(COMMENT_MODIFICATION_DATE,
        GregorianCalendar.from(ZonedDateTime.ofInstant(modificationDate, ZoneId.systemDefault())));
  }
}
origin: org.nuxeo.ecm.platform/nuxeo-platform-comment

@Override
public Comment updateComment(CoreSession session, String commentId, Comment comment)
    throws CommentNotFoundException {
  IdRef commentRef = new IdRef(commentId);
  if (!CoreInstance.doPrivileged(session, s -> {return s.exists(commentRef);})) {
    throw new CommentNotFoundException("The comment " + commentId + " does not exist.");
  }
  NuxeoPrincipal principal = session.getPrincipal();
  if (!principal.isAdministrator() && !comment.getAuthor().equals(principal.getName())) {
    throw new CommentSecurityException(
        "The user " + principal.getName() + " can not edit comments of document " + comment.getParentId());
  }
  return CoreInstance.doPrivileged(session, s -> {
    // Initiate Modification Date if it is not done yet
    if (comment.getModificationDate() == null) {
      comment.setModificationDate(Instant.now());
    }
    DocumentModel commentModel = s.getDocument(commentRef);
    Comments.commentToDocumentModel(comment, commentModel);
    if (comment instanceof ExternalEntity) {
      Comments.externalEntityToDocumentModel((ExternalEntity) comment, commentModel);
    }
    s.saveDocument(commentModel);
    return Comments.newComment(commentModel);
  });
}
origin: org.nuxeo.ecm.platform/nuxeo-platform-comment

  protected void writeRepliesSummary(CoreSession session, Comment entity, JsonGenerator jg) throws IOException {
    PartialList<Comment> comments = commentManager.getComments(session, entity.getId(), 1L, 0L, false);
    jg.writeNumberField(COMMENT_NUMBER_OF_REPLIES, comments.totalSize());
    if (comments.size() > 0) {
      jg.writeStringField(COMMENT_LAST_REPLY_DATE, comments.get(0).getCreationDate().toString());
    }
  }
}
origin: org.nuxeo.ecm.platform/nuxeo-platform-comment

@Override
public Comment createComment(CoreSession session, Comment comment)
    throws CommentNotFoundException, CommentSecurityException {
  String parentId = comment.getParentId();
  DocumentRef docRef = new IdRef(parentId);
    throw new CommentNotFoundException("The document or comment " + comment.getParentId() + " does not exist.");
  if (comment.getCreationDate() == null) {
    comment.setCreationDate(Instant.now());
origin: org.nuxeo.ecm.platform/nuxeo-platform-comment-rest-api

protected List<Comment> getAllComments(String annotationId, CommentManager commentManager, CoreSession session) {
  List<Comment> allComments = new ArrayList<>();
  List<Comment> comments = commentManager.getComments(session, annotationId);
  for (Comment comment : comments) {
    allComments.addAll(getAllComments(comment.getId(), commentManager, session));
    allComments.add(comment);
  }
  return allComments;
}
origin: org.nuxeo.ecm.platform/nuxeo-platform-comment

@Override
public Comment updateExternalComment(CoreSession session, String entityId, Comment comment)
    throws CommentNotFoundException {
  DocumentModel commentModel = getExternalCommentModel(session, entityId);
  if (commentModel == null) {
    throw new CommentNotFoundException("The external comment " + entityId + " does not exist.");
  }
  NuxeoPrincipal principal = session.getPrincipal();
  if (!principal.isAdministrator() && !comment.getAuthor().equals(principal.getName())) {
    throw new CommentSecurityException(
        "The user " + principal.getName() + " can not edit comments of document " + comment.getParentId());
  }
  return CoreInstance.doPrivileged(session, s -> {
    Comments.commentToDocumentModel(comment, commentModel);
    if (comment instanceof ExternalEntity) {
      Comments.externalEntityToDocumentModel((ExternalEntity) comment, commentModel);
    }
    s.saveDocument(commentModel);
    return Comments.newComment(commentModel);
  });
}
origin: org.nuxeo.ecm.platform/nuxeo-platform-comment

@Override
public Comment createComment(CoreSession session, Comment comment)
    throws CommentNotFoundException, CommentSecurityException {
  DocumentRef commentRef = new IdRef(comment.getParentId());
  if (!session.exists(commentRef)) {
    throw new CommentNotFoundException("The document " + comment.getParentId() + " does not exist.");
  }
  DocumentModel docToComment = session.getDocument(commentRef);
  DocumentModel commentModel = session.createDocumentModel(COMMENT_DOC_TYPE);
  commentModel.setPropertyValue("dc:created", Calendar.getInstance());
  Comments.commentToDocumentModel(comment, commentModel);
  if (comment instanceof ExternalEntity) {
    commentModel.addFacet(EXTERNAL_ENTITY_FACET);
    Comments.externalEntityToDocumentModel((ExternalEntity) comment, commentModel);
  }
  DocumentModel createdCommentModel = createComment(docToComment, commentModel);
  return Comments.newComment(createdCommentModel);
}
origin: org.nuxeo.ecm.platform/nuxeo-platform-comment-api

public List<DocumentModel> getComments(DocumentModel parent) {
  CoreSession session = docModel.getCoreSession();
  List<Comment> comments = commentManager.getComments(session, parent.getId());
  return CoreInstance.doPrivileged(session, s -> {
    return comments.stream().map(comment -> {
      DocumentModel commentModel = s.getDocument(new IdRef(comment.getId()));
      commentModel.detach(true);
      return commentModel;
    }).collect(Collectors.toList());
  });
}
origin: org.nuxeo.ecm.platform/nuxeo-platform-comment-api

@SuppressWarnings("unchecked")
public static void documentModelToComment(DocumentModel documentModel, Comment comment) {
  comment.setId(documentModel.getId());
  comment.setAuthor((String) documentModel.getPropertyValue(COMMENT_AUTHOR));
  comment.setText((String) documentModel.getPropertyValue(COMMENT_TEXT));
  Collection<String> ancestorIds = (Collection<String>) documentModel.getPropertyValue(COMMENT_ANCESTOR_IDS);
  ancestorIds.forEach(comment::addAncestorId);
  String parentId = (String) documentModel.getPropertyValue(COMMENT_PARENT_ID);
  comment.setParentId(parentId);
  Calendar creationDate = (Calendar) documentModel.getPropertyValue(COMMENT_CREATION_DATE);
  if (creationDate != null) {
    comment.setCreationDate(creationDate.toInstant());
  }
  Calendar modificationDate = (Calendar) documentModel.getPropertyValue(COMMENT_MODIFICATION_DATE);
  if (modificationDate != null) {
    comment.setModificationDate(modificationDate.toInstant());
  }
}
origin: org.nuxeo.ecm.platform/nuxeo-platform-comment

protected void deleteCommentChildren(CoreSession coreSession, CommentManager commentManager,
    DocumentModel documentModel) {
  commentManager.getComments(coreSession, documentModel.getId())
         .forEach(comment -> coreSession.removeDocument(new IdRef(comment.getId())));
}
origin: org.nuxeo.ecm.platform/nuxeo-platform-comment

@Override
protected void writeEntityBody(Comment entity, JsonGenerator jg) throws IOException {
  writeCommentEntity(entity, jg);
  CoreSession session = ctx.getSession(null).getSession();
  NuxeoPrincipal principal = session.getPrincipal();
  PermissionProvider permissionProvider = Framework.getService(PermissionProvider.class);
  // Write permissions of current user on the annotation,
  // which are the ones granted on the commented document
  Collection<String> permissions = CoreInstance.doPrivileged(session, s -> {
    if (entity.getId() == null) {
      return Collections.emptyList();
    }
    DocumentRef ancestorRef = new IdRef(
        (String) commentManager.getThreadForComment(s.getDocument(new IdRef(entity.getId())))
                    .getPropertyValue(COMMENT_PARENT_ID));
    return s.filterGrantedPermissions(principal, ancestorRef,
        Arrays.asList(permissionProvider.getPermissions()));
  });
  jg.writeArrayFieldStart(COMMENT_PERMISSIONS);
  for (String permission : permissions) {
    jg.writeString(permission);
  }
  jg.writeEndArray();
  boolean includeRepliesSummary = ctx.getFetched(COMMENT_ENTITY_TYPE).contains(FETCH_REPLIES_SUMMARY);
  if (includeRepliesSummary) {
    writeRepliesSummary(session, entity, jg);
  }
}
org.nuxeo.ecm.platform.comment.apiComment

Javadoc

Comment interface.

Most used methods

  • getId
    Gets comment id.
  • getAuthor
    Gets comment author.
  • getCreationDate
    Gets comment creation date.
  • getModificationDate
    Sets comment modification date.
  • getParentId
    Gets parent id.
  • getText
    Gets comment text.
  • setAuthor
    Sets comment author.
  • setCreationDate
    Sets comment creation date.
  • setModificationDate
    Sets comment modification date.
  • setParentId
    Sets parent id.
  • setText
    Sets comment text.
  • getAncestorIds
    Gets the list of ancestor ids.
  • setText,
  • getAncestorIds,
  • setId

Popular in Java

  • Reactive rest calls using spring rest template
  • notifyDataSetChanged (ArrayAdapter)
  • getSystemService (Context)
  • putExtra (Intent)
  • FileReader (java.io)
    A specialized Reader that reads from a file in the file system. All read requests made by calling me
  • Socket (java.net)
    Provides a client-side TCP socket.
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate(i
  • Manifest (java.util.jar)
    The Manifest class is used to obtain attribute information for a JarFile and its entries.
  • JList (javax.swing)
  • IsNull (org.hamcrest.core)
    Is the value null?
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now