Author: julien_viet
Date: 2009-09-13 08:21:54 -0400 (Sun, 13 Sep 2009)
New Revision: 181
Modified:
components/mop/trunk/api/src/main/java/org/gatein/mop/api/content/Customization.java
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/ModelImpl.java
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/content/AbstractCustomization.java
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/content/WorkspaceClone.java
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/content/WorkspaceSpecialization.java
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/content/portlet/PortletPreferencesState.java
components/mop/trunk/core/src/main/java/org/gatein/mop/core/content/portlet/Preference.java
components/mop/trunk/core/src/main/java/org/gatein/mop/core/content/portlet/Preferences.java
components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/content/CustomizationTestCase.java
components/mop/trunk/core/src/test/java/org/gatein/mop/core/impl/portlet/PortletContentProvider.java
Log:
start to support virtual customization state
Modified:
components/mop/trunk/api/src/main/java/org/gatein/mop/api/content/Customization.java
===================================================================
---
components/mop/trunk/api/src/main/java/org/gatein/mop/api/content/Customization.java 2009-09-11
22:06:22 UTC (rev 180)
+++
components/mop/trunk/api/src/main/java/org/gatein/mop/api/content/Customization.java 2009-09-13
12:21:54 UTC (rev 181)
@@ -88,6 +88,13 @@
Customization<S> customize(CustomizationMode mode,
Collection<CustomizationContext> contexts);
/**
+ * Returns the customization cascaded state.
+ *
+ * @return the cascaded state
+ */
+ S getVirtualState();
+
+ /**
* Returns the customization state.
*
* @return the state
Modified: components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/ModelImpl.java
===================================================================
---
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/ModelImpl.java 2009-09-11
22:06:22 UTC (rev 180)
+++
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/ModelImpl.java 2009-09-13
12:21:54 UTC (rev 181)
@@ -24,7 +24,7 @@
import org.gatein.mop.core.api.workspace.WorkspaceImpl;
import org.gatein.mop.api.workspace.WorkspaceCustomizationContext;
import org.gatein.mop.core.api.workspace.content.ContextSpecialization;
-import org.gatein.mop.core.api.workspace.content.WorkspaceClone;
+import org.gatein.mop.core.api.workspace.content.AbstractCustomization;
import org.gatein.mop.api.content.CustomizationContext;
import org.gatein.mop.api.workspace.Workspace;
import org.gatein.mop.api.workspace.ObjectType;
@@ -125,10 +125,11 @@
}
private void inject(Object o, boolean persistent) {
+ if (o instanceof AbstractCustomization && persistent) {
+ ((AbstractCustomization)o).registry = contentManagers;
+ }
if (o instanceof ContextSpecialization) {
-
((ContextSpecialization)o).setCustomizationContextResolver(customizationContextResolver);
- } else if (o instanceof WorkspaceClone && persistent) {
- ((WorkspaceClone)o).registry = contentManagers;
+
((ContextSpecialization)o).setCustomizationContextResolver(customizationContextResolver);
}
}
}
Modified:
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/content/AbstractCustomization.java
===================================================================
---
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/content/AbstractCustomization.java 2009-09-11
22:06:22 UTC (rev 180)
+++
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/content/AbstractCustomization.java 2009-09-13
12:21:54 UTC (rev 181)
@@ -20,10 +20,13 @@
import org.gatein.mop.api.content.Customization;
import org.gatein.mop.api.content.CustomizationContext;
+import org.gatein.mop.api.content.ContentType;
import org.gatein.mop.api.content.customization.CustomizationMode;
import org.gatein.mop.api.workspace.WorkspaceCustomizationContext;
import org.gatein.mop.core.api.content.CustomizationContextComparator;
+import org.gatein.mop.core.api.content.ContentManagerRegistry;
import org.gatein.mop.core.api.workspace.content.portlet.PortletPreferencesState;
+import org.gatein.mop.spi.content.ContentProvider;
import org.chromattic.api.annotations.OneToOne;
import org.chromattic.api.annotations.MappedBy;
import org.chromattic.api.annotations.Create;
@@ -34,6 +37,7 @@
import java.util.TreeSet;
import java.util.Map;
import java.util.LinkedHashSet;
+import java.util.Arrays;
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
@@ -53,6 +57,9 @@
comparator = _comparator;
}
+ /** . */
+ public ContentManagerRegistry registry;
+
@OneToOne
@MappedBy("state")
public abstract CustomizationState getContentState();
@@ -76,21 +83,42 @@
public abstract AbstractCustomization getParentCustomization();
+ public Object getVirtualState() {
+ Object childPayload = null;
+ CustomizationState state = getContentState();
+ if (state != null) {
+ childPayload = state.getPayload();
+ }
+ //
+ Object parentPayload = null;
+ AbstractCustomization parent = getParentCustomization();
+ if (parent != null) {
+ parentPayload = parent.getVirtualState();
+ }
+
+ //
+ if (parentPayload != null) {
+ if (childPayload != null) {
+ ContentType contentType = getType();
+ String mimeType = contentType.getMimeType();
+ ContentProvider contentProvider =
registry.providers.get(mimeType).getProvider();
+ return contentProvider.combine(Arrays.asList(parentPayload, childPayload));
+ } else {
+ return parentPayload;
+ }
+ } else {
+ return childPayload;
+ }
+ }
+
public Object getState() {
-
CustomizationState state = getContentState();
if (state != null) {
- return getContentState().getPayload();
+ return state.getPayload();
} else {
- AbstractCustomization parent = getParentCustomization();
- if (parent != null) {
- return parent.getState();
- } else {
- return null;
- }
+ return null;
}
-
}
public void setState(Object state) {
Modified:
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/content/WorkspaceClone.java
===================================================================
---
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/content/WorkspaceClone.java 2009-09-11
22:06:22 UTC (rev 180)
+++
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/content/WorkspaceClone.java 2009-09-13
12:21:54 UTC (rev 181)
@@ -27,7 +27,6 @@
import org.gatein.mop.api.content.CustomizationContext;
import org.gatein.mop.api.content.ContentType;
import org.gatein.mop.api.workspace.WorkspaceCustomizationContext;
-import org.gatein.mop.core.api.content.ContentManagerRegistry;
import org.gatein.mop.core.api.content.ContentRegistration;
import java.util.Set;
@@ -42,8 +41,6 @@
@NodeMapping(name = "mop:workspaceclone")
public abstract class WorkspaceClone extends WorkspaceCustomization {
- public ContentManagerRegistry registry;
-
public Set<CustomizationContext> getContexts() {
return Collections.emptySet();
}
@@ -87,10 +84,8 @@
//
for (WorkspaceSpecialization specialization : specializations) {
- // Compute flat state
- Object state = specialization.getState();
-
- // Update with flat state
+ // Update the specialization with its virtual state
+ Object state = specialization.getVirtualState();
specialization.setState(state);
// Clear ref
Modified:
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/content/WorkspaceSpecialization.java
===================================================================
---
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/content/WorkspaceSpecialization.java 2009-09-11
22:06:22 UTC (rev 180)
+++
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/content/WorkspaceSpecialization.java 2009-09-13
12:21:54 UTC (rev 181)
@@ -37,6 +37,10 @@
public abstract void setCustomization(WorkspaceCustomization customization);
+ public void destroy() {
+ doDestroy();
+ }
+
public String getName() {
AbstractCustomization parent = getParentCustomization();
if (parent == null) {
Modified:
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/content/portlet/PortletPreferencesState.java
===================================================================
---
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/content/portlet/PortletPreferencesState.java 2009-09-11
22:06:22 UTC (rev 180)
+++
components/mop/trunk/core/src/main/java/org/gatein/mop/core/api/workspace/content/portlet/PortletPreferencesState.java 2009-09-13
12:21:54 UTC (rev 181)
@@ -52,7 +52,7 @@
Map<String, PortletPreferenceState> entries = getChildren();
entries.clear();
- for (Preference pref : payload.getEntries()) {
+ for (Preference pref : payload) {
PortletPreferenceState prefState = create();
entries.put(pref.getName(), prefState);
prefState.setValue(pref.getValues());
Modified:
components/mop/trunk/core/src/main/java/org/gatein/mop/core/content/portlet/Preference.java
===================================================================
---
components/mop/trunk/core/src/main/java/org/gatein/mop/core/content/portlet/Preference.java 2009-09-11
22:06:22 UTC (rev 180)
+++
components/mop/trunk/core/src/main/java/org/gatein/mop/core/content/portlet/Preference.java 2009-09-13
12:21:54 UTC (rev 181)
@@ -23,6 +23,8 @@
import java.util.ArrayList;
/**
+ * An immutable preference.
+ *
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
@@ -80,6 +82,10 @@
return name;
}
+ public String getValue() {
+ return values.get(0);
+ }
+
public List<String> getValues() {
return values;
}
Modified:
components/mop/trunk/core/src/main/java/org/gatein/mop/core/content/portlet/Preferences.java
===================================================================
---
components/mop/trunk/core/src/main/java/org/gatein/mop/core/content/portlet/Preferences.java 2009-09-11
22:06:22 UTC (rev 180)
+++
components/mop/trunk/core/src/main/java/org/gatein/mop/core/content/portlet/Preferences.java 2009-09-13
12:21:54 UTC (rev 181)
@@ -20,10 +20,11 @@
import org.gatein.mop.api.content.ContentType;
-import java.util.Collection;
import java.util.Map;
import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
+import java.util.Iterator;
/**
* A set of preferences.
@@ -31,7 +32,7 @@
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-public final class Preferences {
+public final class Preferences implements Iterable<Preference> {
/** . */
public static final ContentType<Preferences> CONTENT_TYPE = new
ContentType<Preferences>("application/portlet", Preferences.class);
@@ -57,10 +58,66 @@
this.entries = Collections.unmodifiableMap(this.state);
}
- public Collection<Preference> getEntries() {
- return entries.values();
+ public List<String> getValues(String name) {
+ Preference entry = entries.get(name);
+ return entry != null ? entry.getValues() : null;
}
+ public Preferences setValues(String name, List<String> values) {
+ Preference entry = entries.get(name);
+ if (entry == null) {
+ entry = new Preference(name, values, false);
+ } else {
+ entry = new Preference(entry.getName(), values, entry.isReadOnly());
+ }
+ entries.put(name, entry);
+ return this;
+ }
+
+ public String getValue(String name) {
+ Preference entry = entries.get(name);
+ return entry != null ? entry.getValue() : null;
+ }
+
+ public Preferences setValue(String name, String value) {
+ Preference entry = entries.get(name);
+ if (entry == null) {
+ entry = new Preference(name, value, false);
+ } else {
+ entry = new Preference(entry.getName(), value, entry.isReadOnly());
+ }
+ entries.put(name, entry);
+ return this;
+ }
+
+ public Boolean isReadOnly(String name) {
+ Preference entry = entries.get(name);
+ return entry != null ? entry.isReadOnly() : null;
+ }
+
+ public Preferences setReadOnly(String name, boolean readOnly) {
+ Preference entry = entries.get(name);
+ if (entry == null) {
+ throw new IllegalStateException();
+ }
+ entry = new Preference(entry.getName(), entry.getValues(), readOnly);
+ entries.put(name, entry);
+ return this;
+ }
+
+ public Preference getPreference(String name) {
+ return entries.get(name);
+ }
+
+ public Preferences putPreference(Preference preference) {
+ entries.put(preference.getName(), preference);
+ return this;
+ }
+
+ public Iterator<Preference> iterator() {
+ return entries.values().iterator();
+ }
+
@Override
public boolean equals(Object obj) {
if (obj == this) {
Modified:
components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/content/CustomizationTestCase.java
===================================================================
---
components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/content/CustomizationTestCase.java 2009-09-11
22:06:22 UTC (rev 180)
+++
components/mop/trunk/core/src/test/java/org/gatein/mop/core/api/workspace/content/CustomizationTestCase.java 2009-09-13
12:21:54 UTC (rev 181)
@@ -39,21 +39,34 @@
public class CustomizationTestCase extends AbstractPOMTestCase {
/** . */
- private final Preferences prefs1 = new PreferencesBuilder().add("foo",
"foo1").add("bar", "bar1", true).build();
+ private final Preferences marseille = new PreferencesBuilder().add("city",
"marseille").add("temperature", "celsius").build();
/** . */
- private final Preferences prefs2 = new PreferencesBuilder().add("foo",
"foo2").add("bar", "bar2", true).build();
+ private final Preferences paris = new PreferencesBuilder().add("city",
"paris").build();
/** . */
- private final Preferences prefs3 = new PreferencesBuilder().add("foo",
"foo3").add("bar", "bar3").build();
+ private final Preferences parisCelsius = new PreferencesBuilder().add("city",
"paris").add("temperature", "celsius").build();
- public void testCustmizeWorkspace() {
+ /** . */
+ private final Preferences parisFarenheit = new
PreferencesBuilder().add("city", "paris").add("temperature",
"farenheit").build();
+
+ public void testCustomizationBlending() {
Workspace workspace = pomService.getModel().getWorkspace();
+ Customization<Preferences> customization1 =
workspace.customize("marseille", Preferences.CONTENT_TYPE,
"WeatherPortlet", marseille);
+ Customization<Preferences> customization2 =
workspace.customize("paris", customization1);
+ customization2.setState(paris);
+ assertEquals(paris, customization2.getState());
+ assertEquals(parisCelsius, customization2.getVirtualState());
+//
customization1.setState(customization1.getState().setReadOnly("temperature",
true));
+ }
+
+ public void testCustomizeWorkspace() {
+ Workspace workspace = pomService.getModel().getWorkspace();
assertNull(workspace.getCustomization("marseille"));
- Customization<Preferences> customization =
workspace.customize("marseille", Preferences.CONTENT_TYPE,
"WeatherPortlet", prefs1);
+ Customization<Preferences> customization =
workspace.customize("marseille", Preferences.CONTENT_TYPE,
"WeatherPortlet", marseille);
assertNotNull(customization);
Preferences b = customization.getState();
- assertEquals(prefs1, b);
+ assertEquals(marseille, b);
assertEquals(0, customization.getContexts().size());
assertEquals("WeatherPortlet", customization.getContentId());
assertEquals(Preferences.CONTENT_TYPE, customization.getType());
@@ -65,10 +78,12 @@
Site portal = workspace.addSite(ObjectType.PORTAL_SITE, "portal");
UIContainer layout = portal.getRootPage().getRootComponent();
UIWindow window = layout.add(ObjectType.WINDOW, "window");
- Customization<Preferences> customization =
window.customize(Preferences.CONTENT_TYPE, "WeatherPortlet", prefs1);
+
+ //
+ Customization<Preferences> customization =
window.customize(Preferences.CONTENT_TYPE, "WeatherPortlet", marseille);
assertSame(customization, window.getCustomization());
assertEquals(null, customization.getName());
- assertEquals(prefs1, customization.getState());
+ assertEquals(marseille, customization.getState());
}
public void testCustomizeWindowByCloneWithNoState() {
@@ -76,6 +91,8 @@
Site portal = workspace.addSite(ObjectType.PORTAL_SITE, "portal");
UIContainer layout = portal.getRootPage().getRootComponent();
UIWindow window = layout.add(ObjectType.WINDOW, "window");
+
+ //
Customization<Preferences> customization =
window.customize(Preferences.CONTENT_TYPE, "WeatherPortlet", null);
assertSame(customization, window.getCustomization());
assertEquals(null, customization.getName());
@@ -85,59 +102,69 @@
public void testCustomizeWindowBySpecialization() {
Workspace workspace = pomService.getModel().getWorkspace();
Site portal = workspace.addSite(ObjectType.PORTAL_SITE, "portal");
- Customization<Preferences> workspaceCustomization =
portal.customize("marseille", Preferences.CONTENT_TYPE,
"WeatherPortlet", prefs1);
UIContainer layout = portal.getRootPage().getRootComponent();
UIWindow window = layout.add(ObjectType.WINDOW, "window");
+
+ //
+ Customization<Preferences> workspaceCustomization =
portal.customize("marseille", Preferences.CONTENT_TYPE,
"WeatherPortlet", marseille);
Customization<Preferences> windowCustomization =
window.customize(workspaceCustomization);
//
assertNotNull(windowCustomization);
- assertEquals(Arrays.asList(window, portal), new
ArrayList<CustomizationContext>(windowCustomization.getContexts()));
+ assertEquals(Arrays.<CustomizationContext>asList(window, portal), new
ArrayList<CustomizationContext>(windowCustomization.getContexts()));
assertSame(windowCustomization, window.getCustomization());
assertTrue(((Customization)windowCustomization) instanceof WorkspaceSpecialization);
assertEquals("marseille", windowCustomization.getName());
//
- assertPreferences(prefs1, windowCustomization.getState());
- assertPreferences(prefs1, workspaceCustomization.getState());
+ assertPreferences(null, windowCustomization.getState());
+ assertPreferences(marseille, windowCustomization.getVirtualState());
+ assertPreferences(marseille, workspaceCustomization.getState());
//
- workspaceCustomization.setState(prefs2);
- assertPreferences(prefs2, windowCustomization.getState());
- assertPreferences(prefs2, workspaceCustomization.getState());
+ workspaceCustomization.setState(paris);
+ assertPreferences(paris, windowCustomization.getVirtualState());
+ assertPreferences(null, windowCustomization.getState());
+ assertPreferences(paris, workspaceCustomization.getState());
//
- windowCustomization.setState(prefs3);
- assertPreferences(prefs3, windowCustomization.getState());
- assertPreferences(prefs2, workspaceCustomization.getState());
+ windowCustomization.setState(parisFarenheit);
+ assertPreferences(parisFarenheit, windowCustomization.getVirtualState());
+ assertPreferences(parisFarenheit, windowCustomization.getState());
+ assertPreferences(paris, workspaceCustomization.getState());
}
public void testDestroySpecializedCustomization() {
Workspace workspace = pomService.getModel().getWorkspace();
Site portal = workspace.addSite(ObjectType.PORTAL_SITE, "portal");
- Customization<Preferences> workspaceCustomization =
portal.customize("marseille", Preferences.CONTENT_TYPE,
"WeatherPortlet", prefs1);
UIContainer layout = portal.getRootPage().getRootComponent();
UIWindow window = layout.add(ObjectType.WINDOW, "window");
+
+ //
+ Customization<Preferences> workspaceCustomization =
portal.customize("marseille", Preferences.CONTENT_TYPE,
"WeatherPortlet", marseille);
Customization<Preferences> windowCustomization =
window.customize(workspaceCustomization);
//
workspaceCustomization.destroy();
- assertEquals(prefs1, windowCustomization.getState());
+
+ //
+ assertEquals(marseille, windowCustomization.getVirtualState());
+ assertEquals(marseille, windowCustomization.getState());
}
-/*
- public void testDeleteSpecializedCustomization() {
+ public void testDestroySpecialization() {
Workspace workspace = pomService.getModel().getWorkspace();
Site portal = workspace.addSite(ObjectType.PORTAL_SITE, "portal");
- Customization<Preferences> workspaceCustomization =
portal.customize("marseille", Preferences.CONTENT_TYPE,
"WeatherPortlet", prefs1);
- UIContainer layout = portal.getRootPage().getLayout();
- UIWindow window = layout.addComponent(ObjectType.WINDOW, "window");
+ UIContainer layout = portal.getRootPage().getRootComponent();
+ UIWindow window = layout.add(ObjectType.WINDOW, "window");
+
+ //
+ Customization<Preferences> workspaceCustomization =
portal.customize("marseille", Preferences.CONTENT_TYPE,
"WeatherPortlet", marseille);
Customization<Preferences> windowCustomization =
window.customize(workspaceCustomization);
//
- workspaceCustomization.destroy();
+ windowCustomization.destroy();
}
-*/
private void assertPreferences(Preferences expectedPrefs, Preferences prefs) {
assertEquals("Was expecting to have prefs " + prefs + " equals to
" + expectedPrefs, expectedPrefs, prefs);
Modified:
components/mop/trunk/core/src/test/java/org/gatein/mop/core/impl/portlet/PortletContentProvider.java
===================================================================
---
components/mop/trunk/core/src/test/java/org/gatein/mop/core/impl/portlet/PortletContentProvider.java 2009-09-11
22:06:22 UTC (rev 180)
+++
components/mop/trunk/core/src/test/java/org/gatein/mop/core/impl/portlet/PortletContentProvider.java 2009-09-13
12:21:54 UTC (rev 181)
@@ -58,10 +58,10 @@
//
for (Preferences preferences : states) {
- for (Preference entry : preferences.getEntries()) {
- Preference previous = entries.get(entry.getName());
+ for (Preference preference : preferences) {
+ Preference previous = entries.get(preference.getName());
if (previous == null || !previous.isReadOnly()) {
- entries.put(entry.getName(), entry);
+ entries.put(preference.getName(), preference);
}
}
}