Search in sources :

Example 1 with EnvironmentNotFoundException

use of io.gravitee.rest.api.service.exceptions.EnvironmentNotFoundException in project gravitee-management-rest-api by gravitee-io.

the class EnvironmentServiceImpl method findById.

@Override
public EnvironmentEntity findById(String environmentId) {
    try {
        LOGGER.debug("Find environment by ID: {}", environmentId);
        Optional<Environment> optEnvironment = environmentRepository.findById(environmentId);
        if (!optEnvironment.isPresent()) {
            throw new EnvironmentNotFoundException(environmentId);
        }
        return convert(optEnvironment.get());
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to find environment by ID", ex);
        throw new TechnicalManagementException("An error occurs while trying to find environment by ID", ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) EnvironmentNotFoundException(io.gravitee.rest.api.service.exceptions.EnvironmentNotFoundException) Environment(io.gravitee.repository.management.model.Environment) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 2 with EnvironmentNotFoundException

use of io.gravitee.rest.api.service.exceptions.EnvironmentNotFoundException 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

EnvironmentNotFoundException (io.gravitee.rest.api.service.exceptions.EnvironmentNotFoundException)2 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1 Environment (io.gravitee.repository.management.model.Environment)1 EnvironmentEntity (io.gravitee.rest.api.model.EnvironmentEntity)1 ActivationTarget (io.gravitee.rest.api.service.configuration.identity.IdentityProviderActivationService.ActivationTarget)1 OrganizationNotFoundException (io.gravitee.rest.api.service.exceptions.OrganizationNotFoundException)1 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)1