Search in sources :

Example 1 with OrganizationNotFoundException

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());
}
Also used : OrganizationNotFoundException(io.gravitee.rest.api.service.exceptions.OrganizationNotFoundException) UpdateEnvironmentEntity(io.gravitee.rest.api.model.UpdateEnvironmentEntity) Test(org.junit.Test)

Example 2 with OrganizationNotFoundException

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);
    }
}
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 3 with OrganizationNotFoundException

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);
    }
}
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 4 with OrganizationNotFoundException

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()]);
}
Also used : ActivationTarget(io.gravitee.rest.api.service.configuration.identity.IdentityProviderActivationService.ActivationTarget) OrganizationNotFoundException(io.gravitee.rest.api.service.exceptions.OrganizationNotFoundException) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) EnvironmentNotFoundException(io.gravitee.rest.api.service.exceptions.EnvironmentNotFoundException)

Aggregations

OrganizationNotFoundException (io.gravitee.rest.api.service.exceptions.OrganizationNotFoundException)4 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)2 Organization (io.gravitee.repository.management.model.Organization)2 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 EnvironmentEntity (io.gravitee.rest.api.model.EnvironmentEntity)1 OrganizationEntity (io.gravitee.rest.api.model.OrganizationEntity)1 UpdateEnvironmentEntity (io.gravitee.rest.api.model.UpdateEnvironmentEntity)1 UpdateOrganizationEntity (io.gravitee.rest.api.model.UpdateOrganizationEntity)1 ActivationTarget (io.gravitee.rest.api.service.configuration.identity.IdentityProviderActivationService.ActivationTarget)1 EnvironmentNotFoundException (io.gravitee.rest.api.service.exceptions.EnvironmentNotFoundException)1 Test (org.junit.Test)1