Search in sources :

Example 1 with Promotion

use of io.gravitee.repository.management.model.Promotion in project gravitee-management-rest-api by gravitee-io.

the class PromotionServiceImpl method convert.

private Promotion convert(String apiId, String apiDefinition, EnvironmentEntity source, PromotionRequestEntity target, UserEntity author) {
    PromotionAuthor promotionAuthor = new PromotionAuthor();
    promotionAuthor.setUserId(author.getId());
    promotionAuthor.setDisplayName(author.getDisplayName());
    promotionAuthor.setEmail(author.getEmail());
    promotionAuthor.setPicture(author.getPicture());
    promotionAuthor.setSource(author.getSource());
    promotionAuthor.setSourceId(author.getSourceId());
    Promotion promotion = new Promotion();
    promotion.setCreatedAt(new Date());
    promotion.setStatus(PromotionStatus.CREATED);
    promotion.setApiDefinition(apiDefinition);
    promotion.setApiId(apiId);
    promotion.setSourceEnvCockpitId(source.getCockpitId());
    promotion.setSourceEnvName(source.getName());
    promotion.setTargetEnvCockpitId(target.getTargetEnvCockpitId());
    promotion.setTargetEnvName(target.getTargetEnvName());
    promotion.setAuthor(promotionAuthor);
    return promotion;
}
Also used : PromotionAuthor(io.gravitee.repository.management.model.PromotionAuthor) Promotion(io.gravitee.repository.management.model.Promotion) Date(java.util.Date)

Example 2 with Promotion

use of io.gravitee.repository.management.model.Promotion in project gravitee-management-rest-api by gravitee-io.

the class PromotionServiceImpl method convert.

private Promotion convert(PromotionEntity promotionEntity) {
    PromotionAuthor promotionAuthor = new PromotionAuthor();
    promotionAuthor.setUserId(promotionEntity.getAuthor().getUserId());
    promotionAuthor.setDisplayName(promotionEntity.getAuthor().getDisplayName());
    promotionAuthor.setEmail(promotionEntity.getAuthor().getEmail());
    promotionAuthor.setPicture(promotionEntity.getAuthor().getPicture());
    promotionAuthor.setSource(promotionEntity.getAuthor().getSource());
    promotionAuthor.setSourceId(promotionEntity.getAuthor().getSourceId());
    Promotion promotion = new Promotion();
    promotion.setId(promotionEntity.getId());
    promotion.setApiId(promotionEntity.getApiId());
    promotion.setCreatedAt(promotionEntity.getCreatedAt());
    promotion.setUpdatedAt(promotionEntity.getUpdatedAt());
    promotion.setSourceEnvCockpitId(promotionEntity.getSourceEnvCockpitId());
    promotion.setSourceEnvName(promotionEntity.getSourceEnvName());
    promotion.setTargetEnvCockpitId(promotionEntity.getTargetEnvCockpitId());
    promotion.setTargetEnvName(promotionEntity.getTargetEnvName());
    promotion.setApiDefinition(promotionEntity.getApiDefinition());
    promotion.setStatus(convert(promotionEntity.getStatus()));
    promotion.setAuthor(promotionAuthor);
    return promotion;
}
Also used : PromotionAuthor(io.gravitee.repository.management.model.PromotionAuthor) Promotion(io.gravitee.repository.management.model.Promotion)

Example 3 with Promotion

use of io.gravitee.repository.management.model.Promotion in project gravitee-management-rest-api by gravitee-io.

the class PromotionServiceTest method getAPromotion.

private Promotion getAPromotion() {
    PromotionAuthor promotionAuthor = new PromotionAuthor();
    promotionAuthor.setUserId("user#1");
    promotionAuthor.setDisplayName("User 1");
    promotionAuthor.setEmail("user1@gv.io");
    promotionAuthor.setSource("cockpit");
    promotionAuthor.setSourceId("user1");
    Promotion promotion = new Promotion();
    promotion.setCreatedAt(new Date());
    promotion.setStatus(PromotionStatus.TO_BE_VALIDATED);
    promotion.setApiId("api#1");
    promotion.setApiDefinition("apiDefinition");
    promotion.setSourceEnvCockpitId("sourceEnvId");
    promotion.setSourceEnvName("sourceEnv Name");
    promotion.setTargetEnvCockpitId("targetEnvironmentId");
    promotion.setTargetEnvName("targetEnv Name");
    promotion.setAuthor(promotionAuthor);
    return promotion;
}
Also used : PromotionAuthor(io.gravitee.repository.management.model.PromotionAuthor) Promotion(io.gravitee.repository.management.model.Promotion) Date(java.util.Date)

