use of io.gravitee.rest.api.service.exceptions.OrganizationNotFoundException in project gravitee-management-rest-api by gravitee-io.
the class EnvironmentService_CreateTest method shouldHaveBadOrganizationExceptionWhenNoOrganizationInEntity.
@Test(expected = OrganizationNotFoundException.class)
public void shouldHaveBadOrganizationExceptionWhenNoOrganizationInEntity() {
when(mockOrganizationService.findById("UNKNOWN")).thenThrow(new OrganizationNotFoundException("UNKNOWN"));
environmentService.createOrUpdate("UNKNOWN", "env_id", new UpdateEnvironmentEntity());
}
use of io.gravitee.rest.api.service.exceptions.OrganizationNotFoundException 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.service.exceptions.OrganizationNotFoundException 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.rest.api.service.exceptions.OrganizationNotFoundException in project gravitee-management-rest-api by gravitee-io.
the class IdentityProviderUpgrader method getActivationsTarget.
private ActivationTarget[] getActivationsTarget(int providerIndex) {
List<String> targetStrings = getListOfString("security.providers[" + providerIndex + "].activations");
List<ActivationTarget> activationTargets = new ArrayList<>();
targetStrings.forEach(target -> {
final String[] orgEnv = target.split(":");
if (orgEnv.length == 1) {
try {
this.organizationService.findById(orgEnv[0]);
activationTargets.add(new ActivationTarget(orgEnv[0], IdentityProviderActivationReferenceType.ORGANIZATION));
} catch (OrganizationNotFoundException onfe) {
logger.warn("Organization {} does not exist", orgEnv[0]);
}
} else if (orgEnv.length == 2) {
try {
this.organizationService.findById(orgEnv[0]);
EnvironmentEntity env = this.environmentService.findById(orgEnv[1]);
if (env.getOrganizationId().equals(orgEnv[0])) {
activationTargets.add(new ActivationTarget(orgEnv[1], IdentityProviderActivationReferenceType.ENVIRONMENT));
} else {
logger.warn("Environment {} does not exist in organization {}", orgEnv[1], orgEnv[0]);
}
} catch (OrganizationNotFoundException onfe) {
logger.warn("Organization {} does not exist", orgEnv[0]);
} catch (EnvironmentNotFoundException Enfe) {
logger.warn("Environment {} does not exist", orgEnv[1]);
}
}
});
return activationTargets.toArray(new ActivationTarget[activationTargets.size()]);
}
Aggregations