Skip to content

Commit

Permalink
support saved search relative resources
Browse files Browse the repository at this point in the history
  • Loading branch information
ruan-wei committed Aug 16, 2016
1 parent 7a92fda commit c627a17
Show file tree
Hide file tree
Showing 28 changed files with 539 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,50 @@
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.SavedSearch;
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.Search.PropertyListExpression;
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.SearchTemplate.FullTextVariable;
import com.emc.documentum.rest.client.sample.model.builder.SearchBuilder;
import com.emc.documentum.rest.client.sample.model.plain.PlainSavedSearch;
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;

@RestServiceSample("Search")
@RestServiceSample("Search (Advanced)")
@RestServiceVersion(7.3)
public class SearchSample extends Sample {
public void search() {
printStep("search with aql 1");
printStep("search with aql");
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);
print(client, search);
printNewLine();
SearchFeed<RestObject> result = client.search(search);
SearchFeed<RestObject> result = client.search(search, "items-per-page", "5");
printSearchFeed(result);
printNewLine();

printStep("search with aql 2");
printStep("search with aql and facet");
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);
print(client, search);
printNewLine();
result = client.search(search);
result = client.search(search, "items-per-page", "5");
printSearchFeed(result);
printNewLine();
}
Expand All @@ -70,16 +70,13 @@ public void searchTemplate() {
.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");
SearchTemplate createdSearchTemplateWithoutVariables = client.createSearchTemplate(new PlainSearchTemplate(search, "object_name", "my-search-template-without-variables"));
print(client, createdSearchTemplateWithoutVariables);
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());
print(client, searchTemplateWithoutVariables);
printNewLine();

printStep("create a search template with external variables");
Expand All @@ -94,16 +91,13 @@ public void searchTemplate() {
.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");
SearchTemplate createdSearchTemplateWithVariables = client.createSearchTemplate(new PlainSearchTemplate(search, "object_name", "my-search-template-with-variables"));
print(client, createdSearchTemplateWithVariables);
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());
print(client, searchTemplateWithVariables);
printNewLine();

printStep("get all search templates");
Expand All @@ -117,5 +111,97 @@ public void searchTemplate() {
client.delete(searchTemplateWithVariables);
printHttpStatus();
printNewLine();

printStep("create a search template with external variables to execute");
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)
.columns("r_object_id", "r_object_type", "object_name")
.fullTextExpression("to be replaced", true).asTemplate()
.sort("r_object_id", false, null, null)
.build();
SearchTemplate createdSearchTemplateToExecute = client.createSearchTemplate(new PlainSearchTemplate(search, "object_name", "my-search-template-to-execute"));
print(client, createdSearchTemplateToExecute);
FullTextVariable fullTextVariable = (FullTextVariable)createdSearchTemplateToExecute.getExternalVariables().get(0);
fullTextVariable.setVariableValue("test");
SearchFeed<RestObject> result = client.executeSearchTemplate(createdSearchTemplateToExecute, "items-per-page", "5");
printSearchFeed(result);
printNewLine();

printStep("delete the created search templates");
client.delete(createdSearchTemplateToExecute);
printHttpStatus();
}

