Skip to content

Commit

Permalink
support advanced search with aql
Browse files Browse the repository at this point in the history
  • Loading branch information
ruan-wei committed Aug 9, 2016
1 parent aa93bcb commit 46f7e41
Show file tree
Hide file tree
Showing 61 changed files with 2,267 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.emc.documentum.rest.client.sample.model.RestObject;
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.BatchBuilder;
import com.emc.documentum.rest.client.sample.model.builder.BatchBuilder;
import com.emc.documentum.rest.client.sample.model.batch.Capabilities;
import com.emc.documentum.rest.client.sample.model.plain.PlainRestObject;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2016. EMC Corporation. All Rights Reserved.
*/
package com.emc.documentum.rest.client.sample.cases;

import java.util.Arrays;

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.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.SearchFeed;
import com.emc.documentum.rest.client.sample.model.builder.SearchBuilder;

import static com.emc.documentum.rest.client.sample.client.util.Debug.debugSerialize;
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;

@RestServiceSample("Search")
@RestServiceVersion(7.3)
public class SearchSample extends Sample {
public void search() {
printStep("search with aql 1");
SearchBuilder builder = SearchBuilder.builder(client);
Search search = builder.allVersions(true)
.columns("r_object_id", "r_object_type", "object_name")
.fullTextExpression("test", true)
.sort("r_object_id", false, null, null)
.build();
System.out.println("The aql is: ");
debugSerialize(client, search);
printNewLine();
SearchFeed<RestObject> result = client.search(search);
printSearchFeed(result);
printNewLine();

printStep("search with aql 2");
search = builder.reset()
.fullTextExpression("test", 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)
.build();
System.out.println("The aql is: ");
debugSerialize(client, search);
printNewLine();
result = client.search(search);
printSearchFeed(result);
printNewLine();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,33 @@

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.Facet;
import com.emc.documentum.rest.client.sample.model.FacetValue;
import com.emc.documentum.rest.client.sample.model.RestObject;
import com.emc.documentum.rest.client.sample.model.SearchEntry;
import com.emc.documentum.rest.client.sample.model.SearchFeed;

import static com.emc.documentum.rest.client.sample.client.util.Debug.print;
import static com.emc.documentum.rest.client.sample.client.util.Debug.printSearchFeed;
import static com.emc.documentum.rest.client.sample.client.util.Debug.printNewLine;
import static com.emc.documentum.rest.client.sample.client.util.Debug.printStep;
import static com.emc.documentum.rest.client.sample.client.util.Reader.read;

@RestServiceSample("Search")
@RestServiceSample("Simple Search")
@RestServiceVersion(7.2)
public class SimpleSearchSample extends Sample {
public void search() {
printStep("simple search");
String searchValue = read("Please input the value you want to search:");
SearchFeed<RestObject> result = client.search(searchValue);
for(SearchEntry<RestObject> e : result.getEntries()) {
System.out.println(e.getTitle() + " -> " + e.getContentSrc());
System.out.println("score:" + e.getScore() + ", terms:" + e.getTerms());
}
printSearchFeed(result);
printNewLine();

printStep("simple search with facet");
result = client.search(searchValue, "facet", "r_modify_date");
for(SearchEntry<RestObject> e : result.getEntries()) {
System.out.println(e.getTitle() + " -> " + e.getContentSrc());
System.out.println("score:" + e.getScore() + ", terms:" + e.getTerms());
}
for(Facet f : result.getFacets()) {
System.out.println("facet id:" + f.getId() + ", facet label:" + f.getLabel());
for(FacetValue fv : f.getValues()) {
System.out.println("facet-id:" + fv.getFacetId() + ", facet-value-id:" + fv.getId()
+ ", facet-value-count:" + fv.getCount() + "facet-value-constraint:" + fv.getConstraint());
print(fv);
}
}
printSearchFeed(result);
printNewLine();

printStep("simple search with inline result");
result = client.search(searchValue, "inline", "true");
for(SearchEntry<RestObject> e : result.getEntries()) {
System.out.println("score:" + e.getScore() + ", terms:" + e.getTerms());
print(e.getContentObject());
}
printSearchFeed(result);

printNewLine();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.emc.documentum.rest.client.sample.model.Repository;
import com.emc.documentum.rest.client.sample.model.RestObject;
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.ValueAssistant;
import com.emc.documentum.rest.client.sample.model.ValueAssistantRequest;
Expand Down Expand Up @@ -106,6 +107,14 @@ public interface DCTMRestClient {
*/
public SearchFeed<RestObject> search(String search, String... params);

/**
* execute the search
* @param search the Search object
* @param params the query parameters
* @return the search result feed
*/
public SearchFeed<RestObject> search(Search search, String... params);

/**
* @param params the query parameters
* @return the cabinets feed based on query parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@ protected <T> T post(String uri, Object body, Class<? extends T> responseBodyCla
return sendRequest(uri, POST, isXml()?ACCEPT_XML_HEADERS_WITH_CONTENT:ACCEPT_JSON_HEADERS_WITH_CONTENT, body, responseBodyClass, params);
}

protected <T> T post(String uri, Object body, HttpHeaders headers, Class<? extends T> responseBodyClass, String... params) {
return sendRequest(uri, POST, headers, body, responseBodyClass, params);
}

protected <T> T post(String uri, Object content, String contentMediaType, Class<? extends T> responseBodyClass, String... params) {
return sendRequest(uri, POST, new Headers().accept(isXml()?SupportedMediaTypes.APPLICATION_VND_DCTM_XML_VALUE:SupportedMediaTypes.APPLICATION_VND_DCTM_JSON_VALUE).contentType(contentMediaType).toHttpHeaders(),
content, responseBodyClass, params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.emc.documentum.rest.client.sample.model.Repository;
import com.emc.documentum.rest.client.sample.model.RestObject;
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.ValueAssistant;
import com.emc.documentum.rest.client.sample.model.ValueAssistantRequest;
Expand Down Expand Up @@ -168,6 +169,12 @@ public SearchFeed<RestObject> search(String search, String... params) {
return (SearchFeed<RestObject>)feed;
}

@Override
public SearchFeed<RestObject> search(Search search, String... params) {
SearchFeed<? extends RestObject> feed = post(getRepository().getHref(SEARCH), search, JsonFeeds.SearchFeed.class, params);
return (SearchFeed<RestObject>)feed;
}

@Override
public Feed<RestObject> getCabinets(String... params) {
Repository repository = getRepository();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javax.annotation.concurrent.NotThreadSafe;

import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.converter.FormHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter;
Expand All @@ -17,6 +18,7 @@
import com.emc.documentum.rest.client.sample.client.DCTMRestClient;
import com.emc.documentum.rest.client.sample.client.impl.AbstractRestTemplateClient;
import com.emc.documentum.rest.client.sample.client.util.Headers;
import com.emc.documentum.rest.client.sample.client.util.SupportedMediaTypes;
import com.emc.documentum.rest.client.sample.client.util.UriHelper;
import com.emc.documentum.rest.client.sample.model.Comment;
import com.emc.documentum.rest.client.sample.model.Entry;
Expand All @@ -32,6 +34,7 @@
import com.emc.documentum.rest.client.sample.model.Repository;
import com.emc.documentum.rest.client.sample.model.RestObject;
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.ValueAssistant;
import com.emc.documentum.rest.client.sample.model.ValueAssistantRequest;
Expand Down Expand Up @@ -174,6 +177,11 @@ public SearchFeed<RestObject> search(String search, String... params) {
return get(getRepository().getHref(SEARCH), true, JaxbSearchFeed.class, UriHelper.append(params, "q", search));
}

@Override
public SearchFeed<RestObject> search(Search search, String... params) {
return post(getRepository().getHref(SEARCH), search, new Headers().accept(MediaType.APPLICATION_ATOM_XML_VALUE).contentType(SupportedMediaTypes.APPLICATION_VND_DCTM_XML_VALUE).toHttpHeaders(), JaxbSearchFeed.class, params);
}

@Override
public Feed<RestObject> getCabinets(String... params) {
Repository repository = getRepository();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
package com.emc.documentum.rest.client.sample.client.util;

import java.io.ByteArrayOutputStream;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
Expand All @@ -15,7 +16,10 @@
import org.springframework.util.StringUtils;

import com.emc.documentum.rest.client.sample.client.DCTMRestClient;
import com.emc.documentum.rest.client.sample.client.impl.AbstractRestTemplateClient;
import com.emc.documentum.rest.client.sample.model.Entry;
import com.emc.documentum.rest.client.sample.model.Facet;
import com.emc.documentum.rest.client.sample.model.FacetValue;
import com.emc.documentum.rest.client.sample.model.Feed;
import com.emc.documentum.rest.client.sample.model.Link;
import com.emc.documentum.rest.client.sample.model.LinkRelation;
Expand All @@ -24,6 +28,8 @@
import com.emc.documentum.rest.client.sample.model.PermissionSet;
import com.emc.documentum.rest.client.sample.model.Preference;
import com.emc.documentum.rest.client.sample.model.RestObject;
import com.emc.documentum.rest.client.sample.model.SearchEntry;
import com.emc.documentum.rest.client.sample.model.SearchFeed;
import com.emc.documentum.rest.client.sample.model.batch.Batch;
import com.emc.documentum.rest.client.sample.model.batch.Operation;

Expand Down Expand Up @@ -64,6 +70,12 @@ public static void debugObject(Object object) {
}
}

public static void debugSerialize(DCTMRestClient client, Object object) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
((AbstractRestTemplateClient)client).serialize(object, os);
System.out.println(os);
}

public static void debugRestObject(RestObject object) {
if(object != null) {
debug("RestObject: type=" + object.getType() + ", properties=" + object.getProperties());
Expand Down Expand Up @@ -112,6 +124,32 @@ public static void printEntryContent(Feed<?> feed, String... properties) {
}
}
}

public static void printSearchFeed(SearchFeed<RestObject> result) {
if(result.getEntries() != null) {
for(SearchEntry<RestObject> e : result.getEntries()) {
if(e.getContentSrc() != null) {
System.out.println(e.getTitle() + " -> " + e.getContentSrc());
} else {
print(e.getContentObject());
}
System.out.println("score:" + e.getScore() + ", terms:" + e.getTerms());
}
} else {
System.out.println("no search result");
}

if(result.getFacets() != null) {
for(Facet f : result.getFacets()) {
System.out.println("facet id:" + f.getId() + ", facet label:" + f.getLabel());
for(FacetValue fv : f.getValues()) {
System.out.println("facet-id:" + fv.getFacetId() + ", facet-value-id:" + fv.getId()
+ ", facet-value-count:" + fv.getCount() + "facet-value-constraint:" + fv.getConstraint());
print(fv);
}
}
}
}

public static void print(RestObject object) {
print(object, "r_object_id", "object_name", "r_object_type");
Expand Down
Loading

0 comments on commit 46f7e41

Please sign in to comment.