REPO-1661: properties and aspects no longer appear in /comments listing.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@133552 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Matt Ward
2016-12-09 16:54:07 +00:00
parent 3b4599a91a
commit cfed51f84b
8 changed files with 106 additions and 65 deletions

View File

@@ -423,6 +423,7 @@
<property name="commentService" ref="CommentService" /> <property name="commentService" ref="CommentService" />
<property name="contentService" ref="ContentService" /> <property name="contentService" ref="ContentService" />
<property name="typeConstraint" ref="nodeTypeConstraint" /> <property name="typeConstraint" ref="nodeTypeConstraint" />
<property name="people" ref="people"/>
</bean> </bean>
<bean id="Comments" class="org.springframework.aop.framework.ProxyFactoryBean"> <bean id="Comments" class="org.springframework.aop.framework.ProxyFactoryBean">

View File

@@ -29,6 +29,8 @@ import org.alfresco.rest.api.model.Comment;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.Paging; import org.alfresco.rest.framework.resource.parameters.Paging;
import java.util.List;
/** /**
* *
* @author steveglover * @author steveglover
@@ -39,5 +41,5 @@ public interface Comments
public Comment createComment(String nodeId, Comment comment); public Comment createComment(String nodeId, Comment comment);
public Comment updateComment(String nodeId, Comment comment); public Comment updateComment(String nodeId, Comment comment);
public void deleteComment(String nodeId, String commentNodeId); public void deleteComment(String nodeId, String commentNodeId);
public CollectionWithPagingInfo<Comment> getComments(String nodeId, Paging paging); public CollectionWithPagingInfo<Comment> getComments(String nodeId, Paging paging, List<String> include);
} }

View File

@@ -31,6 +31,8 @@ import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.NoSuchPersonException; import org.alfresco.service.cmr.security.NoSuchPersonException;
import java.util.List;
public interface People public interface People
{ {
String DEFAULT_USER = "-me-"; String DEFAULT_USER = "-me-";
@@ -45,11 +47,21 @@ public interface People
NodeRef getAvatar(String personId); NodeRef getAvatar(String personId);
/** /**
* Get a person. This included a full representation of the person.
* *
* @throws NoSuchPersonException if personId does not exist * @throws NoSuchPersonException if personId does not exist
*/ */
Person getPerson(final String personId); Person getPerson(final String personId);
/**
* Get a person, specifying optional includes as required.
*
* @param personId
* @param include
* @return
*/
Person getPerson(String personId, List<String> include);
/** /**
* Create a person. * Create a person.
* *

View File

@@ -25,39 +25,38 @@
*/ */
package org.alfresco.rest.api.impl; 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.io.Serializable;
import java.util.AbstractList; import java.util.AbstractList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.alfresco.model.ContentModel; import static org.alfresco.rest.api.People.PARAM_INCLUDE_ASPECTNAMES;
import org.alfresco.query.PagingRequest; import static org.alfresco.rest.api.People.PARAM_INCLUDE_PROPERTIES;
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;
/** /**
* Centralises access to comment services and maps between representations. * Centralises access to comment services and maps between representations.
@@ -67,11 +66,15 @@ import org.alfresco.util.TypeConstraint;
*/ */
public class CommentsImpl implements Comments public class CommentsImpl implements Comments
{ {
private static final List<String> INCLUDE_FULL_PERSON = Arrays.asList(
PARAM_INCLUDE_ASPECTNAMES,
PARAM_INCLUDE_PROPERTIES);;
private Nodes nodes; private Nodes nodes;
private NodeService nodeService; private NodeService nodeService;
private CommentService commentService; private CommentService commentService;
private ContentService contentService; private ContentService contentService;
private TypeConstraint typeConstraint; private TypeConstraint typeConstraint;
private People people;
public void setTypeConstraint(TypeConstraint typeConstraint) public void setTypeConstraint(TypeConstraint typeConstraint)
{ {
@@ -98,7 +101,12 @@ public class CommentsImpl implements Comments
this.contentService = contentService; 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<String> include)
{ {
Map<QName, Serializable> nodeProps = nodeService.getProperties(commentNodeRef); Map<QName, Serializable> nodeProps = nodeService.getProperties(commentNodeRef);
@@ -115,6 +123,11 @@ public class CommentsImpl implements Comments
boolean canEdit = map.get(CommentService.CAN_EDIT); boolean canEdit = map.get(CommentService.CAN_EDIT);
boolean canDelete = map.get(CommentService.CAN_DELETE); 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); Comment comment = new Comment(commentNodeRef.getId(), nodeProps, canEdit, canDelete);
return comment; return comment;
@@ -132,7 +145,7 @@ public class CommentsImpl implements Comments
try try
{ {
NodeRef commentNode = commentService.createComment(nodeRef, comment.getTitle(), comment.getContent(), false); NodeRef commentNode = commentService.createComment(nodeRef, comment.getTitle(), comment.getContent(), false);
return toComment(nodeRef, commentNode); return toComment(nodeRef, commentNode, INCLUDE_FULL_PERSON);
} }
catch(IllegalArgumentException e) catch(IllegalArgumentException e)
{ {
@@ -157,7 +170,7 @@ public class CommentsImpl implements Comments
} }
commentService.updateComment(commentNodeRef, title, content); commentService.updateComment(commentNodeRef, title, content);
return toComment(nodeRef, commentNodeRef); return toComment(nodeRef, commentNodeRef, INCLUDE_FULL_PERSON);
} }
catch(IllegalArgumentException e) catch(IllegalArgumentException e)
{ {
@@ -165,7 +178,7 @@ public class CommentsImpl implements Comments
} }
} }
public CollectionWithPagingInfo<Comment> getComments(String nodeId, Paging paging) public CollectionWithPagingInfo<Comment> getComments(String nodeId, Paging paging, List<String> include)
{ {
final NodeRef nodeRef = nodes.validateNode(nodeId); final NodeRef nodeRef = nodes.validateNode(nodeId);
@@ -186,7 +199,7 @@ public class CommentsImpl implements Comments
@Override @Override
public Comment get(int index) public Comment get(int index)
{ {
return toComment(nodeRef, page.get(index)); return toComment(nodeRef, page.get(index), include);
} }
@Override @Override

View File

@@ -303,6 +303,7 @@ public class PeopleImpl implements People
} }
/** /**
* Get a full representation of a person.
* *
* @throws NoSuchPersonException * @throws NoSuchPersonException
* if personId does not exist * if personId does not exist
@@ -318,6 +319,14 @@ public class PeopleImpl implements People
return person; return person;
} }
public Person getPerson(String personId, List<String> include)
{
personId = validatePerson(personId);
Person person = getPersonWithProperties(personId, include);
return person;
}
public CollectionWithPagingInfo<Person> getPeople(final Parameters parameters) public CollectionWithPagingInfo<Person> getPeople(final Parameters parameters)
{ {
Paging paging = parameters.getPaging(); Paging paging = parameters.getPaging();

View File

@@ -45,14 +45,16 @@ import org.alfresco.service.namespace.QName;
public class Comment public class Comment
{ {
public static final QName PROP_COMMENT_CONTENT = QName.createQName("RestApi", "commentContent"); 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 id;
private String title; private String title;
private String content; private String content;
private Date createdAt; private Date createdAt;
private String createdBy; private Person createdBy;
private Date modifiedAt; private Date modifiedAt;
private String modifiedBy; private Person modifiedBy;
private Boolean edited; private Boolean edited;
// permissions // permissions
@@ -118,14 +120,12 @@ public class Comment
return createdAt; return createdAt;
} }
@EmbeddedEntityResource(propertyName = "createdBy", entityResource = PeopleEntityResource.class) public Person getCreatedBy()
public String getCreatedBy()
{ {
return createdBy; return createdBy;
} }
@EmbeddedEntityResource(propertyName = "modifiedBy", entityResource = PeopleEntityResource.class) public Person getModifiedBy()
public String getModifiedBy()
{ {
return modifiedBy; return modifiedBy;
} }
@@ -156,11 +156,14 @@ public class Comment
this.edited = Boolean.valueOf(diff >= 100); // logic is consistent with existing (Javascript) comments implementation 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); this.content = (String)nodeProps.get(PROP_COMMENT_CONTENT);
nodeProps.remove(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 @Override

View File

@@ -42,8 +42,9 @@ import java.util.Map;
* @author steveglover * @author steveglover
* *
*/ */
public class Person public class Person implements Serializable
{ {
private static final long serialVersionUID = 1L;
protected String userName; protected String userName;
protected Boolean enabled; protected Boolean enabled;
protected NodeRef avatarId; protected NodeRef avatarId;

View File

@@ -93,7 +93,7 @@ public class NodeCommentsRelation implements RelationshipResourceAction.Read<Com
@WebApiDescription(title = "Returns a paged list of comments for the document/folder identified by nodeId, sorted chronologically with the newest first.") @WebApiDescription(title = "Returns a paged list of comments for the document/folder identified by nodeId, sorted chronologically with the newest first.")
public CollectionWithPagingInfo<Comment> readAll(String nodeId, Parameters parameters) public CollectionWithPagingInfo<Comment> readAll(String nodeId, Parameters parameters)
{ {
return comments.getComments(nodeId, parameters.getPaging()); return comments.getComments(nodeId, parameters.getPaging(), parameters.getInclude());
} }
@Override @Override