Author: theute
Date: 2011-08-25 02:35:14 -0400 (Thu, 25 Aug 2011)
New Revision: 7219
Modified:
epp/portal/branches/EPP_5_2_Branch/
epp/portal/branches/EPP_5_2_Branch/component/
epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/NavigationImportTask.java
epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/management/operations/MopImportResource.java
Log:
JBEPP-1121 Support navigation rollback during management operation import-resource.
Property changes on: epp/portal/branches/EPP_5_2_Branch
___________________________________________________________________
Modified: svn:mergeinfo
- /epp/portal/branches/EPP_5_1_0_GA_JBEPP-795:5868
/portal/branches/branch-GTNPORTAL-1592:4894
/portal/branches/branch-GTNPORTAL-1643:5002,5063,5167
/portal/branches/branch-GTNPORTAL-1700:5348,5363,5402,5445
/portal/branches/branch-GTNPORTAL-1731:5622,5668
/portal/branches/branch-GTNPORTAL-1745:5765
/portal/branches/branch-GTNPORTAL-1790:5871
/portal/branches/branch-GTNPORTAL-1822:5943,5952
/portal/branches/branch-GTNPORTAL-1832:6030,6063
/portal/branches/branch-GTNPORTAL-1872:6400,6551
/portal/branches/branch-GTNPORTAL-1921:6603
/portal/branches/branch-GTNPORTAL-1963:6904,6915-6916
/portal/branches/decoupled-webos:6214-6243
/portal/branches/gatein-management:6920-6958
/portal/branches/global-portlet-metadata:6298-6384
/portal/branches/site-describability:6171-6235
/portal/trunk:4891,5744,5822,5943,6168,6196,6201-6203,6205-6206,6437,6440,6449,6452,6573,6783-6784,6912-6913,6960,7042,7061,7117,7125
+ /epp/portal/branches/EPP_5_1_0_GA_JBEPP-795:5868
/portal/branches/branch-GTNPORTAL-1592:4894
/portal/branches/branch-GTNPORTAL-1643:5002,5063,5167
/portal/branches/branch-GTNPORTAL-1700:5348,5363,5402,5445
/portal/branches/branch-GTNPORTAL-1731:5622,5668
/portal/branches/branch-GTNPORTAL-1745:5765
/portal/branches/branch-GTNPORTAL-1790:5871
/portal/branches/branch-GTNPORTAL-1822:5943,5952
/portal/branches/branch-GTNPORTAL-1832:6030,6063
/portal/branches/branch-GTNPORTAL-1872:6400,6551
/portal/branches/branch-GTNPORTAL-1921:6603
/portal/branches/branch-GTNPORTAL-1963:6904,6915-6916
/portal/branches/decoupled-webos:6214-6243
/portal/branches/gatein-management:6920-6958
/portal/branches/global-portlet-metadata:6298-6384
/portal/branches/site-describability:6171-6235
/portal/trunk:4891,5744,5822,5943,6168,6196,6201-6203,6205-6206,6437,6440,6449,6452,6573,6783-6784,6912-6913,6960,7042,7061,7117,7125,7132,7134
Property changes on: epp/portal/branches/EPP_5_2_Branch/component
___________________________________________________________________
Modified: svn:mergeinfo
- /epp/portal/branches/EPP_5_1_0_GA_JBEPP-795/component:5868
/portal/branches/branch-GTNPORTAL-1592/component:4894
/portal/branches/branch-GTNPORTAL-1643/component:5002,5063,5167
/portal/branches/branch-GTNPORTAL-1700/component:5348,5363,5402,5445
/portal/branches/branch-GTNPORTAL-1731/component:5622,5668
/portal/branches/branch-GTNPORTAL-1745/component:5765
/portal/branches/branch-GTNPORTAL-1790/component:5871
/portal/branches/branch-GTNPORTAL-1822/component:5943,5952
/portal/branches/branch-GTNPORTAL-1832/component:6030,6063
/portal/branches/branch-GTNPORTAL-1872/component:6400,6551
/portal/branches/branch-GTNPORTAL-1921/component:6603
/portal/branches/branch-GTNPORTAL-1963/component:6904,6915-6916
/portal/trunk/component:4891,5744,5822,5943,6031,6033,6168,6196,6201-6203,6205-6206,6292,6437,6440,6449,6452,6573,6783-6784,6912-6913,6960,7042,7061,7117,7125
+ /epp/portal/branches/EPP_5_1_0_GA_JBEPP-795/component:5868
/portal/branches/branch-GTNPORTAL-1592/component:4894
/portal/branches/branch-GTNPORTAL-1643/component:5002,5063,5167
/portal/branches/branch-GTNPORTAL-1700/component:5348,5363,5402,5445
/portal/branches/branch-GTNPORTAL-1731/component:5622,5668
/portal/branches/branch-GTNPORTAL-1745/component:5765
/portal/branches/branch-GTNPORTAL-1790/component:5871
/portal/branches/branch-GTNPORTAL-1822/component:5943,5952
/portal/branches/branch-GTNPORTAL-1832/component:6030,6063
/portal/branches/branch-GTNPORTAL-1872/component:6400,6551
/portal/branches/branch-GTNPORTAL-1921/component:6603
/portal/branches/branch-GTNPORTAL-1963/component:6904,6915-6916
/portal/trunk/component:4891,5744,5822,5943,6031,6033,6168,6196,6201-6203,6205-6206,6292,6437,6440,6449,6452,6573,6783-6784,6912-6913,6960,7042,7061,7117,7125,7132,7134
Modified:
epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/NavigationImportTask.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/NavigationImportTask.java 2011-08-25
04:34:28 UTC (rev 7218)
+++
epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/NavigationImportTask.java 2011-08-25
06:35:14 UTC (rev 7219)
@@ -23,20 +23,25 @@
package org.exoplatform.portal.mop.management.exportimport;
import org.exoplatform.portal.config.DataStorage;
+import org.exoplatform.portal.config.model.NavigationFragment;
import org.exoplatform.portal.config.model.PageNavigation;
import org.exoplatform.portal.config.model.PortalConfig;
import org.exoplatform.portal.mop.SiteKey;
import org.exoplatform.portal.mop.description.DescriptionService;
import org.exoplatform.portal.mop.importer.ImportMode;
import org.exoplatform.portal.mop.importer.NavigationImporter;
+import org.exoplatform.portal.mop.management.operations.navigation.NavigationUtils;
import org.exoplatform.portal.mop.navigation.NavigationContext;
import org.exoplatform.portal.mop.navigation.NavigationService;
-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.navigation.NodeChangeListener;
+import org.exoplatform.portal.mop.navigation.NodeContext;
+import org.exoplatform.portal.mop.navigation.NodeState;
+import org.exoplatform.portal.mop.navigation.Scope;
import org.gatein.common.logging.Logger;
import org.gatein.common.logging.LoggerFactory;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Locale;
/**
@@ -91,25 +96,64 @@
rollbackTask = new RollbackTask()
{
@Override
+ public String getDescription()
+ {
+ return "Deleting navigation for site " + siteKey;
+ }
+
+ @Override
public void rollback() throws Exception
{
+ log.debug("Rollback: " + getDescription());
navigationService.destroyNavigation(navContext);
}
};
}
else
{
- //TODO: Rollback updates.
+
+ final List<NodeContext<NodeContext<?>>> snapshots = new
ArrayList<NodeContext<NodeContext<?>>>(data.getFragments().size());
+ for (NavigationFragment fragment : data.getFragments())
+ {
+ snapshots.add(NavigationUtils.loadNode(navigationService, navContext,
fragment.getParentURI()));
+ }
+
rollbackTask = new RollbackTask()
{
@Override
+ public String getDescription()
+ {
+ return "Rolling back navigation changes...";
+ }
+
+ @Override
public void rollback() throws Exception
{
- log.warn("Rollback for existing navigation not supported at the
moment.");
+ log.debug(getDescription());
+
+ for (NodeContext<NodeContext<?>> snapshot : snapshots)
+ {
+ RollbackChangeListener listener = new RollbackChangeListener();
+ navigationService.updateNode(snapshot, Scope.ALL, listener);
+
+ // Rollback...
+ listener.rollback();
+
+ // If any errors, throw exception
+ if (listener.errors)
+ {
+ throw new Exception("Error rolling back navigation snapshot
'" + snapshot.getName() + "'");
+ }
+
+ navigationService.saveNode(snapshot, null);
+ }
+
+ log.debug("Successfully rolled back navigation changes.");
}
};
}
+ // Import navigation using gatein navigation importer.
NavigationImporter importer = new NavigationImporter(locale, mode, data,
navigationService, descriptionService);
importer.perform();
}
@@ -125,6 +169,183 @@
private static interface RollbackTask
{
+ String getDescription();
+
void rollback() throws Exception;
}
+
+ private static class RollbackChangeListener implements
NodeChangeListener<NodeContext<NodeContext<?>>>
+ {
+ private List<RollbackTask> tasks = new ArrayList<RollbackTask>();
+ private boolean errors;
+
+ @Override
+ public void onAdd(final NodeContext<NodeContext<?>> target, final
NodeContext<NodeContext<?>> parent, NodeContext<NodeContext<?>>
previous)
+ {
+ tasks.add(new RollbackTask()
+ {
+ @Override
+ public String getDescription()
+ {
+ return "Removing node " + target.getName() + " from parent
" + parent.getName();
+ }
+
+ @Override
+ public void rollback() throws Exception
+ {
+ parent.removeNode(target.getName());
+ }
+ });
+ }
+
+ @Override
+ public void onCreate(final NodeContext<NodeContext<?>> target, final
NodeContext<NodeContext<?>> parent, final
NodeContext<NodeContext<?>> previous, final String name)
+ {
+ tasks.add(new RollbackTask()
+ {
+ @Override
+ public String getDescription()
+ {
+ return "Removing node " + name + " from parent " +
parent.getName();
+ }
+
+ @Override
+ public void rollback() throws Exception
+ {
+ parent.removeNode(name);
+ }
+ });
+ }
+
+ @Override
+ public void onRemove(final NodeContext<NodeContext<?>> target, final
NodeContext<NodeContext<?>> parent)
+ {
+ tasks.add(new RollbackTask()
+ {
+ // Copy all state for rollback
+ private String name = target.getName();
+ private Integer index = target.getIndex();
+ boolean hidden = target.isHidden();
+ private NodeState state = target.getState();
+
+ @Override
+ public String getDescription()
+ {
+ return "Adding node " + target.getName() + " to parent
" + parent.getName();
+ }
+
+ @Override
+ public void rollback() throws Exception
+ {
+ NodeContext node = parent.add(index, name);
+ node.setState(state);
+ node.setHidden(hidden);
+ }
+ });
+ }
+
+ @Override
+ public void onDestroy(final NodeContext<NodeContext<?>> target, final
NodeContext<NodeContext<?>> parent)
+ {
+ tasks.add(new RollbackTask()
+ {
+ @Override
+ public String getDescription()
+ {
+ return "Adding node " + target.getName() + " from parent
" + parent.getName();
+ }
+
+ @Override
+ public void rollback() throws Exception
+ {
+ parent.add(null, target);
+ }
+ });
+ }
+
+ @Override
+ public void onRename(final NodeContext<NodeContext<?>> target, final
NodeContext<NodeContext<?>> parent, final String name)
+ {
+ tasks.add(new RollbackTask()
+ {
+ // Copy previous name for rollback
+ private String targetName = target.getName();
+
+ @Override
+ public String getDescription()
+ {
+ return "Renaming node " + name + " to " + targetName +
" for parent " + parent.getName();
+ }
+
+ @Override
+ public void rollback() throws Exception
+ {
+ target.setName(targetName);
+ }
+ });
+ }
+
+ @Override
+ public void onUpdate(final NodeContext<NodeContext<?>> target, final
NodeState state)
+ {
+ tasks.add(new RollbackTask()
+ {
+ // Copy state for rollback
+ private NodeState targetState = target.getState();
+
+ @Override
+ public String getDescription()
+ {
+ return "Setting node " + target.getName() + " back to
previous state " + targetState;
+ }
+
+ @Override
+ public void rollback() throws Exception
+ {
+ target.setState(targetState);
+ }
+ });
+ }
+
+ @Override
+ public void onMove(final NodeContext<NodeContext<?>> target, final
NodeContext<NodeContext<?>> from, final
NodeContext<NodeContext<?>> to, NodeContext<NodeContext<?>>
previous)
+ {
+ tasks.add(new RollbackTask()
+ {
+ @Override
+ public String getDescription()
+ {
+ return "Moving node " + target.getName() + " from " +
to.getName() + " to " + from.getName();
+ }
+
+ @Override
+ public void rollback() throws Exception
+ {
+ from.add(target.getIndex(), target);
+ to.removeNode(target.getName());
+ }
+ });
+ }
+
+ public void rollback()
+ {
+ boolean debug = log.isDebugEnabled();
+ for (RollbackTask task : tasks)
+ {
+ try
+ {
+ if (debug)
+ {
+ log.debug("Rollback: " + task.getDescription());
+ }
+ task.rollback();
+ }
+ catch (Exception e)
+ {
+ log.error("Exception during NodeChangeListener's rollback task:
" + task.getDescription(), e);
+ errors = true;
+ }
+ }
+ }
+ }
}
Modified:
epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/management/operations/MopImportResource.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/management/operations/MopImportResource.java 2011-08-25
04:34:28 UTC (rev 7218)
+++
epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/management/operations/MopImportResource.java 2011-08-25
06:35:14 UTC (rev 7219)
@@ -187,7 +187,7 @@
}
// Perform import
- Map<SiteKey, MopImport> completedImportMap = new HashMap<SiteKey,
MopImport>();
+ Map<SiteKey, MopImport> importsRan = new HashMap<SiteKey,
MopImport>();
try
{
log.info("Performing import using strategy '" + strategy.getName()
+ "'");
@@ -195,13 +195,13 @@
{
SiteKey siteKey = mopImportEntry.getKey();
MopImport mopImport = mopImportEntry.getValue();
- MopImport completed = new MopImport();
+ MopImport ran = new MopImport();
- if (completedImportMap.containsKey(siteKey))
+ if (importsRan.containsKey(siteKey))
{
throw new IllegalStateException("Multiple site imports for same
operation.");
}
- completedImportMap.put(siteKey, completed);
+ importsRan.put(siteKey, ran);
log.debug("Importing data for site " + siteKey);
@@ -209,24 +209,24 @@
if (mopImport.siteTask != null)
{
log.debug("Importing site layout data.");
+ ran.siteTask = mopImport.siteTask;
mopImport.siteTask.importData(strategy);
- completed.siteTask = mopImport.siteTask;
}
// Page import
if (mopImport.pageTask != null)
{
log.debug("Importing page data.");
+ ran.pageTask = mopImport.pageTask;
mopImport.pageTask.importData(strategy);
- completed.pageTask = mopImport.pageTask;
}
// Navigation import
if (mopImport.navigationTask != null)
{
log.debug("Importing navigation data.");
+ ran.navigationTask = mopImport.navigationTask;
mopImport.navigationTask.importData(strategy);
- completed.navigationTask = mopImport.navigationTask;
}
}
log.info("Import successful !");
@@ -236,7 +236,7 @@
boolean rollbackSuccess = true;
log.error("Exception importing data.", t);
log.info("Attempting to rollback data modified by import.");
- for (Map.Entry<SiteKey, MopImport> mopImportEntry :
completedImportMap.entrySet())
+ for (Map.Entry<SiteKey, MopImport> mopImportEntry :
importsRan.entrySet())
{
SiteKey siteKey = mopImportEntry.getKey();
MopImport mopImport = mopImportEntry.getValue();
@@ -292,7 +292,7 @@
finally
{
importMap.clear();
- completedImportMap.clear();
+ importsRan.clear();
}
}