Skip to content

Commit adbade0

Browse files
committed
support comment related
1 parent 6881994 commit adbade0

File tree

16 files changed

+691
-57
lines changed

16 files changed

+691
-57
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 2016. EMC Corporation. All Rights Reserved.
3+
*/
4+
package com.emc.documentum.rest.client.sample.cases;
5+
6+
import com.emc.documentum.rest.client.sample.client.annotation.RestServiceSample;
7+
import com.emc.documentum.rest.client.sample.client.annotation.RestServiceVersion;
8+
import com.emc.documentum.rest.client.sample.model.Comment;
9+
import com.emc.documentum.rest.client.sample.model.Feed;
10+
import com.emc.documentum.rest.client.sample.model.RestObject;
11+
import com.emc.documentum.rest.client.sample.model.plain.PlainComment;
12+
import com.emc.documentum.rest.client.sample.model.plain.PlainRestObject;
13+
14+
import static com.emc.documentum.rest.client.sample.client.util.Debug.printEntryContentSrc;
15+
import static com.emc.documentum.rest.client.sample.client.util.Debug.printFields;
16+
import static com.emc.documentum.rest.client.sample.client.util.Debug.printNewLine;
17+
import static com.emc.documentum.rest.client.sample.client.util.Debug.printStep;
18+
19+
@RestServiceSample("Comments and Replies")
20+
@RestServiceVersion(7.3)
21+
public class CommentSample extends Sample {
22+
public void acls() {
23+
RestObject tempCabinet = client.getCabinet("Temp");
24+
RestObject object = new PlainRestObject("object_name", "obj_for_comment");
25+
RestObject createdObject = client.createObject(tempCabinet, object);
26+
27+
printStep("create a comment for the object " + createdObject.getObjectId());
28+
Comment createdComment1 = client.createComment(createdObject, new PlainComment("this is my first comment"));
29+
printFields(createdComment1);
30+
printNewLine();
31+
32+
printStep("create another comment for the object " + createdObject.getObjectId());
33+
Comment createdComment2 = client.createComment(createdObject, new PlainComment("this is my second comment"));
34+
printFields(createdComment2);
35+
printNewLine();
36+
37+
printStep("get comments feed of the object " + createdObject.getObjectId());
38+
Feed<Comment> comments = client.getComments(createdObject);
39+
printEntryContentSrc(comments);
40+
printNewLine();
41+
42+
printStep("create a replay for the first comment " + createdComment1.getCommentId());
43+
Comment createdReply1 = client.createReply(createdComment1, new PlainComment("this is my first reply"));
44+
printFields(createdReply1);
45+
printNewLine();
46+
47+
printStep("create another replay for the first comment " + createdComment1.getCommentId());
48+
Comment createdReply2 = client.createReply(createdComment1, new PlainComment("this is my second reply"));
49+
printFields(createdReply2);
50+
printNewLine();
51+
52+
printStep("get replies feed of the first comment " + createdComment1.getCommentId());
53+
Feed<Comment> replies = client.getReplies(createdComment1);
54+
printEntryContentSrc(replies);
55+
printNewLine();
56+
57+
printStep("delete the comments and replies");
58+
client.delete(createdReply1);
59+
printHttpStatus();
60+
client.delete(createdReply2);
61+
printHttpStatus();
62+
client.delete(createdComment1);
63+
printHttpStatus();
64+
client.delete(createdComment2);
65+
printHttpStatus();
66+
67+
client.delete(createdObject);
68+
printNewLine();
69+
}
70+
}

src/main/java/com/emc/documentum/rest/client/sample/client/DCTMRestClient.java

+38
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.springframework.http.HttpStatus;
1313

