Search in sources :

Example 1 with PageNotFoundException

use of io.gravitee.management.service.exceptions.PageNotFoundException 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);
    }
}
Also used : PageNotFoundException(io.gravitee.management.service.exceptions.PageNotFoundException) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 2 with PageNotFoundException

use of io.gravitee.management.service.exceptions.PageNotFoundException 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);
    }
}
Also used : PageNotFoundException(io.gravitee.management.service.exceptions.PageNotFoundException) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Aggregations

PageNotFoundException (io.gravitee.management.service.exceptions.PageNotFoundException)2 TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)2 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)2