public static void externalEntityToDocumentModel(ExternalEntity entity, DocumentModel documentModel) { documentModel.setPropertyValue(EXTERNAL_ENTITY_ID_PROPERTY, entity.getEntityId()); documentModel.setPropertyValue(EXTERNAL_ENTITY_ORIGIN_PROPERTY, entity.getOrigin()); documentModel.setPropertyValue(EXTERNAL_ENTITY_PROPERTY, entity.getEntity()); }
public static void documentModelToExternalEntity(DocumentModel documentModel, ExternalEntity entity) { if (documentModel.hasFacet(EXTERNAL_ENTITY_FACET)) { entity.setEntityId((String) documentModel.getPropertyValue(EXTERNAL_ENTITY_ID_PROPERTY)); entity.setOrigin((String) documentModel.getPropertyValue(EXTERNAL_ENTITY_ORIGIN_PROPERTY)); entity.setEntity((String) documentModel.getPropertyValue(EXTERNAL_ENTITY_PROPERTY)); } }
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; } }
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()); } }