Search in sources :

Example 1 with FacetedSearchResult

use of alien4cloud.dao.model.FacetedSearchResult in project alien4cloud by alien4cloud.

the class EsDaoPaginatedSearchTest method saveDataToES.

private void saveDataToES() throws IOException, IndexingServiceException {
    testDataList.clear();
    Path path = Paths.get("src/test/resources/nodetypes-faceted-search-result.json");
    FacetedSearchResult res = jsonMapper.readValue(path.toFile(), FacetedSearchResult.class);
    Object[] data = res.getData();
    for (Object element : data) {
        String serializeDatum = jsonMapper.writeValueAsString(element);
        NodeType indexedNodeType = jsonMapper.readValue(serializeDatum, NodeType.class);
        indexedNodeType.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
        String typeName = MappingBuilder.indexTypeFromClass(NodeType.class);
        dao.save(indexedNodeType);
        assertDocumentExisit(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, typeName, indexedNodeType.getId(), true);
        testDataList.add(indexedNodeType);
        for (CapabilityDefinition capaDef : indexedNodeType.getCapabilities()) {
            if (capaDef.getType().equals("jndi")) {
                jndiTestDataList.add(indexedNodeType);
            }
        }
    }
    refresh();
}
Also used : Path(java.nio.file.Path) NodeType(org.alien4cloud.tosca.model.types.NodeType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) FacetedSearchResult(alien4cloud.dao.model.FacetedSearchResult)

Example 2 with FacetedSearchResult

use of alien4cloud.dao.model.FacetedSearchResult in project alien4cloud by alien4cloud.

the class ApplicationController method search.

/**
 * Search for an application.
 *
 * @param searchRequest The element that contains criterias for search operation.
 * @return A rest response that contains a {@link FacetedSearchResult} containing applications.
 */
@ApiOperation(value = "Search for applications", notes = "Returns a search result with that contains applications matching the request. A application is returned only if the connected user has at least one application role in [ APPLICATION_MANAGER | APPLICATION_USER | APPLICATION_DEVOPS | DEPLOYMENT_MANAGER ]")
@RequestMapping(value = "/search", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<FacetedSearchResult> search(@RequestBody FilteredSearchRequest searchRequest) {
    FilterBuilder authorizationFilter = AuthorizationUtil.getResourceAuthorizationFilters();
    // We want to sort applications by deployed/undeployed and then application name.
    // Query all application ids and name.
    QueryBuilder queryBuilder = alienDAO.buildSearchQuery(Application.class, searchRequest.getQuery()).setFilters(searchRequest.getFilters(), authorizationFilter).queryBuilder();
    SearchResponse response = alienDAO.getClient().prepareSearch(alienDAO.getIndexForType(Application.class)).setQuery(queryBuilder).setFetchSource(new String[] { "name" }, null).setSize(Integer.MAX_VALUE).get();
    // Get their status (deployed vs undeployed)
    List<DeployedAppHolder> appHolders = Lists.newLinkedList();
    for (SearchHit hit : response.getHits().getHits()) {
        String id = hit.getId();
        String appName = (String) hit.getSource().get("name");
        boolean isDeployed = alienDAO.buildQuery(Deployment.class).setFilters(fromKeyValueCouples("sourceId", id, "endDate", null)).count() > 0;
        appHolders.add(new DeployedAppHolder(id, appName, isDeployed));
    }
    // Sort to have first all deployed apps sorted by name and then all undeployed apps sorted by name.
    Collections.sort(appHolders);
    // Compute the list of app ids to fetch based on the query pagination parameters
    List<String> appIdsToFetch = Lists.newArrayList();
    int to = searchRequest.getFrom() + searchRequest.getSize();
    for (int i = searchRequest.getFrom(); i < appHolders.size() && i < to; i++) {
        appIdsToFetch.add(appHolders.get(i).appId);
    }
    List<Application> applications;
    if (appIdsToFetch.size() == 0) {
        applications = Lists.newArrayList();
    } else {
        applications = alienDAO.findByIds(Application.class, appIdsToFetch.toArray(new String[appIdsToFetch.size()]));
    }
    return RestResponseBuilder.<FacetedSearchResult>builder().data(new FacetedSearchResult<>(searchRequest.getFrom(), to, response.getTookInMillis(), appHolders.size(), new String[] { Application.class.getSimpleName() }, applications.toArray(new Application[applications.size()]), Maps.newHashMap())).build();
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) Deployment(alien4cloud.model.deployment.Deployment) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse) FilterBuilder(org.elasticsearch.index.query.FilterBuilder) Application(alien4cloud.model.application.Application) FacetedSearchResult(alien4cloud.dao.model.FacetedSearchResult) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 3 with FacetedSearchResult

