use of io.gravitee.management.service.exceptions.PageAlreadyExistsException 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.PageAlreadyExistsException 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);
}
}
Aggregations