Search in sources :

Example 16 with FacetedSearchResult

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

Example 17 with FacetedSearchResult

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;
}
Also used : FacetedSearchResult(alien4cloud.dao.model.FacetedSearchResult) SneakyThrows(lombok.SneakyThrows)

Example 18 with 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());
}
Also used : FilteredSearchRequest(alien4cloud.rest.model.FilteredSearchRequest) FacetedSearchResult(alien4cloud.dao.model.FacetedSearchResult) Then(cucumber.api.java.en.Then)

Example 19 with FacetedSearchResult

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;
            }
        }
    }
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) FacetedSearchResult(alien4cloud.dao.model.FacetedSearchResult) Then(cucumber.api.java.en.Then)

Example 20 with FacetedSearchResult

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);
    }
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) FacetedSearchResult(alien4cloud.dao.model.FacetedSearchResult)

Aggregations

FacetedSearchResult (alien4cloud.dao.model.FacetedSearchResult)22 Then (cucumber.api.java.en.Then)6 FilteredSearchRequest (alien4cloud.rest.model.FilteredSearchRequest)5 NodeType (org.alien4cloud.tosca.model.types.NodeType)5 Application (alien4cloud.model.application.Application)3 HashMap (java.util.HashMap)3 SneakyThrows (lombok.SneakyThrows)3 FacetedSearchFacet (alien4cloud.dao.model.FacetedSearchFacet)2 GetMultipleDataResult (alien4cloud.dao.model.GetMultipleDataResult)2 TestUtils.nullAsString (alien4cloud.it.utils.TestUtils.nullAsString)2 Deployment (alien4cloud.model.deployment.Deployment)2 Given (cucumber.api.java.en.Given)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 Function (java.util.function.Function)2 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 FilterBuilder (org.elasticsearch.index.query.FilterBuilder)2