use of io.gravitee.rest.api.model.UpdateEnvironmentEntity in project gravitee-management-rest-api by gravitee-io.
the class EnvironmentCommandHandler method handle.
@Override
public Single<EnvironmentReply> handle(EnvironmentCommand command) {
EnvironmentPayload environmentPayload = command.getPayload();
try {
UpdateEnvironmentEntity newEnvironment = new UpdateEnvironmentEntity();
newEnvironment.setCockpitId(environmentPayload.getCockpitId());
newEnvironment.setHrids(environmentPayload.getHrids());
newEnvironment.setName(environmentPayload.getName());
newEnvironment.setDescription(environmentPayload.getDescription());
newEnvironment.setDomainRestrictions(environmentPayload.getDomainRestrictions());
final EnvironmentEntity environment = environmentService.createOrUpdate(environmentPayload.getOrganizationId(), environmentPayload.getId(), newEnvironment);
logger.info("Environment [{}] handled with id [{}].", environment.getName(), environment.getId());
return Single.just(new EnvironmentReply(command.getId(), CommandStatus.SUCCEEDED));
} catch (Exception e) {
logger.error("Error occurred when handling environment [{}] with id [{}].", environmentPayload.getName(), environmentPayload.getId(), e);
return Single.just(new EnvironmentReply(command.getId(), CommandStatus.ERROR));
}
}
use of io.gravitee.rest.api.model.UpdateEnvironmentEntity in project gravitee-management-rest-api by gravitee-io.
the class CockpitIdUpgrader method upgrade.
@Override
public boolean upgrade() {
Collection<OrganizationEntity> organizations = organizationService.findAll();
organizations.stream().filter(org -> !org.getId().equals(GraviteeContext.getDefaultOrganization()) && org.getCockpitId() == null).forEach(org -> {
UpdateOrganizationEntity newOrganization = new UpdateOrganizationEntity(org);
newOrganization.setCockpitId(org.getId());
organizationService.update(org.getId(), newOrganization);
});
organizations.forEach(org -> environmentService.findByOrganization(org.getId()).stream().filter(env -> !env.getId().equals(GraviteeContext.getDefaultEnvironment()) && env.getCockpitId() == null).forEach(env -> {
UpdateEnvironmentEntity updateEnv = new UpdateEnvironmentEntity(env);
updateEnv.setCockpitId(env.getId());
environmentService.createOrUpdate(org.getId(), env.getId(), updateEnv);
}));
return true;
}
use of io.gravitee.rest.api.model.UpdateEnvironmentEntity in project gravitee-management-rest-api by gravitee-io.
the class EnvironmentService_CreateTest method shouldCreateEnvironment.
@Test
public void shouldCreateEnvironment() throws TechnicalException {
when(mockOrganizationService.findById(any())).thenReturn(null);
when(mockEnvironmentRepository.findById(any())).thenReturn(Optional.empty());
UpdateEnvironmentEntity env1 = new UpdateEnvironmentEntity();
env1.setHrids(Arrays.asList("envhrid"));
env1.setName("env_name");
env1.setDescription("env_desc");
List<String> domainRestrictions = Arrays.asList("domain", "restriction");
env1.setDomainRestrictions(domainRestrictions);
Environment createdEnv = new Environment();
createdEnv.setId("env_id");
when(mockEnvironmentRepository.create(any())).thenReturn(createdEnv);
EnvironmentEntity environment = environmentService.createOrUpdate("DEFAULT", "env_id", env1);
assertNotNull("result is null", environment);
verify(mockEnvironmentRepository, times(1)).create(argThat(arg -> arg != null && arg.getHrids().equals(Arrays.asList("envhrid")) && arg.getName().equals("env_name") && arg.getDescription().equals("env_desc") && arg.getDomainRestrictions().equals(domainRestrictions) && arg.getOrganizationId().equals("DEFAULT")));
verify(mockEnvironmentRepository, never()).update(any());
verify(mockAPIHeaderService, times(1)).initialize("env_id");
verify(mockPageService, times(1)).initialize("env_id");
}
use of io.gravitee.rest.api.model.UpdateEnvironmentEntity in project gravitee-management-rest-api by gravitee-io.
the class EnvironmentService_CreateTest method shouldUpdateEnvironment.
@Test
public void shouldUpdateEnvironment() throws TechnicalException {
when(mockOrganizationService.findById(any())).thenReturn(null);
when(mockEnvironmentRepository.findById(any())).thenReturn(Optional.of(new Environment()));
UpdateEnvironmentEntity env1 = new UpdateEnvironmentEntity();
env1.setHrids(Arrays.asList("envhrid"));
env1.setName("env_name");
env1.setDescription("env_desc");
List<String> domainRestrictions = Arrays.asList("domain", "restriction");
env1.setDomainRestrictions(domainRestrictions);
Environment updatedEnv = new Environment();
when(mockEnvironmentRepository.update(any())).thenReturn(updatedEnv);
EnvironmentEntity environment = environmentService.createOrUpdate("DEFAULT", "env_id", env1);
assertNotNull("result is null", environment);
verify(mockEnvironmentRepository, times(1)).update(argThat(arg -> arg != null && arg.getHrids().equals(Arrays.asList("envhrid")) && arg.getName().equals("env_name") && arg.getDescription().equals("env_desc") && arg.getDomainRestrictions().equals(domainRestrictions) && arg.getOrganizationId().equals("DEFAULT")));
verify(mockEnvironmentRepository, never()).create(any());
verify(mockAPIHeaderService, never()).initialize("env_id");
verify(mockPageService, never()).initialize("env_id");
}
use of io.gravitee.rest.api.model.UpdateEnvironmentEntity in project gravitee-management-rest-api by gravitee-io.
the class EnvironmentService_CreateTest method shouldHaveBadOrganizationExceptionWhenNoOrganizationInEntity.
@Test(expected = OrganizationNotFoundException.class)
public void shouldHaveBadOrganizationExceptionWhenNoOrganizationInEntity() {
when(mockOrganizationService.findById("UNKNOWN")).thenThrow(new OrganizationNotFoundException("UNKNOWN"));
environmentService.createOrUpdate("UNKNOWN", "env_id", new UpdateEnvironmentEntity());
}
Aggregations