diff --git a/config/alfresco/public-rest-context.xml b/config/alfresco/public-rest-context.xml index 97550882c6..03db25b028 100644 --- a/config/alfresco/public-rest-context.xml +++ b/config/alfresco/public-rest-context.xml @@ -423,6 +423,7 @@ + diff --git a/source/java/org/alfresco/rest/api/Comments.java b/source/java/org/alfresco/rest/api/Comments.java index 5817640cd2..fce22fcc7a 100644 --- a/source/java/org/alfresco/rest/api/Comments.java +++ b/source/java/org/alfresco/rest/api/Comments.java @@ -23,21 +23,23 @@ * along with Alfresco. If not, see . * #L% */ -package org.alfresco.rest.api; - -import org.alfresco.rest.api.model.Comment; -import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; -import org.alfresco.rest.framework.resource.parameters.Paging; - -/** - * - * @author steveglover - * @since publicapi1.0 - */ -public interface Comments -{ - public Comment createComment(String nodeId, Comment comment); - public Comment updateComment(String nodeId, Comment comment); - public void deleteComment(String nodeId, String commentNodeId); - public CollectionWithPagingInfo getComments(String nodeId, Paging paging); -} +package org.alfresco.rest.api; + +import org.alfresco.rest.api.model.Comment; +import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; +import org.alfresco.rest.framework.resource.parameters.Paging; + +import java.util.List; + +/** + * + * @author steveglover + * @since publicapi1.0 + */ +public interface Comments +{ + public Comment createComment(String nodeId, Comment comment); + public Comment updateComment(String nodeId, Comment comment); + public void deleteComment(String nodeId, String commentNodeId); + public CollectionWithPagingInfo getComments(String nodeId, Paging paging, List include); +} diff --git a/source/java/org/alfresco/rest/api/People.java b/source/java/org/alfresco/rest/api/People.java index b4c40aa0b3..ea58e68bdf 100644 --- a/source/java/org/alfresco/rest/api/People.java +++ b/source/java/org/alfresco/rest/api/People.java @@ -31,6 +31,8 @@ import org.alfresco.rest.framework.resource.parameters.Parameters; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.security.NoSuchPersonException; +import java.util.List; + public interface People { String DEFAULT_USER = "-me-"; @@ -45,11 +47,21 @@ public interface People NodeRef getAvatar(String personId); /** + * Get a person. This included a full representation of the person. * * @throws NoSuchPersonException if personId does not exist */ Person getPerson(final String personId); + /** + * Get a person, specifying optional includes as required. + * + * @param personId + * @param include + * @return + */ + Person getPerson(String personId, List include); + /** * Create a person. * diff --git a/source/java/org/alfresco/rest/api/impl/CommentsImpl.java b/source/java/org/alfresco/rest/api/impl/CommentsImpl.java index a377b072e1..cd20ff0b7f 100644 --- a/source/java/org/alfresco/rest/api/impl/CommentsImpl.java +++ b/source/java/org/alfresco/rest/api/impl/CommentsImpl.java @@ -25,39 +25,38 @@ */ package org.alfresco.rest.api.impl; +import org.alfresco.model.ContentModel; +import org.alfresco.query.PagingRequest; +import org.alfresco.query.PagingResults; +import org.alfresco.repo.forum.CommentService; +import org.alfresco.rest.api.Comments; +import org.alfresco.rest.api.Nodes; +import org.alfresco.rest.api.People; +import org.alfresco.rest.api.model.Comment; +import org.alfresco.rest.api.model.Person; +import org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException; +import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException; +import org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException; +import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; +import org.alfresco.rest.framework.resource.parameters.Paging; +import org.alfresco.service.cmr.repository.ContentReader; +import org.alfresco.service.cmr.repository.ContentService; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.namespace.QName; +import org.alfresco.util.TypeConstraint; + import java.io.Serializable; import java.util.AbstractList; import java.util.Arrays; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import org.alfresco.model.ContentModel; -import org.alfresco.query.PagingRequest; -import org.alfresco.query.PagingResults; -import org.alfresco.repo.forum.CommentService; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.site.SiteModel; -import org.alfresco.rest.api.Comments; -import org.alfresco.rest.api.Nodes; -import org.alfresco.rest.api.model.Comment; -import org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException; -import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException; -import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException; -import org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException; -import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; -import org.alfresco.rest.framework.resource.parameters.Paging; -import org.alfresco.service.cmr.lock.LockService; -import org.alfresco.service.cmr.lock.LockStatus; -import org.alfresco.service.cmr.repository.ContentReader; -import org.alfresco.service.cmr.repository.ContentService; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.security.AccessStatus; -import org.alfresco.service.cmr.security.PermissionService; -import org.alfresco.service.namespace.QName; -import org.alfresco.util.TypeConstraint; +import static org.alfresco.rest.api.People.PARAM_INCLUDE_ASPECTNAMES; +import static org.alfresco.rest.api.People.PARAM_INCLUDE_PROPERTIES; /** * Centralises access to comment services and maps between representations. @@ -67,11 +66,15 @@ import org.alfresco.util.TypeConstraint; */ public class CommentsImpl implements Comments { - private Nodes nodes; + private static final List INCLUDE_FULL_PERSON = Arrays.asList( + PARAM_INCLUDE_ASPECTNAMES, + PARAM_INCLUDE_PROPERTIES);; + private Nodes nodes; private NodeService nodeService; private CommentService commentService; private ContentService contentService; private TypeConstraint typeConstraint; + private People people; public void setTypeConstraint(TypeConstraint typeConstraint) { @@ -98,7 +101,12 @@ public class CommentsImpl implements Comments this.contentService = contentService; } - private Comment toComment(NodeRef nodeRef, NodeRef commentNodeRef) + public void setPeople(People people) + { + this.people = people; + } + + private Comment toComment(NodeRef nodeRef, NodeRef commentNodeRef, List include) { Map nodeProps = nodeService.getProperties(commentNodeRef); @@ -115,7 +123,12 @@ public class CommentsImpl implements Comments boolean canEdit = map.get(CommentService.CAN_EDIT); boolean canDelete = map.get(CommentService.CAN_DELETE); - + Person createdBy = people.getPerson((String) nodeProps.get(ContentModel.PROP_CREATOR), include); + nodeProps.put(Comment.PROP_COMMENT_CREATED_BY, createdBy); + + Person modifiedBy = people.getPerson((String) nodeProps.get(ContentModel.PROP_MODIFIER), include); + nodeProps.put(Comment.PROP_COMMENT_MODIFIED_BY, modifiedBy); + Comment comment = new Comment(commentNodeRef.getId(), nodeProps, canEdit, canDelete); return comment; } @@ -132,7 +145,7 @@ public class CommentsImpl implements Comments try { NodeRef commentNode = commentService.createComment(nodeRef, comment.getTitle(), comment.getContent(), false); - return toComment(nodeRef, commentNode); + return toComment(nodeRef, commentNode, INCLUDE_FULL_PERSON); } catch(IllegalArgumentException e) { @@ -157,7 +170,7 @@ public class CommentsImpl implements Comments } commentService.updateComment(commentNodeRef, title, content); - return toComment(nodeRef, commentNodeRef); + return toComment(nodeRef, commentNodeRef, INCLUDE_FULL_PERSON); } catch(IllegalArgumentException e) { @@ -165,7 +178,7 @@ public class CommentsImpl implements Comments } } - public CollectionWithPagingInfo getComments(String nodeId, Paging paging) + public CollectionWithPagingInfo getComments(String nodeId, Paging paging, List include) { final NodeRef nodeRef = nodes.validateNode(nodeId); @@ -186,7 +199,7 @@ public class CommentsImpl implements Comments @Override public Comment get(int index) { - return toComment(nodeRef, page.get(index)); + return toComment(nodeRef, page.get(index), include); } @Override diff --git a/source/java/org/alfresco/rest/api/impl/PeopleImpl.java b/source/java/org/alfresco/rest/api/impl/PeopleImpl.java index 8347ae075e..be0dba52fe 100644 --- a/source/java/org/alfresco/rest/api/impl/PeopleImpl.java +++ b/source/java/org/alfresco/rest/api/impl/PeopleImpl.java @@ -303,6 +303,7 @@ public class PeopleImpl implements People } /** + * Get a full representation of a person. * * @throws NoSuchPersonException * if personId does not exist @@ -317,6 +318,14 @@ public class PeopleImpl implements People return person; } + + public Person getPerson(String personId, List include) + { + personId = validatePerson(personId); + Person person = getPersonWithProperties(personId, include); + + return person; + } public CollectionWithPagingInfo getPeople(final Parameters parameters) { diff --git a/source/java/org/alfresco/rest/api/model/Comment.java b/source/java/org/alfresco/rest/api/model/Comment.java index 6db930d2f6..4b48ced11c 100644 --- a/source/java/org/alfresco/rest/api/model/Comment.java +++ b/source/java/org/alfresco/rest/api/model/Comment.java @@ -45,14 +45,16 @@ import org.alfresco.service.namespace.QName; public class Comment { public static final QName PROP_COMMENT_CONTENT = QName.createQName("RestApi", "commentContent"); + public static final QName PROP_COMMENT_CREATED_BY = QName.createQName("RestApi", "createdBy"); + public static final QName PROP_COMMENT_MODIFIED_BY = QName.createQName("RestApi", "modifiedBy"); private String id; private String title; private String content; private Date createdAt; - private String createdBy; + private Person createdBy; private Date modifiedAt; - private String modifiedBy; + private Person modifiedBy; private Boolean edited; // permissions @@ -117,15 +119,13 @@ public class Comment { return createdAt; } - - @EmbeddedEntityResource(propertyName = "createdBy", entityResource = PeopleEntityResource.class) - public String getCreatedBy() + + public Person getCreatedBy() { return createdBy; } - - @EmbeddedEntityResource(propertyName = "modifiedBy", entityResource = PeopleEntityResource.class) - public String getModifiedBy() + + public Person getModifiedBy() { return modifiedBy; } @@ -155,13 +155,16 @@ public class Comment long diff = modifiedAt.getTime() - createdAt.getTime(); this.edited = Boolean.valueOf(diff >= 100); // logic is consistent with existing (Javascript) comments implementation } - - this.createdBy = (String)nodeProps.get(ContentModel.PROP_CREATOR); - this.modifiedBy = (String)nodeProps.get(ContentModel.PROP_MODIFIER); - + this.content = (String)nodeProps.get(PROP_COMMENT_CONTENT); nodeProps.remove(PROP_COMMENT_CONTENT); - } + + this.createdBy = (Person) nodeProps.get(PROP_COMMENT_CREATED_BY); + nodeProps.remove(PROP_COMMENT_CREATED_BY); + + this.modifiedBy = (Person) nodeProps.get(PROP_COMMENT_MODIFIED_BY); + nodeProps.remove(PROP_COMMENT_MODIFIED_BY); + } @Override public String toString() diff --git a/source/java/org/alfresco/rest/api/model/Person.java b/source/java/org/alfresco/rest/api/model/Person.java index 82c39562cf..9c6d10a781 100644 --- a/source/java/org/alfresco/rest/api/model/Person.java +++ b/source/java/org/alfresco/rest/api/model/Person.java @@ -42,8 +42,9 @@ import java.util.Map; * @author steveglover * */ -public class Person +public class Person implements Serializable { + private static final long serialVersionUID = 1L; protected String userName; protected Boolean enabled; protected NodeRef avatarId; diff --git a/source/java/org/alfresco/rest/api/nodes/NodeCommentsRelation.java b/source/java/org/alfresco/rest/api/nodes/NodeCommentsRelation.java index c58ac01355..923032fb2a 100644 --- a/source/java/org/alfresco/rest/api/nodes/NodeCommentsRelation.java +++ b/source/java/org/alfresco/rest/api/nodes/NodeCommentsRelation.java @@ -93,7 +93,7 @@ public class NodeCommentsRelation implements RelationshipResourceAction.Read readAll(String nodeId, Parameters parameters) { - return comments.getComments(nodeId, parameters.getPaging()); + return comments.getComments(nodeId, parameters.getPaging(), parameters.getInclude()); } @Override