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)
{
Page existPage = dataService.getPage(page.getPageId());
if (existPage != null)
{
uiPortalApp.addMessage(new ApplicationMessage("UIPageForm.msg.sameName", null));
pcontext.addUIComponentToUpdateByAjax(uiPortalApp.getUIPopupMessages());
return;
}
page.setModifiable(true);
if (page.getChildren() == null)
page.setChildren(new ArrayList<ModelObject>());
dataService.create(page);
postSave(uiPortalApp, pcontext);
return;
}
page.setOwnerType(uiPage.getOwnerType());
List<UIPortlet> uiPortlets = new ArrayList<UIPortlet>();
findAllPortlet(uiPortlets, uiPage);
ArrayList<ModelObject> applications = new ArrayList<ModelObject>();
for (UIPortlet uiPortlet : uiPortlets)
{
applications.add(PortalDataMapper.buildModelObject(uiPortlet));
}
if (Page.DESKTOP_PAGE.equals(uiPage.getFactoryId()) && !Page.DESKTOP_PAGE.equals(page.getFactoryId()))
{
page.setShowMaxWindow(false);
uiPage.getChildren().clear();
page.setChildren(applications);
PortalDataMapper.toUIPage(uiPage, page);
// if (page.getTemplate() == null)
// page.setTemplate(uiPage.getTemplate());
if (page.getChildren() == null)
page.setChildren(new ArrayList<ModelObject>());
dataService.save(page);
postSave(uiPortalApp, pcontext);
return;
}
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>());
if (Page.DESKTOP_PAGE.equals(uiPage.getFactoryId()))
{
dataService.save(page);
postSave(uiPortalApp, pcontext);
}
}