Search in sources :

Example 1 with PromotionQuery

use of io.gravitee.rest.api.model.promotion.PromotionQuery in project gravitee-management-rest-api by gravitee-io.

the class GoodbyeCommandHandler method rejectAllPromotionToValidate.

private void rejectAllPromotionToValidate() {
    PromotionQuery promotionQuery = new PromotionQuery();
    promotionQuery.setStatuses(List.of(PromotionEntityStatus.TO_BE_VALIDATED));
    promotionService.search(promotionQuery, null, null).getContent().forEach(promotionEntity -> {
        promotionEntity.setStatus(PromotionEntityStatus.REJECTED);
        promotionService.createOrUpdate(promotionEntity);
    });
}
Also used : PromotionQuery(io.gravitee.rest.api.model.promotion.PromotionQuery)

Example 2 with PromotionQuery

use of io.gravitee.rest.api.model.promotion.PromotionQuery in project gravitee-management-rest-api by gravitee-io.

the class PromotionsResource method searchPromotions.

@POST
@Path("_search")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Search for Promotion")
@ApiResponses({ @ApiResponse(code = 200, message = "List promotions matching request parameters", response = PromotionEntity.class, responseContainer = "List"), @ApiResponse(code = 500, message = "Internal server error") })
public Response searchPromotions(@ApiParam(name = "statuses", required = true) @NotNull @QueryParam("statuses") List<String> statuses, @ApiParam(name = "apiId", required = true) @NotNull @QueryParam("apiId") String apiId) {
    PromotionQuery promotionQuery = new PromotionQuery();
    promotionQuery.setStatuses(statuses.stream().map(PromotionEntityStatus::valueOf).collect(toList()));
    promotionQuery.setApiId(apiId);
    List<PromotionEntity> promotions = promotionService.search(promotionQuery, new SortableImpl("created_at", false), null).getContent();
    return Response.ok().entity(promotions).build();
}
Also used : SortableImpl(io.gravitee.rest.api.model.common.SortableImpl) PromotionEntityStatus(io.gravitee.rest.api.model.promotion.PromotionEntityStatus) PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity) PromotionQuery(io.gravitee.rest.api.model.promotion.PromotionQuery) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 3 with PromotionQuery

use of io.gravitee.rest.api.model.promotion.PromotionQuery in project gravitee-management-rest-api by gravitee-io.

the class PromotionTasksServiceImpl method getPromotionTasksForEnvironments.

