Skip to content

Commit

Permalink
add support for link/unlink/move/copy
Browse files Browse the repository at this point in the history
  • Loading branch information
ruan-wei committed May 25, 2016
1 parent 6acacb7 commit 7b15740
Show file tree
Hide file tree
Showing 30 changed files with 808 additions and 302 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import javax.annotation.concurrent.NotThreadSafe;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;

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;
import com.emc.documentum.rest.client.sample.model.LinkRelation;
import com.emc.documentum.rest.client.sample.model.Linkable;
Expand Down Expand Up @@ -190,6 +192,17 @@ public interface DCTMRestClient {
*/
public RestObject update(RestObject oldObject, RestObject newObject, String... params);

/**
* update the RestObject with new properties
* @param oldObject
* @param rel
* @param newObject
* @param method
* @param params
* @return
*/
public RestObject update(RestObject oldObject, LinkRelation rel, RestObject newObject, HttpMethod method, String... params);

/**
* delete the resource
* @param linkable
Expand Down Expand Up @@ -516,4 +529,37 @@ public interface DCTMRestClient {
* @return
*/
public RestObject getNetworkLocation(String uri, String... params);

/**
* get folder links of the object
* @param params
* @return
*/
public Feed<FolderLink> getFolderLinks(RestObject object, LinkRelation rel, String... params);

/**
* get single folder link
* @param uri
* @param params
* @return
*/
public FolderLink getFolderLink(String uri, String... params);

/**
* move the object by the folder link
* @param oldLink
* @param newLink
* @param params
* @return
*/
public FolderLink move(FolderLink oldLink, FolderLink newLink, String... params);

/**
* link an object to another place
* @param object
* @param rel
* @param link
* @return
*/
public FolderLink link(RestObject object, LinkRelation rel, FolderLink link);
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@
import com.emc.documentum.rest.client.sample.model.Feed;
import com.emc.documentum.rest.client.sample.model.HomeDocument;
import com.emc.documentum.rest.client.sample.model.LinkRelation;
import com.emc.documentum.rest.client.sample.model.Linkable;
import com.emc.documentum.rest.client.sample.model.Repository;
import com.emc.documentum.rest.client.sample.model.RestError;
import com.emc.documentum.rest.client.sample.model.RestObject;

import static com.emc.documentum.rest.client.sample.model.LinkRelation.DELETE;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.EDIT;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.SELF;

/**
* the basic implementation with Spring RestTemplate
*/
Expand Down Expand Up @@ -268,6 +273,19 @@ public void delete(String uri, String... params) {
sendRequest(uri, HttpMethod.DELETE, isXml()?Headers.ACCEPT_XML_HEADERS:Headers.ACCEPT_JSON_HEADERS, null, null, params);
}

@Override
public void delete(Linkable linkable, String... params) {
if(linkable.getHref(DELETE) != null) {
delete(linkable.getHref(DELETE), params);
} else if(linkable.getHref(SELF) != null) {
delete(linkable.getHref(SELF), params);
} else if(linkable.getHref(EDIT) != null) {
delete(linkable.getHref(EDIT), params);
} else {
throw new IllegalArgumentException(String.valueOf(linkable));
}
}

protected <T> T post(String uri, Object body, Class<? extends T> responseBodyClass, String... params) {
return sendRequest(uri, HttpMethod.POST, isXml()?Headers.ACCEPT_XML_HEADERS_WITH_CONTENT:Headers.ACCEPT_JSON_HEADERS_WITH_CONTENT, body, responseBodyClass, params);
}
Expand All @@ -281,6 +299,24 @@ protected <T> T put(String uri, Class<? extends T> responseBodyClass, String...
return sendRequest(uri, HttpMethod.PUT, isXml()?Headers.ACCEPT_XML_HEADERS:Headers.ACCEPT_JSON_HEADERS, null, responseBodyClass, params);
}

@Override
public RestObject update(RestObject oldObject, LinkRelation rel, RestObject newObject, HttpMethod method, String... params) {
try {
RestObject newRestObject = newRestObject(oldObject, newObject);
if(method == HttpMethod.PUT) {
return put(oldObject.getHref(rel), newRestObject, newRestObject.getClass(), params);
} else {
return post(oldObject.getHref(rel), newRestObject, newRestObject.getClass(), params);
}
} catch (Exception e) {
throw new IllegalArgumentException(oldObject.getClass().getName());
}
}

protected <T> T put(String uri, Object body, Class<? extends T> responseBodyClass, String... params) {
return sendRequest(uri, HttpMethod.PUT, isXml()?Headers.ACCEPT_XML_HEADERS_WITH_CONTENT:Headers.ACCEPT_JSON_HEADERS_WITH_CONTENT, body, responseBodyClass, params);
}

protected <T> T post(String uri, T object, Object content, Class<? extends T> responseBodyClass, String... params) {
T t = null;
if(content == null) {
Expand Down
Loading

0 comments on commit 7b15740

Please sign in to comment.