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();
}
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();
}
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;
}
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;
}
}
}
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);
}
}
Aggregations