Skip to content

Commit

Permalink
support search template(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruan-wei committed Aug 12, 2016
1 parent 46f7e41 commit 7a92fda
Show file tree
Hide file tree
Showing 22 changed files with 1,108 additions and 223 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@

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.Feed;
import com.emc.documentum.rest.client.sample.model.RestObject;
import com.emc.documentum.rest.client.sample.model.Search;
import com.emc.documentum.rest.client.sample.model.Search.FacetDefinition;
import com.emc.documentum.rest.client.sample.model.Search.PropertyExpression;
import com.emc.documentum.rest.client.sample.model.SearchFeed;
import com.emc.documentum.rest.client.sample.model.SearchTemplate;
import com.emc.documentum.rest.client.sample.model.builder.SearchBuilder;
import com.emc.documentum.rest.client.sample.model.plain.PlainSearchTemplate;

import static com.emc.documentum.rest.client.sample.client.util.Debug.debugSerialize;
import static com.emc.documentum.rest.client.sample.client.util.Debug.print;
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.printSearchFeed;
import static com.emc.documentum.rest.client.sample.client.util.Debug.printStep;
Expand Down Expand Up @@ -49,4 +56,66 @@ public void search() {
printSearchFeed(result);
printNewLine();
}

public void searchTemplate() {
printStep("create a standard search template without external variable");
SearchBuilder builder = SearchBuilder.builder(client);
Search search = builder.allVersions(true)
.facetDefinition("f1", Arrays.asList("r_object_type"), FacetDefinition.GROUP_BY_ALPHARANGE, FacetDefinition.SORT_FREQUENCY, 8, "range", "a:e, f:z")
.facetDefinition("f2", Arrays.asList("r_modify_date"), FacetDefinition.GROUP_BY_DATE_RELATIVE_DATE, FacetDefinition.SORT_VALUE_ASCENDING, 9)
.pathLocation("/Temp", false)
.types("dm_sysobject")
.columns("r_object_id", "r_object_type", "object_name")
.fullTextExpression("test", true)
.propertyExpression("object_name", "test", PropertyExpression.OPERATOR_CONTAINS, false, false, false, true)
.sort("r_object_id", false, null, null)
.build();
SearchTemplate createdSearchTemplateWithoutVariables = client.createSearchTemmplate(new PlainSearchTemplate(search, "object_name", "my-search-template-without-variables"));
print(createdSearchTemplateWithoutVariables, "r_object_id", "object_name", "r_object_type", "r_is_public");
printNewLine();

printStep("get the single search template " + createdSearchTemplateWithoutVariables.getObjectName());
SearchTemplate searchTemplateWithoutVariables = client.getSearchTemplate(createdSearchTemplateWithoutVariables.self());
print(searchTemplateWithoutVariables, "r_object_id", "object_name", "r_object_type", "r_is_public");
printFields(searchTemplateWithoutVariables.getExternalVariables(), "variableType", "id", "expressionType", "dataType", "propertyName", "operator", "variableValue");
System.out.println("The aql is: ");
debugSerialize(client, searchTemplateWithoutVariables.getSearch());
printNewLine();

printStep("create a search template with external variables");
search = builder.reset()
.allVersions(true)
.facetDefinition("f1", Arrays.asList("r_object_type"), FacetDefinition.GROUP_BY_ALPHARANGE, FacetDefinition.SORT_FREQUENCY, 8, "range", "a:e, f:z")
.facetDefinition("f2", Arrays.asList("r_modify_date"), FacetDefinition.GROUP_BY_DATE_RELATIVE_DATE, FacetDefinition.SORT_VALUE_ASCENDING, 9)
.pathLocation("/Temp", false)
.types("dm_sysobject")
.columns("r_object_id", "r_object_type", "object_name")
.fullTextExpression("test", true).asTemplate()
.propertyExpression("object_name", "test", PropertyExpression.OPERATOR_CONTAINS, false, false, false, true).asTemplate()
.sort("r_object_id", false, null, null)
.build();
SearchTemplate createdSearchTemplateWithVariables = client.createSearchTemmplate(new PlainSearchTemplate(search, "object_name", "my-search-template-with-variables"));
print(createdSearchTemplateWithVariables, "r_object_id", "object_name", "r_object_type", "r_is_public");
printNewLine();

printStep("get a single search template " + createdSearchTemplateWithVariables.getObjectName());
SearchTemplate searchTemplateWithVariables = client.getSearchTemplate(createdSearchTemplateWithVariables.self());
print(searchTemplateWithVariables, "r_object_id", "object_name", "r_object_type", "r_is_public");
printFields(searchTemplateWithVariables.getExternalVariables(), "variableType", "id", "expressionType", "dataType", "propertyName", "operator", "variableValue");
System.out.println("The aql is: ");
debugSerialize(client, searchTemplateWithVariables.getSearch());
printNewLine();

printStep("get all search templates");
Feed<SearchTemplate> searchTemplates = client.getSearchTemplates();
printEntryContentSrc(searchTemplates);
printNewLine();

printStep("delete the created search templates");
client.delete(searchTemplateWithoutVariables);
printHttpStatus();
client.delete(searchTemplateWithVariables);
printHttpStatus();
printNewLine();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.emc.documentum.rest.client.sample.model.RestType;
import com.emc.documentum.rest.client.sample.model.Search;
import com.emc.documentum.rest.client.sample.model.SearchFeed;
import com.emc.documentum.rest.client.sample.model.SearchTemplate;
import com.emc.documentum.rest.client.sample.model.ValueAssistant;
import com.emc.documentum.rest.client.sample.model.ValueAssistantRequest;
import com.emc.documentum.rest.client.sample.model.VirtualDocumentNode;
Expand Down Expand Up @@ -894,4 +895,26 @@ public interface DCTMRestClient {
* @return the virtual document nodes feed of the specified object
*/
public Feed<VirtualDocumentNode> getVirtualDocumentNodes(Linkable linkable, String... params);

/**
* get search templates of the repository
* @param params the query parameters
* @return the search template feed
*/
public Feed<SearchTemplate> getSearchTemplates(String... params);

/**
* get single search template
* @param uri the uri of the search template
* @param params the query parameters
* @return the search template
*/
public SearchTemplate getSearchTemplate(String uri, String... params);

/**
* create a search template
* @param template the search template to be created
* @return the created search template
*/
public SearchTemplate createSearchTemmplate(SearchTemplate template);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public final class DCTMRestClientBuilder {
private boolean ignoreAuthenticateServer;

/**
* build the DCTMRestClient with the promption
* build the DCTMRestClient with the prompt
* @return the DCTMRestClient
*/
public static DCTMRestClient buildWithPrompt() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.emc.documentum.rest.client.sample.model.RestType;
import com.emc.documentum.rest.client.sample.model.Search;
import com.emc.documentum.rest.client.sample.model.SearchFeed;
import com.emc.documentum.rest.client.sample.model.SearchTemplate;
import com.emc.documentum.rest.client.sample.model.ValueAssistant;
import com.emc.documentum.rest.client.sample.model.ValueAssistantRequest;
import com.emc.documentum.rest.client.sample.model.VirtualDocumentNode;
Expand All @@ -52,11 +53,11 @@
import com.emc.documentum.rest.client.sample.model.json.JsonPermissionSet;
import com.emc.documentum.rest.client.sample.model.json.JsonPreference;
import com.emc.documentum.rest.client.sample.model.json.JsonRepository;
import com.emc.documentum.rest.client.sample.model.json.JsonSearchTemplate;
import com.emc.documentum.rest.client.sample.model.json.JsonType;
import com.emc.documentum.rest.client.sample.model.json.JsonValueAssistance;
import com.emc.documentum.rest.client.sample.model.json.JsonValueAssistantRequest;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;

import static com.emc.documentum.rest.client.sample.model.LinkRelation.ABOUT;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.ACLS;
Expand Down Expand Up @@ -94,6 +95,7 @@
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.SEARCH_TEMPLATES;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.SELF;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.SHARED_PARENT;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.TYPES;
Expand All @@ -106,8 +108,6 @@
*/
@NotThreadSafe
public class DCTMJacksonClient extends AbstractRestTemplateClient implements DCTMRestClient {
private final ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_EMPTY);

public DCTMJacksonClient(String contextRoot, String repositoryName,
String username, String password, boolean useFormatExtension) {
super(contextRoot, repositoryName, username, password, useFormatExtension);
Expand Down Expand Up @@ -629,6 +629,22 @@ public Feed<VirtualDocumentNode> getVirtualDocumentNodes(Linkable linkable, Stri
return (Feed<VirtualDocumentNode>)feed;
}

@Override
public Feed<SearchTemplate> getSearchTemplates(String... params) {
Feed<? extends SearchTemplate> feed = get(getRepository().getHref(SEARCH_TEMPLATES), true, JsonFeeds.SearchTemplateFeed.class, params);
return (Feed<SearchTemplate>)feed;
}

@Override
public SearchTemplate getSearchTemplate(String uri, String... params) {
return get(uri, false, JsonSearchTemplate.class, params);
}

@Override
public SearchTemplate createSearchTemmplate(SearchTemplate template) {
return post(getRepository().getHref(SEARCH_TEMPLATES), new JsonSearchTemplate(template), JsonSearchTemplate.class);
}

@Override
public <T extends Linkable> Feed<T> nextPage(Feed<T> feed) {
return page(feed.getHref(PAGING_NEXT), feed.getClass());
Expand Down Expand Up @@ -685,7 +701,7 @@ protected void initRestTemplate(RestTemplate restTemplate) {
@Override
public void serialize(Object object, OutputStream os) {
try {
mapper.writeValue(os, object);
DCTMJacksonMapper.marshal(os, object);
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2016. EMC Corporation. All Rights Reserved.
*/
package com.emc.documentum.rest.client.sample.client.impl.jackson;

import java.io.ByteArrayOutputStream;
import java.io.OutputStream;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
* the class to unmarshal the xml
*/
public final class DCTMJacksonMapper {
private static final ObjectMapper MAPPER = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_EMPTY);

public static <T> T unmarshal(String json, Class<T> clazz) {
T obj = null;
try {
obj = MAPPER.readValue(json, clazz);
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
return obj;
}

public static void marshal(OutputStream os, Object object) {
try {
MAPPER.writeValue(os, object);
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
}

public static String marshal(Object object) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
marshal(os, object);
return os.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.emc.documentum.rest.client.sample.model.RestType;
import com.emc.documentum.rest.client.sample.model.Search;
import com.emc.documentum.rest.client.sample.model.SearchFeed;
import com.emc.documentum.rest.client.sample.model.SearchTemplate;
import com.emc.documentum.rest.client.sample.model.ValueAssistant;
import com.emc.documentum.rest.client.sample.model.ValueAssistantRequest;
import com.emc.documentum.rest.client.sample.model.VirtualDocumentNode;
Expand Down Expand Up @@ -66,6 +67,7 @@
import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbRelationType;
import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbRepository;
import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbSearchFeed;
import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbSearchTemplate;
import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbSysObject;
import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbType;
import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbUser;
Expand Down Expand Up @@ -108,6 +110,7 @@
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.SEARCH_TEMPLATES;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.SELF;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.SHARED_PARENT;
import static com.emc.documentum.rest.client.sample.model.LinkRelation.TYPES;
Expand Down Expand Up @@ -629,6 +632,22 @@ public Feed<VirtualDocumentNode> getVirtualDocumentNodes(Linkable linkable, Stri
return (Feed<VirtualDocumentNode>)feed;
}

@Override
public Feed<SearchTemplate> getSearchTemplates(String... params) {
Feed<JaxbSearchTemplate> feed = get(getRepository().getHref(SEARCH_TEMPLATES), true, JaxbFeed.class, params);
return (Feed)feed;
}

@Override
public SearchTemplate getSearchTemplate(String uri, String... params) {
return get(uri, false, JaxbSearchTemplate.class, params);
}

@Override
public SearchTemplate createSearchTemmplate(SearchTemplate template) {
return post(getRepository().getHref(SEARCH_TEMPLATES), new JaxbSearchTemplate(template), JaxbSearchTemplate.class);
}

@Override
public <T extends Linkable> Feed<T> nextPage(Feed<T> feed) {
return page(feed.getHref(PAGING_NEXT));
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.impl.jaxb;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;

import javax.xml.bind.JAXBContext;
Expand Down Expand Up @@ -32,12 +34,36 @@ public static Object unmarshal(Node node) {
try {
obj = context.createUnmarshaller().unmarshal(node);
} catch (JAXBException e) {
e.printStackTrace();
throw new IllegalArgumentException(e);
}
return obj;
}

public static Object unmarshal(String xml) {
Object obj = null;
try {
obj = context.createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes()));
} catch (JAXBException e) {
throw new IllegalArgumentException(e);
}
return obj;
}

public static void marshal(OutputStream os, Object object) throws Exception {
context.createMarshaller().marshal(object, os);
public static void marshal(OutputStream os, Object object) {
try {
context.createMarshaller().marshal(object, os);
} catch (JAXBException e) {
throw new IllegalArgumentException(e);
}
}

public static String marshal(Object object) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
context.createMarshaller().marshal(object, os);
} catch (JAXBException e) {
throw new IllegalArgumentException(e);
}
return os.toString();
}
}
Loading

0 comments on commit 7a92fda

Please sign in to comment.