Skip to content

Commit

Permalink
support comment related
Browse files Browse the repository at this point in the history
  • Loading branch information
ruan-wei committed Aug 3, 2016
1 parent 6881994 commit adbade0
Show file tree
Hide file tree
Showing 16 changed files with 691 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2016. EMC Corporation. All Rights Reserved.
*/
package com.emc.documentum.rest.client.sample.cases;

import com.emc.documentum.rest.client.sample.client.annotation.RestServiceSample;
import com.emc.documentum.rest.client.sample.client.annotation.RestServiceVersion;
import com.emc.documentum.rest.client.sample.model.Comment;
import com.emc.documentum.rest.client.sample.model.Feed;
import com.emc.documentum.rest.client.sample.model.RestObject;
import com.emc.documentum.rest.client.sample.model.plain.PlainComment;
import com.emc.documentum.rest.client.sample.model.plain.PlainRestObject;

import static com.emc.documentum.rest.client.sample.client.util.Debug.printEntryContentSrc;
import static com.emc.documentum.rest.client.sample.client.util.Debug.printFields;
import static com.emc.documentum.rest.client.sample.client.util.Debug.printNewLine;
import static com.emc.documentum.rest.client.sample.client.util.Debug.printStep;

@RestServiceSample("Comments and Replies")
@RestServiceVersion(7.3)
public class CommentSample extends Sample {
public void acls() {
RestObject tempCabinet = client.getCabinet("Temp");
RestObject object = new PlainRestObject("object_name", "obj_for_comment");
RestObject createdObject = client.createObject(tempCabinet, object);

printStep("create a comment for the object " + createdObject.getObjectId());
Comment createdComment1 = client.createComment(createdObject, new PlainComment("this is my first comment"));
printFields(createdComment1);
printNewLine();

printStep("create another comment for the object " + createdObject.getObjectId());
Comment createdComment2 = client.createComment(createdObject, new PlainComment("this is my second comment"));
printFields(createdComment2);
printNewLine();

printStep("get comments feed of the object " + createdObject.getObjectId());
Feed<Comment> comments = client.getComments(createdObject);
printEntryContentSrc(comments);
printNewLine();

printStep("create a replay for the first comment " + createdComment1.getCommentId());
Comment createdReply1 = client.createReply(createdComment1, new PlainComment("this is my first reply"));
printFields(createdReply1);
printNewLine();

printStep("create another replay for the first comment " + createdComment1.getCommentId());
Comment createdReply2 = client.createReply(createdComment1, new PlainComment("this is my second reply"));
printFields(createdReply2);
printNewLine();

printStep("get replies feed of the first comment " + createdComment1.getCommentId());
Feed<Comment> replies = client.getReplies(createdComment1);
printEntryContentSrc(replies);
printNewLine();

printStep("delete the comments and replies");
client.delete(createdReply1);
printHttpStatus();
client.delete(createdReply2);
printHttpStatus();
client.delete(createdComment1);
printHttpStatus();
client.delete(createdComment2);
printHttpStatus();

client.delete(createdObject);
printNewLine();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.http.HttpStatus;

import com.emc.documentum.rest.client.sample.client.annotation.NotBatchable;
import com.emc.documentum.rest.client.sample.model.Comment;
import com.emc.documentum.rest.client.sample.model.Feed;
import com.emc.documentum.rest.client.sample.model.FolderLink;
import com.emc.documentum.rest.client.sample.model.HomeDocument;
Expand Down Expand Up @@ -839,4 +840,41 @@ public interface DCTMRestClient {
* @return the permission set object
*/
public PermissionSet getPermissionSet(Linkable linkable, String... params);

/**
* @param parent the parent object
* @param params the query parameters
* @return the comments feed of the specified object
*/
public Feed<Comment> getComments(Linkable parent, String... params);

/**
* create a Comment of the specified object
* @param parent the object to create comment to
* @param comment the comment to be created
* @return the created comment
*/
public Comment createComment(Linkable parent, Comment comment);

/**
* @param commentUri the uri of the comment
* @param params the query parameters
* @return the comment of the specified uri
*/
public Comment getComment(String commentUri, String... params);

/**
* @param parent the parent comment
* @param params the query parameters
* @return the comment replies feed of the specified comment
*/
public Feed<Comment> getReplies(Linkable parent, String... params);

/**
* create a reply of the specified comment
* @param parent the comment to create reply to
* @param comment the reply to be created
* @return the created reply
*/
public Comment createReply(Linkable parent, Comment comment);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.emc.documentum.rest.client.sample.client.impl.AbstractRestTemplateClient;
import com.emc.documentum.rest.client.sample.client.util.Headers;
import com.emc.documentum.rest.client.sample.client.util.UriHelper;
import com.emc.documentum.rest.client.sample.model.Comment;
import com.emc.documentum.rest.client.sample.model.Entry;
import com.emc.documentum.rest.client.sample.model.Feed;
import com.emc.documentum.rest.client.sample.model.FolderLink;
Expand All @@ -39,6 +40,7 @@
import com.emc.documentum.rest.client.sample.model.batch.Capabilities;
import com.emc.documentum.rest.client.sample.model.json.JsonBatch;
import com.emc.documentum.rest.client.sample.model.json.JsonBatchCapabilities;
import com.emc.documentum.rest.client.sample.model.json.JsonComment;
import com.emc.documentum.rest.client.sample.model.json.JsonFeeds;
import com.emc.documentum.rest.client.sample.model.json.JsonFolderLink;
import com.emc.documentum.rest.client.sample.model.json.JsonHomeDocument;
Expand Down Expand Up @@ -66,6 +68,7 @@
import static com.emc.documentum.rest.client.sample.model.LinkRelation.CHECKIN_NEXT_MAJOR;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.CHECKIN_NEXT_MINOR;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.CHECKOUT;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.COMMENTS;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.CONTENTS;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.CURRENT_USER_PREFERENCES;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.DELETE;
Expand All @@ -86,6 +89,7 @@
import static com.emc.documentum.rest.client.sample.model.LinkRelation.PRIMARY_CONTENT;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.RELATIONS;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.RELATION_TYPES;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.REPLIES;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.REPOSITORIES;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.SEARCH;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.SELF;
Expand Down Expand Up @@ -583,6 +587,33 @@ public PermissionSet getPermissionSet(Linkable linkable, String... params) {
return get(linkable.getHref(LinkRelation.PERMISSION_SET), false, JsonPermissionSet.class, params);
}

@Override
public Feed<Comment> getComments(Linkable parent, String... params) {
Feed<? extends Comment> feed = get(parent.getHref(COMMENTS), true, JsonFeeds.CommentFeed.class, params);
return (Feed<Comment>)feed;
}

@Override
public Comment createComment(Linkable parent, Comment comment) {
return post(parent.getHref(COMMENTS), new JsonComment(comment), JsonComment.class);
}

@Override
public Comment getComment(String commentUri, String... params) {
return get(commentUri, false, JsonComment.class, params);
}

@Override
public Feed<Comment> getReplies(Linkable parent, String... params) {
Feed<? extends Comment> feed = get(parent.getHref(REPLIES), true, JsonFeeds.CommentFeed.class, params);
return (Feed<Comment>)feed;
}

@Override
public Comment createReply(Linkable parent, Comment comment) {
return post(parent.getHref(REPLIES), new JsonComment(comment), JsonComment.class);
}

@Override
public <T extends Linkable> Feed<T> nextPage(Feed<T> feed) {
return page(feed.getHref(PAGING_NEXT), feed.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.emc.documentum.rest.client.sample.client.impl.AbstractRestTemplateClient;
import com.emc.documentum.rest.client.sample.client.util.Headers;
import com.emc.documentum.rest.client.sample.client.util.UriHelper;
import com.emc.documentum.rest.client.sample.model.Comment;
import com.emc.documentum.rest.client.sample.model.Entry;
import com.emc.documentum.rest.client.sample.model.Feed;
import com.emc.documentum.rest.client.sample.model.FolderLink;
Expand All @@ -42,6 +43,7 @@
import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbBatch;
import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbBatchCapabilities;
import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbCabinet;
import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbComment;
import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbContent;
import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbDocument;
import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbFeed;
Expand Down Expand Up @@ -78,6 +80,7 @@
import static com.emc.documentum.rest.client.sample.model.LinkRelation.CHECKIN_NEXT_MAJOR;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.CHECKIN_NEXT_MINOR;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.CHECKOUT;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.COMMENTS;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.CONTENTS;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.CURRENT_USER_PREFERENCES;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.DELETE;
Expand All @@ -98,6 +101,7 @@
import static com.emc.documentum.rest.client.sample.model.LinkRelation.PRIMARY_CONTENT;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.RELATIONS;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.RELATION_TYPES;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.REPLIES;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.REPOSITORIES;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.SEARCH;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.SELF;
Expand Down Expand Up @@ -580,6 +584,33 @@ public Permission getPermission(Linkable linkable, String... params) {
public PermissionSet getPermissionSet(Linkable linkable, String... params) {
return get(linkable.getHref(LinkRelation.PERMISSION_SET), false, JaxbPermissionSet.class, params);
}

@Override
public Feed<Comment> getComments(Linkable parent, String... params) {
Feed<? extends Comment> feed = get(parent.getHref(COMMENTS), true, JaxbFeed.class, params);
return (Feed<Comment>)feed;
}

@Override
public Comment createComment(Linkable parent, Comment comment) {
return post(parent.getHref(COMMENTS), new JaxbComment(comment), JaxbComment.class);
}

@Override
public Comment getComment(String commentUri, String... params) {
return get(commentUri, false, JaxbComment.class, params);
}

@Override
public Feed<Comment> getReplies(Linkable parent, String... params) {
Feed<? extends Comment> feed = get(parent.getHref(REPLIES), true, JaxbFeed.class, params);
return (Feed<Comment>)feed;
}

@Override
public Comment createReply(Linkable parent, Comment comment) {
return post(parent.getHref(REPLIES), new JaxbComment(comment), JaxbComment.class);
}

@Override
public <T extends Linkable> Feed<T> nextPage(Feed<T> feed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*/
package com.emc.documentum.rest.client.sample.client.util;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;

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

public static void printFields(Object object, String... fields) {
StringBuilder sb = new StringBuilder();
if(fields == null || fields.length == 0) {
fields = new String[object.getClass().getDeclaredFields().length];
for(int i=0;i<fields.length;++i) {
fields[i] = object.getClass().getDeclaredFields()[i].getName();
}
Arrays.sort(fields);
}
for(String p : fields) {
if(sb.length() > 0) {
sb.append(", ");
}
try {
Field f = object.getClass().getDeclaredField(p);
f.setAccessible(true);
sb.append(p.replaceAll("([A-Z])", " $1").toLowerCase()).append(':').append(f.get(object));
} catch (Exception e) {
e.printStackTrace();
throw new IllegalArgumentException(p);
}
}
System.out.println(sb);
}

public static void print(Batch batch) {
System.out.println((batch.getDescription()==null?"":(batch.getDescription()+" ")) + "started: " + batch.getStarted() + ", finished: " + batch.getFinished() + ", state: " + batch.getState() + (batch.getSubstate() == null ? "" : (", substate: " + batch.getSubstate())));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.emc.documentum.rest.client.sample.model;

public interface Comment extends Linkable {
public String getObjectId();
public String getCommentId();;
public String getOwnerName();
public String getCreationDate();
public String getModifyDate();
public String getContentValue();
public String getParentId();
public String getTitle();
public boolean isCanDelete();
public boolean isCanReply();
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public enum LinkRelation {
TYPES("types", true),
ASPECT_TYPES("aspect-types", true),
ASSIS_VALUES("assist-values", true),
OBJECT_ASPECTS("object-aspects", true),
ACL("acl", true),

// Documentum specific link relations
FOLDERS("folders", true),
Expand All @@ -50,7 +50,9 @@ public enum LinkRelation {
ASSOCIATIONS("associations", true),
PERMISSIONS("permissions", true),
PERMISSION_SET("permission-set", true),
ACL("acl", true),
OBJECT_ASPECTS("object-aspects", true),
COMMENTS("comments", true),
REPLIES("replies", true),

//Home Document link relations
REPOSITORIES("repositories", true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public void addOperation(Operation op) {
operations.add((JsonBatchOperation)op);
}

@SuppressWarnings("deprecation")
@Override
public boolean hasAttachment() {
for(Operation o : operations) {
Expand Down
Loading

0 comments on commit adbade0

Please sign in to comment.