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;
}
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);
}
}
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);
}
}
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);
}
}
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());
}
Aggregations