Author: hoang_to
Date: 2010-08-26 12:50:46 -0400 (Thu, 26 Aug 2010)
New Revision: 3943
Added:
portal/branches/branched-r3845/component/portal/src/test/java/conf/test-mop-nodetypes.xml
portal/branches/branched-r3845/component/portal/src/test/java/org/exoplatform/portal/config/SampleMixin.java
portal/branches/branched-r3845/component/portal/src/test/java/org/exoplatform/portal/config/TestHandleMixin.java
Modified:
portal/branches/branched-r3845/component/portal/src/main/java/org/exoplatform/portal/config/DataStorage.java
portal/branches/branched-r3845/component/portal/src/main/java/org/exoplatform/portal/config/DataStorageImpl.java
portal/branches/branched-r3845/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMDataStorage.java
portal/branches/branched-r3845/component/portal/src/main/java/org/exoplatform/portal/pom/data/ModelDataStorage.java
portal/branches/branched-r3845/component/portal/src/test/java/conf/exo.portal.component.portal-configuration1.xml
Log:
GTNPORTAL-1419: Public API to access/modify MOP Mixins
Modified:
portal/branches/branched-r3845/component/portal/src/main/java/org/exoplatform/portal/config/DataStorage.java
===================================================================
---
portal/branches/branched-r3845/component/portal/src/main/java/org/exoplatform/portal/config/DataStorage.java 2010-08-26
11:20:30 UTC (rev 3942)
+++
portal/branches/branched-r3845/component/portal/src/main/java/org/exoplatform/portal/config/DataStorage.java 2010-08-26
16:50:46 UTC (rev 3943)
@@ -26,6 +26,7 @@
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.pom.data.ModelChange;
import org.exoplatform.portal.config.model.Page;
import org.exoplatform.portal.config.model.PageNavigation;
@@ -270,4 +271,13 @@
* @throws Exception any exception
*/
public List<String> getAllPortalNames() throws Exception;
+
+ /*************************************************************
+ Public API to access/modify MOP mixin, temporarily put here
+ **************************************************************/
+
+ public <A> A adapt(ModelObject modelObject, Class<A> type);
+
+ public <A> A adapt(ModelObject modelObject, Class<A> type, boolean
create);
+
}
\ No newline at end of file
Modified:
portal/branches/branched-r3845/component/portal/src/main/java/org/exoplatform/portal/config/DataStorageImpl.java
===================================================================
---
portal/branches/branched-r3845/component/portal/src/main/java/org/exoplatform/portal/config/DataStorageImpl.java 2010-08-26
11:20:30 UTC (rev 3942)
+++
portal/branches/branched-r3845/component/portal/src/main/java/org/exoplatform/portal/config/DataStorageImpl.java 2010-08-26
16:50:46 UTC (rev 3943)
@@ -18,6 +18,13 @@
*/
package org.exoplatform.portal.config;
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.LinkedList;
+import java.util.List;
+
import org.exoplatform.commons.utils.LazyPageList;
import org.exoplatform.commons.utils.ListAccess;
import org.exoplatform.portal.application.PortletPreferences;
@@ -41,9 +48,6 @@
import org.exoplatform.portal.pom.data.PortalKey;
import org.exoplatform.services.listener.ListenerService;
-import java.lang.reflect.Array;
-import java.util.*;
-
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
@@ -340,4 +344,16 @@
{
delegate.saveDashboard(dashboard.build());
}
+
+ @Override
+ public <A> A adapt(ModelObject modelObject, Class<A> type)
+ {
+ return delegate.adapt(modelObject.build(), type);
+ }
+
+ @Override
+ public <A> A adapt(ModelObject modelObject, Class<A> type, boolean
create)
+ {
+ return delegate.adapt(modelObject.build(), type, create);
+ }
}
Modified:
portal/branches/branched-r3845/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMDataStorage.java
===================================================================
---
portal/branches/branched-r3845/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMDataStorage.java 2010-08-26
11:20:30 UTC (rev 3942)
+++
portal/branches/branched-r3845/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMDataStorage.java 2010-08-26
16:50:46 UTC (rev 3943)
@@ -19,6 +19,12 @@
package org.exoplatform.portal.pom.config;
+import java.io.ByteArrayInputStream;
+import java.util.Comparator;
+import java.util.List;
+import java.util.UUID;
+
+import org.chromattic.api.ChromatticSession;
import org.exoplatform.commons.utils.IOUtil;
import org.exoplatform.commons.utils.LazyPageList;
import org.exoplatform.container.configuration.ConfigurationManager;
@@ -41,6 +47,7 @@
import org.exoplatform.portal.pom.config.tasks.SearchTask;
import org.exoplatform.portal.pom.data.DashboardData;
import org.exoplatform.portal.pom.data.ModelChange;
+import org.exoplatform.portal.pom.data.ModelData;
import org.exoplatform.portal.pom.data.ModelDataStorage;
import org.exoplatform.portal.pom.data.NavigationData;
import org.exoplatform.portal.pom.data.NavigationKey;
@@ -50,14 +57,8 @@
import org.exoplatform.portal.pom.data.PortalKey;
import org.jibx.runtime.BindingDirectory;
import org.jibx.runtime.IBindingFactory;
-import org.jibx.runtime.IUnmarshallingContext;
import org.jibx.runtime.impl.UnmarshallingContext;
-import java.io.ByteArrayInputStream;
-import java.util.Comparator;
-import java.util.List;
-import java.util.UUID;
-
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
@@ -313,4 +314,38 @@
}
});
}
+
+ @Override
+ public <A> A adapt(ModelData modelData, Class<A> type)
+ {
+ return adapt(modelData, type, true);
+ }
+
+ @Override
+ public <A> A adapt(ModelData modelData, Class<A> type, boolean create)
+ {
+ try
+ {
+ POMSession pomSession = pomMgr.getSession();
+ ChromatticSession chromSession = pomSession.getSession();
+
+ //TODO: Deal with the case where modelData is not persisted before invocation to
adapt
+ // Get the workspace object
+ Object o = pomSession.findObjectById(modelData.getStorageId());
+
+ A a = chromSession.getEmbedded(o, type);
+ if(a == null && create)
+ {
+ a = chromSession.create(type);
+ chromSession.setEmbedded(o, type, a);
+ }
+
+ return a;
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ return null;
+ }
+ }
}
Modified:
portal/branches/branched-r3845/component/portal/src/main/java/org/exoplatform/portal/pom/data/ModelDataStorage.java
===================================================================
---
portal/branches/branched-r3845/component/portal/src/main/java/org/exoplatform/portal/pom/data/ModelDataStorage.java 2010-08-26
11:20:30 UTC (rev 3942)
+++
portal/branches/branched-r3845/component/portal/src/main/java/org/exoplatform/portal/pom/data/ModelDataStorage.java 2010-08-26
16:50:46 UTC (rev 3943)
@@ -109,4 +109,14 @@
public void saveDashboard(DashboardData dashboard) throws Exception;
public void save() throws Exception;
+
+ /****************************************************************
+ * Proxy methods of public API to access/modify MOP mixins,
+ *
+ * temporarily put here
+ ***************************************************************/
+ public <A> A adapt(ModelData modelData, Class<A> type);
+
+ public <A> A adapt(ModelData modelData, Class<A> type, boolean create);
+
}
\ No newline at end of file
Modified:
portal/branches/branched-r3845/component/portal/src/test/java/conf/exo.portal.component.portal-configuration1.xml
===================================================================
---
portal/branches/branched-r3845/component/portal/src/test/java/conf/exo.portal.component.portal-configuration1.xml 2010-08-26
11:20:30 UTC (rev 3942)
+++
portal/branches/branched-r3845/component/portal/src/test/java/conf/exo.portal.component.portal-configuration1.xml 2010-08-26
16:50:46 UTC (rev 3943)
@@ -130,6 +130,7 @@
<value>jar:/conf/gatein-nodetypes.xml</value>
<value>jar:/conf/mop-nodetypes.xml</value>
<value>jar:/conf/content-nodetypes.xml</value>
+ <value>jar:/conf/test-mop-nodetypes.xml</value>
</values-param>
</init-params>
</component-plugin>
@@ -189,6 +190,7 @@
<value>org.exoplatform.portal.mop.ProtectedResource</value>
<value>org.exoplatform.portal.mop.Described</value>
<value>org.exoplatform.portal.mop.Visible</value>
+ <value>org.exoplatform.portal.config.SampleMixin</value>
</values-param>
</init-params>
</component-plugin>
Added:
portal/branches/branched-r3845/component/portal/src/test/java/conf/test-mop-nodetypes.xml
===================================================================
---
portal/branches/branched-r3845/component/portal/src/test/java/conf/test-mop-nodetypes.xml
(rev 0)
+++
portal/branches/branched-r3845/component/portal/src/test/java/conf/test-mop-nodetypes.xml 2010-08-26
16:50:46 UTC (rev 3943)
@@ -0,0 +1,29 @@
+<!--
+ ~ Copyright (C) 2009 eXo Platform SAS.
+ ~
+ ~ 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.
+ -->
+<nodeTypes
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
xmlns:mix="http://www.jcp.org/jcr/mix/1.0"
xmlns:jcr="http://www.jcp.org/jcr/1.0">
+
+ <nodeType name="gtn:sampleMixin" isMixin="true"
hasOrderableChildNodes="false" primaryItemName="">
+ <propertyDefinitions>
+ <propertyDefinition name="gtn:sampleProperty"
requiredType="String" autoCreated="false" mandatory="false"
onParentVersion="COPY" protected="false"
multiple="true">
+ <valueConstraints/>
+ </propertyDefinition>
+ </propertyDefinitions>
+ </nodeType>
+
+</nodeTypes>
Added:
portal/branches/branched-r3845/component/portal/src/test/java/org/exoplatform/portal/config/SampleMixin.java
===================================================================
---
portal/branches/branched-r3845/component/portal/src/test/java/org/exoplatform/portal/config/SampleMixin.java
(rev 0)
+++
portal/branches/branched-r3845/component/portal/src/test/java/org/exoplatform/portal/config/SampleMixin.java 2010-08-26
16:50:46 UTC (rev 3943)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * 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.config;
+
+import org.chromattic.api.annotations.MixinType;
+import org.chromattic.api.annotations.Property;
+
+/**
+ * @author <a href="mailto:hoang281283@gmail.com">Minh Hoang
TO</a>
+ * Aug 26, 2010
+ */
+
+@MixinType(name = "gtn:sampleMixin")
+public abstract class SampleMixin
+{
+
+ @Property(name = "gtn:sampleProperty", defaultValue =
{"SampleProperty"})
+ public abstract String getSampleProperty();
+
+ public abstract void setSampleProperty(String sampleProperty);
+}
Added:
portal/branches/branched-r3845/component/portal/src/test/java/org/exoplatform/portal/config/TestHandleMixin.java
===================================================================
---
portal/branches/branched-r3845/component/portal/src/test/java/org/exoplatform/portal/config/TestHandleMixin.java
(rev 0)
+++
portal/branches/branched-r3845/component/portal/src/test/java/org/exoplatform/portal/config/TestHandleMixin.java 2010-08-26
16:50:46 UTC (rev 3943)
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * 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.config;
+
+import org.exoplatform.container.PortalContainer;
+import org.exoplatform.portal.config.model.Page;
+import org.exoplatform.portal.config.model.PortalConfig;
+import org.exoplatform.portal.pom.config.POMSession;
+import org.exoplatform.portal.pom.config.POMSessionManager;
+
+/**
+ * @author <a href="mailto:hoang281283@gmail.com">Minh Hoang
TO</a>
+ * Aug 25, 2010
+ */
+
+public class TestHandleMixin extends AbstractPortalTest
+{
+
+ private DataStorage dataStorage;
+
+ private POMSessionManager pomMgr;
+
+ private POMSession session;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ begin();
+
+ PortalContainer container = PortalContainer.getInstance();
+ dataStorage =
(DataStorage)container.getComponentInstanceOfType(DataStorage.class);
+ POMSessionManager pomMgr =
(POMSessionManager)container.getComponentInstanceOfType(POMSessionManager.class);
+ session = pomMgr.getSession();
+ }
+
+ private void createPage() throws Exception
+ {
+
+ Page page = new Page();
+ page.setTitle("MyTitle");
+ page.setOwnerType(PortalConfig.PORTAL_TYPE);
+ page.setOwnerId("test");
+ page.setName("foo");
+
+ dataStorage.create(page);
+ }
+
+ public void testAccessMixin() throws Exception
+ {
+ createPage();
+ Page page = dataStorage.getPage("portal::test::foo");
+
+ assertNotNull(page);
+ assertEquals("MyTitle", page.getTitle());
+ assertEquals("test", page.getOwnerId());
+ assertEquals("foo", page.getName());
+
+ SampleMixin sampleMixin = dataStorage.adapt(page, SampleMixin.class);
+ //Check the default value of sampleProperty property
+ assertEquals("SampleProperty", sampleMixin.getSampleProperty());
+ }
+
+ public void testModifyMixin() throws Exception
+ {
+ createPage();
+ Page page = dataStorage.getPage("portal::test::foo");
+
+ assertNotNull(page);
+ assertEquals("MyTitle", page.getTitle());
+ assertEquals("test", page.getOwnerId());
+ assertEquals("foo", page.getName());
+
+ SampleMixin sampleMixin = dataStorage.adapt(page, SampleMixin.class);
+ sampleMixin.setSampleProperty("FYM!");
+
+ Page page2 = dataStorage.getPage("portal::test::foo");
+ assertNotNull(page2);
+ SampleMixin sampleMixin2 = dataStorage.adapt(page2, SampleMixin.class);
+ assertEquals("FYM!", sampleMixin2.getSampleProperty());
+
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ session.close();
+ end();
+ super.tearDown();
+ }
+}