public void execute(Event<UIPageForm> event) throws Exception {
UIPageForm uiPageForm = event.getSource();
UIPortalApplication uiPortalApp = uiPageForm.getAncestorOfType(UIPortalApplication.class);
PortalRequestContext pcontext = Util.getPortalRequestContext();
UIPage uiPage = uiPageForm.getUIPage();
Page page = new Page();
uiPageForm.invokeSetBindingBean(page);
DataStorage dataService = uiPageForm.getApplicationComponent(DataStorage.class);
// create new page
if (uiPage == null) {
PageService pageService = uiPageForm.getApplicationComponent(PageService.class);
PageContext existPage = pageService.loadPage(page.getPageKey());
if (existPage != null) {
uiPortalApp.addMessage(new ApplicationMessage("UIPageForm.msg.sameName", null));
return;
}
page.setModifiable(true);
if (page.getChildren() == null) {
page.setChildren(new ArrayList<ModelObject>());
}
//
PageState pageState = new PageState(page.getTitle(), page.getDescription(), page.isShowMaxWindow(),
page.getFactoryId(), page.getAccessPermissions() != null ? Arrays.asList(page.getAccessPermissions())
: null, page.getEditPermission());
pageService.savePage(new PageContext(page.getPageKey(), pageState));
//
dataService.save(page);
postSave(uiPortalApp, pcontext);
return;
}
page.setOwnerType(uiPage.getSiteKey().getTypeName());
List<UIPortlet> uiPortlets = new ArrayList<UIPortlet>();
findAllPortlet(uiPortlets, uiPage);
ArrayList<ModelObject> applications = new ArrayList<ModelObject>();
for (UIPortlet uiPortlet : uiPortlets) {
applications.add(PortalDataMapper.buildModelObject(uiPortlet));
}
List<UIComponent> uiChildren = uiPage.getChildren();
if (uiChildren == null)
return;
ArrayList<ModelObject> children = new ArrayList<ModelObject>();
for (UIComponent child : uiChildren) {
ModelObject component = PortalDataMapper.buildModelObject(child);
if (component != null)
children.add(component);
}
page.setChildren(children);
uiPage.getChildren().clear();
PortalDataMapper.toUIPage(uiPage, page);
// if (page.getTemplate() == null) page.setTemplate(uiPage.getTemplate());
if (page.getChildren() == null)
page.setChildren(new ArrayList<ModelObject>());
}