use of alien4cloud.dao.model.FacetedSearchResult in project alien4cloud by alien4cloud.
the class DeploymentController method search.
/**
* Search for deployments
*
* @return A rest response that contains a {@link FacetedSearchResult} containing deployments, including if asked some details of the related applications..
*/
@ApiOperation(value = "Search for deployments", notes = "Returns a search result with that contains deployments matching the request.")
@RequestMapping(value = "/search", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('ADMIN')")
public RestResponse<FacetedSearchResult> search(@ApiParam(value = "Query text.") @RequestParam(required = false) String query, @ApiParam(value = "Query from the given index.") @RequestParam(required = false, defaultValue = "0") int from, @ApiParam(value = "Maximum number of results to retrieve.") @RequestParam(required = false, defaultValue = "50") int size, @ApiParam(value = "Id of the orchestrator for which to get deployments. If not provided, get deployments for all orchestrators") @RequestParam(required = false) String orchestratorId, @ApiParam(value = "Id of the application for which to get deployments. if not provided, get deployments for all applications") @RequestParam(required = false) String sourceId, @ApiParam(value = "Id of the environment for which to get deployments. if not provided, get deployments without filtering by environment") @RequestParam(required = false) String environmentId, @ApiParam(value = "include or not the source (application or csar) summary in the results") @RequestParam(required = false, defaultValue = "false") boolean includeSourceSummary) {
FacetedSearchResult searchResult = deploymentService.searchDeployments(query, orchestratorId, environmentId, sourceId, from, size);
List<DeploymentDTO> deploymentsDTOS = buildDeploymentsDTOS(includeSourceSummary, (Deployment[]) searchResult.getData());
searchResult.setData(deploymentsDTOS.toArray());
return RestResponseBuilder.<FacetedSearchResult>builder().data(searchResult).build();
}
use of alien4cloud.dao.model.FacetedSearchResult in project alien4cloud by alien4cloud.
the class ESGenericSearchDAO method toFacetedSearchResult.
@SneakyThrows({ IOException.class })
private <T> FacetedSearchResult<T> toFacetedSearchResult(Class<T> clazz, int from, SearchResponse searchResponse) {
// return an empty object if nothing found
if (!somethingFound(searchResponse)) {
T[] resultData = (T[]) Array.newInstance(clazz, 0);
FacetedSearchResult toReturn = new FacetedSearchResult(from, 0, 0, 0, new String[0], resultData, new HashMap<String, FacetedSearchFacet[]>());
if (searchResponse != null) {
toReturn.setQueryDuration(searchResponse.getTookInMillis());
}
return toReturn;
}
FacetedSearchResult facetedSearchResult = new FacetedSearchResult();
// set data from the query
fillMultipleDataResult(clazz, searchResponse, facetedSearchResult, from, true);
// set aggregations
parseAggregations(searchResponse, facetedSearchResult, null);
return facetedSearchResult;
}
use of alien4cloud.dao.model.FacetedSearchResult in project alien4cloud by alien4cloud.
the class AuditLogStepsDefinitions method I_should_have_no_audit_trace_in_Alien.
@Then("^I should have no audit trace in Alien$")
public void I_should_have_no_audit_trace_in_Alien() throws Throwable {
FilteredSearchRequest req = new FilteredSearchRequest("", 0, 1, null);
String jSon = JsonUtil.toString(req);
String restResponse = Context.getRestClientInstance().postJSon("/rest/v1/audit/search", jSon);
FacetedSearchResult searchResult = JsonUtil.read(restResponse, FacetedSearchResult.class).getData();
Assert.assertEquals(0, searchResult.getTotalResults());
}
use of alien4cloud.dao.model.FacetedSearchResult in project alien4cloud by alien4cloud.
the class SearchDefinitionSteps method The_in_the_response_should_all_have_the.
@Then("^The \"([^\"]*)\" in the response should all have the \"([^\"]*)\" \"([^\"]*)\"$")
public void The_in_the_response_should_all_have_the(String searchedComponentType, String propertyValue, String property) throws Throwable {
RestResponse<FacetedSearchResult> restResponse = JsonUtil.read(Context.getInstance().takeRestResponse(), FacetedSearchResult.class);
FacetedSearchResult searchResp = restResponse.getData();
List<Object> resultData = Lists.newArrayList(searchResp.getData());
if (searchedComponentType.equalsIgnoreCase("node types")) {
for (Object object : resultData) {
NodeType idnt = JsonUtil.readObject(JsonUtil.toString(object), NodeType.class);
switch(property) {
case "capability":
assertNotNull(idnt.getCapabilities());
assertTrue(idnt.getCapabilities().contains(new CapabilityDefinition(propertyValue, propertyValue, 1)));
break;
case "requirement":
assertNotNull(idnt.getRequirements());
assertTrue(idnt.getRequirements().contains(new RequirementDefinition(propertyValue, propertyValue)));
break;
default:
break;
}
}
} else if (searchedComponentType.equalsIgnoreCase("relationship types")) {
for (Object object : resultData) {
RelationshipType idrt = JsonUtil.readObject(JsonUtil.toString(object), RelationshipType.class);
switch(property) {
case "validSource":
assertNotNull(idrt.getValidSources());
assertTrue(Arrays.equals(new String[] { propertyValue }, idrt.getValidSources()));
break;
default:
break;
}
}
}
}
use of alien4cloud.dao.model.FacetedSearchResult in project alien4cloud by alien4cloud.
the class SearchDefinitionSteps method checkPaginatedResult.
private void checkPaginatedResult(int expectedSize, RestResponse<FacetedSearchResult> restResponse) throws IOException {
List<NodeType> toCheckInDataList = notYetSearchedDataList == null ? new ArrayList<>(testDataList) : notYetSearchedDataList;
assertTrue(" The size of data to check (" + toCheckInDataList.size() + ") is less than the expected size (" + expectedSize + ") of search result ", toCheckInDataList.size() >= expectedSize);
FacetedSearchResult searchResp;
searchResp = restResponse.getData();
assertNotNull(searchResp);
assertNotNull(searchResp.getTypes());
assertNotNull(searchResp.getData());
assertEquals(expectedSize, searchResp.getTypes().length);
assertEquals(expectedSize, searchResp.getData().length);
// testing the pertinence of returned data
Object[] data = searchResp.getData();
for (int i = 0; i < data.length; i++) {
NodeType nt = JsonUtil.readObject(JsonUtil.toString(data[i]), NodeType.class);
assertTrue(toCheckInDataList.contains(nt));
toCheckInDataList.remove(nt);
}
}
Aggregations