Search in sources :

Example 1 with Organization

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

the class OrganizationServiceImpl method convert.

private Organization convert(final UpdateOrganizationEntity organizationEntity) {
    final Organization organization = new Organization();
    organization.setHrids(organizationEntity.getHrids());
    organization.setCockpitId(organizationEntity.getCockpitId());
    organization.setName(organizationEntity.getName());
    organization.setDescription(organizationEntity.getDescription());
    organization.setDomainRestrictions(organizationEntity.getDomainRestrictions());
    String flowMode = organizationEntity.getFlowMode() != null ? organizationEntity.getFlowMode().name() : FlowMode.DEFAULT.name();
    organization.setFlowMode(flowMode);
    return organization;
}
Also used : Organization(io.gravitee.repository.management.model.Organization)

Example 2 with Organization

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

the class OrganizationServiceImpl method initialize.

@Override
public void initialize() {
    Organization defaultOrganization = new Organization();
    defaultOrganization.setId(GraviteeContext.getDefaultOrganization());
    defaultOrganization.setName("Default organization");
    defaultOrganization.setDescription("Default organization");
    try {
        organizationRepository.create(defaultOrganization);
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to create default organization", ex);
        throw new TechnicalManagementException("An error occurs while trying to create default organization", ex);
    }
}
Also used : Organization(io.gravitee.repository.management.model.Organization) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 3 with Organization

use of io.gravitee.repository.management.model.Organization 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);
    }
}
Also used : OrganizationNotFoundException(io.gravitee.rest.api.service.exceptions.OrganizationNotFoundException) Organization(io.gravitee.repository.management.model.Organization) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) UpdateOrganizationEntity(io.gravitee.rest.api.model.UpdateOrganizationEntity) OrganizationEntity(io.gravitee.rest.api.model.OrganizationEntity) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 4 with Organization

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

the class OrganizationServiceImpl method findById.

@Override
public OrganizationEntity findById(String organizationId) {
    try {
        LOGGER.debug("Find organization by ID: {}", organizationId);
        Optional<Organization> optOrganization = organizationRepository.findById(organizationId);
        if (!optOrganization.isPresent()) {
            throw new OrganizationNotFoundException(organizationId);
        }
        return convert(optOrganization.get());
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to find organization by ID", ex);
        throw new TechnicalManagementException("An error occurs while trying to find organization by ID", ex);
    }
}
Also used : OrganizationNotFoundException(io.gravitee.rest.api.service.exceptions.OrganizationNotFoundException) Organization(io.gravitee.repository.management.model.Organization) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 5 with Organization

use of io.gravitee.repository.management.model.Organization 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());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) InjectMocks(org.mockito.InjectMocks) UpdateOrganizationEntity(io.gravitee.rest.api.model.UpdateOrganizationEntity) Arrays(java.util.Arrays) Organization(io.gravitee.repository.management.model.Organization) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) OrganizationEntity(io.gravitee.rest.api.model.OrganizationEntity) Assert.assertNotNull(org.junit.Assert.assertNotNull) Mock(org.mockito.Mock) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Flow(io.gravitee.definition.model.flow.Flow) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) ArrayList(java.util.ArrayList) Mockito(org.mockito.Mockito) List(java.util.List) FlowService(io.gravitee.rest.api.service.configuration.flow.FlowService) OrganizationServiceImpl(io.gravitee.rest.api.service.impl.OrganizationServiceImpl) FlowReferenceType(io.gravitee.repository.management.model.flow.FlowReferenceType) Optional(java.util.Optional) OrganizationRepository(io.gravitee.repository.management.api.OrganizationRepository) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Organization(io.gravitee.repository.management.model.Organization) UpdateOrganizationEntity(io.gravitee.rest.api.model.UpdateOrganizationEntity) UpdateOrganizationEntity(io.gravitee.rest.api.model.UpdateOrganizationEntity) OrganizationEntity(io.gravitee.rest.api.model.OrganizationEntity) Test(org.junit.Test)

Aggregations

Organization (io.gravitee.repository.management.model.Organization)6 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)5 OrganizationEntity (io.gravitee.rest.api.model.OrganizationEntity)3 UpdateOrganizationEntity (io.gravitee.rest.api.model.UpdateOrganizationEntity)3 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Flow (io.gravitee.definition.model.flow.Flow)2 OrganizationRepository (io.gravitee.repository.management.api.OrganizationRepository)2 FlowReferenceType (io.gravitee.repository.management.model.flow.FlowReferenceType)2 FlowService (io.gravitee.rest.api.service.configuration.flow.FlowService)2 OrganizationNotFoundException (io.gravitee.rest.api.service.exceptions.OrganizationNotFoundException)2 OrganizationServiceImpl (io.gravitee.rest.api.service.impl.OrganizationServiceImpl)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Optional (java.util.Optional)2 Assert.assertNotNull (org.junit.Assert.assertNotNull)2 Test (org.junit.Test)2 RunWith (org.junit.runner.RunWith)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2