use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.
the class SubscriptionServiceImpl method delete.
@Override
public void delete(String subscriptionId) {
try {
logger.debug("Delete subscription {}", subscriptionId);
Optional<Subscription> optSubscription = subscriptionRepository.findById(subscriptionId);
if (!optSubscription.isPresent()) {
throw new SubscriptionNotFoundException(subscriptionId);
}
Subscription subscription = optSubscription.get();
// Delete API Keys
apiKeyService.findBySubscription(subscriptionId).forEach(apiKey -> apiKeyService.delete(apiKey.getKey()));
// Delete subscription
subscriptionRepository.delete(subscriptionId);
createAudit(planService.findById(subscription.getPlan()).getApis().iterator().next(), subscription.getApplication(), SUBSCRIPTION_DELETED, subscription.getUpdatedAt(), subscription, null);
} catch (TechnicalException ex) {
logger.error("An error occurs while trying to delete subscription: {}", subscriptionId, ex);
throw new TechnicalManagementException(String.format("An error occurs while trying to delete subscription: %s", subscriptionId), ex);
}
}
use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.
the class TagServiceImpl method create.
@Override
public List<TagEntity> create(final List<NewTagEntity> tagEntities) {
// First we prevent the duplicate tag name
final List<String> tagNames = tagEntities.stream().map(NewTagEntity::getName).collect(Collectors.toList());
final Optional<TagEntity> optionalTag = findAll().stream().filter(tag -> tagNames.contains(tag.getName())).findAny();
if (optionalTag.isPresent()) {
throw new DuplicateTagNameException(optionalTag.get().getName());
}
final List<TagEntity> savedTags = new ArrayList<>(tagEntities.size());
tagEntities.forEach(tagEntity -> {
try {
Tag tag = convert(tagEntity);
savedTags.add(convert(tagRepository.create(tag)));
auditService.createPortalAuditLog(Collections.singletonMap(TAG, tag.getId()), TAG_CREATED, new Date(), null, tag);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to create tag {}", tagEntity.getName(), ex);
throw new TechnicalManagementException("An error occurs while trying to create 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 create.
@Override
public List<TenantEntity> create(final List<NewTenantEntity> tenantEntities) {
// First we prevent the duplicate tenant name
final List<String> tenantNames = tenantEntities.stream().map(NewTenantEntity::getName).collect(Collectors.toList());
final Optional<TenantEntity> optionalTenant = findAll().stream().filter(tenant -> tenantNames.contains(tenant.getName())).findAny();
if (optionalTenant.isPresent()) {
throw new DuplicateTenantNameException(optionalTenant.get().getName());
}
final List<TenantEntity> savedTenants = new ArrayList<>(tenantEntities.size());
tenantEntities.forEach(tenantEntity -> {
try {
Tenant tenant = convert(tenantEntity);
savedTenants.add(convert(tenantRepository.create(tenant)));
auditService.createPortalAuditLog(Collections.singletonMap(TENANT, tenant.getId()), TENANT_CREATED, new Date(), null, tenant);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to create tenant {}", tenantEntity.getName(), ex);
throw new TechnicalManagementException("An error occurs while trying to create tenant " + tenantEntity.getName(), ex);
}
});
return savedTenants;
}
use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.
the class UserServiceImpl method findAll.
@Override
public Set<UserEntity> findAll(boolean loadRoles) {
try {
LOGGER.debug("Find all users");
Set<User> users = userRepository.findAll();
return users.stream().map(u -> convert(u, loadRoles)).collect(Collectors.toSet());
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to find all users", ex);
throw new TechnicalManagementException("An error occurs while trying to find all users", ex);
}
}
use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.
the class UserServiceImpl method findByUsername.
@Override
public UserEntity findByUsername(String username, boolean loadRoles) {
try {
LOGGER.debug("Find user by name: {}", username);
Optional<User> optionalUser = userRepository.findByUsername(username);
if (optionalUser.isPresent()) {
return convert(optionalUser.get(), loadRoles);
}
// should never happen
throw new UserNotFoundException(username);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to find user using its username {}", username, ex);
throw new TechnicalManagementException("An error occurs while trying to find user using its username " + username, ex);
}
}
Aggregations