Search in sources :

Example 51 with TechnicalManagementException

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

the class PolicyServiceImpl method findAll.

@Override
public Set<PolicyEntity> findAll() {
    try {
        LOGGER.debug("List all policies");
        final Collection<PolicyPlugin> policyDefinitions = policyManager.findAll();
        return policyDefinitions.stream().map(policyDefinition -> convert(policyDefinition, false)).collect(Collectors.toSet());
    } catch (Exception ex) {
        LOGGER.error("An error occurs while trying to list all policies", ex);
        throw new TechnicalManagementException("An error occurs while trying to list all policies", ex);
    }
}
Also used : PolicyNotFoundException(io.gravitee.management.service.exceptions.PolicyNotFoundException) PolicyService(io.gravitee.management.service.PolicyService) Logger(org.slf4j.Logger) PolicyEntity(io.gravitee.management.model.PolicyEntity) PluginEntity(io.gravitee.management.model.PluginEntity) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) PolicyDevelopmentEntity(io.gravitee.management.model.PolicyDevelopmentEntity) Component(org.springframework.stereotype.Component) Plugin(io.gravitee.plugin.core.api.Plugin) PolicyPlugin(io.gravitee.plugin.policy.PolicyPlugin) PolicyPluginManager(io.gravitee.plugin.policy.PolicyPluginManager) PolicyPlugin(io.gravitee.plugin.policy.PolicyPlugin) PolicyNotFoundException(io.gravitee.management.service.exceptions.PolicyNotFoundException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException) IOException(java.io.IOException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 52 with TechnicalManagementException

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

the class PortalNotificationConfigServiceImpl method save.

@Override
public PortalNotificationConfigEntity save(PortalNotificationConfigEntity notificationEntity) {
    try {
        if (notificationEntity.getHooks() == null || notificationEntity.getHooks().isEmpty()) {
            portalNotificationConfigRepository.delete(convert(notificationEntity));
            return getDefaultEmpty(notificationEntity.getUser(), NotificationReferenceType.valueOf(notificationEntity.getReferenceType()), notificationEntity.getReferenceId());
        } else {
            Optional<PortalNotificationConfig> optionalConfig = portalNotificationConfigRepository.findById(notificationEntity.getUser(), NotificationReferenceType.valueOf(notificationEntity.getReferenceType()), notificationEntity.getReferenceId());
            PortalNotificationConfig notificationConfig = convert(notificationEntity);
            if (optionalConfig.isPresent()) {
                notificationConfig.setCreatedAt(optionalConfig.get().getCreatedAt());
                notificationConfig.setUpdatedAt(new Date());
                return convert(portalNotificationConfigRepository.update(notificationConfig));
            } else {
                notificationConfig.setCreatedAt(new Date());
                notificationConfig.setUpdatedAt(notificationConfig.getCreatedAt());
                return convert(portalNotificationConfigRepository.create(notificationConfig));
            }
        }
    } catch (TechnicalException te) {
        LOGGER.error("An error occurs while trying to save the notification settings {}", notificationEntity, te);
        throw new TechnicalManagementException("An error occurs while trying to save the notification settings " + notificationEntity, te);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) PortalNotificationConfig(io.gravitee.repository.management.model.PortalNotificationConfig) Date(java.util.Date) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 53 with TechnicalManagementException

use of io.gravitee.management.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 (!enabled) {
        throw new ApiRatingUnavailableException();
    }
    try {
        final Page<Rating> pageRating = ratingRepository.findByApiPageable(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.management.service.exceptions.ApiRatingUnavailableException) PageableBuilder(io.gravitee.repository.management.api.search.builder.PageableBuilder) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 54 with TechnicalManagementException

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

the class RatingServiceImpl method deleteAnswer.

@Override
public void deleteAnswer(final String ratingId, final String answerId) {
    if (!enabled) {
        throw new ApiRatingUnavailableException();
    }
    try {
        Rating rating = findById(ratingId);
        ratingAnswerRepository.delete(answerId);
        auditService.createApiAuditLog(rating.getApi(), null, RatingAnswer.RatingAnswerEvent.RATING_ANSWER_DELETED, new Date(), rating, null);
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to delete rating answer {}", answerId, ex);
        throw new TechnicalManagementException("An error occurs while trying to delete rating answer " + answerId, ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Rating(io.gravitee.repository.management.model.Rating) ApiRatingUnavailableException(io.gravitee.management.service.exceptions.ApiRatingUnavailableException) Date(java.util.Date) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 55 with TechnicalManagementException

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

the class RatingServiceImpl method convert.

private RatingEntity convert(final Rating rating) {
    final RatingEntity ratingEntity = new RatingEntity();
    final UserEntity user = userService.findById(rating.getUser());
    ratingEntity.setUser(user.getId());
    if (user.getFirstname() != null && user.getLastname() != null) {
        ratingEntity.setUserDisplayName(user.getFirstname() + ' ' + user.getLastname());
    } else {
        ratingEntity.setUserDisplayName(user.getUsername());
    }
    ratingEntity.setId(rating.getId());
    ratingEntity.setApi(rating.getApi());
    ratingEntity.setTitle(rating.getTitle());
    ratingEntity.setComment(rating.getComment());
    ratingEntity.setRate(rating.getRate());
    ratingEntity.setCreatedAt(rating.getCreatedAt());
    ratingEntity.setUpdatedAt(rating.getUpdatedAt());
    try {
        final List<RatingAnswer> ratingAnswers = ratingAnswerRepository.findByRating(rating.getId());
        if (ratingAnswers != null) {
            ratingEntity.setAnswers(ratingAnswers.stream().map(ratingAnswer -> {
                final RatingAnswerEntity ratingAnswerEntity = new RatingAnswerEntity();
                ratingAnswerEntity.setId(ratingAnswer.getId());
                final UserEntity userAnswer = userService.findById(ratingAnswer.getUser());
                ratingAnswerEntity.setUser(userAnswer.getId());
                if (userAnswer.getFirstname() != null && userAnswer.getLastname() != null) {
                    ratingAnswerEntity.setUserDisplayName(userAnswer.getFirstname() + ' ' + userAnswer.getLastname());
                } else {
                    ratingAnswerEntity.setUserDisplayName(userAnswer.getUsername());
                }
                ratingAnswerEntity.setComment(ratingAnswer.getComment());
                ratingAnswerEntity.setCreatedAt(ratingAnswer.getCreatedAt());
                return ratingAnswerEntity;
            }).sorted(comparing(RatingAnswerEntity::getCreatedAt, reverseOrder())).collect(toList()));
        }
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurred while trying to find rating answers by rating id {}", rating.getId(), ex);
        throw new TechnicalManagementException("An error occurred while trying to find rating answers by rating id " + rating.getId(), ex);
    }
    return ratingEntity;
}
Also used : Rating(io.gravitee.repository.management.model.Rating) RatingAnswer(io.gravitee.repository.management.model.RatingAnswer) RatingAlreadyExistsException(io.gravitee.management.service.exceptions.RatingAlreadyExistsException) Date(java.util.Date) Page(io.gravitee.common.data.domain.Page) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) LoggerFactory(org.slf4j.LoggerFactory) OptionalDouble(java.util.OptionalDouble) Autowired(org.springframework.beans.factory.annotation.Autowired) AuditService(io.gravitee.management.service.AuditService) Value(org.springframework.beans.factory.annotation.Value) UUID(io.gravitee.common.utils.UUID) io.gravitee.management.model(io.gravitee.management.model) PageableBuilder(io.gravitee.repository.management.api.search.builder.PageableBuilder) RatingAnswerRepository(io.gravitee.repository.management.api.RatingAnswerRepository) Comparator.comparing(java.util.Comparator.comparing) Logger(org.slf4j.Logger) RatingService(io.gravitee.management.service.RatingService) RatingRepository(io.gravitee.repository.management.api.RatingRepository) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException) Pageable(io.gravitee.repository.management.api.search.Pageable) Collectors(java.util.stream.Collectors) Component(org.springframework.stereotype.Component) List(java.util.List) ApiRatingUnavailableException(io.gravitee.management.service.exceptions.ApiRatingUnavailableException) UserService(io.gravitee.management.service.UserService) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) Optional(java.util.Optional) Comparator.reverseOrder(java.util.Comparator.reverseOrder) RatingNotFoundException(io.gravitee.management.service.exceptions.RatingNotFoundException) RatingAnswer(io.gravitee.repository.management.model.RatingAnswer) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Aggregations

TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)90 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)83 Logger (org.slf4j.Logger)17 LoggerFactory (org.slf4j.LoggerFactory)17 Autowired (org.springframework.beans.factory.annotation.Autowired)17 Component (org.springframework.stereotype.Component)17 Collectors (java.util.stream.Collectors)13 java.util (java.util)11 Date (java.util.Date)11 AuditService (io.gravitee.management.service.AuditService)10 IdGenerator (io.gravitee.common.utils.IdGenerator)9 io.gravitee.management.model (io.gravitee.management.model)9 User (io.gravitee.repository.management.model.User)9 ApiRatingUnavailableException (io.gravitee.management.service.exceptions.ApiRatingUnavailableException)8 UserNotFoundException (io.gravitee.management.service.exceptions.UserNotFoundException)8 Metadata (io.gravitee.repository.management.model.Metadata)8 Rating (io.gravitee.repository.management.model.Rating)8 DuplicateMetadataNameException (io.gravitee.management.service.exceptions.DuplicateMetadataNameException)7 ApiService (io.gravitee.management.service.ApiService)6 MetadataService (io.gravitee.management.service.MetadataService)6