return pages;
}
@Override
public void savePage(Page page) {
PageImpl pageImpl = (PageImpl) page;
Parameters.requireNonNull(pageImpl, "page");
if (getSite(pageImpl.getSiteId()) == null) {
throw new EntityNotFoundException("Site " + pageImpl.getSiteId() + " doesn't exist");
}
if (pageImpl.isCreate() && getPage(pageImpl.getId()) != null) {
// There is still a small chance someone else creates the page, but this is currently the best we can do
throw new EntityAlreadyExistsException("Cannot create page. Page " + pageImpl.getId() + " already exists.");
}
PageContext context = pageImpl.getPageContext();
try {
pageService.savePage(context);
if (!pageImpl.isChildrenSet()) {
// it seems that the page was created without a container, and it wasn't loaded,
// so, we are done
return;
}
// Added as required by the Compose Page API work:
// In addition to the pageService, which stores only metadata about the page, we also send it
// to the dataStorage for persistence, because this one takes care of persisting the children as well.
// As such, we need to get the ModelObject representation of the Page, which is the only representation
// that the dataStorage would accept.
dataStorage.save(getModelObjectFor(pageImpl));
dataStorage.save();
} catch (Throwable t) {
throw new ApiException("Failed to save page " + pageImpl.getId(), t);
}
}