Author: nscavell
Date: 2011-08-12 15:48:51 -0400 (Fri, 12 Aug 2011)
New Revision: 7061
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/description/DescriptionServiceImpl.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/importer/NavigationFragmentImporter.java
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/mop/importer/TestNavigationImporter.java
Log:
GTNPORTAL-2000: Navigation Importer doesn't update extended labels during import.
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/description/DescriptionServiceImpl.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/description/DescriptionServiceImpl.java 2011-08-12
14:07:17 UTC (rev 7060)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/description/DescriptionServiceImpl.java 2011-08-12
19:48:51 UTC (rev 7061)
@@ -187,10 +187,15 @@
{
cache.removeState(new CacheKey(locale, id));
}
- for (Map.Entry<Locale, Described.State> entry : descriptions.entrySet())
+
+ // Interface specifies it allows a null description map
+ if (descriptions != null)
{
- Described described = able.addI18NMixin(Described.class, entry.getKey());
- described.setState(entry.getValue());
+ for (Map.Entry<Locale, Described.State> entry : descriptions.entrySet())
+ {
+ Described described = able.addI18NMixin(Described.class, entry.getKey());
+ described.setState(entry.getValue());
+ }
}
}
}
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/importer/NavigationFragmentImporter.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/importer/NavigationFragmentImporter.java 2011-08-12
14:07:17 UTC (rev 7060)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/mop/importer/NavigationFragmentImporter.java 2011-08-12
19:48:51 UTC (rev 7061)
@@ -257,7 +257,7 @@
//
if (config.updatedSame)
{
- dstChild.setState(srcChild.getState());
+ update(srcChild, dstChild, labelMap);
}
//
@@ -280,7 +280,7 @@
{
if (config.updatedSame)
{
- dstChild.setState(srcChild.getState());
+ update(srcChild, dstChild, labelMap);
}
previousChild = dstChild;
}
@@ -362,4 +362,39 @@
//
return child;
}
+
+ private void update(PageNode src, NodeContext<?> target,
+ Map<NodeContext<?>, Map<Locale,
Described.State>> labelMap)
+ {
+ target.setState(src.getState());
+
+ // Update extended labels if necessary
+ I18NString labels = src.getLabels();
+ Map<Locale, Described.State> description;
+ if (labels.isSimple())
+ {
+ description = null;
+ }
+ else if (labels.isEmpty())
+ {
+ description = null;
+ }
+ else
+ {
+ description = new HashMap<Locale, Described.State>();
+ for (Map.Entry<Locale, String> entry :
labels.getExtended(portalLocale).entrySet())
+ {
+ description.put(entry.getKey(), new Described.State(entry.getValue(),
null));
+ }
+ }
+
+ if (description != null)
+ {
+ labelMap.put(target, description);
+ }
+ else
+ {
+ labelMap.put(target, Collections.<Locale, Described.State>emptyMap());
+ }
+ }
}
Modified:
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/mop/importer/TestNavigationImporter.java
===================================================================
---
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/mop/importer/TestNavigationImporter.java 2011-08-12
14:07:17 UTC (rev 7060)
+++
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/mop/importer/TestNavigationImporter.java 2011-08-12
19:48:51 UTC (rev 7061)
@@ -338,6 +338,84 @@
Map<Locale, Described.State> cDesc =
descriptionService.getDescriptions(c.getId());
assertNull(cDesc);
assertEquals("c_en", c.getState().getLabel());
+
+ //----------------- Now test extended labels merge -----------------//
+ src = new PageNavigation("portal",
"extended_label").addFragment(fragment().add(node("a"),
node("b"), node("c")).build());
+ fragment = src.getFragment();
+ fragment.getNode("a").setLabels(new I18NString(new
LocalizedString("a_it", Locale.ITALIAN), new LocalizedString("a_de",
Locale.GERMAN)));
+ fragment.getNode("b").setLabels(new I18NString(new
LocalizedString("foo_b_en"), new LocalizedString("b_it",
Locale.ITALIAN)));
+ fragment.getNode("c").setLabels(new I18NString(new
LocalizedString("foo_c_en")));
+ src.setOwnerId("extended_label");
+
+ importer = new NavigationImporter(Locale.ENGLISH, ImportMode.MERGE, src, service,
descriptionService);
+ importer.perform();
+
+ //
+ ctx = service.loadNavigation(SiteKey.portal("extended_label"));
+ node = service.loadNode(NodeModel.SELF_MODEL, ctx, Scope.ALL, null).getNode();
+
+ // The fully explicit case
+ a = (NodeContext<?>)node.getNode("a");
+ aDesc = descriptionService.getDescriptions(a.getId());
+ assertNotNull(aDesc);
+ assertEquals(Tools.toSet(Locale.ITALIAN, Locale.GERMAN), aDesc.keySet());
+ assertEquals(new Described.State("a_it", null),
aDesc.get(Locale.ITALIAN));
+ assertEquals(new Described.State("a_de", null),
aDesc.get(Locale.GERMAN));
+ assertNull(a.getState().getLabel());
+
+ // No explicit language means to use the portal locale
+ b = (NodeContext<?>)node.getNode("b");
+ bDesc = descriptionService.getDescriptions(b.getId());
+ assertNotNull(bDesc);
+ assertEquals(Tools.toSet(Locale.ENGLISH, Locale.ITALIAN), bDesc.keySet());
+ assertEquals(new Described.State("foo_b_en", null),
bDesc.get(Locale.ENGLISH));
+ assertEquals(new Described.State("b_it", null),
bDesc.get(Locale.ITALIAN));
+ assertNull(b.getState().getLabel());
+
+ // The simple use case : one single label without the xml:lang attribute
+ c = (NodeContext<?>)node.getNode("c");
+ cDesc = descriptionService.getDescriptions(c.getId());
+ assertNull(cDesc);
+ assertEquals("foo_c_en", c.getState().getLabel());
+
+ //----------------- Now test extended labels overwrite -----------------//
+ src = new PageNavigation("portal",
"extended_label").addFragment(fragment().add(node("a"),
node("b"), node("c")).build());
+ fragment = src.getFragment();
+ fragment.getNode("a").setLabels(new I18NString(new
LocalizedString("bar_a_en", Locale.ENGLISH), new
LocalizedString("bar_a_fr", Locale.FRENCH)));
+ fragment.getNode("b").setLabels(new I18NString(new
LocalizedString("bar_b_en"), new LocalizedString("bar_b_fr",
Locale.FRENCH)));
+ fragment.getNode("c").setLabels(new I18NString(new
LocalizedString("bar_c_en")));
+ src.setOwnerId("extended_label");
+
+ importer = new NavigationImporter(Locale.ENGLISH, ImportMode.OVERWRITE, src,
service, descriptionService);
+ importer.perform();
+
+ //
+ ctx = service.loadNavigation(SiteKey.portal("extended_label"));
+ node = service.loadNode(NodeModel.SELF_MODEL, ctx, Scope.ALL, null).getNode();
+
+ // The fully explicit case
+ a = (NodeContext<?>)node.getNode("a");
+ aDesc = descriptionService.getDescriptions(a.getId());
+ assertNotNull(aDesc);
+ assertEquals(Tools.toSet(Locale.ENGLISH, Locale.FRENCH), aDesc.keySet());
+ assertEquals(new Described.State("bar_a_en", null),
aDesc.get(Locale.ENGLISH));
+ assertEquals(new Described.State("bar_a_fr", null),
aDesc.get(Locale.FRENCH));
+ assertNull(a.getState().getLabel());
+
+ // No explicit language means to use the portal locale
+ b = (NodeContext<?>)node.getNode("b");
+ bDesc = descriptionService.getDescriptions(b.getId());
+ assertNotNull(bDesc);
+ assertEquals(Tools.toSet(Locale.ENGLISH, Locale.FRENCH), bDesc.keySet());
+ assertEquals(new Described.State("bar_b_en", null),
bDesc.get(Locale.ENGLISH));
+ assertEquals(new Described.State("bar_b_fr", null),
bDesc.get(Locale.FRENCH));
+ assertNull(b.getState().getLabel());
+
+ // The simple use case : one single label without the xml:lang attribute
+ c = (NodeContext<?>)node.getNode("c");
+ cDesc = descriptionService.getDescriptions(c.getId());
+ assertNull(cDesc);
+ assertEquals("bar_c_en", c.getState().getLabel());
}
public void testFullNavigation()