Example 4 with Promotion

use of io.gravitee.repository.management.model.Promotion in project gravitee-management-rest-api by gravitee-io.

the class PromotionServiceTest method shouldProcessRejectedPromotion.

@Test
public void shouldProcessRejectedPromotion() throws Exception {
    when(promotionRepository.findById(any())).thenReturn(Optional.of(getAPromotion()));
    when(environmentService.findByCockpitId(any())).thenReturn(new EnvironmentEntity());
    Page<Promotion> promotionPage = new Page<>(singletonList(getAPromotion()), 0, 1, 1);
    when(promotionRepository.search(any(), any(), any())).thenReturn(promotionPage);
    CockpitReply<PromotionEntity> cockpitReply = new CockpitReply<>(null, CockpitReplyStatus.SUCCEEDED);
    when(cockpitService.processPromotion(any())).thenReturn(cockpitReply);
    when(promotionRepository.update(any())).thenReturn(getAPromotion());
    promotionService.processPromotion(PROMOTION_ID, false, USER_ID);
    verify(apiDuplicatorService, never()).createWithImportedDefinition(any(), eq(USER_ID), any(), any());
    verify(apiDuplicatorService, never()).updateWithImportedDefinition(any(), any(), eq(USER_ID), any(), any());
    verify(promotionRepository, times(1)).update(any());
}
Also used : CockpitReply(io.gravitee.rest.api.service.cockpit.services.CockpitReply) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) Page(io.gravitee.common.data.domain.Page) Promotion(io.gravitee.repository.management.model.Promotion) Test(org.junit.Test)

Example 5 with Promotion

use of io.gravitee.repository.management.model.Promotion in project gravitee-management-rest-api by gravitee-io.

the class PromotionServiceTest method shouldProcessAcceptedPromotionCreateApi.

@Test
public void shouldProcessAcceptedPromotionCreateApi() 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<>(emptyList(), 0, 1, 1);
    when(promotionRepository.search(any(), any(), any())).thenReturn(promotionPage);
    when(apiDuplicatorService.createWithImportedDefinition(any(), any(), any(), any())).thenReturn(new ApiEntity());
    CockpitReply<PromotionEntity> cockpitReply = new CockpitReply<>(null, CockpitReplyStatus.SUCCEEDED);
    when(cockpitService.processPromotion(any())).thenReturn(cockpitReply);
    when(promotionRepository.update(any())).thenReturn(getAPromotion());
    promotionService.processPromotion(PROMOTION_ID, true, USER_ID);
    verify(apiDuplicatorService, times(1)).createWithImportedDefinition(any(), eq(USER_ID), any(), any());
    verify(promotionRepository, times(1)).update(any());
}
Also used : CockpitReply(io.gravitee.rest.api.service.cockpit.services.CockpitReply) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Page(io.gravitee.common.data.domain.Page) Promotion(io.gravitee.repository.management.model.Promotion) Test(org.junit.Test)

Aggregations

Promotion (io.gravitee.repository.management.model.Promotion)14 Page (io.gravitee.common.data.domain.Page)9 EnvironmentEntity (io.gravitee.rest.api.model.EnvironmentEntity)9 Test (org.junit.Test)7 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)5 CockpitReply (io.gravitee.rest.api.service.cockpit.services.CockpitReply)5 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)4 PromotionAuthor (io.gravitee.repository.management.model.PromotionAuthor)4 Date (java.util.Date)3 PromotionCriteria (io.gravitee.repository.management.api.search.PromotionCriteria)2 SortableImpl (io.gravitee.rest.api.model.common.SortableImpl)2 PromotionRepository (io.gravitee.repository.management.api.PromotionRepository)1 Order (io.gravitee.repository.management.api.search.Order)1 PageableBuilder (io.gravitee.repository.management.api.search.builder.PageableBuilder)1 SortableBuilder (io.gravitee.repository.management.api.search.builder.SortableBuilder)1 PROMOTION_CREATED (io.gravitee.repository.management.model.Promotion.AuditEvent.PROMOTION_CREATED)1 PromotionStatus (io.gravitee.repository.management.model.PromotionStatus)1 UserEntity (io.gravitee.rest.api.model.UserEntity)1 Pageable (io.gravitee.rest.api.model.common.Pageable)1 Sortable (io.gravitee.rest.api.model.common.Sortable)1