Author: julien_viet
Date: 2010-04-09 04:20:43 -0400 (Fri, 09 Apr 2010)
New Revision: 2543
Added:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/StaleModelException.java
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/PageTask.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/data/Mapper.java
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java
Log:
GTNPORTAL-962 : applied submitted patch and completed it : Lose permission in clone node
(when edit page navigation)
Added:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/StaleModelException.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/StaleModelException.java
(rev 0)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/StaleModelException.java 2010-04-09
08:20:43 UTC (rev 2543)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.config;
+
+/**
+ * This exception signals that the passed argument model is stale and that the underlying
update operation
+ * could not be accomplished.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class StaleModelException extends StorageException
+{
+
+ public StaleModelException()
+ {
+ }
+
+ public StaleModelException(String message)
+ {
+ super(message);
+ }
+
+ public StaleModelException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ public StaleModelException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/PageTask.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/PageTask.java 2010-04-09
06:37:13 UTC (rev 2542)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/PageTask.java 2010-04-09
08:20:43 UTC (rev 2543)
@@ -21,6 +21,7 @@
import org.exoplatform.portal.config.NoSuchDataException;
import org.exoplatform.portal.mop.Described;
+import org.exoplatform.portal.mop.ProtectedResource;
import org.exoplatform.portal.pom.config.POMTask;
import org.exoplatform.portal.pom.config.cache.DataAccessMode;
import org.exoplatform.portal.pom.config.cache.CacheableDataTask;
@@ -164,6 +165,12 @@
dstDescribed.setName(srcDescribed.getName());
dstDescribed.setDescription(srcDescribed.getDescription());
+ // Copy src permissions to dst permission
+ PageData srcPageData = new Mapper(session).load(srcPage);
+ ProtectedResource pr = dstPage.adapt(ProtectedResource.class);
+ pr.setAccessPermissions(srcPageData.getAccessPermissions());
+ pr.setEditPermission(srcPageData.getEditPermission());
+
copy(srcPage, dstPage, srcPage.getRootComponent(), dstPage.getRootComponent());
//
@@ -178,6 +185,24 @@
UIComponent dstChild = dst.add(srcChild.getObjectType(),
srcChild.getObjectId());
//
+ if (srcChild.isAdapted(Described.class))
+ {
+ Described srcDescribed = srcChild.adapt(Described.class);
+ Described dstDescribed = dstChild.adapt(Described.class);
+ dstDescribed.setName(srcDescribed.getName());
+ dstDescribed.setDescription(srcDescribed.getDescription());
+ }
+
+ //
+ if (srcChild.isAdapted(ProtectedResource.class))
+ {
+ ProtectedResource srcPR = srcChild.adapt(ProtectedResource.class);
+ ProtectedResource dstPR = dstChild.adapt(ProtectedResource.class);
+ dstPR.setAccessPermissions(srcPR.getAccessPermissions());
+ dstPR.setEditPermission(srcPR.getEditPermission());
+ }
+
+ //
Attributes srcAttrs = srcChild.getAttributes();
Attributes dstAttrs = dstChild.getAttributes();
for (String key : srcAttrs.getKeys())
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/data/Mapper.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/data/Mapper.java 2010-04-09
06:37:13 UTC (rev 2542)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/data/Mapper.java 2010-04-09
08:20:43 UTC (rev 2543)
@@ -20,6 +20,7 @@
package org.exoplatform.portal.pom.data;
import org.exoplatform.portal.config.NoSuchDataException;
+import org.exoplatform.portal.config.StaleModelException;
import org.exoplatform.portal.config.UserACL;
import org.exoplatform.portal.config.model.ApplicationState;
import org.exoplatform.portal.config.model.ApplicationType;
@@ -708,7 +709,7 @@
dstChild = session.findObjectById(ObjectType.COMPONENT, srcChildId);
if (dstChild == null)
{
- throw new AssertionError("Could not find supposed present child with
id " + srcChildId);
+ throw new StaleModelException("Could not find supposed present child
with id " + srcChildId);
}
// julien : this can fail due to a bug in chromattic not implementing equals
method properly
@@ -774,7 +775,7 @@
}
else
{
- throw new AssertionError("Was not expecting child " +
srcChild);
+ throw new StaleModelException("Was not expecting child " +
srcChild);
}
changes.add(new ModelChange.Create(dst.getObjectId(), srcChild));
}
Modified:
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java
===================================================================
---
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java 2010-04-09
06:37:13 UTC (rev 2542)
+++
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java 2010-04-09
08:20:43 UTC (rev 2543)
@@ -24,16 +24,7 @@
import org.exoplatform.container.PortalContainer;
import org.exoplatform.portal.application.PortletPreferences;
import org.exoplatform.portal.application.Preference;
-import org.exoplatform.portal.config.model.Application;
-import org.exoplatform.portal.config.model.ApplicationState;
-import org.exoplatform.portal.config.model.ApplicationType;
-import org.exoplatform.portal.config.model.Container;
-import org.exoplatform.portal.config.model.Dashboard;
-import org.exoplatform.portal.config.model.Page;
-import org.exoplatform.portal.config.model.PageNavigation;
-import org.exoplatform.portal.config.model.PageNode;
-import org.exoplatform.portal.config.model.PortalConfig;
-import org.exoplatform.portal.config.model.TransientApplicationState;
+import org.exoplatform.portal.config.model.*;
import org.exoplatform.portal.pom.config.POMSession;
import org.exoplatform.portal.pom.config.POMSessionManager;
import org.exoplatform.portal.pom.data.ModelChange;
@@ -627,6 +618,26 @@
//
Application banner2 = (Application)container.getChildren().get(0);
// assertEquals(banner2.getInstanceId(), banner1.getInstanceId());
+
+ //
+ Page srcPage = storage_.getPage("portal::test::test4");
+ srcPage.setEditPermission("Administrator");
+ Application<Portlet>portlet =
(Application<Portlet>)srcPage.getChildren().get(0);
+ portlet.setDescription("NewPortlet");
+
+ ArrayList<ModelObject> modelObject = srcPage.getChildren();
+ modelObject.set(0, portlet);
+
+ srcPage.setChildren(modelObject);
+
+ storage_.save(srcPage);
+ Page dstPage = storage_.clonePage(srcPage.getPageId(), srcPage.getOwnerType(),
srcPage.getOwnerId(), "_PageTest1234");
+ Application<Portlet>portlet1 =
(Application<Portlet>)dstPage.getChildren().get(0);
+ // Check src's edit permission and dst's edit permission
+ assertEquals(srcPage.getEditPermission(), dstPage.getEditPermission());
+
+ // Check src's children and dst's children
+ assertEquals(portlet.getDescription(), portlet1.getDescription());
}
public void testDashboard() throws Exception