use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class MetadataServiceImpl method delete.
@Override
public void delete(final String key) {
try {
final Optional<Metadata> optMetadata = metadataRepository.findById(key, DEFAUT_REFERENCE_ID, MetadataReferenceType.DEFAULT);
if (optMetadata.isPresent()) {
metadataRepository.delete(key, DEFAUT_REFERENCE_ID, MetadataReferenceType.DEFAULT);
// Audit
auditService.createPortalAuditLog(Collections.singletonMap(METADATA, key), METADATA_DELETED, new Date(), optMetadata.get(), null);
// delete all overridden API metadata
final List<Metadata> apiMetadata = metadataRepository.findByKeyAndReferenceType(key, MetadataReferenceType.API);
for (final Metadata metadata : apiMetadata) {
metadataRepository.delete(key, metadata.getReferenceId(), metadata.getReferenceType());
// Audit
auditService.createApiAuditLog(metadata.getReferenceId(), Collections.singletonMap(METADATA, key), METADATA_DELETED, new Date(), metadata, null);
}
}
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to delete metadata {}", key, ex);
throw new TechnicalManagementException("An error occurs while trying to delete metadata " + key, ex);
}
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class PageServiceImpl method delete.
@Override
public void delete(String pageId) {
try {
logger.debug("Delete Page : {}", pageId);
Optional<Page> optPage = pageRepository.findById(pageId);
if (!optPage.isPresent()) {
throw new PageNotFoundException(pageId);
}
pageRepository.delete(pageId);
createAuditLog(optPage.get().getApi(), PAGE_DELETED, new Date(), optPage.get(), null);
} catch (TechnicalException ex) {
logger.error("An error occurs while trying to delete Page {}", pageId, ex);
throw new TechnicalManagementException("An error occurs while trying to delete Page " + pageId, ex);
}
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class PageServiceImpl method findById.
@Override
public PageEntity findById(String pageId, boolean transform) {
try {
logger.debug("Find page by ID: {}", pageId);
Optional<Page> page = pageRepository.findById(pageId);
if (page.isPresent()) {
PageEntity pageEntity = convert(page.get());
if (transform) {
transformUsingConfiguration(pageEntity);
if (page.get().getApi() != null) {
transformWithTemplate(pageEntity, page.get().getApi());
}
}
return pageEntity;
}
throw new PageNotFoundException(pageId);
} catch (TechnicalException ex) {
logger.error("An error occurs while trying to find a page using its ID {}", pageId, ex);
throw new TechnicalManagementException("An error occurs while trying to find a page using its ID " + pageId, ex);
}
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class PageServiceImpl method createApiPage.
@Override
public PageEntity createApiPage(String apiId, NewPageEntity newPageEntity) {
try {
logger.debug("Create page {} for API {}", newPageEntity, apiId);
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);
page.setApi(apiId);
// Set date fields
page.setCreatedAt(new Date());
page.setUpdatedAt(page.getCreatedAt());
Page createdPage = pageRepository.create(page);
// only one homepage is allowed
onlyOneHomepage(page);
createAuditLog(apiId, 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 createMultipleValue.
@Override
public void createMultipleValue(final String key, final String value) {
try {
final Optional<Parameter> optionalParameter = parameterRepository.findById(key);
final Parameter parameter = new Parameter();
parameter.setKey(key);
if (optionalParameter.isPresent()) {
final String existingValue = optionalParameter.get().getValue();
if (existingValue.isEmpty()) {
parameter.setValue(value);
} else {
parameter.setValue(existingValue + SEPARATOR + value);
}
update(parameter.getKey(), parameter.getValue());
} else {
parameter.setValue(value);
create(parameter.getKey(), parameter.getValue());
}
} 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);
}
}
Aggregations