Search in sources :

Example 1 with OrganizationEntity

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;
}
Also used : UpdateOrganizationEntity(io.gravitee.rest.api.model.UpdateOrganizationEntity) Upgrader(io.gravitee.rest.api.service.Upgrader) Ordered(org.springframework.core.Ordered) Component(org.springframework.stereotype.Component) OrganizationEntity(io.gravitee.rest.api.model.OrganizationEntity) UpdateEnvironmentEntity(io.gravitee.rest.api.model.UpdateEnvironmentEntity) Collection(java.util.Collection) EnvironmentService(io.gravitee.rest.api.service.EnvironmentService) Autowired(org.springframework.beans.factory.annotation.Autowired) GraviteeContext(io.gravitee.rest.api.service.common.GraviteeContext) OrganizationService(io.gravitee.rest.api.service.OrganizationService) UpdateEnvironmentEntity(io.gravitee.rest.api.model.UpdateEnvironmentEntity) UpdateOrganizationEntity(io.gravitee.rest.api.model.UpdateOrganizationEntity) OrganizationEntity(io.gravitee.rest.api.model.OrganizationEntity) UpdateOrganizationEntity(io.gravitee.rest.api.model.UpdateOrganizationEntity)

Example 2 with OrganizationEntity

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));
}
Also used : UpdateOrganizationEntity(io.gravitee.rest.api.model.UpdateOrganizationEntity) Arrays(java.util.Arrays) ArgumentMatchers(org.mockito.ArgumentMatchers) OrganizationEntity(io.gravitee.rest.api.model.OrganizationEntity) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) OrganizationService(io.gravitee.rest.api.service.OrganizationService) Command(io.gravitee.cockpit.api.command.Command) OrganizationPayload(io.gravitee.cockpit.api.command.organization.OrganizationPayload) OrganizationReply(io.gravitee.cockpit.api.command.organization.OrganizationReply) OrganizationCommand(io.gravitee.cockpit.api.command.organization.OrganizationCommand) CommandStatus(io.gravitee.cockpit.api.command.CommandStatus) Collections(java.util.Collections) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) OrganizationPayload(io.gravitee.cockpit.api.command.organization.OrganizationPayload) OrganizationReply(io.gravitee.cockpit.api.command.organization.OrganizationReply) UpdateOrganizationEntity(io.gravitee.rest.api.model.UpdateOrganizationEntity) OrganizationEntity(io.gravitee.rest.api.model.OrganizationEntity) OrganizationCommand(io.gravitee.cockpit.api.command.organization.OrganizationCommand) Test(org.junit.Test)

Example 3 with OrganizationEntity

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")));
}
Also used : ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) GraviteeContext(io.gravitee.rest.api.service.common.GraviteeContext) Command(io.gravitee.cockpit.api.command.Command) InstallationEntity(io.gravitee.rest.api.model.InstallationEntity) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) Before(org.junit.Before) Node(io.gravitee.node.api.Node) OrganizationEntity(io.gravitee.rest.api.model.OrganizationEntity) HelloReply(io.gravitee.cockpit.api.command.hello.HelloReply) InstallationService(io.gravitee.rest.api.service.InstallationService) Assert.assertTrue(org.junit.Assert.assertTrue) EnvironmentService(io.gravitee.rest.api.service.EnvironmentService) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) OrganizationService(io.gravitee.rest.api.service.OrganizationService) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) Mockito.verify(org.mockito.Mockito.verify) HelloPayload(io.gravitee.cockpit.api.command.hello.HelloPayload) CommandStatus(io.gravitee.cockpit.api.command.CommandStatus) HelloCommand(io.gravitee.cockpit.api.command.hello.HelloCommand) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) OrganizationEntity(io.gravitee.rest.api.model.OrganizationEntity) HelloReply(io.gravitee.cockpit.api.command.hello.HelloReply) Test(org.junit.Test)

Example 4 with OrganizationEntity

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;
}
Also used : UpdateOrganizationEntity(io.gravitee.rest.api.model.UpdateOrganizationEntity) OrganizationEntity(io.gravitee.rest.api.model.OrganizationEntity) FlowMode(io.gravitee.definition.model.FlowMode) Flow(io.gravitee.definition.model.flow.Flow)

Example 5 with 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));
    }
}
Also used : OrganizationPayload(io.gravitee.cockpit.api.command.organization.OrganizationPayload) OrganizationReply(io.gravitee.cockpit.api.command.organization.OrganizationReply) UpdateOrganizationEntity(io.gravitee.rest.api.model.UpdateOrganizationEntity) UpdateOrganizationEntity(io.gravitee.rest.api.model.UpdateOrganizationEntity) OrganizationEntity(io.gravitee.rest.api.model.OrganizationEntity)

Aggregations

OrganizationEntity (io.gravitee.rest.api.model.OrganizationEntity)8 UpdateOrganizationEntity (io.gravitee.rest.api.model.UpdateOrganizationEntity)7 Test (org.junit.Test)4 RunWith (org.junit.runner.RunWith)4 Mock (org.mockito.Mock)4 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)4 Flow (io.gravitee.definition.model.flow.Flow)3 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)3 Organization (io.gravitee.repository.management.model.Organization)3 OrganizationService (io.gravitee.rest.api.service.OrganizationService)3 Arrays (java.util.Arrays)3 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Command (io.gravitee.cockpit.api.command.Command)2 CommandStatus (io.gravitee.cockpit.api.command.CommandStatus)2 OrganizationPayload (io.gravitee.cockpit.api.command.organization.OrganizationPayload)2 OrganizationReply (io.gravitee.cockpit.api.command.organization.OrganizationReply)2 OrganizationRepository (io.gravitee.repository.management.api.OrganizationRepository)2 FlowReferenceType (io.gravitee.repository.management.model.flow.FlowReferenceType)2 EnvironmentService (io.gravitee.rest.api.service.EnvironmentService)2