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; } }
@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()); } }