use of com.opentext.ia.sdk.dto.query.Comparison in project infoarchive-sip-sdk by Enterprise-Content-Management.
the class WhenUsingInfoArchive method shouldQuerySuccessfully.
@Test
public void shouldQuerySuccessfully() throws IOException {
when(aics.getItems()).thenReturn(Stream.of(aic));
Link dipLink = new Link();
dipLink.setHref(randomString());
aic.getLinks().put(LINK_DIP, dipLink);
aic.setName("MyAic");
UriBuilder uriBuilder = mock(UriBuilder.class);
String uri = randomString();
when(uriBuilder.build()).thenReturn(uri);
when(uriBuilder.addParameter(anyString(), anyString())).thenReturn(uriBuilder);
when(restClient.uri(anyString())).thenReturn(uriBuilder);
QueryResultFactory queryResultFactory = mock(QueryResultFactory.class);
DefaultQueryResult queryResult = mock(DefaultQueryResult.class);
when(queryResultFactory.create(any(Response.class), any(Runnable.class))).thenReturn(queryResult);
when(restClient.get(eq(uri), any(QueryResultFactory.class))).thenReturn(queryResult);
SearchQuery query = new SearchQuery();
query.getItems().add(new Comparison("variable", Operator.EQUAL, "value"));
String aicName = "MyAic";
String schema = NAMESPACE;
configureServer();
QueryResult result = archiveClient.query(query, aicName, schema, 10);
assertEquals(queryResult, result);
}
use of com.opentext.ia.sdk.dto.query.Comparison in project infoarchive-sip-sdk by Enterprise-Content-Management.
the class WhenUsingInfoArchive method shouldSearchSuccessfully.
@Test
void shouldSearchSuccessfully() throws IOException {
SearchResults searchResults = mock(SearchResults.class);
when(searchResults.getUri("next")).thenReturn(null);
when(restClient.post(anyString(), eq(SearchResults.class), anyString(), eq(MediaTypes.XML))).thenReturn(searchResults);
SearchQuery searchQuery = new SearchQuery();
List<Item> items = new ArrayList<>();
items.add(new Comparison("from", Operator.EQUAL, ""));
items.add(new Comparison("recipient", Operator.EQUAL, ""));
List<String> dates = new ArrayList<>();
dates.add("2014-04-27");
dates.add("2016-10-11");
items.add(new Comparison("sentDate", Operator.BETWEEN, dates));
items.add(new Comparison("fromCountry", Operator.STARTS_WITH, ""));
items.add(new Comparison("toCountry", Operator.NOT_EQUAL, ""));
searchQuery.setItems(items);
SearchComposition searchComparison = new SearchComposition();
Map<String, Link> searchComparisonLinks = new HashMap<>();
Link compositionLink = new Link();
compositionLink.setHref(randomString());
searchComparisonLinks.put("self", compositionLink);
searchComparison.setLinks(searchComparisonLinks);
configureServer();
SearchResults result = archiveClient.search(searchQuery, searchComparison);
assertEquals(searchResults, result);
}
use of com.opentext.ia.sdk.dto.query.Comparison in project infoarchive-sip-sdk by Enterprise-Content-Management.
the class InfoArchiveRestClient method toSearchCriteria.
private String toSearchCriteria(SearchQuery searchQuery) {
SearchDataBuilder searchDataBuilder = SearchDataBuilder.builder();
searchQuery.getItems().stream().filter(item -> item instanceof Comparison).map(Comparison.class::cast).forEach(comparison -> addComparison(comparison, searchDataBuilder));
return searchDataBuilder.build().replaceFirst("<\\?.*\\?>", "").replace(" ", "").replace(System.lineSeparator(), "");
}
Aggregations