1414
import com.emc.documentum.rest.client.sample.client.annotation.NotBatchable;
15+
import com.emc.documentum.rest.client.sample.model.Comment;
1516
import com.emc.documentum.rest.client.sample.model.Feed;
1617
import com.emc.documentum.rest.client.sample.model.FolderLink;
1718
import com.emc.documentum.rest.client.sample.model.HomeDocument;
@@ -839,4 +840,41 @@ public interface DCTMRestClient {
839840
* @return the permission set object
840841
*/
841842
public PermissionSet getPermissionSet(Linkable linkable, String... params);
843+
844+
/**
845+
* @param parent the parent object
846+
* @param params the query parameters
847+
* @return the comments feed of the specified object
848+
*/
849+
public Feed<Comment> getComments(Linkable parent, String... params);
850+
851+
/**
852+
* create a Comment of the specified object
853+
* @param parent the object to create comment to
854+
* @param comment the comment to be created
855+
* @return the created comment
856+
*/
857+
public Comment createComment(Linkable parent, Comment comment);
858+
859+
/**
860+
* @param commentUri the uri of the comment
861+
* @param params the query parameters
862+
* @return the comment of the specified uri
863+
*/
864+
public Comment getComment(String commentUri, String... params);
865+
866+
/**
867+
* @param parent the parent comment
868+
* @param params the query parameters
869+
* @return the comment replies feed of the specified comment
870+
*/
871+
public Feed<Comment> getReplies(Linkable parent, String... params);
872+
873+
/**
874+
* create a reply of the specified comment
875+
* @param parent the comment to create reply to
876+
* @param comment the reply to be created
877+
* @return the created reply
878+
*/
879+
public Comment createReply(Linkable parent, Comment comment);
842880
}

src/main/java/com/emc/documentum/rest/client/sample/client/impl/jackson/DCTMJacksonClient.java

+31
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.emc.documentum.rest.client.sample.client.impl.AbstractRestTemplateClient;
2020
import com.emc.documentum.rest.client.sample.client.util.Headers;
2121
import com.emc.documentum.rest.client.sample.client.util.UriHelper;
22+
import com.emc.documentum.rest.client.sample.model.Comment;
2223
import com.emc.documentum.rest.client.sample.model.Entry;
2324
import com.emc.documentum.rest.client.sample.model.Feed;
2425
import com.emc.documentum.rest.client.sample.model.FolderLink;
@@ -39,6 +40,7 @@
3940
import com.emc.documentum.rest.client.sample.model.batch.Capabilities;
4041
import com.emc.documentum.rest.client.sample.model.json.JsonBatch;
4142
import com.emc.documentum.rest.client.sample.model.json.JsonBatchCapabilities;
43+
import com.emc.documentum.rest.client.sample.model.json.JsonComment;
4244
import com.emc.documentum.rest.client.sample.model.json.JsonFeeds;
4345
import com.emc.documentum.rest.client.sample.model.json.JsonFolderLink;
4446
import com.emc.documentum.rest.client.sample.model.json.JsonHomeDocument;
@@ -66,6 +68,7 @@
6668
import static com.emc.documentum.rest.client.sample.model.LinkRelation.CHECKIN_NEXT_MAJOR;
6769
import static com.emc.documentum.rest.client.sample.model.LinkRelation.CHECKIN_NEXT_MINOR;
6870
import static com.emc.documentum.rest.client.sample.model.LinkRelation.CHECKOUT;
71+
import static com.emc.documentum.rest.client.sample.model.LinkRelation.COMMENTS;
6972
import static com.emc.documentum.rest.client.sample.model.LinkRelation.CONTENTS;
7073
import static com.emc.documentum.rest.client.sample.model.LinkRelation.CURRENT_USER_PREFERENCES;
7174
import static com.emc.documentum.rest.client.sample.model.LinkRelation.DELETE;
@@ -86,6 +89,7 @@
8689
import static com.emc.documentum.rest.client.sample.model.LinkRelation.PRIMARY_CONTENT;
8790
import static com.emc.documentum.rest.client.sample.model.LinkRelation.RELATIONS;
8891
import static com.emc.documentum.rest.client.sample.model.LinkRelation.RELATION_TYPES;
92+
import static com.emc.documentum.rest.client.sample.model.LinkRelation.REPLIES;
8993
import static com.emc.documentum.rest.client.sample.model.LinkRelation.REPOSITORIES;
9094
import static com.emc.documentum.rest.client.sample.model.LinkRelation.SEARCH;
9195
import static com.emc.documentum.rest.client.sample.model.LinkRelation.SELF;
@@ -583,6 +587,33 @@ public PermissionSet getPermissionSet(Linkable linkable, String... params) {
583587
return get(linkable.getHref(LinkRelation.PERMISSION_SET), false, JsonPermissionSet.class, params);
584588
}
585589

