Search in sources :

Example 71 with TechnicalManagementException

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

the class QualityRuleServiceImpl method delete.

@Override
public void delete(final String qualityRule) {
    try {
        final Optional<QualityRule> qualityRuleOptional = qualityRuleRepository.findById(qualityRule);
        if (qualityRuleOptional.isPresent()) {
            qualityRuleRepository.delete(qualityRule);
            // delete all reference on api quality rule
            apiQualityRuleRepository.deleteByQualityRule(qualityRule);
            auditService.createEnvironmentAuditLog(Collections.singletonMap(QUALITY_RULE, qualityRule), QualityRule.AuditEvent.QUALITY_RULE_DELETED, new Date(), null, qualityRuleOptional.get());
        }
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to delete quality rule {}", qualityRule, ex);
        throw new TechnicalManagementException("An error occurs while trying to delete quality rule " + qualityRule, ex);
    }
}
Also used : QualityRule(io.gravitee.repository.management.model.QualityRule) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Date(java.util.Date) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 72 with TechnicalManagementException

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

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

the class RatingServiceImpl method findByApi.

@Override
public Page<RatingEntity> findByApi(final String api, final Pageable pageable) {
    if (!isEnabled()) {
        throw new ApiRatingUnavailableException();
    }
    try {
        final Page<Rating> pageRating = ratingRepository.findByReferenceIdAndReferenceTypePageable(api, RatingReferenceType.API, new PageableBuilder().pageNumber(pageable.pageNumber() - 1).pageSize(pageable.pageSize()).build());
        final List<RatingEntity> ratingEntities = pageRating.getContent().stream().map(this::convert).collect(toList());
        return new Page<>(ratingEntities, pageRating.getPageNumber(), (int) pageRating.getPageElements(), pageRating.getTotalElements());
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurred while trying to find ratings for api {}", api, ex);
        throw new TechnicalManagementException("An error occurred while trying to find ratings for api " + api, ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Rating(io.gravitee.repository.management.model.Rating) Page(io.gravitee.common.data.domain.Page) ApiRatingUnavailableException(io.gravitee.rest.api.service.exceptions.ApiRatingUnavailableException) PageableBuilder(io.gravitee.repository.management.api.search.builder.PageableBuilder) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 74 with TechnicalManagementException

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

the class RatingServiceImpl method update.

@Override
public RatingEntity update(final UpdateRatingEntity ratingEntity) {
    if (!isEnabled()) {
        throw new ApiRatingUnavailableException();
    }
    try {
        final Rating rating = findModelById(ratingEntity.getId());
        final Rating oldRating = new Rating(rating);
        if (!rating.getReferenceId().equals(ratingEntity.getApi())) {
            throw new RatingNotFoundException(ratingEntity.getId(), ratingEntity.getApi());
        }
        final Date now = new Date();
        rating.setUpdatedAt(now);
        rating.setRate(ratingEntity.getRate());
        // we can save a title/comment only once
        if (isBlank(rating.getTitle())) {
            rating.setTitle(ratingEntity.getTitle());
        }
        if (isBlank(rating.getComment())) {
            rating.setComment(ratingEntity.getComment());
        }
        Rating updatedRating = ratingRepository.update(rating);
        auditService.createApiAuditLog(rating.getReferenceId(), null, Rating.RatingEvent.RATING_UPDATED, updatedRating.getUpdatedAt(), oldRating, updatedRating);
        return convert(updatedRating);
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurred while trying to update rating {}", ratingEntity.getId(), ex);
        throw new TechnicalManagementException("An error occurred while trying to update rating " + ratingEntity.getId(), ex);
    }
}
Also used : RatingNotFoundException(io.gravitee.rest.api.service.exceptions.RatingNotFoundException) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Rating(io.gravitee.repository.management.model.Rating) ApiRatingUnavailableException(io.gravitee.rest.api.service.exceptions.ApiRatingUnavailableException) Date(java.util.Date) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 75 with TechnicalManagementException

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

the class RatingServiceImpl method delete.

@Override
public void delete(final String id) {
    if (!isEnabled()) {
        throw new ApiRatingUnavailableException();
    }
    try {
        Rating rating = findModelById(id);
        ratingRepository.delete(id);
        auditService.createApiAuditLog(rating.getReferenceId(), null, Rating.RatingEvent.RATING_DELETED, new Date(), rating, null);
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to delete rating {}", id, ex);
        throw new TechnicalManagementException("An error occurs while trying to delete rating " + id, ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Rating(io.gravitee.repository.management.model.Rating) ApiRatingUnavailableException(io.gravitee.rest.api.service.exceptions.ApiRatingUnavailableException) Date(java.util.Date) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Aggregations

TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)149 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)120 UuidString (io.gravitee.rest.api.service.common.UuidString)26 Date (java.util.Date)23 Component (org.springframework.stereotype.Component)18 Logger (org.slf4j.Logger)17 LoggerFactory (org.slf4j.LoggerFactory)17 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)16 Collectors (java.util.stream.Collectors)13 Autowired (org.springframework.beans.factory.annotation.Autowired)13 IOException (java.io.IOException)12 JsonNode (com.fasterxml.jackson.databind.JsonNode)11 Rating (io.gravitee.repository.management.model.Rating)9 ApiRatingUnavailableException (io.gravitee.rest.api.service.exceptions.ApiRatingUnavailableException)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 Dictionary (io.gravitee.repository.management.model.Dictionary)8 AuditService (io.gravitee.rest.api.service.AuditService)8 java.util (java.util)8 Theme (io.gravitee.repository.management.model.Theme)6 List (java.util.List)6