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