Search in sources :

Example 1 with QualityRuleNotFoundException

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

the class QualityRuleServiceImpl method findById.

@Override
public QualityRuleEntity findById(String id) {
    try {
        LOGGER.debug("Find quality rule by id : {}", id);
        Optional<QualityRule> qualityRule = qualityRuleRepository.findById(id);
        if (qualityRule.isPresent()) {
            return convert(qualityRule.get());
        }
        throw new QualityRuleNotFoundException(id);
    } catch (TechnicalException ex) {
        final String error = "An error occurs while trying to find a quality rule using its ID: " + id;
        LOGGER.error(error, ex);
        throw new TechnicalManagementException(error, ex);
    }
}
Also used : QualityRule(io.gravitee.repository.management.model.QualityRule) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) UuidString(io.gravitee.rest.api.service.common.UuidString) QualityRuleNotFoundException(io.gravitee.rest.api.service.exceptions.QualityRuleNotFoundException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 2 with QualityRuleNotFoundException

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

the class QualityRuleServiceImpl method update.

@Override
public QualityRuleEntity update(UpdateQualityRuleEntity updateEntity) {
    try {
        final Optional<QualityRule> optionalQualityRule = qualityRuleRepository.findById(updateEntity.getId());
        if (!optionalQualityRule.isPresent()) {
            throw new QualityRuleNotFoundException(updateEntity.getId());
        }
        final QualityRule qualityRule = qualityRuleRepository.update(convert(updateEntity, optionalQualityRule.get()));
        auditService.createEnvironmentAuditLog(singletonMap(QUALITY_RULE, qualityRule.getId()), QUALITY_RULE_UPDATED, qualityRule.getUpdatedAt(), optionalQualityRule.get(), qualityRule);
        return convert(qualityRule);
    } catch (TechnicalException e) {
        LOGGER.error("An error occurs while trying to update quality rule {}", updateEntity, e);
        throw new TechnicalManagementException("An error occurs while trying to update quality rule " + updateEntity, e);
    }
}
Also used : QualityRule(io.gravitee.repository.management.model.QualityRule) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) QualityRuleNotFoundException(io.gravitee.rest.api.service.exceptions.QualityRuleNotFoundException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Aggregations

TechnicalException (io.gravitee.repository.exceptions.TechnicalException)2 QualityRule (io.gravitee.repository.management.model.QualityRule)2 QualityRuleNotFoundException (io.gravitee.rest.api.service.exceptions.QualityRuleNotFoundException)2 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)2 UuidString (io.gravitee.rest.api.service.common.UuidString)1