use of alien4cloud.dao.model.FacetedSearchResult in project alien4cloud by alien4cloud.

the class ToscaTypeSearchService method search.

// we need to override for aspect purpose
@Override
public FacetedSearchResult search(Class<? extends AbstractToscaType> clazz, String query, Integer size, Map<String, String[]> filters) {
    FacetedSearchResult result = super.search(clazz, query, size, filters);
    reorderIfNodeType(clazz, query, result);
    return result;
}
Also used : FacetedSearchResult(alien4cloud.dao.model.FacetedSearchResult)

Example 4 with FacetedSearchResult

use of alien4cloud.dao.model.FacetedSearchResult in project alien4cloud by alien4cloud.

the class ApplicationStepDefinitions method I_search_for_application.

@When("^I search for \"([^\"]*)\" application$")
public void I_search_for_application(String applicationName) throws Throwable {
    ComponentSearchRequest searchRequest = new ComponentSearchRequest(null, applicationName, 0, 10, null);
    String searchResponse = getRestClientInstance().postJSon("/rest/v1/applications/search", JsonUtil.toString(searchRequest));
    Context.getInstance().registerRestResponse(searchResponse);
    RestResponse<FacetedSearchResult> response = JsonUtil.read(searchResponse, FacetedSearchResult.class);
    for (Object appAsObj : response.getData().getData()) {
        Application app = JsonUtil.readObject(JsonUtil.toString(appAsObj), Application.class);
        if (applicationName.equals(app.getName())) {
            CURRENT_APPLICATION = app;
        }
    }
}
Also used : ComponentSearchRequest(alien4cloud.rest.component.ComponentSearchRequest) TestUtils.nullAsString(alien4cloud.it.utils.TestUtils.nullAsString) Application(alien4cloud.model.application.Application) FacetedSearchResult(alien4cloud.dao.model.FacetedSearchResult) When(cucumber.api.java.en.When)

Example 5 with FacetedSearchResult

use of alien4cloud.dao.model.FacetedSearchResult in project alien4cloud by alien4cloud.

the class ApplicationStepDefinitions method There_is_a_application.

@Given("^There is a \"([^\"]*)\" application$")
public void There_is_a_application(String applicationName) throws Throwable {
    FilteredSearchRequest searchRequest = new FilteredSearchRequest(applicationName, 0, 50, null);
    String searchResponse = getRestClientInstance().postJSon("/rest/v1/applications/search", JsonUtil.toString(searchRequest));
    RestResponse<FacetedSearchResult> response = JsonUtil.read(searchResponse, FacetedSearchResult.class);
    boolean hasApplication = false;
    for (Object appAsObj : response.getData().getData()) {
        Application app = JsonUtil.readObject(JsonUtil.toString(appAsObj), Application.class);
        if (applicationName.equals(app.getName())) {
            hasApplication = true;
            CURRENT_APPLICATION = app;
        }
    }
    if (!hasApplication) {
        doCreateApplication(applicationName, appToArchName(applicationName), null, null, true);
    }
}
Also used : FilteredSearchRequest(alien4cloud.rest.model.FilteredSearchRequest) TestUtils.nullAsString(alien4cloud.it.utils.TestUtils.nullAsString) Application(alien4cloud.model.application.Application) FacetedSearchResult(alien4cloud.dao.model.FacetedSearchResult) Given(cucumber.api.java.en.Given)

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