use of io.gravitee.rest.api.model.OrganizationEntity 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.OrganizationEntity in project gravitee-management-rest-api by gravitee-io.
the class OrganizationCommandHandlerTest method handle.
@Test
public void handle() {
OrganizationPayload organizationPayload = new OrganizationPayload();
OrganizationCommand command = new OrganizationCommand(organizationPayload);
organizationPayload.setId("orga#1");
organizationPayload.setCockpitId("org#cockpit-1");
organizationPayload.setHrids(Collections.singletonList("orga-1"));
organizationPayload.setDescription("Organization description");
organizationPayload.setName("Organization name");
organizationPayload.setDomainRestrictions(Arrays.asList("domain.restriction1.io", "domain.restriction2.io"));
when(organizationService.createOrUpdate(eq("orga#1"), argThat(newOrganization -> newOrganization.getCockpitId().equals(organizationPayload.getCockpitId()) && newOrganization.getHrids().equals(organizationPayload.getHrids()) && newOrganization.getDescription().equals(organizationPayload.getDescription()) && newOrganization.getName().equals(organizationPayload.getName()) && newOrganization.getDomainRestrictions().equals(organizationPayload.getDomainRestrictions())))).thenReturn(new OrganizationEntity());
TestObserver<OrganizationReply> obs = cut.handle(command).test();
obs.awaitTerminalEvent();
obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.SUCCEEDED));
}
use of io.gravitee.rest.api.model.OrganizationEntity in project gravitee-management-rest-api by gravitee-io.
the class HelloCommandProducerTest method handleReplay_shouldUpdateDefaultOrganizationCockpitId.
@Test
public void handleReplay_shouldUpdateDefaultOrganizationCockpitId() {
HelloReply helloReply = new HelloReply();
helloReply.setCommandStatus(CommandStatus.SUCCEEDED);
helloReply.setDefaultOrganizationCockpitId("org#cockpit-1");
String defaultOrgId = "DEFAULT";
OrganizationEntity defaultOrganization = new OrganizationEntity();
defaultOrganization.setId(defaultOrgId);
when(organizationService.findById(defaultOrgId)).thenReturn(defaultOrganization);
cut.handleReply(helloReply);
verify(organizationService).createOrUpdate(eq(defaultOrgId), argThat(org -> org.getCockpitId().equals("org#cockpit-1")));
}
use of io.gravitee.rest.api.model.OrganizationEntity in project gravitee-management-rest-api by gravitee-io.
the class OrganizationServiceImpl method convert.
private OrganizationEntity convert(final Organization organization) {
final OrganizationEntity organizationEntity = new OrganizationEntity();
organizationEntity.setId(organization.getId());
organizationEntity.setCockpitId(organization.getCockpitId());
organizationEntity.setHrids(organization.getHrids());
organizationEntity.setName(organization.getName());
organizationEntity.setDescription(organization.getDescription());
organizationEntity.setDomainRestrictions(organization.getDomainRestrictions());
FlowMode flowMode = organization.getFlowMode() != null ? FlowMode.valueOf(organization.getFlowMode()) : FlowMode.DEFAULT;
organizationEntity.setFlowMode(flowMode);
List<Flow> flows = flowService.findByReference(FlowReferenceType.ORGANIZATION, organization.getId());
organizationEntity.setFlows(flows);
return organizationEntity;
}
use of io.gravitee.rest.api.model.OrganizationEntity 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));
}
}
Aggregations