use of io.gravitee.rest.api.model.EnvironmentEntity 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());
}
use of io.gravitee.rest.api.model.EnvironmentEntity in project gravitee-management-rest-api by gravitee-io.
the class VirtualHostServiceTest method validate_nullIsNotASubDomain.
@Test
public void validate_nullIsNotASubDomain() {
VirtualHost vhost = new VirtualHost();
vhost.setHost(null);
vhost.setPath("/validVhostPath");
EnvironmentEntity environmentEntity = new EnvironmentEntity();
environmentEntity.setDomainRestrictions(Arrays.asList("test.gravitee.io", "other.gravitee.io"));
when(environmentService.findById(any())).thenReturn(environmentEntity);
final Collection<VirtualHost> virtualHosts = virtualHostService.sanitizeAndValidate(Collections.singletonList(vhost));
Assert.assertEquals(1, virtualHosts.size());
Assert.assertEquals("test.gravitee.io", virtualHosts.iterator().next().getHost());
}
use of io.gravitee.rest.api.model.EnvironmentEntity in project gravitee-management-rest-api by gravitee-io.
the class VirtualHostServiceTest method validate_hostSubDomainOfDomainConstraint.
@Test
public void validate_hostSubDomainOfDomainConstraint() {
VirtualHost vhost = getValidVirtualHost();
String domainConstraint = vhost.getHost();
vhost.setHost("level2.level1." + domainConstraint);
EnvironmentEntity environmentEntity = new EnvironmentEntity();
environmentEntity.setDomainRestrictions(Collections.singletonList(domainConstraint));
when(environmentService.findById(any())).thenReturn(environmentEntity);
virtualHostService.sanitizeAndValidate(Collections.singletonList(vhost));
}
use of io.gravitee.rest.api.model.EnvironmentEntity in project gravitee-management-rest-api by gravitee-io.
the class VirtualHostServiceTest method validate_notASubDomain.
@Test(expected = InvalidVirtualHostException.class)
public void validate_notASubDomain() {
VirtualHost vhost = getValidVirtualHost();
EnvironmentEntity environmentEntity = new EnvironmentEntity();
environmentEntity.setDomainRestrictions(Arrays.asList("test.gravitee.io", "other.gravitee.io"));
when(environmentService.findById(any())).thenReturn(environmentEntity);
virtualHostService.sanitizeAndValidate(Collections.singletonList(vhost));
}
use of io.gravitee.rest.api.model.EnvironmentEntity in project gravitee-management-rest-api by gravitee-io.
the class PromotionServiceTest method shouldNotProcessPromotionIfCockpitReplyError.
@Test(expected = BridgeOperationException.class)
public void shouldNotProcessPromotionIfCockpitReplyError() throws Exception {
when(promotionRepository.findById(any())).thenReturn(Optional.of(getAPromotion()));
when(environmentService.findByCockpitId(any())).thenReturn(new EnvironmentEntity());
when(permissionService.hasPermission(any(), any(), any())).thenReturn(true);
Page<Promotion> promotionPage = new Page<>(singletonList(getAPromotion()), 0, 1, 1);
when(promotionRepository.search(any(), any(), any())).thenReturn(promotionPage);
when(apiService.exists(any())).thenReturn(true);
when(apiDuplicatorService.updateWithImportedDefinition(any(), any(), any(), any(), any())).thenReturn(new ApiEntity());
ApiEntity existingApi = new ApiEntity();
existingApi.setId("api#existing");
when(apiService.findById(any())).thenReturn(existingApi);
CockpitReply<PromotionEntity> cockpitReply = new CockpitReply<>(null, CockpitReplyStatus.ERROR);
when(cockpitService.processPromotion(any())).thenReturn(cockpitReply);
promotionService.processPromotion(PROMOTION_ID, true, USER_ID);
verify(apiDuplicatorService, times(1)).updateWithImportedDefinition(any(), any(), eq(USER_ID), any(), any());
verify(promotionRepository, times(0)).update(any());
}
Aggregations