Search in sources :

Example 91 with TechnicalException

use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.

the class PageServiceImpl method findMaxApiPageOrderByApi.

@Override
public int findMaxApiPageOrderByApi(String apiName) {
    try {
        logger.debug("Find Max Order Page for api name : {}", apiName);
        final Integer maxPageOrder = pageRepository.findMaxApiPageOrderByApiId(apiName);
        return maxPageOrder == null ? 0 : maxPageOrder;
    } catch (TechnicalException ex) {
        logger.error("An error occured when searching max order page for api name [{}]", apiName, ex);
        throw new TechnicalManagementException("An error occured when searching max order page for api name " + apiName, ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 92 with TechnicalException

use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.

the class SubscriptionServiceImpl method close.

@Override
public SubscriptionEntity close(String subscriptionId) {
    try {
        logger.debug("Close subscription {}", subscriptionId);
        Optional<Subscription> optSubscription = subscriptionRepository.findById(subscriptionId);
        if (!optSubscription.isPresent()) {
            throw new SubscriptionNotFoundException(subscriptionId);
        }
        Subscription subscription = optSubscription.get();
        if (subscription.getStatus() == Subscription.Status.ACCEPTED) {
            Subscription previousSubscription = new Subscription(subscription);
            final Date now = new Date();
            subscription.setUpdatedAt(now);
            subscription.setStatus(Subscription.Status.CLOSED);
            subscription.setClosedAt(new Date());
            subscription = subscriptionRepository.update(subscription);
            // Send an email to subscriber
            final ApplicationEntity application = applicationService.findById(subscription.getApplication());
            final PlanEntity plan = planService.findById(subscription.getPlan());
            String apiId = plan.getApis().iterator().next();
            final ApiModelEntity api = apiService.findByIdForTemplates(apiId);
            final PrimaryOwnerEntity owner = application.getPrimaryOwner();
            final Map<String, Object> params = new NotificationParamsBuilder().owner(owner).api(api).plan(plan).application(application).build();
            notifierService.trigger(ApiHook.SUBSCRIPTION_CLOSED, apiId, params);
            notifierService.trigger(ApplicationHook.SUBSCRIPTION_CLOSED, application.getId(), params);
            createAudit(apiId, subscription.getApplication(), SUBSCRIPTION_CLOSED, subscription.getUpdatedAt(), previousSubscription, subscription);
            // API Keys are automatically revoked
            Set<ApiKeyEntity> apiKeys = apiKeyService.findBySubscription(subscription.getId());
            for (ApiKeyEntity apiKey : apiKeys) {
                Date expireAt = apiKey.getExpireAt();
                if (!apiKey.isRevoked() && (expireAt == null || expireAt.equals(now) || expireAt.before(now))) {
                    apiKey.setExpireAt(now);
                    apiKey.setRevokedAt(now);
                    apiKey.setRevoked(true);
                    apiKeyService.revoke(apiKey.getKey(), false);
                }
            }
            return convert(subscription);
        }
        throw new SubscriptionNotClosableException(subscription);
    } catch (TechnicalException ex) {
        logger.error("An error occurs while trying to close subscription {}", subscriptionId, ex);
        throw new TechnicalManagementException(String.format("An error occurs while trying to close subscription %s", subscriptionId), ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) NotificationParamsBuilder(io.gravitee.management.service.notification.NotificationParamsBuilder) Subscription(io.gravitee.repository.management.model.Subscription)

Example 93 with TechnicalException

use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.

the class TagServiceImpl method delete.

@Override
public void delete(final String tagId) {
    try {
        Optional<Tag> tagOptional = tagRepository.findById(tagId);
        if (tagOptional.isPresent()) {
            tagRepository.delete(tagId);
            // delete all reference on APIs
            apiService.deleteTagFromAPIs(tagId);
            auditService.createPortalAuditLog(Collections.singletonMap(TAG, tagId), TAG_DELETED, new Date(), null, tagOptional.get());
        }
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to delete tag {}", tagId, ex);
        throw new TechnicalManagementException("An error occurs while trying to delete tag " + tagId, ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Tag(io.gravitee.repository.management.model.Tag) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 94 with TechnicalException

use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.

the class TagServiceImpl method update.

@Override
public List<TagEntity> update(final List<UpdateTagEntity> tagEntities) {
    final List<TagEntity> savedTags = new ArrayList<>(tagEntities.size());
    tagEntities.forEach(tagEntity -> {
        try {
            Tag tag = convert(tagEntity);
            Optional<Tag> tagOptional = tagRepository.findById(tag.getId());
            if (tagOptional.isPresent()) {
                savedTags.add(convert(tagRepository.update(tag)));
                auditService.createPortalAuditLog(Collections.singletonMap(TAG, tag.getId()), TAG_UPDATED, new Date(), tagOptional.get(), tag);
            }
        } catch (TechnicalException ex) {
            LOGGER.error("An error occurs while trying to update tag {}", tagEntity.getName(), ex);
            throw new TechnicalManagementException("An error occurs while trying to update tag " + tagEntity.getName(), ex);
        }
    });
    return savedTags;
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) NewTagEntity(io.gravitee.management.model.NewTagEntity) TagEntity(io.gravitee.management.model.TagEntity) UpdateTagEntity(io.gravitee.management.model.UpdateTagEntity) Tag(io.gravitee.repository.management.model.Tag) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 95 with TechnicalException

use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.

the class TenantServiceImpl method update.

@Override
public List<TenantEntity> update(final List<UpdateTenantEntity> tenantEntities) {
    final List<TenantEntity> savedTenants = new ArrayList<>(tenantEntities.size());
    tenantEntities.forEach(tenantEntity -> {
        try {
            Tenant tenant = convert(tenantEntity);
            Optional<Tenant> tenantOptional = tenantRepository.findById(tenant.getId());
            if (tenantOptional.isPresent()) {
                savedTenants.add(convert(tenantRepository.update(tenant)));
                auditService.createPortalAuditLog(Collections.singletonMap(TENANT, tenant.getId()), TENANT_UPDATED, new Date(), tenantOptional.get(), tenant);
            }
        } catch (TechnicalException ex) {
            LOGGER.error("An error occurs while trying to update tenant {}", tenantEntity.getName(), ex);
            throw new TechnicalManagementException("An error occurs while trying to update tenant " + tenantEntity.getName(), ex);
        }
    });
    return savedTenants;
}
Also used : Tenant(io.gravitee.repository.management.model.Tenant) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TenantEntity(io.gravitee.management.model.TenantEntity) NewTenantEntity(io.gravitee.management.model.NewTenantEntity) UpdateTenantEntity(io.gravitee.management.model.UpdateTenantEntity) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Aggregations

TechnicalException (io.gravitee.repository.exceptions.TechnicalException)102 TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)80 Logger (org.slf4j.Logger)22 LoggerFactory (org.slf4j.LoggerFactory)22 Autowired (org.springframework.beans.factory.annotation.Autowired)22 Component (org.springframework.stereotype.Component)20 java.util (java.util)18 Collectors (java.util.stream.Collectors)18 io.gravitee.management.model (io.gravitee.management.model)16 AuditService (io.gravitee.management.service.AuditService)12 UUID (io.gravitee.common.utils.UUID)11 Date (java.util.Date)11 IdGenerator (io.gravitee.common.utils.IdGenerator)9 IOException (java.io.IOException)9 io.gravitee.management.service (io.gravitee.management.service)8 ApiRatingUnavailableException (io.gravitee.management.service.exceptions.ApiRatingUnavailableException)8 Metadata (io.gravitee.repository.management.model.Metadata)8 Rating (io.gravitee.repository.management.model.Rating)8 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7