From e75700703a53cecfbe49a5a737b899ec9158b7c8 Mon Sep 17 00:00:00 2001 From: nscavell Date: Mon, 8 Jul 2013 14:59:24 -0400 Subject: [PATCH] GTNPORTAL-3162 Site layout with containers causes the import to fail --- .../binding/xml/AbstractMarshaller.java | 7 + .../binding/xml/SiteLayoutMarshaller.java | 20 +++ .../binding/xml/SiteLayoutMarshallerTest.java | 51 ++++++-- .../portal/mop/management/portal-pagebody.xml | 123 ++++++++++++++++++ 4 files changed, 191 insertions(+), 10 deletions(-) create mode 100644 component/portal/src/test/resources/org/exoplatform/portal/mop/management/portal-pagebody.xml diff --git a/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/AbstractMarshaller.java b/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/AbstractMarshaller.java index 11939fbc7..8741c3e86 100644 --- a/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/AbstractMarshaller.java +++ b/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/AbstractMarshaller.java @@ -165,6 +165,13 @@ protected Container unmarshalContainer(StaxNavigator navigator) throws container.getChildren().add(unmarshalGadgetApplication(navigator.fork())); current = navigator.sibling(); break; + case PAGE_BODY: + if (container.getChildren() == null) { + container.setChildren(new ArrayList()); + } + container.getChildren().add(new PageBody()); + current = navigator.sibling(); + break; case UNKNOWN: throw unknownElement(navigator); default: diff --git a/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/SiteLayoutMarshaller.java b/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/SiteLayoutMarshaller.java index 277348e69..3f9d4673a 100644 --- a/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/SiteLayoutMarshaller.java +++ b/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/SiteLayoutMarshaller.java @@ -228,6 +228,13 @@ private PortalConfig unmarshalPortalConfig(StaxNavigator navigator) thr throw expectedElement(navigator, Element.ACCESS_PERMISSIONS); if (portalLayout == null) { portalLayout = PortalConfig.DEFAULT_LAYOUT; + } else { + int count = countPageBodyElements(portalLayout, 0); + if (count < 1) { + throw new StaxNavException("No page-body element found."); + } else if (count > 1) { + throw new StaxNavException("Multiple page-body elements found."); + } } portalConfig.setPortalLayout(portalLayout); @@ -253,4 +260,17 @@ public String getLocalName() { return name; } } + + private static int countPageBodyElements(Container container, int pageBodyCount) { + if (container.getChildren() != null) { + for (ModelObject child : container.getChildren()) { + if (child instanceof PageBody) { + pageBodyCount++; + } else if (child instanceof Container) { + pageBodyCount = countPageBodyElements((Container) child, pageBodyCount); + } + } + } + return pageBodyCount; + } } diff --git a/component/portal/src/test/java/org/exoplatform/portal/mop/management/binding/xml/SiteLayoutMarshallerTest.java b/component/portal/src/test/java/org/exoplatform/portal/mop/management/binding/xml/SiteLayoutMarshallerTest.java index 80ef86c0a..c71b3c0f6 100644 --- a/component/portal/src/test/java/org/exoplatform/portal/mop/management/binding/xml/SiteLayoutMarshallerTest.java +++ b/component/portal/src/test/java/org/exoplatform/portal/mop/management/binding/xml/SiteLayoutMarshallerTest.java @@ -86,16 +86,6 @@ public void testPortalDataUnmarshalling() { assertNull(layout.getAccessPermissions()); List children = data.getPortalLayout().getChildren(); assertEquals(5, children.size()); - int bodyCount = 0; - for (ModelObject component : children) { - if (component instanceof Application) { - } else if (component instanceof PageBody) { - bodyCount++; - } else { - fail("Only application data and one body data should be created for a portal layout."); - } - } - assertEquals(1, bodyCount); // Verify banner portlet app { @@ -211,4 +201,45 @@ public void testPortalDataMarshalling() { compareComponents(expected.getPortalLayout().getChildren(), actual.getPortalLayout().getChildren()); } + + public void testPortalWithPageBodyInContainer() { + SiteLayoutMarshaller marshaller = new SiteLayoutMarshaller(); + PortalConfig data = marshaller.unmarshal(getClass().getResourceAsStream( + "/org/exoplatform/portal/mop/management/portal-pagebody.xml")); + assertNotNull(data); + assertEquals("classic", data.getName()); + assertEquals("site-label", data.getLabel()); + assertEquals("site-description", data.getDescription()); + assertEquals("en", data.getLocale()); + assertEquals("Everyone", Utils.join(";", data.getAccessPermissions())); + assertEquals("*:/platform/administrators", data.getEditPermission()); + assertNotNull(data.getProperties()); + assertEquals(1, data.getProperties().size()); + assertTrue(data.getProperties().containsKey("sessionAlive")); + assertEquals("onDemand", data.getProperties().get("sessionAlive")); + + // Verify portal layout container only has children + assertNotNull(data.getPortalLayout()); + Container layout = data.getPortalLayout(); + assertNull(layout.getStorageId()); + assertNull(layout.getId()); + assertNull(layout.getName()); + assertNull(layout.getIcon()); + assertNull(layout.getTemplate()); + assertNull(layout.getFactoryId()); + assertNull(layout.getTitle()); + assertNull(layout.getDescription()); + assertNull(layout.getWidth()); + assertNull(layout.getHeight()); + assertNull(layout.getAccessPermissions()); + List children = data.getPortalLayout().getChildren(); + assertEquals(5, children.size()); + + // Verify container w/ page-body + Container container = (Container) layout.getChildren().get(3); + assertNotNull(container.getChildren()); + assertEquals(2, container.getChildren().size()); + PageBody body = (PageBody) ((Container) container.getChildren().get(0)).getChildren().get(0); + assertNotNull(body); + } } diff --git a/component/portal/src/test/resources/org/exoplatform/portal/mop/management/portal-pagebody.xml b/component/portal/src/test/resources/org/exoplatform/portal/mop/management/portal-pagebody.xml new file mode 100644 index 000000000..63ccdce8c --- /dev/null +++ b/component/portal/src/test/resources/org/exoplatform/portal/mop/management/portal-pagebody.xml @@ -0,0 +1,123 @@ + + + + + classic + + site-description + en + Everyone + *:/platform/administrators + + onDemand + + + + + web + BannerPortlet + + + template + par:/groovy/groovy/webui/component/UIBannerPortlet.gtmpl + false + + + + Default:DefaultTheme::Mac:MacTheme::Vista:VistaTheme + Banner + *:/platform/administrators;*:/organization/management/executive-board + false + true + false + Banner Portlet + PortletIcon + 250px + 350px + + + + web + NavigationPortlet + + Everyone + false + true + true + + + + web + BreadcumbsPortlet + + Everyone + false + true + true + + + Everyone + TableColumnContainer + + Everyone + ColumnContainer + + + + Everyone + ColumnContainer + + + exoadmin + AccountPortlet + + Default:DefaultTheme::Vista:VistaTheme::Mac:MacTheme + *:/platform/administrators;*:/organization/management/executive-board + false + true + true + New Account + + + + + + web + FooterPortlet + + + template + par:/groovy/groovy/webui/component/UIFooterPortlet.gtmpl + false + + + + Everyone + false + true + true + + + \ No newline at end of file