use of alien4cloud.dao.model.GetMultipleDataResult in project alien4cloud by alien4cloud.
the class EsQuickSearchTest method simpleQuickSearchTest.
@Test
public void simpleQuickSearchTest() throws IndexingServiceException, InterruptedException, IOException {
String searchText = "app";
GetMultipleDataResult searchResp = alienDAO.search(new String[] { APPLICATION_INDEX, ElasticSearchDAO.TOSCA_ELEMENT_INDEX }, new Class<?>[] { NodeType.class, Application.class }, searchText, null, null, 0, 10);
assertNotNull(searchResp);
assertNotNull(searchResp.getTypes());
assertNotNull(searchResp.getData());
assertEquals(2, searchResp.getTypes().length);
assertEquals(2, searchResp.getData().length);
assertElementIn("nodetype", searchResp.getTypes());
assertElementIn("application", searchResp.getTypes());
}
use of alien4cloud.dao.model.GetMultipleDataResult in project alien4cloud by alien4cloud.
the class OrchestratorController method search.
@ApiOperation(value = "Search for orchestrators.")
@RequestMapping(method = RequestMethod.GET)
@PreAuthorize("isAuthenticated()")
public RestResponse<GetMultipleDataResult<Orchestrator>> search(@ApiParam(value = "Query text.") @RequestParam(required = false) String query, @ApiParam(value = "If true only connected orchestrators will be retrieved.") @RequestParam(required = false, defaultValue = "false") boolean connectedOnly, @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 = "20") int size) {
FilterBuilder authorizationFilter = AuthorizationUtil.getResourceAuthorizationFilters();
OrchestratorState filterStatus = connectedOnly ? OrchestratorState.CONNECTED : null;
GetMultipleDataResult<Orchestrator> result = orchestratorService.search(query, filterStatus, from, size, authorizationFilter);
return RestResponseBuilder.<GetMultipleDataResult<Orchestrator>>builder().data(result).build();
}
use of alien4cloud.dao.model.GetMultipleDataResult in project alien4cloud by alien4cloud.
the class QuickSearchController method search.
@ApiOperation(value = "Search for applications or tosca elements in ALIEN's repository.")
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<GetMultipleDataResult> search(@RequestBody BasicSearchRequest requestObject) {
Set<String> authoIndexes = Sets.newHashSet();
Set<Class<?>> classes = Sets.newHashSet();
// First phase : COMPONENTS search, needed role Role.COMPONENTS_BROWSER or Role.ADMIN
if (AuthorizationUtil.hasOneRoleIn(Role.COMPONENTS_BROWSER)) {
authoIndexes.add(ElasticSearchDAO.TOSCA_ELEMENT_INDEX);
classes.add(NodeType.class);
}
GetMultipleDataResult searchResultComponents = searchByType(requestObject, authoIndexes, classes, null, null);
// Second phase : APPLICATION search (with rights filter) or with the Role.ADMIN
authoIndexes.clear();
classes.clear();
authoIndexes.add(Application.class.getSimpleName().toLowerCase());
classes.add(Application.class);
// Adding filters to get only authorized applications
// only filter on users roles on the application if the current user is not an ADMIN
FilterBuilder authorizationFilter = AuthorizationUtil.getResourceAuthorizationFilters();
GetMultipleDataResult<?> searchResultApplications = searchByType(requestObject, authoIndexes, classes, null, authorizationFilter);
// Final merge result : COMPONENTS + APPLICATIONS
GetMultipleDataResult searchResult = new GetMultipleDataResult();
searchResult.setQueryDuration(searchResultComponents.getQueryDuration() + searchResultApplications.getQueryDuration());
searchResult.setTypes(ArrayUtils.addAll(searchResultComponents.getTypes(), searchResultApplications.getTypes()));
searchResult.setData(ArrayUtils.addAll(searchResultComponents.getData(), searchResultApplications.getData()));
searchResult.setTotalResults(searchResultComponents.getTotalResults() + searchResultApplications.getTotalResults());
return RestResponseBuilder.<GetMultipleDataResult>builder().data(searchResult).build();
}
use of alien4cloud.dao.model.GetMultipleDataResult in project alien4cloud by alien4cloud.
the class QuickSearchController method searchRelationshipTypes.
@ApiOperation(value = "Search for relationship types in ALIEN's repository.")
@RequestMapping(value = "relationship_types", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<GetMultipleDataResult> searchRelationshipTypes(@RequestBody BasicSearchRequest requestObject) {
AuthorizationUtil.checkHasOneRoleIn(Role.COMPONENTS_BROWSER);
Set<String> authoIndexes = Sets.newHashSet();
Set<Class<?>> classes = Sets.newHashSet();
authoIndexes.add(ElasticSearchDAO.TOSCA_ELEMENT_INDEX);
classes.add(RelationshipType.class);
GetMultipleDataResult searchResult = searchByType(requestObject, authoIndexes, classes, null, null);
return RestResponseBuilder.<GetMultipleDataResult>builder().data(searchResult).build();
}
use of alien4cloud.dao.model.GetMultipleDataResult in project alien4cloud by alien4cloud.
the class ApplicationEnvironmentStepDefinitions method getAllApplicationEnvironments.
@When("^I get all application environments for application \"([^\"]*)\"$")
public void getAllApplicationEnvironments(String applicationId) throws Throwable {
FilteredSearchRequest request = new FilteredSearchRequest();
request.setFrom(0);
// This is actually the maximum search size in a4c (1000 by default)
request.setSize(AlienConstants.MAX_ES_SEARCH_SIZE);
Context.getInstance().registerRestResponse(Context.getRestClientInstance().postJSon("/rest/v1/applications/" + applicationId + "/environments/search", JsonUtil.toString(request)));
try {
RestResponse<GetMultipleDataResult> restResponse = JsonUtil.read(Context.getInstance().getRestResponse(), GetMultipleDataResult.class);
ALL_ENVIRONMENTS = new ApplicationEnvironmentDTO[restResponse.getData().getData().length];
TestUtils.convert(restResponse.getData(), ALL_ENVIRONMENTS, ApplicationEnvironmentDTO.class);
CURRENT_ENVIRONMENT_DTO = ALL_ENVIRONMENTS[0];
} catch (IOException e) {
// Registration is optional
}
}
Aggregations