use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class ApiKeyServiceImpl method findBySubscription.
@Override
public Set<ApiKeyEntity> findBySubscription(String subscription) {
try {
LOGGER.debug("Find API Keys for subscription {}", subscription);
SubscriptionEntity subscriptionEntity = subscriptionService.findById(subscription);
Set<ApiKey> keys = apiKeyRepository.findBySubscription(subscriptionEntity.getId());
return keys.stream().map(ApiKeyServiceImpl::convert).collect(Collectors.toSet());
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while finding API keys for subscription {}", subscription, ex);
throw new TechnicalManagementException(String.format("An error occurs while finding API keys for subscription %s", subscription), ex);
}
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class ApiKeyServiceImpl method findByKey.
@Override
public ApiKeyEntity findByKey(String apiKey) {
try {
LOGGER.debug("Find an API Key by key: {}", apiKey);
Optional<ApiKey> optApiKey = apiKeyRepository.findById(apiKey);
if (optApiKey.isPresent()) {
return convert(optApiKey.get());
}
throw new ApiKeyNotFoundException();
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to find an API Key by key {}", apiKey, ex);
throw new TechnicalManagementException(String.format("An error occurs while trying to find an API Key by key: %s", apiKey), ex);
}
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class PageServiceImpl method createPortalPage.
@Override
public PageEntity createPortalPage(NewPageEntity newPageEntity) {
try {
logger.debug("Create portal page {}", newPageEntity);
String id = UUID.toString(UUID.random());
Optional<Page> checkPage = pageRepository.findById(id);
if (checkPage.isPresent()) {
throw new PageAlreadyExistsException(id);
}
Page page = convert(newPageEntity);
if (page.getSource() != null) {
String fetchedContent = this.getContentFromFetcher(page.getSource());
if (fetchedContent != null && !fetchedContent.isEmpty()) {
page.setContent(fetchedContent);
}
}
page.setId(id);
// Set date fields
page.setCreatedAt(new Date());
page.setUpdatedAt(page.getCreatedAt());
Page createdPage = pageRepository.create(page);
// only one homepage is allowed
onlyOneHomepage(page);
createAuditLog(null, PAGE_CREATED, page.getCreatedAt(), null, page);
return convert(createdPage);
} catch (TechnicalException | FetcherException ex) {
logger.error("An error occurs while trying to create {}", newPageEntity, ex);
throw new TechnicalManagementException("An error occurs while trying create " + newPageEntity, ex);
}
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class ParameterServiceImpl method update.
@Override
public Parameter update(final String key, final String value) {
try {
final Optional<Parameter> optionalParameter = parameterRepository.findById(key);
if (!optionalParameter.isPresent()) {
throw new ParameterNotFoundException(key);
}
final Parameter parameter = new Parameter();
parameter.setKey(key);
parameter.setValue(value);
final Parameter updatedParameter = parameterRepository.update(parameter);
auditService.createPortalAuditLog(singletonMap(PARAMETER, updatedParameter.getKey()), PARAMETER_UPDATED, new Date(), optionalParameter.get(), updatedParameter);
return updatedParameter;
} catch (final TechnicalException ex) {
final String message = "An error occurs while trying to update parameter for key/value: " + key + '/' + value;
LOGGER.error(message, ex);
throw new TechnicalManagementException(message, ex);
}
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class ParameterServiceImpl method create.
@Override
public Parameter create(final String key, final String value) {
try {
final Optional<Parameter> optionalParameter = parameterRepository.findById(key);
if (optionalParameter.isPresent()) {
throw new ParameterAlreadyExistsException(key);
}
final Parameter parameter = new Parameter();
parameter.setKey(key);
parameter.setValue(value);
final Parameter savedParameter = parameterRepository.create(parameter);
auditService.createPortalAuditLog(singletonMap(PARAMETER, savedParameter.getKey()), PARAMETER_CREATED, new Date(), null, savedParameter);
return savedParameter;
} catch (final TechnicalException ex) {
final String message = "An error occurs while trying to create parameter for key/value: " + key + '/' + value;
LOGGER.error(message, ex);
throw new TechnicalManagementException(message, ex);
}
}
Aggregations