Search in sources :

Example 6 with GetMultipleDataResult

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());
}
Also used : GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) Test(org.junit.Test)

Example 7 with GetMultipleDataResult

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();
}
Also used : OrchestratorState(alien4cloud.model.orchestrators.OrchestratorState) FilterBuilder(org.elasticsearch.index.query.FilterBuilder) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) Orchestrator(alien4cloud.model.orchestrators.Orchestrator) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with GetMultipleDataResult

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();
}
Also used : FilterBuilder(org.elasticsearch.index.query.FilterBuilder) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with GetMultipleDataResult

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();
}
Also used : GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with GetMultipleDataResult

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
    }
}
Also used : FilteredSearchRequest(alien4cloud.rest.model.FilteredSearchRequest) IOException(java.io.IOException) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) When(cucumber.api.java.en.When)

Aggregations

GetMultipleDataResult (alien4cloud.dao.model.GetMultipleDataResult)32 Test (org.junit.Test)9 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 ApiOperation (io.swagger.annotations.ApiOperation)7 HashMap (java.util.HashMap)7 NodeType (org.alien4cloud.tosca.model.types.NodeType)7 Application (alien4cloud.model.application.Application)4 User (alien4cloud.security.model.User)4 Then (cucumber.api.java.en.Then)4 Location (alien4cloud.model.orchestrators.locations.Location)3 IdsFilterBuilder (org.elasticsearch.index.query.IdsFilterBuilder)3 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)2 IGenericSearchDAO (alien4cloud.dao.IGenericSearchDAO)2 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)2 Orchestrator (alien4cloud.model.orchestrators.Orchestrator)2 FilteredSearchRequest (alien4cloud.rest.model.FilteredSearchRequest)2 Group (alien4cloud.security.model.Group)2 Arrays (java.util.Arrays)2 Resource (javax.annotation.Resource)2