590+
@Override
591+
public Feed<Comment> getComments(Linkable parent, String... params) {
592+
Feed<? extends Comment> feed = get(parent.getHref(COMMENTS), true, JsonFeeds.CommentFeed.class, params);
593+
return (Feed<Comment>)feed;
594+
}
595+
596+
@Override
597+
public Comment createComment(Linkable parent, Comment comment) {
598+
return post(parent.getHref(COMMENTS), new JsonComment(comment), JsonComment.class);
599+
}
600+
601+
@Override
602+
public Comment getComment(String commentUri, String... params) {
603+
return get(commentUri, false, JsonComment.class, params);
604+
}
605+
606+
@Override
607+
public Feed<Comment> getReplies(Linkable parent, String... params) {
608+
Feed<? extends Comment> feed = get(parent.getHref(REPLIES), true, JsonFeeds.CommentFeed.class, params);
609+
return (Feed<Comment>)feed;
610+
}
611+
612+
@Override
613+
public Comment createReply(Linkable parent, Comment comment) {
614+
return post(parent.getHref(REPLIES), new JsonComment(comment), JsonComment.class);
615+
}
616+
586617
@Override
587618
public <T extends Linkable> Feed<T> nextPage(Feed<T> feed) {
588619
return page(feed.getHref(PAGING_NEXT), feed.getClass());

src/main/java/com/emc/documentum/rest/client/sample/client/impl/jaxb/DCTMJaxbClient.java

+31
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.emc.documentum.rest.client.sample.client.impl.AbstractRestTemplateClient;
1919
import com.emc.documentum.rest.client.sample.client.util.Headers;
2020
import com.emc.documentum.rest.client.sample.client.util.UriHelper;
21+
import com.emc.documentum.rest.client.sample.model.Comment;
2122
import com.emc.documentum.rest.client.sample.model.Entry;
2223
import com.emc.documentum.rest.client.sample.model.Feed;
2324
import com.emc.documentum.rest.client.sample.model.FolderLink;
@@ -42,6 +43,7 @@
4243
import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbBatch;
4344
import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbBatchCapabilities;
4445
import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbCabinet;
46+
import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbComment;
4547
import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbContent;
4648
import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbDocument;
4749
import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbFeed;
@@ -78,6 +80,7 @@
7880
import static com.emc.documentum.rest.client.sample.model.LinkRelation.CHECKIN_NEXT_MAJOR;
7981
import static com.emc.documentum.rest.client.sample.model.LinkRelation.CHECKIN_NEXT_MINOR;
8082
import static com.emc.documentum.rest.client.sample.model.LinkRelation.CHECKOUT;
83+
import static com.emc.documentum.rest.client.sample.model.LinkRelation.COMMENTS;
8184
import static com.emc.documentum.rest.client.sample.model.LinkRelation.CONTENTS;
8285
import static com.emc.documentum.rest.client.sample.model.LinkRelation.CURRENT_USER_PREFERENCES;
8386
import static com.emc.documentum.rest.client.sample.model.LinkRelation.DELETE;
@@ -98,6 +101,7 @@
98101
import static com.emc.documentum.rest.client.sample.model.LinkRelation.PRIMARY_CONTENT;
99102
import static com.emc.documentum.rest.client.sample.model.LinkRelation.RELATIONS;
100103
import static com.emc.documentum.rest.client.sample.model.LinkRelation.RELATION_TYPES;
104+
import static com.emc.documentum.rest.client.sample.model.LinkRelation.REPLIES;
101105
import static com.emc.documentum.rest.client.sample.model.LinkRelation.REPOSITORIES;
102106
import static com.emc.documentum.rest.client.sample.model.LinkRelation.SEARCH;
103107
import static com.emc.documentum.rest.client.sample.model.LinkRelation.SELF;
@@ -580,6 +584,33 @@ public Permission getPermission(Linkable linkable, String... params) {
580584
public PermissionSet getPermissionSet(Linkable linkable, String... params) {
581585
return get(linkable.getHref(LinkRelation.PERMISSION_SET), false, JaxbPermissionSet.class, params);
582586
}
587+
588+
@Override
589+
public Feed<Comment> getComments(Linkable parent, String... params) {
590+
Feed<? extends Comment> feed = get(parent.getHref(COMMENTS), true, JaxbFeed.class, params);
591+
return (Feed<Comment>)feed;
592+
}
593+
594+
@Override
595+
public Comment createComment(Linkable parent, Comment comment) {
596+
return post(parent.getHref(COMMENTS), new JaxbComment(comment), JaxbComment.class);
597+
}
598+
599+
@Override
600+
public Comment getComment(String commentUri, String... params) {
601+
return get(commentUri, false, JaxbComment.class, params);
602+
}
603+
604+
@Override
605+
public Feed<Comment> getReplies(Linkable parent, String... params) {
606+
Feed<? extends Comment> feed = get(parent.getHref(REPLIES), true, JaxbFeed.class, params);
607+
return (Feed<Comment>)feed;
608+
}
609+
610+
@Override
611+
public Comment createReply(Linkable parent, Comment comment) {
612+
return post(parent.getHref(REPLIES), new JaxbComment(comment), JaxbComment.class);
613+
}
583614

584615
@Override
585616
public <T extends Linkable> Feed<T> nextPage(Feed<T> feed) {

src/main/java/com/emc/documentum/rest/client/sample/client/util/Debug.java

+27
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
*/
44
package com.emc.documentum.rest.client.sample.client.util;
55

6+
import java.lang.reflect.Field;
7+
import java.util.Arrays;
68
import java.util.List;
79

810
import javax.xml.transform.Source;
@@ -110,6 +112,31 @@ public static void print(RestObject object, String... properties) {
110112
System.out.println(sb);
111113
}
112114

115+
public static void printFields(Object object, String... fields) {
116+
StringBuilder sb = new StringBuilder();
117+
if(fields == null || fields.length == 0) {
118+
fields = new String[object.getClass().getDeclaredFields().length];
119+
for(int i=0;i<fields.length;++i) {
120+
fields[i] = object.getClass().getDeclaredFields()[i].getName();
121+
}
122+
Arrays.sort(fields);
123+
}
124+
for(String p : fields) {
125+
if(sb.length() > 0) {
126+
sb.append(", ");
127+
}
128+
try {
129+
Field f = object.getClass().getDeclaredField(p);
130+
f.setAccessible(true);
131+
sb.append(p.replaceAll("([A-Z])", " $1").toLowerCase()).append(':').append(f.get(object));
132+
} catch (Exception e) {
133+
e.printStackTrace();
134+
throw new IllegalArgumentException(p);
135+
}
136+
}
137+
System.out.println(sb);
138+
}
139+
113140
public static void print(Batch batch) {
114141
System.out.println((batch.getDescription()==null?"":(batch.getDescription()+" ")) + "started: " + batch.getStarted() + ", finished: " + batch.getFinished() + ", state: " + batch.getState() + (batch.getSubstate() == null ? "" : (", substate: " + batch.getSubstate())));
115142
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.emc.documentum.rest.client.sample.model;
2+
3+
public interface Comment extends Linkable {
4+
public String getObjectId();
5+
public String getCommentId();;
6+
public String getOwnerName();
7+
public String getCreationDate();
8+
public String getModifyDate();
9+
public String getContentValue();
10+
public String getParentId();
11+
public String getTitle();
12+
public boolean isCanDelete();
13+
public boolean isCanReply();
14+
}

src/main/java/com/emc/documentum/rest/client/sample/model/LinkRelation.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public enum LinkRelation {
3232
TYPES("types", true),
3333
ASPECT_TYPES("aspect-types", true),
3434
ASSIS_VALUES("assist-values", true),
35-
OBJECT_ASPECTS("object-aspects", true),
35+
ACL("acl", true),
3636

3737
// Documentum specific link relations
3838
FOLDERS("folders", true),
@@ -50,7 +50,9 @@ public enum LinkRelation {
5050
ASSOCIATIONS("associations", true),
5151
PERMISSIONS("permissions", true),
5252
PERMISSION_SET("permission-set", true),
53-
ACL("acl", true),
53+
OBJECT_ASPECTS("object-aspects", true),
54+
COMMENTS("comments", true),
55+
REPLIES("replies", true),
5456

5557
//Home Document link relations
5658
REPOSITORIES("repositories", true),

src/main/java/com/emc/documentum/rest/client/sample/model/json/JsonBatch.java

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public void addOperation(Operation op) {
162162
operations.add((JsonBatchOperation)op);
163163
}
164164

165+
@SuppressWarnings("deprecation")
165166
@Override
166167
public boolean hasAttachment() {
167168
for(Operation o : operations) {

0 commit comments

Comments
 (0)