public void savedSearch() {
printStep("create a saved search");
SearchBuilder builder = SearchBuilder.builder(client);
Search search = builder.allVersions(false)
.includeHiddenObjects(true)
.facetDefinition("facet", Arrays.asList("r_modify_date"), FacetDefinition.GROUP_BY_DATE_RELATIVE_DATE, FacetDefinition.SORT_VALUE_ASCENDING, 9)
.types("dm_sysobject")
.columns("r_object_id", "r_object_type", "object_name")
.propertyExpression("object_name", "test", PropertyExpression.OPERATOR_CONTAINS, false, false, false, true)
.propertyListExpression("object_name", Arrays.asList("test", "rest", "hello", "world"), PropertyListExpression.OPERATOR_NOT_IN, false)
.sort("r_modify_date", true, null, null)
.build();
SavedSearch createdSavedSearch = client.createSavedSearch(new PlainSavedSearch(search, "object_name", "my-saved-search"));
print(client, createdSavedSearch);
printNewLine();

printStep("get the single saved search " + createdSavedSearch.getObjectName());
SavedSearch savedSearch = client.getSavedSearch(createdSavedSearch.self());
print(client, savedSearch);
printNewLine();

printStep("update the saved search " + createdSavedSearch.getObjectName());
search = builder.reset()
.facetDefinition("facet", Arrays.asList("r_modify_date"), FacetDefinition.GROUP_BY_DATE_RELATIVE_DATE, FacetDefinition.SORT_VALUE_ASCENDING, 9)
.types("dm_sysobject")
.columns("r_object_id", "r_object_type", "object_name")
.fullTextExpression("test", true)
.sort("r_modify_date", true, null, null)
.build();
SavedSearch updatedSavedSearch = client.updateSavedSearch(createdSavedSearch, new PlainSavedSearch(search, "object_name", "updated-saved-search"));
print(client, updatedSavedSearch);
printNewLine();

printStep("execute the saved search " + updatedSavedSearch.getObjectName());
SearchFeed<RestObject> result = client.executeSavedSearch(updatedSavedSearch, "items-per-page", "5");
printSearchFeed(result);
printNewLine();

printStep("enable and refresh the saved search result of " + updatedSavedSearch.getObjectName());
result = client.enableSavedSearchResult(updatedSavedSearch);
printSearchFeed(result);
printNewLine();

printStep("get the saved search result of " + updatedSavedSearch.getObjectName());
result = client.getSavedSearchResult(updatedSavedSearch, "items-per-page", "5");
printSearchFeed(result);
printNewLine();

printStep("disable the saved search result of " + updatedSavedSearch.getObjectName());
client.disableSavedSearchResult(updatedSavedSearch);
printHttpStatus();
printNewLine();

printStep("convert the saved search to a search template");
SearchTemplate convertedSearchTemplate = client.createSearchTemplate(new PlainSearchTemplate(updatedSavedSearch.self()));
print(client, convertedSearchTemplate);
printNewLine();

printStep("get all saved searches");
Feed<SavedSearch> savedSearches = client.getSavedSearches();
printEntryContentSrc(savedSearches);
printNewLine();

printStep("delete the saved search and the search template");
client.delete(convertedSearchTemplate);
printHttpStatus();
client.delete(updatedSavedSearch);
printHttpStatus();
printNewLine();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import com.emc.documentum.rest.client.sample.model.RestObject;
import com.emc.documentum.rest.client.sample.model.SearchFeed;

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.printSearchFeed;
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("Simple Search")
@RestServiceSample("Search (Simple)")
@RestServiceVersion(7.2)
public class SimpleSearchSample extends Sample {
public void search() {
Expand Down
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.SavedSearch;
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;
Expand Down Expand Up @@ -916,5 +917,75 @@ public interface DCTMRestClient {
* @param template the search template to be created
* @return the created search template
*/
public SearchTemplate createSearchTemmplate(SearchTemplate template);
public SearchTemplate createSearchTemplate(SearchTemplate template);

/**
* execute a search template
* @param toBeExecuted the search template to be execute
* @param params the query parameters
* @return the search result
*/
public SearchFeed<RestObject> executeSearchTemplate(SearchTemplate toBeExecuted, String... params);

/**
* get saved searches of the repository
* @param params the query parameters
* @return the saved search feed
*/
public Feed<SavedSearch> getSavedSearches(String... params);

/**
* get single saved search
* @param uri the uri of the saved search
* @param params the query parameters
* @return the saved search
*/
public SavedSearch getSavedSearch(String uri, String... params);

/**
* create a saved search
* @param savedSearch the saved search to be created
* @return the created saved search
*/
public SavedSearch createSavedSearch(SavedSearch savedSearch);

/**
* update a saved search
* @param oldSavedSearch the saved search to be updated
* @param newSavedSearch the new saved search
* @return updated saved search
*/
public SavedSearch updateSavedSearch(SavedSearch oldSavedSearch, SavedSearch newSavedSearch);

/**
* execute a saved search
* @param toBeExecuted the saved search to be execute
* @param params the query parameters
* @return the search result
*/
public SearchFeed<RestObject> executeSavedSearch(SavedSearch toBeExecuted, String... params);

/**
* enable and refresh the saved search result
* @param toBeExecuted the saved search to be enable
* @param params the query parameters
* @return the search result
*/
public SearchFeed<RestObject> enableSavedSearchResult(SavedSearch toBeExecuted, String... params);

/**
* disable the saved search result
* @param toBeExecuted the saved search to be execute
* @param params the query parameters
* @return the search result
*/
public void disableSavedSearchResult(SavedSearch toBeExecuted);

/**
* get the saved search result
* @param toBeExecuted the saved search to be execute
* @param params the query parameters
* @return the search result
*/
public SearchFeed<RestObject> getSavedSearchResult(SavedSearch toBeExecuted, String... params);
}
Loading

0 comments on commit c627a17

Please sign in to comment.