From 7a92fda5c3b8c7024802f34223dd3e98fbf53b85 Mon Sep 17 00:00:00 2001 From: ruan-wei Date: Fri, 12 Aug 2016 10:10:40 +0800 Subject: [PATCH] support search template(s) --- .../client/sample/cases/SearchSample.java | 69 +++++ .../client/sample/client/DCTMRestClient.java | 23 ++ .../sample/client/DCTMRestClientBuilder.java | 2 +- .../impl/jackson/DCTMJacksonClient.java | 24 +- .../impl/jackson/DCTMJacksonMapper.java | 41 +++ .../client/impl/jaxb/DCTMJaxbClient.java | 19 ++ .../client/impl/jaxb/DCTMJaxbContext.java | 32 +- .../rest/client/sample/client/util/Debug.java | 45 ++- .../client/sample/model/LinkRelation.java | 4 + .../rest/client/sample/model/Search.java | 25 +- .../client/sample/model/SearchTemplate.java | 64 ++++ .../sample/model/builder/BatchBuilder.java | 5 +- .../sample/model/builder/SearchBuilder.java | 4 + .../client/sample/model/json/JsonFeeds.java | 3 + .../client/sample/model/json/JsonSearch.java | 292 +++++++++++------- .../sample/model/json/JsonSearchBuilder.java | 24 +- .../sample/model/json/JsonSearchTemplate.java | 206 ++++++++++++ .../model/plain/PlainSearchTemplate.java | 41 +++ .../sample/model/xml/jaxb/JaxbSearch.java | 201 +++++++----- .../model/xml/jaxb/JaxbSearchBuilder.java | 12 + .../model/xml/jaxb/JaxbSearchTemplate.java | 194 ++++++++++++ .../client/sample/model/xml/jaxb/jaxb.index | 1 + 22 files changed, 1108 insertions(+), 223 deletions(-) create mode 100644 src/main/java/com/emc/documentum/rest/client/sample/client/impl/jackson/DCTMJacksonMapper.java create mode 100644 src/main/java/com/emc/documentum/rest/client/sample/model/SearchTemplate.java create mode 100644 src/main/java/com/emc/documentum/rest/client/sample/model/json/JsonSearchTemplate.java create mode 100644 src/main/java/com/emc/documentum/rest/client/sample/model/plain/PlainSearchTemplate.java create mode 100644 src/main/java/com/emc/documentum/rest/client/sample/model/xml/jaxb/JaxbSearchTemplate.java diff --git a/src/main/java/com/emc/documentum/rest/client/sample/cases/SearchSample.java b/src/main/java/com/emc/documentum/rest/client/sample/cases/SearchSample.java index 8ae45c0..21f4485 100644 --- a/src/main/java/com/emc/documentum/rest/client/sample/cases/SearchSample.java +++ b/src/main/java/com/emc/documentum/rest/client/sample/cases/SearchSample.java @@ -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; @@ -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 searchTemplates = client.getSearchTemplates(); + printEntryContentSrc(searchTemplates); + printNewLine(); + + printStep("delete the created search templates"); + client.delete(searchTemplateWithoutVariables); + printHttpStatus(); + client.delete(searchTemplateWithVariables); + printHttpStatus(); + printNewLine(); + } } diff --git a/src/main/java/com/emc/documentum/rest/client/sample/client/DCTMRestClient.java b/src/main/java/com/emc/documentum/rest/client/sample/client/DCTMRestClient.java index df26070..f639959 100644 --- a/src/main/java/com/emc/documentum/rest/client/sample/client/DCTMRestClient.java +++ b/src/main/java/com/emc/documentum/rest/client/sample/client/DCTMRestClient.java @@ -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; @@ -894,4 +895,26 @@ public interface DCTMRestClient { * @return the virtual document nodes feed of the specified object */ public Feed getVirtualDocumentNodes(Linkable linkable, String... params); + + /** + * get search templates of the repository + * @param params the query parameters + * @return the search template feed + */ + public Feed 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); } diff --git a/src/main/java/com/emc/documentum/rest/client/sample/client/DCTMRestClientBuilder.java b/src/main/java/com/emc/documentum/rest/client/sample/client/DCTMRestClientBuilder.java index d4d90ce..6d97aeb 100644 --- a/src/main/java/com/emc/documentum/rest/client/sample/client/DCTMRestClientBuilder.java +++ b/src/main/java/com/emc/documentum/rest/client/sample/client/DCTMRestClientBuilder.java @@ -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() { diff --git a/src/main/java/com/emc/documentum/rest/client/sample/client/impl/jackson/DCTMJacksonClient.java b/src/main/java/com/emc/documentum/rest/client/sample/client/impl/jackson/DCTMJacksonClient.java index 2bc10ff..aa84e3d 100644 --- a/src/main/java/com/emc/documentum/rest/client/sample/client/impl/jackson/DCTMJacksonClient.java +++ b/src/main/java/com/emc/documentum/rest/client/sample/client/impl/jackson/DCTMJacksonClient.java @@ -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; @@ -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; @@ -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; @@ -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); @@ -629,6 +629,22 @@ public Feed getVirtualDocumentNodes(Linkable linkable, Stri return (Feed)feed; } + @Override + public Feed getSearchTemplates(String... params) { + Feed feed = get(getRepository().getHref(SEARCH_TEMPLATES), true, JsonFeeds.SearchTemplateFeed.class, params); + return (Feed)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 Feed nextPage(Feed feed) { return page(feed.getHref(PAGING_NEXT), feed.getClass()); @@ -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); } diff --git a/src/main/java/com/emc/documentum/rest/client/sample/client/impl/jackson/DCTMJacksonMapper.java b/src/main/java/com/emc/documentum/rest/client/sample/client/impl/jackson/DCTMJacksonMapper.java new file mode 100644 index 0000000..506e451 --- /dev/null +++ b/src/main/java/com/emc/documentum/rest/client/sample/client/impl/jackson/DCTMJacksonMapper.java @@ -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 unmarshal(String json, Class 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(); + } +} diff --git a/src/main/java/com/emc/documentum/rest/client/sample/client/impl/jaxb/DCTMJaxbClient.java b/src/main/java/com/emc/documentum/rest/client/sample/client/impl/jaxb/DCTMJaxbClient.java index bca3a07..6192b96 100644 --- a/src/main/java/com/emc/documentum/rest/client/sample/client/impl/jaxb/DCTMJaxbClient.java +++ b/src/main/java/com/emc/documentum/rest/client/sample/client/impl/jaxb/DCTMJaxbClient.java @@ -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; @@ -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; @@ -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; @@ -629,6 +632,22 @@ public Feed getVirtualDocumentNodes(Linkable linkable, Stri return (Feed)feed; } + @Override + public Feed getSearchTemplates(String... params) { + Feed 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 Feed nextPage(Feed feed) { return page(feed.getHref(PAGING_NEXT)); diff --git a/src/main/java/com/emc/documentum/rest/client/sample/client/impl/jaxb/DCTMJaxbContext.java b/src/main/java/com/emc/documentum/rest/client/sample/client/impl/jaxb/DCTMJaxbContext.java index c52c4f9..2b58688 100644 --- a/src/main/java/com/emc/documentum/rest/client/sample/client/impl/jaxb/DCTMJaxbContext.java +++ b/src/main/java/com/emc/documentum/rest/client/sample/client/impl/jaxb/DCTMJaxbContext.java @@ -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; @@ -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(); } } diff --git a/src/main/java/com/emc/documentum/rest/client/sample/client/util/Debug.java b/src/main/java/com/emc/documentum/rest/client/sample/client/util/Debug.java index e267b1f..a3b0a25 100644 --- a/src/main/java/com/emc/documentum/rest/client/sample/client/util/Debug.java +++ b/src/main/java/com/emc/documentum/rest/client/sample/client/util/Debug.java @@ -6,6 +6,7 @@ import java.io.ByteArrayOutputStream; import java.lang.reflect.Field; import java.util.Arrays; +import java.util.Collection; import java.util.List; import javax.xml.transform.Source; @@ -104,8 +105,12 @@ public static void debugContent(Object content) { } public static void printEntryContentSrc(Feed feed) { - for(Entry e : feed.getEntries()) { - System.out.println(e.getTitle() + " -> " + e.getContentSrc()); + if(feed.getEntries() != null) { + for(Entry e : feed.getEntries()) { + System.out.println(e.getTitle() + " -> " + e.getContentSrc()); + } + } else { + System.out.println("no entries"); } } @@ -166,6 +171,16 @@ public static void print(RestObject object, String... properties) { System.out.println(sb); } + public static void printFields(Collection objects, String... fields) { + if(objects == null || objects.isEmpty()) { + System.out.println("no result"); + } else { + for(Object o : objects) { + printFields(o, fields); + } + } + } + public static void printFields(Object object, String... fields) { StringBuilder sb = new StringBuilder(); if(fields == null || fields.length == 0) { @@ -176,13 +191,14 @@ public static void printFields(Object object, String... fields) { 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)); + Field f = getField(object.getClass(), p); + if(f != null) { + if(sb.length() > 0) { + sb.append(", "); + } + sb.append(p.replaceAll("([A-Z])", " $1").toLowerCase()).append(':').append(f.get(object)); + } } catch (Exception e) { e.printStackTrace(); throw new IllegalArgumentException(p); @@ -191,6 +207,19 @@ public static void printFields(Object object, String... fields) { System.out.println(sb); } + private static Field getField(Class clazz, String field) { + if(clazz == null || field == null) { + return null; + } + try { + Field f = clazz.getDeclaredField(field); + f.setAccessible(true); + return f; + } catch(NoSuchFieldException no) { + return getField(clazz.getSuperclass(), field); + } + } + 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()))); } diff --git a/src/main/java/com/emc/documentum/rest/client/sample/model/LinkRelation.java b/src/main/java/com/emc/documentum/rest/client/sample/model/LinkRelation.java index 1c8339c..90a8410 100644 --- a/src/main/java/com/emc/documentum/rest/client/sample/model/LinkRelation.java +++ b/src/main/java/com/emc/documentum/rest/client/sample/model/LinkRelation.java @@ -85,6 +85,10 @@ public enum LinkRelation { DQL("dql", true), SEARCH("search", true), + SAVED_SEARCHES("saved-searches", true), + SAVED_SEARCH_SAVED_RESULTS("saved-search-results", true), + SAVED_SEARCH_EXECUTION("search-execution", true), + SEARCH_TEMPLATES("search-templates", true), CABINETS("cabinets", true), FORMATS("formats", true), NETWORK_LOCATIONS("network-locations", true), diff --git a/src/main/java/com/emc/documentum/rest/client/sample/model/Search.java b/src/main/java/com/emc/documentum/rest/client/sample/model/Search.java index 0ed2eee..fce4564 100644 --- a/src/main/java/com/emc/documentum/rest/client/sample/model/Search.java +++ b/src/main/java/com/emc/documentum/rest/client/sample/model/Search.java @@ -7,6 +7,7 @@ import java.util.Map; public interface Search extends Linkable { + public List getRepositories(); public List getTypes(); public List getColumns(); public List getSorts(); @@ -24,13 +25,14 @@ public interface Column { public interface Sort { public String getProperty(); - public Boolean isAscending(); + public Boolean getAscending(); public String getLang(); - public Boolean isAscii(); + public Boolean getAscii(); } public interface Location { - public boolean isDescendent(); + public String getRepository(); + public Boolean getDescendent(); } public interface IdLocation extends Location { @@ -41,7 +43,6 @@ public interface PathLocation extends Location { public String getPath(); } - public interface FacetDefinition { public static final String SORT_FREQUENCY = "FREQUENCY"; public static final String SORT_VALUE_ASCENDING = "VALUE_ASCENDING"; @@ -66,6 +67,7 @@ public interface FacetDefinition { } public interface Expression { + public Boolean getTemplate(); } public interface ExpressionSet extends Expression { @@ -92,14 +94,14 @@ public interface PropertyExpression extends Expression { public String getName(); public String getValue(); public String getOperator(); - public boolean isExactMatch(); - public boolean isRepeated(); - public boolean isCaseSensitive(); - public boolean isFuzzy(); + public Boolean getExactMatch(); + public Boolean getRepeating(); + public Boolean getCaseSensitive(); + public Boolean getFuzzy(); } public interface FullTextExpression extends Expression { - public boolean isFuzzy(); + public Boolean getFuzzy(); public String getValue(); } @@ -119,6 +121,7 @@ public interface RelativeDateExpression extends Expression { public int getValue(); public String getTimeUnit(); public String getOperator(); + public Boolean getRepeating(); } public interface PropertyListExpression extends Expression { @@ -127,7 +130,7 @@ public interface PropertyListExpression extends Expression { public String getName(); public String getOperator(); public List getValues(); - public boolean isRepeated(); + public Boolean getRepeating(); } public interface PropertyRangeExpression extends Expression { @@ -136,6 +139,6 @@ public interface PropertyRangeExpression extends Expression { public String getOperator(); public String getFrom(); public String getTo(); - public boolean isRepeated(); + public Boolean getRepeating(); } } diff --git a/src/main/java/com/emc/documentum/rest/client/sample/model/SearchTemplate.java b/src/main/java/com/emc/documentum/rest/client/sample/model/SearchTemplate.java new file mode 100644 index 0000000..c79be16 --- /dev/null +++ b/src/main/java/com/emc/documentum/rest/client/sample/model/SearchTemplate.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2016. EMC Corporation. All Rights Reserved. + */ +package com.emc.documentum.rest.client.sample.model; + +import java.util.List; + +/** + * the class represents the search template of the REST services + */ +public interface SearchTemplate extends RestObject { + public String getQueryDocumentTemplate(); + public Search getSearch(); + public List getExternalVariables(); + public String getSearchReference(); + + public interface ExternalVariable { + public String getId(); + public String getExpressionType(); + public String getDataType(); + public Object getVariableValue(); + } + + public interface FullTextVariable extends ExternalVariable { + public String getVariableValue(); + } + + public interface PropertyVariable extends ExternalVariable { + public String getPropertyName(); + public String getOperator(); + } + + public interface PropertyValueVariable extends PropertyVariable { + public static final String OPERATOR_UNDEFINED = "UNDEFINED"; + public static final String OPERATOR_EQUAL = "EQUAL"; + public static final String OPERATOR_NOT_EQUAL = "NOT_EQUAL"; + public static final String OPERATOR_GREATER_THAN = "GREATER_THAN"; + public static final String OPERATOR_LESS_THAN = "LESS_THAN"; + public static final String OPERATOR_GREATER_EQUAL = "GREATER_EQUAL"; + public static final String OPERATOR_LESS_EQUAL = "LESS_EQUAL"; + public static final String OPERATOR_BEGINS_WITH = "BEGINS_WITH"; + public static final String OPERATOR_CONTAINS = "CONTAINS"; + public static final String OPERATOR_DOES_NOT_CONTAIN = "DOES_NOT_CONTAIN"; + public static final String OPERATOR_ENDS_WITH = "ENDS_WITH"; + public static final String OPERATOR_IS_NULL = "IS_NULL"; + public static final String OPERATOR_IS_NOT_NULL = "IS_NOT_NULL"; + public String getVariableValue(); + } + + public interface RelativeDateVariable extends PropertyVariable { + public static final String OPERATOR_EQUAL = "EQUAL"; + public static final String OPERATOR_GREATER_THAN = "GREATER_THAN"; + public static final String OPERATOR_LESS_THAN = "LESS_THAN"; + public static final String OPERATOR_GREATER_EQUAL = "GREATER_EQUAL"; + public static final String OPERATOR_LESS_EQUAL = "LESS_EQUAL"; + public String getVariableValue(); + } + + public interface PropertyListVariable extends PropertyVariable { + public static final String OPERATOR_IN = "IN"; + public static final String OPERATOR_NOT_IN = "NOT_IN"; + public List getVariableValue(); + } +} diff --git a/src/main/java/com/emc/documentum/rest/client/sample/model/builder/BatchBuilder.java b/src/main/java/com/emc/documentum/rest/client/sample/model/builder/BatchBuilder.java index 74d74dd..fcc1c50 100644 --- a/src/main/java/com/emc/documentum/rest/client/sample/model/builder/BatchBuilder.java +++ b/src/main/java/com/emc/documentum/rest/client/sample/model/builder/BatchBuilder.java @@ -1,3 +1,6 @@ +/* + * Copyright (c) 2016. EMC Corporation. All Rights Reserved. + */ package com.emc.documentum.rest.client.sample.model.builder; import java.io.ByteArrayOutputStream; @@ -22,13 +25,13 @@ import com.emc.documentum.rest.client.sample.client.util.SupportedMediaTypes; import com.emc.documentum.rest.client.sample.model.batch.Attachment; import com.emc.documentum.rest.client.sample.model.batch.Batch; +import com.emc.documentum.rest.client.sample.model.batch.Batch.OnError; import com.emc.documentum.rest.client.sample.model.batch.SettableAttachment; import com.emc.documentum.rest.client.sample.model.batch.SettableBatch; import com.emc.documentum.rest.client.sample.model.batch.SettableHeader; import com.emc.documentum.rest.client.sample.model.batch.SettableInclude; import com.emc.documentum.rest.client.sample.model.batch.SettableOperation; import com.emc.documentum.rest.client.sample.model.batch.SettableRequest; -import com.emc.documentum.rest.client.sample.model.batch.Batch.OnError; import com.emc.documentum.rest.client.sample.model.json.JsonBatchBuilder; import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbBatchBuilder; diff --git a/src/main/java/com/emc/documentum/rest/client/sample/model/builder/SearchBuilder.java b/src/main/java/com/emc/documentum/rest/client/sample/model/builder/SearchBuilder.java index d9f909c..b05c82a 100644 --- a/src/main/java/com/emc/documentum/rest/client/sample/model/builder/SearchBuilder.java +++ b/src/main/java/com/emc/documentum/rest/client/sample/model/builder/SearchBuilder.java @@ -1,3 +1,6 @@ +/* + * Copyright (c) 2016. EMC Corporation. All Rights Reserved. + */ package com.emc.documentum.rest.client.sample.model.builder; import java.util.List; @@ -40,4 +43,5 @@ public abstract SearchBuilder propertyExpression(String name, String value, Stri public abstract SearchBuilder propertyListExpression(String name, List values, String operator, boolean repeated); public abstract SearchBuilder propertyRangeExpression(String name, String from, String to); public abstract SearchBuilder expression(Expression expression); + public abstract SearchBuilder asTemplate(); } diff --git a/src/main/java/com/emc/documentum/rest/client/sample/model/json/JsonFeeds.java b/src/main/java/com/emc/documentum/rest/client/sample/model/json/JsonFeeds.java index e4da2e2..212c2e9 100644 --- a/src/main/java/com/emc/documentum/rest/client/sample/model/json/JsonFeeds.java +++ b/src/main/java/com/emc/documentum/rest/client/sample/model/json/JsonFeeds.java @@ -20,6 +20,9 @@ public static class FolderLinkFeed extends JsonFeed{ public static class SearchFeed extends JsonSearchFeed{ } + public static class SearchTemplateFeed extends JsonFeed{ + } + public static class PreferenceFeed extends JsonFeed{ } diff --git a/src/main/java/com/emc/documentum/rest/client/sample/model/json/JsonSearch.java b/src/main/java/com/emc/documentum/rest/client/sample/model/json/JsonSearch.java index 9d794fa..787732b 100644 --- a/src/main/java/com/emc/documentum/rest/client/sample/model/json/JsonSearch.java +++ b/src/main/java/com/emc/documentum/rest/client/sample/model/json/JsonSearch.java @@ -11,14 +11,17 @@ import com.emc.documentum.rest.client.sample.model.Search; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; public class JsonSearch extends JsonInlineLinkableBase implements Search { + private List repositories; private List types; - private List columns; - private List sorts; - private List locations; + private List columns; + private List sorts; + private List locations; @JsonProperty("expression-set") - private ExpressionSet expressionSet; + private JsonExpressionSet expressionSet; private List collections; @JsonProperty("all-versions") private Boolean allVersions; @@ -27,8 +30,16 @@ public class JsonSearch extends JsonInlineLinkableBase implements Search { @JsonProperty("max-results-for-facets") private Integer maxResultsForFacets; @JsonProperty("facet-definitions") - private List facetDefinitions; + private List facetDefinitions; + public List getRepositories() { + return repositories; + } + + public void setRepositories(List repositories) { + this.repositories = repositories; + } + public List getTypes() { return types; } @@ -37,27 +48,30 @@ public void setTypes(List types) { this.types = types; } + @SuppressWarnings({ "rawtypes", "unchecked" }) public List getColumns() { - return columns; + return (List)columns; } - public void setColumns(List columns) { + public void setColumns(List columns) { this.columns = columns; } + @SuppressWarnings({ "rawtypes", "unchecked" }) public List getSorts() { - return sorts; + return (List)sorts; } - public void setSorts(List sorts) { + public void setSorts(List sorts) { this.sorts = sorts; } + @SuppressWarnings({ "unchecked", "rawtypes" }) public List getLocations() { - return locations; + return (List)locations; } - public void setLocations(List locations) { + public void setLocations(List locations) { this.locations = locations; } @@ -65,7 +79,7 @@ public ExpressionSet getExpressionSet() { return expressionSet; } - public void setExpressionSet(ExpressionSet expressionSet) { + public void setExpressionSet(JsonExpressionSet expressionSet) { this.expressionSet = expressionSet; } @@ -101,11 +115,12 @@ public void setMaxResultsForFacets(Integer maxResultsForFacets) { this.maxResultsForFacets = maxResultsForFacets; } + @SuppressWarnings({ "rawtypes", "unchecked" }) public List getFacetDefinitions() { - return facetDefinitions; + return (List)facetDefinitions; } - public void setFacetDefinitions(List facetDefinitions) { + public void setFacetDefinitions(List facetDefinitions) { this.facetDefinitions = facetDefinitions; } @@ -175,7 +190,7 @@ public String getProperty() { public void setProperty(String property) { this.property = property; } - public Boolean isAscending() { + public Boolean getAscending() { return ascending; } public void setAscending(Boolean ascending) { @@ -187,7 +202,7 @@ public String getLang() { public void setLang(String lang) { this.lang = lang; } - public Boolean isAscii() { + public Boolean getAscii() { return ascii; } public void setAscii(Boolean ascii) { @@ -207,23 +222,48 @@ public int hashCode() { } } + @JsonSubTypes({ + @JsonSubTypes.Type(value = JsonIdLocation.class, name = "id-location"), + @JsonSubTypes.Type(value = JsonPathLocation.class, name = "path-location") + }) + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "location-type") + public static abstract class JsonLocation { + private String repository; + private Boolean descendent; + public JsonLocation() { + } + public JsonLocation(boolean descendent) { + this.descendent = descendent; + } + public String getRepository() { + return repository; + } + public void setRepository(String repository) { + this.repository = repository; + } + public Boolean getDescendent() { + return descendent; + } + public void setDescendent(Boolean descendent) { + this.descendent = descendent; + } + @Override + public boolean equals(Object obj) { + JsonLocation that = (JsonLocation) obj; + return descendent == that.descendent; + } + } + @JsonPropertyOrder({ "locationType" }) - public static class JsonIdLocation implements IdLocation { - private boolean descendent; + public static class JsonIdLocation extends JsonLocation implements IdLocation { private String id; @JsonProperty("location-type") private final String locationType = "id-location"; public JsonIdLocation() { } public JsonIdLocation(String id, boolean descendent) { + super(descendent); this.id = id; - this.descendent = descendent; - } - public boolean isDescendent() { - return descendent; - } - public void setDescendent(boolean descendent) { - this.descendent = descendent; } public String getId() { return id; @@ -237,32 +277,25 @@ public String getLocationType() { @Override public boolean equals(Object obj) { JsonIdLocation that = (JsonIdLocation) obj; - return Equals.equal(descendent, that.descendent) + return super.equals(obj) && Equals.equal(id, that.id); } @Override public int hashCode() { - return Objects.hash(descendent, id); + return Objects.hash(id); } } @JsonPropertyOrder({ "locationType" }) - public static class JsonPathLocation implements PathLocation { - private boolean descendent; + public static class JsonPathLocation extends JsonLocation implements PathLocation { private String path; @JsonProperty("location-type") private final String locationType = "path-location"; public JsonPathLocation() { } public JsonPathLocation(String path, boolean descendent) { + super(descendent); this.path = path; - this.descendent = descendent; - } - public boolean isDescendent() { - return descendent; - } - public void setDescendent(boolean descendent) { - this.descendent = descendent; } public String getPath() { return path; @@ -276,12 +309,12 @@ public String getLocationType() { @Override public boolean equals(Object obj) { JsonPathLocation that = (JsonPathLocation) obj; - return Equals.equal(descendent, that.descendent) + return super.equals(that) && Equals.equal(path, that.path); } @Override public int hashCode() { - return Objects.hash(descendent, path); + return Objects.hash(path); } } @@ -295,7 +328,7 @@ public static class JsonFacetDefinition implements FacetDefinition { @JsonProperty("max-values") private Integer maxValues; @JsonProperty("facet-definition") - private FacetDefinition nestedFacetDefinition; + private JsonFacetDefinition nestedFacetDefinition; public JsonFacetDefinition() { } public JsonFacetDefinition(String id, List attributes, String groupby, String sort, int maxValues) { @@ -344,7 +377,7 @@ public void setMaxValues(Integer maxValues) { public FacetDefinition getNestedFacetDefinition() { return nestedFacetDefinition; } - public void setNestedFacetDefinition(FacetDefinition nestedFacetDefinition) { + public void setNestedFacetDefinition(JsonFacetDefinition nestedFacetDefinition) { this.nestedFacetDefinition = nestedFacetDefinition; } @Override @@ -364,17 +397,46 @@ public int hashCode() { } } - @JsonPropertyOrder({ "name" }) - public static class JsonExpressionSet implements ExpressionSet{ - private final String name = "expression-set"; + @JsonSubTypes({ + @JsonSubTypes.Type(value = JsonExpressionSet.class, name = "expression-set"), + @JsonSubTypes.Type(value = JsonFullTextExpression.class, name = "fulltext"), + @JsonSubTypes.Type(value = JsonPropertyExpression.class, name = "property"), + @JsonSubTypes.Type(value = JsonPropertyListExpression.class, name = "property-list"), + @JsonSubTypes.Type(value = JsonPropertyRangeExpression.class, name = "property-range"), + @JsonSubTypes.Type(value = JsonRelativeDateExpression.class, name = "relative-date") + }) + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "expression-type") + public static abstract class JsonExpression implements Expression { + @JsonProperty("expression-type") + private final String expressionType; + @JsonProperty + private Boolean template; + public JsonExpression(String expressionType) { + this.expressionType = expressionType; + } + public String getExpressionType() { + return expressionType; + } + public Boolean getTemplate() { + return template; + } + public void setTemplate(Boolean template) { + this.template = template; + } + } + + @JsonPropertyOrder({ "expression-type" }) + public static class JsonExpressionSet extends JsonExpression implements ExpressionSet{ private String operator; - private List expressions; + private List expressions; public JsonExpressionSet() { + this(null, null); } - public JsonExpressionSet(List expressions) { - this.expressions = expressions; + public JsonExpressionSet(List expressions) { + this(null, expressions); } - public JsonExpressionSet(String operator, List expressions) { + public JsonExpressionSet(String operator, List expressions) { + super("expression-set"); this.operator = operator; this.expressions = expressions; } @@ -384,15 +446,13 @@ public String getOperator() { public void setOperator(String operator) { this.operator = operator; } + @SuppressWarnings({ "unchecked", "rawtypes" }) public List getExpressions() { - return expressions; + return (List)expressions; } - public void setExpressions(List expressions) { + public void setExpressions(List expressions) { this.expressions = expressions; } - public String getName() { - return name; - } @Override public boolean equals(Object obj) { JsonExpressionSet that = (JsonExpressionSet) obj; @@ -406,32 +466,32 @@ public int hashCode() { } @JsonPropertyOrder({ "expressionType" }) - public static class JsonPropertyExpression implements PropertyExpression { + public static class JsonPropertyExpression extends JsonExpression implements PropertyExpression { @JsonProperty("expression-type") private final String expressionType = "property"; private String name; private String value; private String operator; @JsonProperty("exact-match") - private boolean exactMatch; - private boolean repeated; + private Boolean exactMatch; + private Boolean repeating; @JsonProperty("case-sensitive") - private boolean caseSensitive; - private boolean fuzzy; + private Boolean caseSensitive; + private Boolean fuzzy; public JsonPropertyExpression() { + this(null, null, null, null, null, null, null); } public JsonPropertyExpression(String name, String value, String operator) { - this.name = name; - this.value = value; - this.operator = operator; + this(name, value, operator, null, null, null, null); } public JsonPropertyExpression(String name, String value, String operator, - boolean exactMatch, boolean repeated, boolean caseSensitive, boolean fuzzy) { + Boolean exactMatch, Boolean repeating, Boolean caseSensitive, Boolean fuzzy) { + super("property"); this.name = name; this.value = value; this.operator = operator; this.exactMatch = exactMatch; - this.repeated = repeated; + this.repeating = repeating; this.caseSensitive = caseSensitive; this.fuzzy = fuzzy; } @@ -453,28 +513,28 @@ public String getOperator() { public void setOperator(String operator) { this.operator = operator; } - public boolean isExactMatch() { + public Boolean getExactMatch() { return exactMatch; } - public void setExactMatch(boolean exactMatch) { + public void setExactMatch(Boolean exactMatch) { this.exactMatch = exactMatch; } - public boolean isRepeated() { - return repeated; + public Boolean getRepeating() { + return repeating; } - public void setRepeated(boolean repeated) { - this.repeated = repeated; + public void setRepeating(Boolean repeating) { + this.repeating = repeating; } - public boolean isCaseSensitive() { + public Boolean getCaseSensitive() { return caseSensitive; } - public void setCaseSensitive(boolean caseSensitive) { + public void setCaseSensitive(Boolean caseSensitive) { this.caseSensitive = caseSensitive; } - public boolean isFuzzy() { + public Boolean getFuzzy() { return fuzzy; } - public void setFuzzy(boolean fuzzy) { + public void setFuzzy(Boolean fuzzy) { this.fuzzy = fuzzy; } public String getExpressionType() { @@ -487,7 +547,7 @@ public boolean equals(Object obj) { && Equals.equal(value, that.value) && Equals.equal(operator, that.operator) && Equals.equal(exactMatch, that.exactMatch) - && Equals.equal(repeated, that.repeated) + && Equals.equal(repeating, that.repeating) && Equals.equal(caseSensitive, that.caseSensitive) && Equals.equal(fuzzy, that.fuzzy); } @@ -498,21 +558,21 @@ public int hashCode() { } @JsonPropertyOrder({ "expressionType" }) - public static class JsonFullTextExpression implements FullTextExpression { - @JsonProperty("expression-type") - private final String expressionType = "fulltext"; - private boolean fuzzy; + public static class JsonFullTextExpression extends JsonExpression implements FullTextExpression { + private Boolean fuzzy; private String value; public JsonFullTextExpression() { + this(null, null); } - public JsonFullTextExpression(String value, boolean fuzzy) { + public JsonFullTextExpression(String value, Boolean fuzzy) { + super("fulltext"); this.value = value; this.fuzzy = fuzzy; } - public boolean isFuzzy() { + public Boolean getFuzzy() { return fuzzy; } - public void setFuzzy(boolean fuzzy) { + public void setFuzzy(Boolean fuzzy) { this.fuzzy = fuzzy; } public String getValue() { @@ -521,9 +581,6 @@ public String getValue() { public void setValue(String value) { this.value = value; } - public String getExpressionType() { - return expressionType; - } @Override public boolean equals(Object obj) { JsonFullTextExpression that = (JsonFullTextExpression) obj; @@ -537,17 +594,18 @@ public int hashCode() { } @JsonPropertyOrder({ "expressionType" }) - public static class JsonRelativeDateExpression implements RelativeDateExpression { - @JsonProperty("expression-type") - private final String expressionType = "relative-date"; + public static class JsonRelativeDateExpression extends JsonExpression implements RelativeDateExpression { private String name; private int value; @JsonProperty("time-unit") private String timeUnit; private String operator; + private Boolean repeating; public JsonRelativeDateExpression() { + this(null, 0, null, null); } public JsonRelativeDateExpression(String name, int value, String timeUnit, String operator) { + super("relative-date"); this.name = name; this.value = value; this.timeUnit = timeUnit; @@ -577,8 +635,11 @@ public String getOperator() { public void setOperator(String operator) { this.operator = operator; } - public String getExpressionType() { - return expressionType; + public Boolean getRepeating() { + return repeating; + } + public void setRepeating(Boolean repeating) { + this.repeating = repeating; } @Override public boolean equals(Object obj) { @@ -595,24 +656,23 @@ public int hashCode() { } @JsonPropertyOrder({ "expressionType" }) - public static class JsonPropertyListExpression implements PropertyListExpression { - @JsonProperty("expression-type") - private final String expressionType = "property-list"; + public static class JsonPropertyListExpression extends JsonExpression implements PropertyListExpression { private String name; private String operator; private List values; - private boolean repeated; + private Boolean repeating; public JsonPropertyListExpression() { + this(null, null, null, null); } public JsonPropertyListExpression(String name, List values) { - this.name = name; - this.values = values; + this(name, values, null, null); } - public JsonPropertyListExpression(String name, List values, String operator, boolean repeated) { + public JsonPropertyListExpression(String name, List values, String operator, Boolean repeating) { + super("property-list"); this.name = name; this.values = values; this.operator = operator; - this.repeated = repeated; + this.repeating = repeating; } public String getName() { return name; @@ -632,14 +692,11 @@ public List getValues() { public void setValues(List values) { this.values = values; } - public boolean isRepeated() { - return repeated; + public Boolean getRepeating() { + return repeating; } - public void setRepeated(boolean repeated) { - this.repeated = repeated; - } - public String getExpressionType() { - return expressionType; + public void setRepeating(Boolean repeating) { + this.repeating = repeating; } @Override public boolean equals(Object obj) { @@ -647,7 +704,7 @@ public boolean equals(Object obj) { return Equals.equal(name, that.name) && Equals.equal(operator, that.operator) && Equals.equal(values, that.values) - && Equals.equal(repeated, that.repeated); + && Equals.equal(repeating, that.repeating); } @Override public int hashCode() { @@ -656,18 +713,17 @@ public int hashCode() { } @JsonPropertyOrder({ "expressionType" }) - public static class JsonPropertyRangeExpression implements PropertyRangeExpression { - @JsonProperty("expression-type") - private final String expressionType = "property-range"; + public static class JsonPropertyRangeExpression extends JsonExpression implements PropertyRangeExpression { private String name; - private final String operator = OPERATOR_BETWEEN; private String from; private String to; - private boolean repeated; + private Boolean repeating; public JsonPropertyRangeExpression() { + this(null, null, null); } public JsonPropertyRangeExpression(String name, String from, String to) { + super("property-range"); this.name = name; this.from = from; this.to = to; @@ -679,7 +735,7 @@ public void setName(String name) { this.name = name; } public String getOperator() { - return operator; + return OPERATOR_BETWEEN; } public String getFrom() { return from; @@ -693,27 +749,23 @@ public String getTo() { public void setTo(String to) { this.to = to; } - public boolean isRepeated() { - return repeated; + public Boolean getRepeating() { + return repeating; } - public void setRepeated(boolean repeated) { - this.repeated = repeated; - } - public String getExpressionType() { - return expressionType; + public void setRepeating(Boolean repeating) { + this.repeating = repeating; } @Override public boolean equals(Object obj) { JsonPropertyRangeExpression that = (JsonPropertyRangeExpression) obj; return Equals.equal(name, that.name) - && Equals.equal(operator, that.operator) && Equals.equal(from, that.from) && Equals.equal(to, that.to) - && Equals.equal(repeated, that.repeated); + && Equals.equal(repeating, that.repeating); } @Override public int hashCode() { - return Objects.hash(name, operator, from, to); + return Objects.hash(name, from, to); } } } \ No newline at end of file diff --git a/src/main/java/com/emc/documentum/rest/client/sample/model/json/JsonSearchBuilder.java b/src/main/java/com/emc/documentum/rest/client/sample/model/json/JsonSearchBuilder.java index b141f2d..3f1637c 100644 --- a/src/main/java/com/emc/documentum/rest/client/sample/model/json/JsonSearchBuilder.java +++ b/src/main/java/com/emc/documentum/rest/client/sample/model/json/JsonSearchBuilder.java @@ -1,3 +1,6 @@ +/* + * Copyright (c) 2016. EMC Corporation. All Rights Reserved. + */ package com.emc.documentum.rest.client.sample.model.json; import java.util.ArrayList; @@ -14,10 +17,12 @@ import com.emc.documentum.rest.client.sample.model.Search.Sort; import com.emc.documentum.rest.client.sample.model.builder.SearchBuilder; import com.emc.documentum.rest.client.sample.model.json.JsonSearch.JsonColumn; +import com.emc.documentum.rest.client.sample.model.json.JsonSearch.JsonExpression; import com.emc.documentum.rest.client.sample.model.json.JsonSearch.JsonExpressionSet; import com.emc.documentum.rest.client.sample.model.json.JsonSearch.JsonFacetDefinition; import com.emc.documentum.rest.client.sample.model.json.JsonSearch.JsonFullTextExpression; import com.emc.documentum.rest.client.sample.model.json.JsonSearch.JsonIdLocation; +import com.emc.documentum.rest.client.sample.model.json.JsonSearch.JsonLocation; import com.emc.documentum.rest.client.sample.model.json.JsonSearch.JsonPathLocation; import com.emc.documentum.rest.client.sample.model.json.JsonSearch.JsonPropertyExpression; import com.emc.documentum.rest.client.sample.model.json.JsonSearch.JsonPropertyListExpression; @@ -62,7 +67,7 @@ public SearchBuilder sort(String property, Boolean ascending, String lang, Boole @Override public SearchBuilder sort(Sort sort) { if (search.getSorts() == null) { - search.setSorts(new ArrayList()); + search.setSorts(new ArrayList()); } search.getSorts().add(sort); return this; @@ -81,7 +86,7 @@ public SearchBuilder pathLocation(String path, boolean descendent) { @Override public SearchBuilder location(Location location) { if (search.getLocations() == null) { - search.setLocations(new ArrayList()); + search.setLocations(new ArrayList()); } search.getLocations().add(location); return this; @@ -128,15 +133,16 @@ public SearchBuilder facetDefinition(String id, List attributes, String @Override public SearchBuilder facetDefinition(FacetDefinition facetDefinition) { if (search.getFacetDefinitions() == null) { - search.setFacetDefinitions(new ArrayList()); + search.setFacetDefinitions(new ArrayList()); } search.getFacetDefinitions().add(facetDefinition); return this; } + @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public SearchBuilder expressionSet(List expressions) { - search.setExpressionSet(new JsonExpressionSet(expressions)); + search.setExpressionSet(new JsonExpressionSet((List)expressions)); return this; } @@ -170,10 +176,18 @@ public SearchBuilder propertyRangeExpression(String name, String from, String to public SearchBuilder expression(Expression expression) { if(search.getExpressionSet() == null) { JsonExpressionSet expressionSet = new JsonExpressionSet(); - expressionSet.setExpressions(new ArrayList()); + expressionSet.setExpressions(new ArrayList()); search.setExpressionSet(expressionSet); } search.getExpressionSet().getExpressions().add(expression); return this; } + + @Override + public SearchBuilder asTemplate() { + if(search.getExpressionSet() != null && search.getExpressionSet().getExpressions().size() > 0) { + ((JsonExpression)search.getExpressionSet().getExpressions().get(search.getExpressionSet().getExpressions().size() - 1)).setTemplate(true); + } + return this; + } } diff --git a/src/main/java/com/emc/documentum/rest/client/sample/model/json/JsonSearchTemplate.java b/src/main/java/com/emc/documentum/rest/client/sample/model/json/JsonSearchTemplate.java new file mode 100644 index 0000000..7804a98 --- /dev/null +++ b/src/main/java/com/emc/documentum/rest/client/sample/model/json/JsonSearchTemplate.java @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2016. EMC Corporation. All Rights Reserved. + */ +package com.emc.documentum.rest.client.sample.model.json; + +import java.util.List; + +import com.emc.documentum.rest.client.sample.model.Search; +import com.emc.documentum.rest.client.sample.model.SearchTemplate; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +import static com.emc.documentum.rest.client.sample.client.impl.jackson.DCTMJacksonMapper.marshal; +import static com.emc.documentum.rest.client.sample.client.impl.jackson.DCTMJacksonMapper.unmarshal; + +public class JsonSearchTemplate extends JsonObject implements SearchTemplate { + @JsonProperty("query-document-template") + private String queryDocumentTemplate; + @JsonProperty("external-variables") + private List externalVariables; + @JsonProperty("search-reference") + private String searchReference; + + public JsonSearchTemplate() { + } + + public JsonSearchTemplate(SearchTemplate template) { + super(template); + setSearch(template.getSearch()); + } + + @Override + public String getQueryDocumentTemplate() { + return queryDocumentTemplate; + } + + public void setQueryDocumentTemplate(String queryDocumentTemplate) { + this.queryDocumentTemplate = queryDocumentTemplate; + } + + @Override + @JsonIgnore + public Search getSearch() { + return queryDocumentTemplate==null?null:unmarshal(queryDocumentTemplate, JsonSearch.class); + } + + public void setSearch(Search search) { + try { + queryDocumentTemplate = search == null?null:marshal(search); + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public List getExternalVariables() { + return (List)externalVariables; + } + + public void setExternalVariables(List externalVariables) { + this.externalVariables = externalVariables; + } + + @Override + public String getSearchReference() { + return searchReference; + } + + public void setSearchReference(String searchReference) { + this.searchReference = searchReference; + } + + @JsonSubTypes({ + @JsonSubTypes.Type(value = JsonFullTextVariable.class, name = "fulltext-variable"), + @JsonSubTypes.Type(value = JsonPropertyValueVariable.class, name = "property-variable"), + @JsonSubTypes.Type(value = JsonRelativeDateVariable.class, name = "relative-date-variable"), + @JsonSubTypes.Type(value = JsonPropertyListVariable.class, name = "property-list-variable") + }) + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "variable-type") + public static abstract class JsonExternalVariable implements ExternalVariable { + @JsonProperty + private String id; + @JsonProperty("expression-type") + private String expressionType; + @JsonProperty("data-type") + private String dataType; + @Override + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + @Override + public String getExpressionType() { + return expressionType; + } + public void setExpressionType(String expressionType) { + this.expressionType = expressionType; + } + @Override + public String getDataType() { + return dataType; + } + public void setDataType(String dataType) { + this.dataType = dataType; + } + } + + public abstract static class JsonPropertyVariable extends JsonExternalVariable implements PropertyVariable { + @JsonProperty("property-name") + private String propertyName; + @JsonProperty + private String operator; + @Override + public String getPropertyName() { + return propertyName; + } + public void setPropertyName(String propertyName) { + this.propertyName = propertyName; + } + @Override + public String getOperator() { + return operator; + } + public void setOperator(String operator) { + this.operator = operator; + } + } + + @JsonPropertyOrder({ "variableType" }) + public static class JsonFullTextVariable extends JsonExternalVariable implements FullTextVariable { + @JsonProperty("variable-type") + private final String variableType = "fulltext-variable"; + @JsonProperty("variable-value") + private String variableValue; + @Override + public String getVariableValue() { + return variableValue; + } + public void setVariableValue(String variableValue) { + this.variableValue = variableValue; + } + public String getVariableType() { + return variableType; + } + } + + @JsonPropertyOrder({ "variableType" }) + public static class JsonPropertyValueVariable extends JsonPropertyVariable implements PropertyValueVariable { + @JsonProperty("variable-type") + private final String variableType = "property-variable"; + @JsonProperty("variable-value") + private String variableValue; + @Override + public String getVariableValue() { + return variableValue; + } + public void setVariableValue(String variableValue) { + this.variableValue = variableValue; + } + public String getVariableType() { + return variableType; + } + } + + @JsonPropertyOrder({ "variableType" }) + public static class JsonRelativeDateVariable extends JsonPropertyVariable implements RelativeDateVariable { + @JsonProperty("variable-type") + private final String variableType = "relative-date-variable"; + @JsonProperty("variable-value") + private String variableValue; + @Override + public String getVariableValue() { + return variableValue; + } + public void setVariableValue(String variableValue) { + this.variableValue = variableValue; + } + public String getVariableType() { + return variableType; + } + } + + @JsonPropertyOrder({ "variableType" }) + public static class JsonPropertyListVariable extends JsonPropertyVariable implements PropertyListVariable { + @JsonProperty("variable-type") + private final String variableType = "property-list-variable"; + @JsonProperty("variable-values") + private List variableValue; + @Override + public List getVariableValue() { + return variableValue; + } + public void setVariableValue(List variableValue) { + this.variableValue = variableValue; + } + public String getVariableType() { + return variableType; + } + } +} diff --git a/src/main/java/com/emc/documentum/rest/client/sample/model/plain/PlainSearchTemplate.java b/src/main/java/com/emc/documentum/rest/client/sample/model/plain/PlainSearchTemplate.java new file mode 100644 index 0000000..5a75b21 --- /dev/null +++ b/src/main/java/com/emc/documentum/rest/client/sample/model/plain/PlainSearchTemplate.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2016. EMC Corporation. All Rights Reserved. + */ +package com.emc.documentum.rest.client.sample.model.plain; + +import java.util.List; + +import com.emc.documentum.rest.client.sample.model.Search; +import com.emc.documentum.rest.client.sample.model.SearchTemplate; + +/** + * the plain PlainSearchTemplate implementation which has properties only + * normally used when create/update the SearchTemplate + */ +public class PlainSearchTemplate extends PlainRestObject implements SearchTemplate { + private Search search; + public PlainSearchTemplate(Search search, String...properties) { + super(properties); + this.search = search; + } + + @Override + public String getQueryDocumentTemplate() { + throw new UnsupportedOperationException(); + } + + @Override + public Search getSearch() { + return search; + } + + @Override + public List getExternalVariables() { + throw new UnsupportedOperationException(); + } + + @Override + public String getSearchReference() { + throw new UnsupportedOperationException(); + } +} diff --git a/src/main/java/com/emc/documentum/rest/client/sample/model/xml/jaxb/JaxbSearch.java b/src/main/java/com/emc/documentum/rest/client/sample/model/xml/jaxb/JaxbSearch.java index 7a07dc2..917dc8a 100644 --- a/src/main/java/com/emc/documentum/rest/client/sample/model/xml/jaxb/JaxbSearch.java +++ b/src/main/java/com/emc/documentum/rest/client/sample/model/xml/jaxb/JaxbSearch.java @@ -4,14 +4,15 @@ package com.emc.documentum.rest.client.sample.model.xml.jaxb; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; -import javax.xml.bind.annotation.XmlAnyElement; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlElements; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlSeeAlso; import javax.xml.bind.annotation.XmlTransient; @@ -19,6 +20,7 @@ import com.emc.documentum.rest.client.sample.client.util.Equals; import com.emc.documentum.rest.client.sample.model.Search; +import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbSearch.JaxbExpression; import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbSearch.JaxbFacetProperty; import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbSearch.JaxbFullTextExpression; import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbSearch.JaxbIdLocation; @@ -30,8 +32,9 @@ @XmlRootElement(name = "search") @XmlSeeAlso({JaxbFullTextExpression.class, JaxbPropertyExpression.class, JaxbPropertyListExpression.class, JaxbPropertyRangeExpression.class, - JaxbRelativeDateExpression.class, JaxbIdLocation.class, JaxbPathLocation.class, JaxbFacetProperty.class}) + JaxbRelativeDateExpression.class, JaxbExpression.class, JaxbIdLocation.class, JaxbPathLocation.class, JaxbFacetProperty.class}) public class JaxbSearch extends JaxbDmLinkableBase implements Search { + private List repositories; private List types; private List columns; private List sorts; @@ -43,6 +46,16 @@ public class JaxbSearch extends JaxbDmLinkableBase implements Search { private Integer maxResultsForFacets; private List facetDefinitions; + @XmlElementWrapper + @XmlElement(name = "repository") + public List getRepositories() { + return repositories; + } + + public void setRepositories(List repositories) { + this.repositories = repositories; + } + @XmlElementWrapper @XmlElement(name = "type") public List getTypes() { @@ -74,7 +87,8 @@ public void setSorts(List sorts) { } @XmlElementWrapper - @XmlAnyElement() + @XmlElements({@XmlElement(name="id-location", type=JaxbIdLocation.class), + @XmlElement(name="path-location", type=JaxbPathLocation.class)}) public List getLocations() { return locations; } @@ -210,7 +224,7 @@ public void setProperty(String property) { this.property = property; } @XmlAttribute - public Boolean isAscending() { + public Boolean getAscending() { return ascending; } public void setAscending(Boolean ascending) { @@ -224,7 +238,7 @@ public void setLang(String lang) { this.lang = lang; } @XmlAttribute - public Boolean isAscii() { + public Boolean getAscii() { return ascii; } public void setAscii(Boolean ascii) { @@ -244,23 +258,44 @@ public int hashCode() { } } - @XmlRootElement(name = "id-location") - public static class JaxbIdLocation implements IdLocation { - private boolean descendent; - private String id; - public JaxbIdLocation() { + public static abstract class JaxbLocation implements Location { + private String repository; + private Boolean descendent; + public JaxbLocation() { } - public JaxbIdLocation(String id, boolean descendent) { - this.id = id; + public JaxbLocation(Boolean descendent) { this.descendent = descendent; } @XmlAttribute - public boolean isDescendent() { + public String getRepository() { + return repository; + } + public void setRepository(String repository) { + this.repository = repository; + } + @XmlAttribute + public Boolean getDescendent() { return descendent; } - public void setDescendent(boolean descendent) { + public void setDescendent(Boolean descendent) { this.descendent = descendent; } + @Override + public boolean equals(Object obj) { + JaxbLocation that = (JaxbLocation) obj; + return Equals.equal(descendent, that.descendent); + } + } + + @XmlRootElement(name = "id-location") + public static class JaxbIdLocation extends JaxbLocation implements IdLocation { + private String id; + public JaxbIdLocation() { + } + public JaxbIdLocation(String id, Boolean descendent) { + super(descendent); + this.id = id; + } @XmlElement public String getId() { return id; @@ -271,31 +306,23 @@ public void setId(String id) { @Override public boolean equals(Object obj) { JaxbIdLocation that = (JaxbIdLocation) obj; - return Equals.equal(descendent, that.descendent) + return super.equals(that) && Equals.equal(id, that.id); } @Override public int hashCode() { - return Objects.hash(descendent, id); + return Objects.hash(id); } } @XmlRootElement(name = "path-location") - public static class JaxbPathLocation implements PathLocation { - private boolean descendent; + public static class JaxbPathLocation extends JaxbLocation implements PathLocation { private String path; public JaxbPathLocation() { } - public JaxbPathLocation(String path, boolean descendent) { + public JaxbPathLocation(String path, Boolean descendent) { + super(descendent); this.path = path; - this.descendent = descendent; - } - @XmlAttribute - public boolean isDescendent() { - return descendent; - } - public void setDescendent(boolean descendent) { - this.descendent = descendent; } @XmlElement public String getPath() { @@ -307,12 +334,12 @@ public void setPath(String path) { @Override public boolean equals(Object obj) { JaxbPathLocation that = (JaxbPathLocation) obj; - return Equals.equal(descendent, that.descendent) + return super.equals(that) && Equals.equal(path, that.path); } @Override public int hashCode() { - return Objects.hash(descendent, path); + return Objects.hash(path); } } @@ -375,6 +402,14 @@ public List getPropertiesList() { } return list; } + public void setPropertiesList(List list) { + if(list != null) { + properties = new HashMap(); + for(JaxbFacetProperty p : list) { + properties.put(p.getName(), p.getValue()); + } + } + } @XmlTransient public Map getProperties() { return properties; @@ -439,8 +474,21 @@ public void setValue(String value) { } } + @XmlTransient + public static abstract class JaxbExpression implements Expression { + private Boolean template; + @XmlAttribute + public Boolean getTemplate() { + return template; + } + public void setTemplate(Boolean template) { + this.template = template; + } + + } + @XmlRootElement(name = "expression-set") - public static class JaxbExpressionSet implements ExpressionSet{ + public static class JaxbExpressionSet extends JaxbExpression implements ExpressionSet{ private String operator; private List expressions; public JaxbExpressionSet() { @@ -460,7 +508,12 @@ public void setOperator(String operator) { this.operator = operator; } @XmlElementWrapper - @XmlAnyElement + @XmlElements({@XmlElement(name="expression-set", type=JaxbExpressionSet.class), + @XmlElement(name="fulltext", type=JaxbFullTextExpression.class), + @XmlElement(name="property", type=JaxbPropertyExpression.class), + @XmlElement(name="property-list", type=JaxbPropertyListExpression.class), + @XmlElement(name="property-range", type=JaxbPropertyRangeExpression.class), + @XmlElement(name="relative-date", type=JaxbRelativeDateExpression.class)}) public List getExpressions() { return expressions; } @@ -480,14 +533,14 @@ public int hashCode() { } @XmlRootElement(name = "property") - public static class JaxbPropertyExpression implements PropertyExpression { + public static class JaxbPropertyExpression extends JaxbExpression implements PropertyExpression { private String name; private String value; private String operator; - private boolean exactMatch; - private boolean repeated; - private boolean caseSensitive; - private boolean fuzzy; + private Boolean exactMatch; + private Boolean repeating; + private Boolean caseSensitive; + private Boolean fuzzy; public JaxbPropertyExpression() { } public JaxbPropertyExpression(String name, String value, String operator) { @@ -496,12 +549,12 @@ public JaxbPropertyExpression(String name, String value, String operator) { this.operator = operator; } public JaxbPropertyExpression(String name, String value, String operator, - boolean exactMatch, boolean repeated, boolean caseSensitive, boolean fuzzy) { + Boolean exactMatch, Boolean repeating, Boolean caseSensitive, Boolean fuzzy) { this.name = name; this.value = value; this.operator = operator; this.exactMatch = exactMatch; - this.repeated = repeated; + this.repeating = repeating; this.caseSensitive = caseSensitive; this.fuzzy = fuzzy; } @@ -527,31 +580,31 @@ public void setOperator(String operator) { this.operator = operator; } @XmlAttribute(name="exact-match") - public boolean isExactMatch() { + public Boolean getExactMatch() { return exactMatch; } - public void setExactMatch(boolean exactMatch) { + public void setExactMatch(Boolean exactMatch) { this.exactMatch = exactMatch; } @XmlAttribute - public boolean isRepeated() { - return repeated; + public Boolean getRepeating() { + return repeating; } - public void setRepeated(boolean repeated) { - this.repeated = repeated; + public void setRepeating(Boolean repeating) { + this.repeating = repeating; } @XmlAttribute(name="case-sensitive") - public boolean isCaseSensitive() { + public Boolean getCaseSensitive() { return caseSensitive; } - public void setCaseSensitive(boolean caseSensitive) { + public void setCaseSensitive(Boolean caseSensitive) { this.caseSensitive = caseSensitive; } @XmlAttribute - public boolean isFuzzy() { + public Boolean getFuzzy() { return fuzzy; } - public void setFuzzy(boolean fuzzy) { + public void setFuzzy(Boolean fuzzy) { this.fuzzy = fuzzy; } @Override @@ -561,7 +614,7 @@ public boolean equals(Object obj) { && Equals.equal(value, that.value) && Equals.equal(operator, that.operator) && Equals.equal(exactMatch, that.exactMatch) - && Equals.equal(repeated, that.repeated) + && Equals.equal(repeating, that.repeating) && Equals.equal(caseSensitive, that.caseSensitive) && Equals.equal(fuzzy, that.fuzzy); } @@ -572,8 +625,8 @@ public int hashCode() { } @XmlRootElement(name = "fulltext") - public static class JaxbFullTextExpression implements FullTextExpression { - private boolean fuzzy; + public static class JaxbFullTextExpression extends JaxbExpression implements FullTextExpression { + private Boolean fuzzy; private String value; public JaxbFullTextExpression() { } @@ -582,10 +635,10 @@ public JaxbFullTextExpression(String value, boolean fuzzy) { this.fuzzy = fuzzy; } @XmlAttribute - public boolean isFuzzy() { + public Boolean getFuzzy() { return fuzzy; } - public void setFuzzy(boolean fuzzy) { + public void setFuzzy(Boolean fuzzy) { this.fuzzy = fuzzy; } @XmlValue @@ -608,11 +661,12 @@ public int hashCode() { } @XmlRootElement(name = "relative-date") - public static class JaxbRelativeDateExpression implements RelativeDateExpression { + public static class JaxbRelativeDateExpression extends JaxbExpression implements RelativeDateExpression { private String name; private int value; private String timeUnit; private String operator; + private Boolean repeating; public JaxbRelativeDateExpression() { } public JaxbRelativeDateExpression(String name, int value, String timeUnit, String operator) { @@ -649,6 +703,13 @@ public String getOperator() { public void setOperator(String operator) { this.operator = operator; } + @XmlAttribute + public Boolean getRepeating() { + return repeating; + } + public void setRepeating(Boolean repeating) { + this.repeating = repeating; + } @Override public boolean equals(Object obj) { JaxbRelativeDateExpression that = (JaxbRelativeDateExpression) obj; @@ -664,22 +725,22 @@ public int hashCode() { } @XmlRootElement(name = "property-list") - public static class JaxbPropertyListExpression implements PropertyListExpression { + public static class JaxbPropertyListExpression extends JaxbExpression implements PropertyListExpression { private String name; private String operator; private List values; - private boolean repeated; + private Boolean repeating; public JaxbPropertyListExpression() { } public JaxbPropertyListExpression(String name, List values) { this.name = name; this.values = values; } - public JaxbPropertyListExpression(String name, List values, String operator, boolean repeated) { + public JaxbPropertyListExpression(String name, List values, String operator, boolean repeating) { this.name = name; this.values = values; this.operator = operator; - this.repeated = repeated; + this.repeating = repeating; } @XmlAttribute public String getName() { @@ -704,11 +765,11 @@ public void setValues(List values) { this.values = values; } @XmlAttribute - public boolean isRepeated() { - return repeated; + public Boolean getRepeating() { + return repeating; } - public void setRepeated(boolean repeated) { - this.repeated = repeated; + public void setRepeating(Boolean repeating) { + this.repeating = repeating; } @Override public boolean equals(Object obj) { @@ -716,7 +777,7 @@ public boolean equals(Object obj) { return Equals.equal(name, that.name) && Equals.equal(operator, that.operator) && Equals.equal(values, that.values) - && Equals.equal(repeated, that.repeated); + && Equals.equal(repeating, that.repeating); } @Override public int hashCode() { @@ -725,12 +786,12 @@ public int hashCode() { } @XmlRootElement(name = "property-range") - public static class JaxbPropertyRangeExpression implements PropertyRangeExpression { + public static class JaxbPropertyRangeExpression extends JaxbExpression implements PropertyRangeExpression { private String name; private final String operator = OPERATOR_BETWEEN; private String from; private String to; - private boolean repeated; + private Boolean repeating; public JaxbPropertyRangeExpression() { } public JaxbPropertyRangeExpression(String name, String from, String to) { @@ -764,11 +825,11 @@ public void setTo(String to) { this.to = to; } @XmlAttribute - public boolean isRepeated() { - return repeated; + public Boolean getRepeating() { + return repeating; } - public void setRepeated(boolean repeated) { - this.repeated = repeated; + public void setRepeating(Boolean repeating) { + this.repeating = repeating; } @Override public boolean equals(Object obj) { @@ -777,7 +838,7 @@ public boolean equals(Object obj) { && Equals.equal(operator, that.operator) && Equals.equal(from, that.from) && Equals.equal(to, that.to) - && Equals.equal(repeated, that.repeated); + && Equals.equal(repeating, that.repeating); } @Override public int hashCode() { diff --git a/src/main/java/com/emc/documentum/rest/client/sample/model/xml/jaxb/JaxbSearchBuilder.java b/src/main/java/com/emc/documentum/rest/client/sample/model/xml/jaxb/JaxbSearchBuilder.java index 5969b6e..caadbea 100644 --- a/src/main/java/com/emc/documentum/rest/client/sample/model/xml/jaxb/JaxbSearchBuilder.java +++ b/src/main/java/com/emc/documentum/rest/client/sample/model/xml/jaxb/JaxbSearchBuilder.java @@ -1,3 +1,6 @@ +/* + * Copyright (c) 2016. EMC Corporation. All Rights Reserved. + */ package com.emc.documentum.rest.client.sample.model.xml.jaxb; import java.util.ArrayList; @@ -14,6 +17,7 @@ import com.emc.documentum.rest.client.sample.model.Search.Sort; import com.emc.documentum.rest.client.sample.model.builder.SearchBuilder; import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbSearch.JaxbColumn; +import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbSearch.JaxbExpression; import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbSearch.JaxbExpressionSet; import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbSearch.JaxbFacetDefinition; import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbSearch.JaxbFullTextExpression; @@ -176,4 +180,12 @@ public SearchBuilder expression(Expression expression) { search.getExpressionSet().getExpressions().add(expression); return this; } + + @Override + public SearchBuilder asTemplate() { + if(search.getExpressionSet() != null && search.getExpressionSet().getExpressions().size() > 0) { + ((JaxbExpression)search.getExpressionSet().getExpressions().get(search.getExpressionSet().getExpressions().size() - 1)).setTemplate(true); + } + return this; + } } diff --git a/src/main/java/com/emc/documentum/rest/client/sample/model/xml/jaxb/JaxbSearchTemplate.java b/src/main/java/com/emc/documentum/rest/client/sample/model/xml/jaxb/JaxbSearchTemplate.java new file mode 100644 index 0000000..d8b8191 --- /dev/null +++ b/src/main/java/com/emc/documentum/rest/client/sample/model/xml/jaxb/JaxbSearchTemplate.java @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2016. EMC Corporation. All Rights Reserved. + */ +package com.emc.documentum.rest.client.sample.model.xml.jaxb; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlElements; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSeeAlso; +import javax.xml.bind.annotation.XmlTransient; + +import com.emc.documentum.rest.client.sample.model.Search; +import com.emc.documentum.rest.client.sample.model.SearchTemplate; +import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbSearchTemplate.JaxbFullTextVariable; +import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbSearchTemplate.JaxbPropertyListVariable; +import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbSearchTemplate.JaxbPropertyValueVariable; +import com.emc.documentum.rest.client.sample.model.xml.jaxb.JaxbSearchTemplate.JaxbRelativeDateVariable; + +import static com.emc.documentum.rest.client.sample.client.impl.jaxb.DCTMJaxbContext.marshal; +import static com.emc.documentum.rest.client.sample.client.impl.jaxb.DCTMJaxbContext.unmarshal; + +@XmlRootElement(name = "search-template") +@XmlSeeAlso({JaxbPropertyListVariable.class, JaxbRelativeDateVariable.class, JaxbPropertyValueVariable.class, JaxbFullTextVariable.class}) +public class JaxbSearchTemplate extends JaxbObject implements SearchTemplate { + private String queryDocumentTemplate; + private List externalVariables = new ArrayList<>(); + private String searchReference; + + public JaxbSearchTemplate() { + } + + public JaxbSearchTemplate(SearchTemplate template) { + super(template); + setSearch(template.getSearch()); + } + + @Override + public String getName() { + return "search-template"; + } + + @Override + @XmlElement(name = "query-document-template") + public String getQueryDocumentTemplate() { + return queryDocumentTemplate; + } + + public void setQueryDocumentTemplate(String queryDocumentTemplate) { + this.queryDocumentTemplate = queryDocumentTemplate; + } + + @Override + @XmlTransient + public Search getSearch() { + return queryDocumentTemplate==null?null:(Search)unmarshal(queryDocumentTemplate); + } + + public void setSearch(Search search) { + queryDocumentTemplate = search == null?null:marshal(search); + } + + @XmlElementWrapper(name = "external-variables") + @XmlElements({@XmlElement(name="property-list-variable", type=JaxbPropertyListVariable.class), + @XmlElement(name="relative-date-variable", type=JaxbRelativeDateVariable.class), + @XmlElement(name="property-variable", type=JaxbPropertyValueVariable.class), + @XmlElement(name="fulltext-variable", type=JaxbFullTextVariable.class)}) + @Override + public List getExternalVariables() { + return externalVariables; + } + + public void setExternalVariables(List externalVariables) { + this.externalVariables = externalVariables; + } + + @Override + @XmlAttribute(name = "search-reference") + public String getSearchReference() { + return searchReference; + } + + public void setSearchReference(String searchReference) { + this.searchReference = searchReference; + } + + public static abstract class JaxbExternalVariable implements ExternalVariable { + private String id; + private String expressionType; + private String dataType; + @Override + @XmlElement + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + @Override + @XmlElement(name = "expression-type") + public String getExpressionType() { + return expressionType; + } + public void setExpressionType(String expressionType) { + this.expressionType = expressionType; + } + @Override + @XmlElement(name = "data-type") + public String getDataType() { + return dataType; + } + public void setDataType(String dataType) { + this.dataType = dataType; + } + } + + public abstract static class JaxbPropertyVariable extends JaxbExternalVariable implements PropertyVariable { + private String propertyName; + private String operator; + @Override + @XmlElement(name = "property-name") + public String getPropertyName() { + return propertyName; + } + public void setPropertyName(String propertyName) { + this.propertyName = propertyName; + } + @Override + @XmlElement + public String getOperator() { + return operator; + } + public void setOperator(String operator) { + this.operator = operator; + } + } + + @XmlRootElement(name = "fulltext-variable") + public static class JaxbFullTextVariable extends JaxbExternalVariable implements FullTextVariable { + private String variableValue; + @Override + @XmlElement(name = "variable-value") + public String getVariableValue() { + return variableValue; + } + public void setVariableValue(String variableValue) { + this.variableValue = variableValue; + } + } + + @XmlRootElement(name = "property-variable") + public static class JaxbPropertyValueVariable extends JaxbPropertyVariable implements PropertyValueVariable { + private String variableValue; + @Override + @XmlElement(name = "variable-value") + public String getVariableValue() { + return variableValue; + } + public void setVariableValue(String variableValue) { + this.variableValue = variableValue; + } + } + + @XmlRootElement(name = "relative-date-variable") + public static class JaxbRelativeDateVariable extends JaxbPropertyVariable implements RelativeDateVariable { + private String variableValue; + @Override + @XmlElement(name = "variable-value") + public String getVariableValue() { + return variableValue; + } + public void setVariableValue(String variableValue) { + this.variableValue = variableValue; + } + } + + @XmlRootElement(name = "property-list-variable") + public static class JaxbPropertyListVariable extends JaxbPropertyVariable implements PropertyListVariable { + private List variableValue = new ArrayList<>(); + @Override + @XmlElementWrapper(name = "variable-value") + @XmlElement(name = "item") + public List getVariableValue() { + return variableValue; + } + public void setVariableValue(List variableValue) { + this.variableValue = variableValue; + } + } +} diff --git a/src/main/resources/com/emc/documentum/rest/client/sample/model/xml/jaxb/jaxb.index b/src/main/resources/com/emc/documentum/rest/client/sample/model/xml/jaxb/jaxb.index index 7128564..4b2b5cc 100644 --- a/src/main/resources/com/emc/documentum/rest/client/sample/model/xml/jaxb/jaxb.index +++ b/src/main/resources/com/emc/documentum/rest/client/sample/model/xml/jaxb/jaxb.index @@ -34,6 +34,7 @@ JaxbRepository JaxbSearch JaxbSearchEntry JaxbSearchFeed +JaxbSearchTemplate JaxbSysObject JaxbType JaxbRelation