Author: nscavell
Date: 2011-09-28 21:53:57 -0400 (Wed, 28 Sep 2011)
New Revision: 7554
Removed:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/ImportStrategy.java
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/ImportTask.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/NavigationImportTask.java
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/MopImportResource.java
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/mop/management/exportimport/PageImportTaskTest.java
Log:
GTNPORTAL-2100: Align import strategy of mop mgmt extension with import mode of
extensions.
Deleted:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/ImportStrategy.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/ImportStrategy.java 2011-09-28
22:02:49 UTC (rev 7553)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/ImportStrategy.java 2011-09-29
01:53:57 UTC (rev 7554)
@@ -1,78 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2011, Red Hat, Inc., and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * 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.mop.management.exportimport;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a>
- * @version $Revision$
- */
-public enum ImportStrategy
-{
- /**
- * Import when data does not exist. Otherwise do nothing.
- */
- CONSERVE("conserve"),
-
- /**
- * Import when data does not exist. Otherwise perform a merge
- */
- MERGE("merge"),
-
- /**
- * Delete existing data, import new data.
- */
- OVERWRITE("overwrite");
-
- private String name;
-
- ImportStrategy(String name)
- {
- this.name = name;
- }
-
- private static final Map<String, ImportStrategy> MAP;
-
- static
- {
- Map<String, ImportStrategy> tmp = new HashMap<String,
ImportStrategy>(3);
- for (ImportStrategy strategy : ImportStrategy.values())
- {
- tmp.put(strategy.name, strategy);
- }
-
- MAP = tmp;
- }
-
- public String getName()
- {
- return name;
- }
-
- public static ImportStrategy forName(String name)
- {
- return MAP.get(name);
- }
-}
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/ImportTask.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/ImportTask.java 2011-09-28
22:02:49 UTC (rev 7553)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/ImportTask.java 2011-09-29
01:53:57 UTC (rev 7554)
@@ -22,6 +22,8 @@
package org.exoplatform.portal.mop.management.exportimport;
+import org.exoplatform.portal.mop.importer.ImportMode;
+
/**
* @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a>
* @version $Revision$
@@ -34,7 +36,7 @@
this.data = data;
}
- public abstract void importData(ImportStrategy importStrategy) throws Exception;
+ public abstract void importData(ImportMode importMode) throws Exception;
public abstract void rollback() throws Exception;
}
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/NavigationImportTask.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/NavigationImportTask.java 2011-09-28
22:02:49 UTC (rev 7553)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/NavigationImportTask.java 2011-09-29
01:53:57 UTC (rev 7554)
@@ -67,24 +67,8 @@
}
@Override
- public void importData(ImportStrategy importStrategy) throws Exception
+ public void importData(ImportMode importMode) throws Exception
{
- ImportMode mode;
- switch (importStrategy)
- {
- case CONSERVE:
- mode = ImportMode.INSERT;
- break;
- case MERGE:
- mode = ImportMode.MERGE;
- break;
- case OVERWRITE:
- mode = ImportMode.OVERWRITE;
- break;
- default:
- throw new Exception("Could not map import strategy " +
importStrategy.getName() + " to import mode.");
- }
-
PortalConfig portalConfig = dataStorage.getPortalConfig(siteKey.getTypeName(),
siteKey.getName());
if (portalConfig == null) throw new Exception("Cannot import navigation
because site does not exist for " + siteKey);
@@ -154,7 +138,7 @@
}
// Import navigation using gatein navigation importer.
- NavigationImporter importer = new NavigationImporter(locale, mode, data,
navigationService, descriptionService);
+ NavigationImporter importer = new NavigationImporter(locale, importMode, data,
navigationService, descriptionService);
importer.perform();
}
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-09-28
22:02:49 UTC (rev 7553)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/PageImportTask.java 2011-09-29
01:53:57 UTC (rev 7554)
@@ -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.importer.ImportMode;
import org.exoplatform.portal.mop.management.operations.page.PageUtils;
import java.util.ArrayList;
@@ -49,7 +50,7 @@
}
@Override
- public void importData(ImportStrategy strategy) throws Exception
+ public void importData(ImportMode importMode) throws Exception
{
if (data == null || data.getPages() == null || data.getPages().isEmpty()) return;
@@ -58,7 +59,7 @@
int size = list.getAvailable();
Page.PageSet dst = null;
- switch (strategy)
+ switch (importMode)
{
case CONSERVE:
if (size == 0)
@@ -68,6 +69,17 @@
}
else
{
+ dst = null;
+ }
+ break;
+ case INSERT:
+ if (size == 0)
+ {
+ dst = data; // No pages exist yet.
+ rollbackDeletes = data;
+ }
+ else
+ {
dst = new Page.PageSet();
dst.setPages(new ArrayList<Page>());
List<Page> existingPages = list.getAll();
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-09-28
22:02:49 UTC (rev 7553)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/exportimport/SiteLayoutImportTask.java 2011-09-29
01:53:57 UTC (rev 7554)
@@ -25,6 +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.mop.importer.ImportMode;
import org.exoplatform.portal.mop.management.operations.page.PageUtils;
/**
@@ -44,11 +45,11 @@
}
@Override
- public void importData(ImportStrategy importStrategy) throws Exception
+ public void importData(ImportMode importMode) throws Exception
{
PortalConfig dst = dataStorage.getPortalConfig(siteKey.getTypeName(),
siteKey.getName());
- switch (importStrategy)
+ switch (importMode)
{
// Really doesn't make sense to "merge" site layout data. Really
two modes, conserve (keep) and overwrite.
case CONSERVE:
@@ -62,6 +63,7 @@
dst = null;
}
break;
+ case INSERT:
case MERGE:
case OVERWRITE:
if (dst == null)
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/operations/MopImportResource.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/operations/MopImportResource.java 2011-09-28
22:02:49 UTC (rev 7553)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/management/operations/MopImportResource.java 2011-09-29
01:53:57 UTC (rev 7554)
@@ -28,7 +28,7 @@
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.management.exportimport.ImportStrategy;
+import org.exoplatform.portal.mop.importer.ImportMode;
import org.exoplatform.portal.mop.management.exportimport.NavigationExportTask;
import org.exoplatform.portal.mop.management.exportimport.NavigationImportTask;
import org.exoplatform.portal.mop.management.exportimport.PageExportTask;
@@ -96,12 +96,18 @@
DescriptionService descriptionService =
operationContext.getRuntimeContext().getRuntimeComponent(DescriptionService.class);
if (descriptionService == null) throw new OperationException(operationName,
"Description service was null");
- String strategyAttribute =
operationContext.getAttributes().getValue("import-strategy");
- ImportStrategy strategy = ImportStrategy.MERGE;
- if (strategyAttribute != null)
+ ImportMode importMode = ImportMode.MERGE;
+ String mode = operationContext.getAttributes().getValue("importMode");
+ if (mode != null)
{
- strategy = ImportStrategy.forName(strategyAttribute);
- if (strategy == null) throw new OperationException(operationName, "Unknown
import strategy " + strategyAttribute);
+ try
+ {
+ importMode = ImportMode.valueOf(mode.trim().toUpperCase());
+ }
+ catch (Exception e)
+ {
+ throw new OperationException(operationName, "Unknown importMode " +
mode);
+ }
}
Map<SiteKey, MopImport> importMap = new HashMap<SiteKey, MopImport>();
@@ -200,7 +206,7 @@
Map<SiteKey, MopImport> importsRan = new HashMap<SiteKey,
MopImport>();
try
{
- log.info("Performing import using strategy '" + strategy.getName()
+ "'");
+ log.info("Performing import using importMode '" + mode +
"'");
for (Map.Entry<SiteKey, MopImport> mopImportEntry : importMap.entrySet())
{
SiteKey siteKey = mopImportEntry.getKey();
@@ -220,7 +226,7 @@
{
log.debug("Importing site layout data.");
ran.siteTask = mopImport.siteTask;
- mopImport.siteTask.importData(strategy);
+ mopImport.siteTask.importData(importMode);
}
// Page import
@@ -228,7 +234,7 @@
{
log.debug("Importing page data.");
ran.pageTask = mopImport.pageTask;
- mopImport.pageTask.importData(strategy);
+ mopImport.pageTask.importData(importMode);
}
// Navigation import
@@ -236,7 +242,7 @@
{
log.debug("Importing navigation data.");
ran.navigationTask = mopImport.navigationTask;
- mopImport.navigationTask.importData(strategy);
+ mopImport.navigationTask.importData(importMode);
}
}
log.info("Import successful !");
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-09-28
22:02:49 UTC (rev 7553)
+++
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/mop/management/exportimport/PageImportTaskTest.java 2011-09-29
01:53:57 UTC (rev 7554)
@@ -30,6 +30,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.importer.ImportMode;
import org.exoplatform.portal.pom.data.ComponentData;
import org.exoplatform.portal.pom.data.PageData;
import org.mockito.ArgumentMatcher;
@@ -66,7 +67,7 @@
when(dataStorage.find(Matchers.<Query<Page>>any())).thenReturn(list);
when(list.getAvailable()).thenReturn(0); // no pages exist
- task.importData(ImportStrategy.CONSERVE);
+ task.importData(ImportMode.CONSERVE);
verify(dataStorage).find(query("user", "foo"));
verify(list).getAvailable();
@@ -88,6 +89,90 @@
public void testConserve_SamePages() throws Exception
{
Page.PageSet importing = new
Builder().addPage("page1").addPage("page2").addPage("page3").build();
+ PageImportTask task = new PageImportTask(importing, siteKey, dataStorage);
+
+ when(dataStorage.find(Matchers.<Query<Page>>any())).thenReturn(list);
+ when(list.getAvailable()).thenReturn(3);
+
+ task.importData(ImportMode.CONSERVE);
+
+ verify(dataStorage).find(query("user", "foo"));
+ verify(list).getAvailable();
+
+ verifyNoMoreInteractions(dataStorage, list);
+
+ assertNullOrEmpty(task.getRollbackDeletes());
+ assertNullOrEmpty(task.getRollbackSaves());
+ }
+
+ public void testConserve_NewPages() throws Exception
+ {
+ Page.PageSet importing = new
Builder().addPage("page1").addPage("page2").addPage("page3").build();
+ PageImportTask task = new PageImportTask(importing, siteKey, dataStorage);
+
+ when(dataStorage.find(Matchers.<Query<Page>>any())).thenReturn(list);
+ when(list.getAvailable()).thenReturn(3);
+
+ task.importData(ImportMode.CONSERVE);
+
+ verify(dataStorage).find(query("user", "foo"));
+ verify(list).getAvailable();
+
+ verifyNoMoreInteractions(dataStorage, list);
+
+ assertNullOrEmpty(task.getRollbackDeletes());
+ assertNullOrEmpty(task.getRollbackSaves());
+ }
+
+ public void testConserve_NewAndSamePages() throws Exception
+ {
+ Page.PageSet importing = new
Builder().addPage("page1").addPage("page2").addPage("page3").addPage("page4").build();
+ PageImportTask task = new PageImportTask(importing, siteKey, dataStorage);
+
+ when(dataStorage.find(Matchers.<Query<Page>>any())).thenReturn(list);
+ when(list.getAvailable()).thenReturn(3);
+
+ task.importData(ImportMode.CONSERVE);
+
+ verify(dataStorage).find(query("user", "foo"));
+ verify(list).getAvailable();
+
+ verifyNoMoreInteractions(dataStorage, list);
+
+ assertNullOrEmpty(task.getRollbackDeletes());
+ assertNullOrEmpty(task.getRollbackSaves());
+ }
+
+ public void testInsert_NoPages() throws Exception
+ {
+ Page.PageSet importing = new
Builder().addPage("page1").addPage("page2").addPage("page3").build();
+ PageImportTask task = new PageImportTask(importing, siteKey, dataStorage);
+
+ when(dataStorage.find(Matchers.<Query<Page>>any())).thenReturn(list);
+ when(list.getAvailable()).thenReturn(0); // no pages exist
+
+ task.importData(ImportMode.INSERT);
+
+ verify(dataStorage).find(query("user", "foo"));
+ verify(list).getAvailable();
+ verify(list, never()).getAll();
+
+ for (Page page : importing.getPages())
+ {
+ verify(dataStorage).save(page);
+ }
+ verify(dataStorage, times(3)).save();
+
+ verifyNoMoreInteractions(dataStorage, list);
+
+ Assert.assertNotNull(task.getRollbackDeletes());
+ Assert.assertEquals(importing, task.getRollbackDeletes());
+ Assert.assertNull(task.getRollbackSaves());
+ }
+
+ public void testInsert_SamePages() throws Exception
+ {
+ Page.PageSet importing = new
Builder().addPage("page1").addPage("page2").addPage("page3").build();
Page.PageSet existing = new
Builder().addPage("page1").addPage("page2").addPage("page3").build();
PageImportTask task = new PageImportTask(importing, siteKey, dataStorage);
@@ -95,7 +180,7 @@
when(list.getAvailable()).thenReturn(3);
when(list.getAll()).thenReturn(existing.getPages());
- task.importData(ImportStrategy.CONSERVE);
+ task.importData(ImportMode.INSERT);
verify(dataStorage).find(query("user", "foo"));
verify(list).getAvailable();
@@ -107,7 +192,7 @@
assertNullOrEmpty(task.getRollbackSaves());
}
- public void testConserve_NewPages() throws Exception
+ public void testInsert_NewPages() throws Exception
{
Page.PageSet importing = new
Builder().addPage("page1").addPage("page2").addPage("page3").build();
Page.PageSet existing = new
Builder().addPage("foo").addPage("bar").addPage("baz").build();
@@ -117,7 +202,7 @@
when(list.getAvailable()).thenReturn(3);
when(list.getAll()).thenReturn(existing.getPages());
- task.importData(ImportStrategy.CONSERVE);
+ task.importData(ImportMode.INSERT);
verify(dataStorage).find(query("user", "foo"));
verify(list).getAvailable();
@@ -136,7 +221,7 @@
Assert.assertNull(task.getRollbackSaves());
}
- public void testConserve_NewAndSamePages() throws Exception
+ public void testInsert_NewAndSamePages() throws Exception
{
Page.PageSet importing = new
Builder().addPage("page1").addPage("page2").addPage("page3").addPage("page4").build();
Page.PageSet existing = new
Builder().addPage("page2").addPage("bar").addPage("page3").build();
@@ -146,7 +231,7 @@
when(list.getAvailable()).thenReturn(3);
when(list.getAll()).thenReturn(existing.getPages());
- task.importData(ImportStrategy.CONSERVE);
+ task.importData(ImportMode.INSERT);
verify(dataStorage).find(query("user", "foo"));
verify(list).getAvailable();
@@ -174,7 +259,7 @@
when(dataStorage.find(Matchers.<Query<Page>>any())).thenReturn(list);
when(list.getAvailable()).thenReturn(0); // no pages exist
- task.importData(ImportStrategy.MERGE);
+ task.importData(ImportMode.MERGE);
verify(dataStorage).find(query("user", "foo"));
verify(list).getAvailable();
@@ -203,7 +288,7 @@
when(list.getAvailable()).thenReturn(3);
when(list.getAll()).thenReturn(existing.getPages());
- task.importData(ImportStrategy.MERGE);
+ task.importData(ImportMode.MERGE);
verify(dataStorage).find(query("user", "foo"));
verify(list).getAvailable();
@@ -233,7 +318,7 @@
when(list.getAvailable()).thenReturn(3);
when(list.getAll()).thenReturn(existing.getPages());
- task.importData(ImportStrategy.MERGE);
+ task.importData(ImportMode.MERGE);
verify(dataStorage).find(query("user", "foo"));
verify(list).getAvailable();
@@ -262,7 +347,7 @@
when(list.getAvailable()).thenReturn(3);
when(list.getAll()).thenReturn(existing.getPages());
- task.importData(ImportStrategy.MERGE);
+ task.importData(ImportMode.MERGE);
verify(dataStorage).find(query("user", "foo"));
verify(list).getAvailable();
@@ -295,7 +380,7 @@
when(dataStorage.find(Matchers.<Query<Page>>any())).thenReturn(list);
when(list.getAvailable()).thenReturn(0); // no pages exist
- task.importData(ImportStrategy.OVERWRITE);
+ task.importData(ImportMode.OVERWRITE);
verify(dataStorage).find(query("user", "foo"));
verify(list).getAvailable();
@@ -324,7 +409,7 @@
when(list.getAvailable()).thenReturn(3);
when(list.getAll()).thenReturn(existing.getPages());
- task.importData(ImportStrategy.OVERWRITE);
+ task.importData(ImportMode.OVERWRITE);
verify(dataStorage).find(query("user", "foo"));
verify(list).getAvailable();
@@ -360,7 +445,7 @@
when(list.getAvailable()).thenReturn(3);
when(list.getAll()).thenReturn(existing.getPages());
- task.importData(ImportStrategy.OVERWRITE);
+ task.importData(ImportMode.OVERWRITE);
verify(dataStorage).find(query("user", "foo"));
verify(list).getAvailable();
@@ -397,7 +482,7 @@
when(list.getAvailable()).thenReturn(3);
when(list.getAll()).thenReturn(existing.getPages());
- task.importData(ImportStrategy.OVERWRITE);
+ task.importData(ImportMode.OVERWRITE);
verify(dataStorage).find(query("user", "foo"));
verify(list).getAvailable();