use of io.gravitee.rest.api.model.UpdateOrganizationEntity 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.UpdateOrganizationEntity in project gravitee-management-rest-api by gravitee-io.
the class OrganizationCommandHandler method handle.
@Override
public Single<OrganizationReply> handle(OrganizationCommand command) {
OrganizationPayload organizationPayload = command.getPayload();
try {
UpdateOrganizationEntity newOrganization = new UpdateOrganizationEntity();
newOrganization.setCockpitId(organizationPayload.getCockpitId());
newOrganization.setHrids(organizationPayload.getHrids());
newOrganization.setName(organizationPayload.getName());
newOrganization.setDescription(organizationPayload.getDescription());
newOrganization.setDomainRestrictions(organizationPayload.getDomainRestrictions());
final OrganizationEntity organization = organizationService.createOrUpdate(organizationPayload.getId(), newOrganization);
logger.info("Organization [{}] handled with id [{}].", organization.getName(), organization.getId());
return Single.just(new OrganizationReply(command.getId(), CommandStatus.SUCCEEDED));
} catch (Exception e) {
logger.error("Error occurred when handling organization [{}] with id [{}].", organizationPayload.getName(), organizationPayload.getId(), e);
return Single.just(new OrganizationReply(command.getId(), CommandStatus.ERROR));
}
}
use of io.gravitee.rest.api.model.UpdateOrganizationEntity in project gravitee-management-rest-api by gravitee-io.
the class OrganizationServiceImpl method update.
@Override
public OrganizationEntity update(String organizationId, final UpdateOrganizationEntity organizationEntity) {
try {
Optional<Organization> organizationOptional = organizationRepository.findById(organizationId);
if (organizationOptional.isPresent()) {
flowService.save(FlowReferenceType.ORGANIZATION, organizationId, organizationEntity.getFlows());
Organization organization = convert(organizationEntity);
organization.setId(organizationId);
OrganizationEntity updatedOrganization = convert(organizationRepository.update(organization));
createPublishOrganizationEvent(updatedOrganization);
return updatedOrganization;
} else {
throw new OrganizationNotFoundException(organizationId);
}
} catch (TechnicalException | JsonProcessingException ex) {
LOGGER.error("An error occurs while trying to update organization {}", organizationEntity.getName(), ex);
throw new TechnicalManagementException("An error occurs while trying to update organization " + organizationEntity.getName(), ex);
}
}
use of io.gravitee.rest.api.model.UpdateOrganizationEntity in project gravitee-management-rest-api by gravitee-io.
the class OrganizationService_CreateTest method shouldUpdateOrganization.
@Test
public void shouldUpdateOrganization() throws TechnicalException {
when(mockOrganizationRepository.findById(any())).thenReturn(Optional.of(new Organization()));
UpdateOrganizationEntity org1 = new UpdateOrganizationEntity();
org1.setHrids(Arrays.asList("orgid"));
org1.setName("org_name");
org1.setDescription("org_desc");
List<String> domainRestrictions = Arrays.asList("domain", "restriction");
org1.setDomainRestrictions(domainRestrictions);
org1.setFlows(Arrays.asList(mock(Flow.class)));
Organization createdOrganization = new Organization();
createdOrganization.setId("org_id");
when(mockOrganizationRepository.update(any())).thenReturn(createdOrganization);
when(mockFlowService.findByReference(FlowReferenceType.ORGANIZATION, "org_id")).thenReturn(org1.getFlows());
OrganizationEntity organization = organizationService.createOrUpdate("org_id", org1);
assertNotNull("result is null", organization);
verify(mockOrganizationRepository, times(1)).update(argThat(arg -> arg != null && arg.getName().equals("org_name") && arg.getDescription().equals("org_desc") && arg.getDomainRestrictions().equals(domainRestrictions)));
verify(mockOrganizationRepository, never()).create(any());
verify(mockRoleService, never()).initialize("org_id");
verify(mockRoleService, never()).createOrUpdateSystemRoles("org_id");
verify(mockFlowService, times(1)).save(FlowReferenceType.ORGANIZATION, "org_id", org1.getFlows());
}
use of io.gravitee.rest.api.model.UpdateOrganizationEntity in project gravitee-management-rest-api by gravitee-io.
the class OrganizationService_CreateTest method shouldCreateOrganization.
@Test
public void shouldCreateOrganization() throws TechnicalException {
when(mockOrganizationRepository.findById(any())).thenReturn(Optional.empty());
UpdateOrganizationEntity org1 = new UpdateOrganizationEntity();
org1.setHrids(Arrays.asList("orgid"));
org1.setName("org_name");
org1.setDescription("org_desc");
List<String> domainRestrictions = Arrays.asList("domain", "restriction");
org1.setDomainRestrictions(domainRestrictions);
org1.setFlows(Arrays.asList());
Organization createdOrganization = new Organization();
createdOrganization.setId("org_id");
when(mockOrganizationRepository.create(any())).thenReturn(createdOrganization);
when(mockFlowService.findByReference(FlowReferenceType.ORGANIZATION, "org_id")).thenReturn(new ArrayList<>());
OrganizationEntity organization = organizationService.createOrUpdate("org_id", org1);
assertNotNull("result is null", organization);
verify(mockOrganizationRepository, times(1)).create(argThat(arg -> arg != null && arg.getName().equals("org_name") && arg.getDescription().equals("org_desc") && arg.getDomainRestrictions().equals(domainRestrictions)));
verify(mockOrganizationRepository, never()).update(any());
verify(mockRoleService, times(1)).initialize("org_id");
verify(mockRoleService, times(1)).createOrUpdateSystemRoles("org_id");
verify(mockFlowService, times(1)).save(FlowReferenceType.ORGANIZATION, "org_id", Arrays.asList());
}
Aggregations