Author: nscavell
Date: 2011-08-15 15:26:34 -0400 (Mon, 15 Aug 2011)
New Revision: 7133
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/PageImportTask.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/SiteLayoutImportTask.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/operations/page/PageUtils.java
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/mop/management/exportimport/PageImportTaskTest.java
Log:
GTNPORTAL-2023: Stale storage id's result in error during rollback for pages and site
layout.
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/PageImportTask.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/PageImportTask.java 2011-08-15
19:24:14 UTC (rev 7132)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/PageImportTask.java 2011-08-15
19:26:34 UTC (rev 7133)
@@ -27,6 +27,7 @@
import org.exoplatform.portal.config.Query;
import org.exoplatform.portal.config.model.Page;
import org.exoplatform.portal.mop.SiteKey;
+import org.exoplatform.portal.mop.management.operations.page.PageUtils;
import java.util.ArrayList;
import java.util.List;
@@ -109,7 +110,7 @@
}
else
{
- rollbackSaves.getPages().add(found);
+ rollbackSaves.getPages().add(PageUtils.copy(found));
}
}
}
@@ -129,9 +130,10 @@
rollbackDeletes.setPages(new ArrayList<Page>());
for (Page page : existingPages)
{
+ Page copy = PageUtils.copy(page);
dataStorage.remove(page);
dataStorage.save();
- rollbackSaves.getPages().add(page);
+ rollbackSaves.getPages().add(copy);
}
for (Page src : data.getPages())
{
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/SiteLayoutImportTask.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/SiteLayoutImportTask.java 2011-08-15
19:24:14 UTC (rev 7132)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/SiteLayoutImportTask.java 2011-08-15
19:26:34 UTC (rev 7133)
@@ -25,9 +25,7 @@
import org.exoplatform.portal.config.DataStorage;
import org.exoplatform.portal.config.model.PortalConfig;
import org.exoplatform.portal.mop.SiteKey;
-import org.exoplatform.portal.pom.data.ModelDataStorage;
-import org.exoplatform.portal.pom.data.PortalData;
-import org.exoplatform.portal.pom.data.PortalKey;
+import org.exoplatform.portal.mop.management.operations.page.PageUtils;
/**
* @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a>
@@ -72,7 +70,7 @@
}
else
{
- rollbackSave = dst;
+ rollbackSave = PageUtils.copy(dst);
}
dst = data;
break;
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/operations/page/PageUtils.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/operations/page/PageUtils.java 2011-08-15
19:24:14 UTC (rev 7132)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/operations/page/PageUtils.java 2011-08-15
19:26:34 UTC (rev 7133)
@@ -1,8 +1,21 @@
package org.exoplatform.portal.mop.management.operations.page;
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.container.PortalContainer;
import org.exoplatform.portal.config.DataStorage;
import org.exoplatform.portal.config.Query;
+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.ModelObject;
import org.exoplatform.portal.config.model.Page;
+import org.exoplatform.portal.config.model.PageBody;
+import org.exoplatform.portal.config.model.PortalConfig;
+import org.exoplatform.portal.config.model.Properties;
+import org.exoplatform.portal.config.model.TransientApplicationState;
import org.exoplatform.portal.mop.SiteKey;
import org.gatein.management.api.exceptions.OperationException;
@@ -29,7 +42,7 @@
}
}
- public static Page.PageSet getAllPages(DataStorage dataStorage, SiteKey siteKey,
String operationName)
+ public static Page.PageSet getAllPages(DataStorage dataStorage, SiteKey siteKey,
String operationName)
{
Query<Page> query = new Query<Page>(siteKey.getTypeName(),
siteKey.getName(), Page.class);
try
@@ -45,4 +58,180 @@
throw new OperationException(operationName, "Could not retrieve pages for
site " + siteKey);
}
}
+
+ public static <S> Application<S> copy(Application<S> existing)
+ {
+ Application<S> application = new Application<S>(existing.getType());
+ application.setAccessPermissions(copy(existing.getAccessPermissions()));
+ application.setDescription(existing.getDescription());
+ application.setHeight(existing.getHeight());
+ application.setIcon(existing.getIcon());
+ application.setId(existing.getId());
+ application.setModifiable(existing.isModifiable());
+ application.setProperties(new Properties(existing.getProperties()));
+ application.setShowApplicationMode(existing.getShowApplicationMode());
+ application.setShowApplicationState(existing.getShowApplicationState());
+ application.setShowInfoBar(existing.getShowInfoBar());
+ application.setState(copy(existing.getType(), existing.getState()));
+ application.setTheme(existing.getTheme());
+ application.setTitle(existing.getTitle());
+ application.setWidth(existing.getWidth());
+
+ return application;
+ }
+
+ public static <S> ApplicationState<S> copy(ApplicationType<S> type,
ApplicationState<S> existing)
+ {
+ if (existing instanceof TransientApplicationState)
+ {
+ TransientApplicationState<S> state = (TransientApplicationState<S>)
existing;
+ return new TransientApplicationState<S>(state.getContentId(),
state.getContentState(), state.getOwnerType(), state.getOwnerId(), state.getUniqueId());
+ }
+ else
+ {
+ // Hate doing this, but it's the only way to deal with persistent
application state...
+ ExoContainer container = ExoContainerContext.getCurrentContainer();
+ if (container instanceof PortalContainer)
+ {
+ DataStorage ds = (DataStorage)
container.getComponentInstanceOfType(DataStorage.class);
+ try
+ {
+ S s = ds.load(existing, type);
+ String contentId = ds.getId(existing);
+
+ return new TransientApplicationState<S>(contentId, s);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Exception copying persistent application
state.", e);
+ }
+ }
+ else
+ {
+ throw new RuntimeException("Unable to copy persistent application state
with kernel container " + container);
+ }
+ }
+ }
+
+ public static Container copy(Container existing)
+ {
+ Container container = new Container();
+ copyFields(existing, container);
+
+ return container;
+ }
+
+ public static Dashboard copy(Dashboard existing)
+ {
+ Dashboard dashboard = new Dashboard();
+ copyFields(existing, dashboard);
+
+ return dashboard;
+ }
+
+ public static Page copy(Page existing)
+ {
+ Page page = new Page();
+
+ // Copy page specific data
+ page.setEditPermission(existing.getEditPermission());
+ page.setModifiable(existing.isModifiable());
+ page.setOwnerId(existing.getOwnerId());
+ page.setOwnerType(existing.getOwnerType());
+ page.setPageId(existing.getPageId());
+ page.setShowMaxWindow(existing.isShowMaxWindow());
+
+ // Copy container specific data.
+ copyFields(existing, page);
+
+ return page;
+ }
+
+ public static Page.PageSet copy(Page.PageSet existingPageSet)
+ {
+ Page.PageSet pageSet = new Page.PageSet();
+ ArrayList<Page> pages = new
ArrayList<Page>(existingPageSet.getPages().size());
+ pageSet.setPages(pages);
+
+ for (Page existingPage : existingPageSet.getPages())
+ {
+ pages.add(copy(existingPage));
+ }
+
+ return pageSet;
+ }
+
+ @SuppressWarnings("unused")
+ public static PageBody copy(PageBody existing)
+ {
+ return new PageBody();
+ }
+
+ public static PortalConfig copy(PortalConfig existing)
+ {
+ PortalConfig portalConfig = new PortalConfig(existing.getType(),
existing.getName());
+ portalConfig.setAccessPermissions(copy(existing.getAccessPermissions()));
+ portalConfig.setDescription(existing.getDescription());
+ portalConfig.setEditPermission(existing.getEditPermission());
+ portalConfig.setLabel(existing.getLabel());
+ portalConfig.setLocale(existing.getLocale());
+ portalConfig.setModifiable(existing.isModifiable());
+ portalConfig.setPortalLayout(copy(existing.getPortalLayout()));
+ portalConfig.setProperties(new Properties(existing.getProperties()));
+
+ return portalConfig;
+ }
+
+ private static void copyFields(Container existing, Container container)
+ {
+ container.setAccessPermissions(copy(existing.getAccessPermissions()));
+ container.setChildren(copyChildren(existing.getChildren()));
+ container.setDecorator(existing.getDecorator());
+ container.setDescription(existing.getDescription());
+ container.setFactoryId(existing.getFactoryId());
+ container.setHeight(existing.getHeight());
+ container.setIcon(existing.getIcon());
+ container.setId(existing.getId());
+ container.setName(existing.getName());
+ container.setTemplate(existing.getTemplate());
+ container.setTitle(existing.getTitle());
+ container.setWidth(existing.getWidth());
+ }
+
+ private static ArrayList<ModelObject> copyChildren(ArrayList<ModelObject>
existing)
+ {
+ if (existing == null) return null;
+ ArrayList<ModelObject> children = new
ArrayList<ModelObject>(existing.size());
+
+ for (ModelObject object : existing)
+ {
+ if (object instanceof Application)
+ {
+ @SuppressWarnings("unchecked")
+ Application app = copy((Application) object);
+
+ children.add(app);
+ }
+ if (object instanceof Dashboard)
+ {
+ children.add(copy((Dashboard) object));
+ }
+ if (object instanceof Container)
+ {
+ children.add(copy((Container) object));
+ }
+ }
+
+ return children;
+ }
+
+ private static String[] copy(String[] existing)
+ {
+ if (existing == null) return null;
+
+ String[] array = new String[existing.length];
+ System.arraycopy(existing, 0, array, 0, existing.length);
+
+ return array;
+ }
}
Modified:
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/mop/management/exportimport/PageImportTaskTest.java
===================================================================
---
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/mop/management/exportimport/PageImportTaskTest.java 2011-08-15
19:24:14 UTC (rev 7132)
+++
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/mop/management/exportimport/PageImportTaskTest.java 2011-08-15
19:26:34 UTC (rev 7133)
@@ -220,7 +220,7 @@
assertNullOrEmpty(task.getRollbackDeletes());
Assert.assertNotNull(task.getRollbackSaves());
Assert.assertEquals(3, task.getRollbackSaves().getPages().size());
- Assert.assertEquals(existing.getPages(), task.getRollbackSaves().getPages());
+ comparePages(existing.getPages(), task.getRollbackSaves().getPages());
}
public void testMerge_NewPages() throws Exception
@@ -283,8 +283,8 @@
Assert.assertNotNull(task.getRollbackSaves());
Assert.assertEquals(2, task.getRollbackSaves().getPages().size());
- Assert.assertEquals(existing.getPages().get(0),
task.getRollbackSaves().getPages().get(0));
- Assert.assertEquals(existing.getPages().get(2),
task.getRollbackSaves().getPages().get(1));
+ comparePage(existing.getPages().get(0),
task.getRollbackSaves().getPages().get(0));
+ comparePage(existing.getPages().get(2),
task.getRollbackSaves().getPages().get(1));
}
public void testOverwrite_NoPages() throws Exception
@@ -347,7 +347,7 @@
assertNullOrEmpty(task.getRollbackDeletes());
Assert.assertNotNull(task.getRollbackSaves());
Assert.assertEquals(3, task.getRollbackSaves().getPages().size());
- Assert.assertEquals(existing.getPages(), task.getRollbackSaves().getPages());
+ comparePages(existing.getPages(), task.getRollbackSaves().getPages());
}
public void testOverwrite_NewPages() throws Exception
@@ -384,7 +384,7 @@
Assert.assertEquals(importing.getPages(), task.getRollbackDeletes().getPages());
Assert.assertNotNull(task.getRollbackSaves());
- Assert.assertEquals(existing.getPages(), task.getRollbackSaves().getPages());
+ comparePages(existing.getPages(), task.getRollbackSaves().getPages());
}
public void testOverwrite_NewAndSamePages() throws Exception
@@ -423,7 +423,7 @@
Assert.assertEquals(importing.getPages().get(3),
task.getRollbackDeletes().getPages().get(1));
Assert.assertNotNull(task.getRollbackSaves());
- Assert.assertEquals(existing.getPages(), task.getRollbackSaves().getPages());
+ comparePages(existing.getPages(), task.getRollbackSaves().getPages());
}
private void assertNullOrEmpty(Page.PageSet pages)
@@ -434,6 +434,27 @@
}
}
+ private void comparePages(ArrayList<Page> expected, ArrayList<Page>
actual)
+ {
+ if (expected == null)
+ {
+ assertNull(actual);
+ return;
+ }
+
+ assertEquals(expected.size(), actual.size());
+
+ for (int i=0; i<expected.size(); i++)
+ {
+ comparePage(expected.get(i), actual.get(i));
+ }
+ }
+
+ private void comparePage(Page expected, Page actual)
+ {
+ assertEquals(expected.getName(), actual.getName());
+ }
+
private Query<Page> query(String ownerType, String ownerId)
{
return argThat(new QueryMatcher(new Query<Page>(ownerType, ownerId,
Page.class)));