@NotNull
private List<TaskEntity> getPromotionTasksForEnvironments(List<EnvironmentEntity> environments, boolean selectUpdatePromotion) {
    if (environments.isEmpty()) {
        return emptyList();
    }
    List<String> envCockpitIds = environments.stream().map(EnvironmentEntity::getCockpitId).filter(Objects::nonNull).collect(toList());
    final PromotionQuery promotionQuery = new PromotionQuery();
    promotionQuery.setStatuses(Collections.singletonList(PromotionEntityStatus.TO_BE_VALIDATED));
    promotionQuery.setTargetEnvCockpitIds(envCockpitIds);
    final Page<PromotionEntity> promotionsPage = promotionService.search(promotionQuery, new SortableImpl("created_at", false), null);
    final PromotionQuery previousPromotionsQuery = new PromotionQuery();
    previousPromotionsQuery.setStatuses(Collections.singletonList(PromotionEntityStatus.ACCEPTED));
    previousPromotionsQuery.setTargetEnvCockpitIds(envCockpitIds);
    previousPromotionsQuery.setTargetApiExists(true);
    List<PromotionEntity> previousPromotions = promotionService.search(previousPromotionsQuery, new SortableImpl("created_at", false), null).getContent();
    final Map<String, List<String>> promotionByApiWithTargetApiId = previousPromotions.stream().collect(groupingBy(PromotionEntity::getApiId, Collectors.mapping(PromotionEntity::getTargetApiId, toList())));
    return promotionsPage.getContent().stream().map(promotionEntity -> {
        Optional<String> foundTargetApiId = promotionByApiWithTargetApiId.getOrDefault(promotionEntity.getApiId(), emptyList()).stream().filter(StringUtils::hasText).findFirst();
        boolean isUpdate = foundTargetApiId.isPresent() && apiService.exists(foundTargetApiId.get());
        return convert(promotionEntity, isUpdate, foundTargetApiId);
    }).filter(taskEntity -> ((Boolean) ((Map<String, Object>) taskEntity.getData()).getOrDefault("isApiUpdate", false) == selectUpdatePromotion)).collect(toList());
}
Also used : java.util(java.util) PromotionQuery(io.gravitee.rest.api.model.promotion.PromotionQuery) Page(io.gravitee.common.data.domain.Page) LoggerFactory(org.slf4j.LoggerFactory) PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity) PromotionEntityStatus(io.gravitee.rest.api.model.promotion.PromotionEntityStatus) ApiService(io.gravitee.rest.api.service.ApiService) UPDATE(io.gravitee.rest.api.model.permissions.RolePermissionAction.UPDATE) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) SortableImpl(io.gravitee.rest.api.model.common.SortableImpl) PermissionService(io.gravitee.rest.api.service.PermissionService) AbstractService(io.gravitee.rest.api.service.impl.AbstractService) TaskType(io.gravitee.rest.api.model.TaskType) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) TaskEntity(io.gravitee.rest.api.model.TaskEntity) Logger(org.slf4j.Logger) ENVIRONMENT_API(io.gravitee.rest.api.model.permissions.RolePermission.ENVIRONMENT_API) Collections.emptyList(java.util.Collections.emptyList) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) EnvironmentService(io.gravitee.rest.api.service.EnvironmentService) PromotionService(io.gravitee.rest.api.service.promotion.PromotionService) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Collectors(java.util.stream.Collectors) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) Component(org.springframework.stereotype.Component) CREATE(io.gravitee.rest.api.model.permissions.RolePermissionAction.CREATE) NotNull(org.jetbrains.annotations.NotNull) PromotionTasksService(io.gravitee.rest.api.service.promotion.PromotionTasksService) StringUtils(org.springframework.util.StringUtils) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) SortableImpl(io.gravitee.rest.api.model.common.SortableImpl) Collections.emptyList(java.util.Collections.emptyList) PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity) PromotionQuery(io.gravitee.rest.api.model.promotion.PromotionQuery) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PromotionQuery (io.gravitee.rest.api.model.promotion.PromotionQuery)3 SortableImpl (io.gravitee.rest.api.model.common.SortableImpl)2 PromotionEntity (io.gravitee.rest.api.model.promotion.PromotionEntity)2 PromotionEntityStatus (io.gravitee.rest.api.model.promotion.PromotionEntityStatus)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Page (io.gravitee.common.data.domain.Page)1 EnvironmentEntity (io.gravitee.rest.api.model.EnvironmentEntity)1 TaskEntity (io.gravitee.rest.api.model.TaskEntity)1 TaskType (io.gravitee.rest.api.model.TaskType)1 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)1 ENVIRONMENT_API (io.gravitee.rest.api.model.permissions.RolePermission.ENVIRONMENT_API)1 CREATE (io.gravitee.rest.api.model.permissions.RolePermissionAction.CREATE)1 UPDATE (io.gravitee.rest.api.model.permissions.RolePermissionAction.UPDATE)1 ApiService (io.gravitee.rest.api.service.ApiService)1 EnvironmentService (io.gravitee.rest.api.service.EnvironmentService)1 PermissionService (io.gravitee.rest.api.service.PermissionService)1 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)1 AbstractService (io.gravitee.rest.api.service.impl.AbstractService)1 PromotionService (io.gravitee.rest.api.service.promotion.PromotionService)1