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