use of io.gravitee.rest.api.model.OrganizationEntity 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.OrganizationEntity 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.OrganizationEntity 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