Search in sources :

Example 21 with GetMultipleDataResult

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

the class ComponentController method getDefaultNodeForCapability.

private NodeType getDefaultNodeForCapability(String capability) {
    Map<String, String[]> filters = new HashMap<>();
    filters.put(AlienConstants.DEFAULT_CAPABILITY_FIELD_NAME, new String[] { capability.toLowerCase() });
    GetMultipleDataResult result = dao.find(NodeType.class, filters, 1);
    if (result == null || result.getData() == null || result.getData().length == 0) {
        return null;
    }
    return (NodeType) result.getData()[0];
}
Also used : HashMap(java.util.HashMap) NodeType(org.alien4cloud.tosca.model.types.NodeType) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult)

Example 22 with GetMultipleDataResult

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

the class ApplicationStepDefinitions method setAppEnvironmentIdToContext.

@SuppressWarnings("rawtypes")
public void setAppEnvironmentIdToContext(String applicationName) throws IOException {
    String applicationId = Context.getInstance().getApplicationId(applicationName);
    FilteredSearchRequest request = new FilteredSearchRequest();
    request.setFrom(0);
    request.setSize(10);
    String applicationEnvironmentsJson = getRestClientInstance().postJSon("/rest/v1/applications/" + applicationId + "/environments/search", JsonUtil.toString(request));
    RestResponse<GetMultipleDataResult> restResponse = JsonUtil.read(applicationEnvironmentsJson, GetMultipleDataResult.class);
    GetMultipleDataResult searchResp = restResponse.getData();
    ApplicationEnvironmentDTO appEnvDTO = JsonUtil.readObject(JsonUtil.toString(searchResp.getData()[0]), ApplicationEnvironmentDTO.class);
    Context.getInstance().registerApplicationEnvironmentId(applicationName, appEnvDTO.getName(), appEnvDTO.getId());
}
Also used : FilteredSearchRequest(alien4cloud.rest.model.FilteredSearchRequest) ApplicationEnvironmentDTO(alien4cloud.rest.application.model.ApplicationEnvironmentDTO) TestUtils.nullAsString(alien4cloud.it.utils.TestUtils.nullAsString) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult)

Example 23 with GetMultipleDataResult

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

the class CsarGitCRUDStepDefinition method getCsarGitRepository.

private CsarGitRepository getCsarGitRepository(String url) throws Throwable {
    RestResponse<GetMultipleDataResult> response = JsonUtil.read(Context.getInstance().getRestResponse(), GetMultipleDataResult.class);
    assertNull(response.getError());
    assertNotNull(response.getData());
    for (Object object : response.getData().getData()) {
        CsarGitRepository csarGitRepository = JsonUtil.readObject(JsonUtil.toString(object), CsarGitRepository.class);
        if (csarGitRepository.getRepositoryUrl().equals(url)) {
            return csarGitRepository;
        }
    }
    return null;
}
Also used : CsarGitRepository(alien4cloud.model.git.CsarGitRepository) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult)

Example 24 with GetMultipleDataResult

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

the class LocationSecurityController method getAuthorizedUsersPaginated.

/**
 * search users authorised to access the location.
 *
 * @return {@link RestResponse} that contains a {@link GetMultipleDataResult} of {@link UserDTO}..
 */
// TODO consider merging this with getAuthorizedUsers
@ApiOperation(value = "List all users authorized to access the location", notes = "Only user with ADMIN role can list authorized users to the location.")
@RequestMapping(value = "/users/search", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
public RestResponse<GetMultipleDataResult<UserDTO>> getAuthorizedUsersPaginated(@PathVariable String orchestratorId, @PathVariable String locationId, @ApiParam(value = "Text Query to search.") @RequestParam(required = false) String query, @ApiParam(value = "Query from the given i*ndex.") @RequestParam(required = false, defaultValue = "0") int from, @ApiParam(value = "Maximum number of results to retrieve.") @RequestParam(required = false, defaultValue = "20") int size) {
    Location location = locationService.getLocation(orchestratorId, locationId);
    if (MapUtils.isEmpty(location.getUserPermissions())) {
        return RestResponseBuilder.<GetMultipleDataResult<UserDTO>>builder().data(new GetMultipleDataResult<>()).build();
    }
    IdsFilterBuilder idFilters = FilterBuilders.idsFilter().ids(location.getUserPermissions().keySet().toArray(new String[location.getUserPermissions().size()]));
    GetMultipleDataResult<User> tempResult = alienUserDao.find(query, from, size, idFilters);
    return RestResponseBuilder.<GetMultipleDataResult<UserDTO>>builder().data(UserDTO.convert(tempResult)).build();
}
Also used : User(alien4cloud.security.model.User) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) Location(alien4cloud.model.orchestrators.locations.Location) IdsFilterBuilder(org.elasticsearch.index.query.IdsFilterBuilder) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 25 with GetMultipleDataResult

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

the class LocationSecurityController method getAuthorizedGroupsPaginated.

/**
 * search groups authorised to access the location.
 *
 * @return {@link RestResponse} that contains a {@link GetMultipleDataResult} of {@link GroupDTO}..
 */
// TODO consider merging this with getAuthorizedGroups
@ApiOperation(value = "List all groups authorized to access the location", notes = "Only user with ADMIN role can list authorized groups to the location.")
@RequestMapping(value = "/groups/search", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
public RestResponse<GetMultipleDataResult<GroupDTO>> getAuthorizedGroupsPaginated(@PathVariable String orchestratorId, @PathVariable String locationId, @ApiParam(value = "Text Query to search.") @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 = "20") int size) {
    Location location = locationService.getLocation(orchestratorId, locationId);
    if (MapUtils.isEmpty(location.getGroupPermissions())) {
        return RestResponseBuilder.<GetMultipleDataResult<GroupDTO>>builder().data(new GetMultipleDataResult<>()).build();
    }
    IdsFilterBuilder idFilters = FilterBuilders.idsFilter().ids(location.getGroupPermissions().keySet().toArray(new String[location.getGroupPermissions().size()]));
    GetMultipleDataResult<Group> tempResult = alienGroupDao.find(query, from, size, idFilters);
    return RestResponseBuilder.<GetMultipleDataResult<GroupDTO>>builder().data(GroupDTO.convert(tempResult)).build();
}
Also used : Group(alien4cloud.security.model.Group) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) Location(alien4cloud.model.orchestrators.locations.Location) IdsFilterBuilder(org.elasticsearch.index.query.IdsFilterBuilder) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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