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