Author: chris.laprun(a)jboss.com
Date: 2011-02-02 17:51:10 -0500 (Wed, 02 Feb 2011)
New Revision: 5852
Added:
portal/branches/wsrp-extraction/component/wsrp/src/main/java/org/gatein/portal/wsrp/jcr/
portal/branches/wsrp-extraction/component/wsrp/src/main/java/org/gatein/portal/wsrp/jcr/JCRPersister.java
Removed:
portal/branches/wsrp-extraction/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/
portal/branches/wsrp-extraction/component/wsrp/src/test/java/org/gatein/portal/wsrp/state/
portal/branches/wsrp-extraction/component/wsrp/src/test/resources/
Modified:
portal/branches/wsrp-extraction/component/wsrp/pom.xml
portal/branches/wsrp-extraction/component/wsrp/src/main/java/org/gatein/portal/wsrp/WSRPServiceIntegration.java
portal/branches/wsrp-extraction/packaging/module/src/main/javascript/portal.packaging.module.js
portal/branches/wsrp-extraction/pom.xml
Log:
- GTNPORTAL-1760, GTNWSRP-196:
+ Upgraded to use WSRP 2.1.0-Alpha01-SNAPSHOT to use the moved JCR persistence
implementation.
+ JCRPersister now implements ChromatticPersister from WSRP JCR persistence module.
+ Removed JCR persistence implementation classes from component and moved JCRPersister
to new org.gatein.portal.wsrp.jcr package.
Modified: portal/branches/wsrp-extraction/component/wsrp/pom.xml
===================================================================
--- portal/branches/wsrp-extraction/component/wsrp/pom.xml 2011-02-02 22:48:53 UTC (rev
5851)
+++ portal/branches/wsrp-extraction/component/wsrp/pom.xml 2011-02-02 22:51:10 UTC (rev
5852)
@@ -47,6 +47,11 @@
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>org.gatein.wsrp</groupId>
+ <artifactId>wsrp-jcr-impl</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>org.gatein.mop</groupId>
<artifactId>mop-api</artifactId>
</dependency>
Modified:
portal/branches/wsrp-extraction/component/wsrp/src/main/java/org/gatein/portal/wsrp/WSRPServiceIntegration.java
===================================================================
---
portal/branches/wsrp-extraction/component/wsrp/src/main/java/org/gatein/portal/wsrp/WSRPServiceIntegration.java 2011-02-02
22:48:53 UTC (rev 5851)
+++
portal/branches/wsrp-extraction/component/wsrp/src/main/java/org/gatein/portal/wsrp/WSRPServiceIntegration.java 2011-02-02
22:51:10 UTC (rev 5852)
@@ -44,11 +44,7 @@
import org.gatein.pc.portlet.state.StateConverter;
import org.gatein.pc.portlet.state.producer.PortletStatePersistenceManager;
import org.gatein.pc.portlet.state.producer.ProducerPortletInvoker;
-import org.gatein.portal.wsrp.state.consumer.JCRConsumerRegistry;
-import org.gatein.portal.wsrp.state.migration.JCRMigrationService;
-import
org.gatein.portal.wsrp.state.producer.configuration.JCRProducerConfigurationService;
-import
org.gatein.portal.wsrp.state.producer.registrations.JCRRegistrationPersistenceManager;
-import org.gatein.portal.wsrp.state.producer.state.JCRPortletStatePersistenceManager;
+import org.gatein.portal.wsrp.jcr.JCRPersister;
import org.gatein.portal.wsrp.structure.MOPConsumerStructureProvider;
import org.gatein.portal.wsrp.structure.MOPPortalStructureAccess;
import org.gatein.portal.wsrp.structure.PortalStructureAccess;
@@ -63,14 +59,19 @@
import org.gatein.wci.WebAppListener;
import org.gatein.wci.impl.DefaultServletContainerFactory;
import org.gatein.wsrp.WSRPConstants;
+import org.gatein.wsrp.consumer.migration.JCRMigrationService;
import org.gatein.wsrp.consumer.migration.MigrationService;
import org.gatein.wsrp.consumer.registry.ActivatingNullInvokerHandler;
import org.gatein.wsrp.consumer.registry.ConsumerRegistry;
+import org.gatein.wsrp.consumer.registry.JCRConsumerRegistry;
import org.gatein.wsrp.payload.WSRPEventPayloadInterceptor;
import org.gatein.wsrp.producer.ProducerHolder;
-import org.gatein.wsrp.producer.WSRPPortletInvoker;
import org.gatein.wsrp.producer.WSRPProducer;
+import org.gatein.wsrp.producer.config.JCRProducerConfigurationService;
import org.gatein.wsrp.producer.config.ProducerConfigurationService;
+import org.gatein.wsrp.producer.invoker.RegistrationCheckingPortletInvoker;
+import org.gatein.wsrp.producer.state.JCRPortletStatePersistenceManager;
+import org.gatein.wsrp.registration.JCRRegistrationPersistenceManager;
import org.picocontainer.Startable;
import javax.servlet.ServletContext;
@@ -164,7 +165,10 @@
JCRProducerConfigurationService producerConfigurationService;
try
{
- producerConfigurationService = new JCRProducerConfigurationService(container);
+ JCRPersister persister = new JCRPersister(container,
JCRPersister.WSRP_WORKSPACE_NAME);
+ persister.initializeBuilderFor(JCRProducerConfigurationService.mappingClasses);
+
+ producerConfigurationService = new JCRProducerConfigurationService(persister);
producerConfigurationService.setDefaultConfigurationIS(configurationIS);
producerConfigurationService.reloadConfiguration();
}
@@ -177,7 +181,10 @@
RegistrationPersistenceManager registrationPersistenceManager;
try
{
- registrationPersistenceManager = new
JCRRegistrationPersistenceManager(container);
+ JCRPersister persister = new JCRPersister(container,
JCRPersister.WSRP_WORKSPACE_NAME);
+
persister.initializeBuilderFor(JCRRegistrationPersistenceManager.mappingClasses);
+
+ registrationPersistenceManager = new
JCRRegistrationPersistenceManager(persister);
}
catch (Exception e)
{
@@ -227,7 +234,10 @@
PortletStatePersistenceManager producerPersistenceManager;
try
{
- producerPersistenceManager = new JCRPortletStatePersistenceManager(container);
+ JCRPersister persister = new JCRPersister(container,
JCRPersister.PORTLET_STATES_WORKSPACE_NAME);
+
persister.initializeBuilderFor(JCRPortletStatePersistenceManager.mappingClasses);
+
+ producerPersistenceManager = new JCRPortletStatePersistenceManager(persister);
}
catch (Exception e)
{
@@ -248,7 +258,7 @@
producerPortletInvoker.setStateManagementPolicy(producerStateManagementPolicy);
producerPortletInvoker.setStateConverter(producerStateConverter);
- WSRPPortletInvoker wsrpPortletInvoker = new WSRPPortletInvoker();
+ RegistrationCheckingPortletInvoker wsrpPortletInvoker = new
RegistrationCheckingPortletInvoker();
wsrpPortletInvoker.setNext(producerPortletInvoker);
wsrpPortletInvoker.setRegistrationManager(registrationManager);
@@ -279,7 +289,10 @@
try
{
- consumerRegistry = new JCRConsumerRegistry(container);
+ JCRPersister persister = new JCRPersister(container,
JCRPersister.WSRP_WORKSPACE_NAME);
+ persister.initializeBuilderFor(JCRConsumerRegistry.mappingClasses);
+
+ consumerRegistry = new JCRConsumerRegistry(persister);
consumerRegistry.setFederatingPortletInvoker(federatingPortletInvoker);
consumerRegistry.setSessionEventBroadcaster(sessionEventBroadcaster);
@@ -292,7 +305,10 @@
listenerService.addListener(DataStorage.PAGE_UPDATED, structureprovider);
// migration service
- MigrationService migrationService = new JCRMigrationService(container);
+ persister = new JCRPersister(container, JCRPersister.WSRP_WORKSPACE_NAME);
+ persister.initializeBuilderFor(JCRMigrationService.mappingClasses);
+
+ MigrationService migrationService = new JCRMigrationService(persister);
migrationService.setStructureProvider(structureprovider);
consumerRegistry.setMigrationService(migrationService);
Copied:
portal/branches/wsrp-extraction/component/wsrp/src/main/java/org/gatein/portal/wsrp/jcr/JCRPersister.java
(from rev 5849,
portal/branches/wsrp-extraction/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/JCRPersister.java)
===================================================================
---
portal/branches/wsrp-extraction/component/wsrp/src/main/java/org/gatein/portal/wsrp/jcr/JCRPersister.java
(rev 0)
+++
portal/branches/wsrp-extraction/component/wsrp/src/main/java/org/gatein/portal/wsrp/jcr/JCRPersister.java 2011-02-02
22:51:10 UTC (rev 5852)
@@ -0,0 +1,344 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.gatein.portal.wsrp.jcr;
+
+import org.chromattic.api.Chromattic;
+import org.chromattic.api.ChromatticBuilder;
+import org.chromattic.api.ChromatticSession;
+import org.chromattic.api.format.FormatterContext;
+import org.chromattic.api.format.ObjectFormatter;
+import org.chromattic.spi.jcr.SessionLifeCycle;
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.services.jcr.RepositoryService;
+import org.exoplatform.services.jcr.core.ManageableRepository;
+import org.exoplatform.services.jcr.ext.common.SessionProvider;
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.wsrp.jcr.ChromatticPersister;
+import org.gatein.wsrp.jcr.mapping.BaseMapping;
+
+import javax.jcr.Credentials;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class JCRPersister implements ChromatticPersister
+{
+ private Chromattic chrome;
+ public static final String WSRP_WORKSPACE_NAME = "wsrp-system";
+ public static final String PORTLET_STATES_WORKSPACE_NAME = "pc-system";
+ private static final String REPOSITORY_NAME = "repository";
+ private String workspaceName;
+ private Map<Class, Class<? extends BaseMapping>> modelToMapping;
+
+ private ThreadLocal<ChromatticSession> sessionHolder = new
ThreadLocal<ChromatticSession>();
+
+ public JCRPersister(ExoContainer container, String workspaceName)
+ {
+ this.workspaceName = workspaceName;
+ }
+
+ public void initializeBuilderFor(List<Class> mappingClasses) throws Exception
+ {
+ ChromatticBuilder builder = ChromatticBuilder.create();
+ builder.setOptionValue(ChromatticBuilder.INSTRUMENTOR_CLASSNAME,
"org.chromattic.apt.InstrumentorImpl");
+ if (PORTLET_STATES_WORKSPACE_NAME.equals(workspaceName))
+ {
+ builder.setOptionValue(ChromatticBuilder.SESSION_LIFECYCLE_CLASSNAME,
PortletStatesSessionLifeCycle.class.getName());
+ }
+ else if (WSRP_WORKSPACE_NAME.equals(workspaceName))
+ {
+ builder.setOptionValue(ChromatticBuilder.SESSION_LIFECYCLE_CLASSNAME,
WSRPSessionLifeCycle.class.getName());
+ }
+ else
+ {
+ throw new IllegalArgumentException("Unknown workspace name: '" +
workspaceName + "'");
+ }
+
+ modelToMapping = new HashMap<Class, Class<? extends
BaseMapping>>(mappingClasses.size());
+ for (Class mappingClass : mappingClasses)
+ {
+ if (BaseMapping.class.isAssignableFrom(mappingClass))
+ {
+ Type[] interfaces = mappingClass.getGenericInterfaces();
+ if (ParameterValidation.existsAndIsNotEmpty(interfaces))
+ {
+ Class type =
(Class)((ParameterizedType)interfaces[0]).getActualTypeArguments()[0];
+ modelToMapping.put(type, mappingClass);
+ }
+ }
+ builder.add(mappingClass);
+ }
+
+ chrome = builder.build();
+ }
+
+ public ChromatticSession getSession()
+ {
+ ChromatticSession chromatticSession = sessionHolder.get();
+ if (chromatticSession == null)
+ {
+ ChromatticSession session = chrome.openSession();
+ sessionHolder.set(session);
+ return session;
+ }
+ else
+ {
+ return chromatticSession;
+ }
+ }
+
+ public void closeSession(boolean save)
+ {
+ ChromatticSession session = getOpenedSessionOrFail();
+ if (save)
+ {
+ synchronized (this)
+ {
+ session.save();
+ }
+ }
+ session.close();
+ sessionHolder.set(null);
+ }
+
+ private ChromatticSession getOpenedSessionOrFail()
+ {
+ ChromatticSession session = sessionHolder.get();
+ if(session == null)
+ {
+ throw new IllegalStateException("Cannot close the session as it hasn't
been opened first!");
+ }
+ return session;
+ }
+
+ public synchronized void save()
+ {
+ getOpenedSessionOrFail().save();
+ }
+
+ public <T> boolean delete(T toDelete,
org.gatein.wsrp.jcr.StoresByPathManager<T> manager)
+ {
+ Class<? extends Object> modelClass = toDelete.getClass();
+ Class<? extends BaseMapping> baseMappingClass =
modelToMapping.get(modelClass);
+ if (baseMappingClass == null)
+ {
+ throw new IllegalArgumentException("Cannot find a mapping class for "
+ modelClass.getName());
+ }
+
+ ChromatticSession session = getSession();
+
+ Object old = session.findByPath(baseMappingClass, manager.getChildPath(toDelete));
+
+ if (old != null)
+ {
+ session.remove(old);
+ closeSession(true);
+ return true;
+ }
+ else
+ {
+ closeSession(false);
+ return false;
+ }
+ }
+
+ public static class WSRPSessionLifeCycle implements SessionLifeCycle
+ {
+ private ManageableRepository repository;
+ private SessionProvider provider;
+
+ public WSRPSessionLifeCycle()
+ {
+ try
+ {
+ ExoContainer container = ExoContainerContext.getCurrentContainer();
+ RepositoryService repoService =
(RepositoryService)container.getComponentInstanceOfType(RepositoryService.class);
+ repository = repoService.getRepository(REPOSITORY_NAME);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+
+ provider = SessionProvider.createSystemProvider();
+ }
+
+ public Session login() throws RepositoryException
+ {
+ return provider.getSession(WSRP_WORKSPACE_NAME, repository);
+ }
+
+ public Session login(String s) throws RepositoryException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Session login(Credentials credentials, String s) throws RepositoryException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Session login(Credentials credentials) throws RepositoryException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void save(Session session) throws RepositoryException
+ {
+ session.save();
+ }
+
+ public void close(Session session)
+ {
+ session.logout();
+ }
+ }
+
+ public static class PortletStatesSessionLifeCycle implements SessionLifeCycle
+ {
+ private ManageableRepository repository;
+ private SessionProvider provider;
+
+ public PortletStatesSessionLifeCycle()
+ {
+ try
+ {
+ ExoContainer container = ExoContainerContext.getCurrentContainer();
+ RepositoryService repoService =
(RepositoryService)container.getComponentInstanceOfType(RepositoryService.class);
+ repository = repoService.getRepository(REPOSITORY_NAME);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+
+ provider = SessionProvider.createSystemProvider();
+ }
+
+ public Session login() throws RepositoryException
+ {
+ return provider.getSession(PORTLET_STATES_WORKSPACE_NAME, repository);
+ }
+
+ public Session login(String s) throws RepositoryException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Session login(Credentials credentials, String s) throws RepositoryException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Session login(Credentials credentials) throws RepositoryException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void save(Session session) throws RepositoryException
+ {
+ session.save();
+ }
+
+ public void close(Session session)
+ {
+ session.logout();
+ }
+ }
+
+ public static class QNameFormatter implements ObjectFormatter
+ {
+ private static final String OPEN_BRACE_REPLACEMENT = "-__";
+ private static final String CLOSE_BRACE_REPLACEMENT = "__-";
+ private static final String COLON_REPLACEMENT = "_-_";
+ private static final String CLOSE_BRACE = "}";
+ private static final String OPEN_BRACE = "{";
+ private static final String COLON = ":";
+
+ public String decodeNodeName(FormatterContext formatterContext, String s)
+ {
+ return decode(s);
+ }
+
+ public String encodeNodeName(FormatterContext formatterContext, String s)
+ {
+ return encode(s);
+ }
+
+ public String decodePropertyName(FormatterContext formatterContext, String s)
+ {
+ return decode(s);
+ }
+
+ public String encodePropertyName(FormatterContext formatterContext, String s)
+ {
+ return encode(s);
+ }
+
+ public static String decode(String s)
+ {
+ return s.replace(CLOSE_BRACE_REPLACEMENT,
CLOSE_BRACE).replace(OPEN_BRACE_REPLACEMENT, OPEN_BRACE).replace(COLON_REPLACEMENT,
COLON);
+ }
+
+ public static String encode(String s)
+ {
+ return s.replace(OPEN_BRACE, OPEN_BRACE_REPLACEMENT).replace(CLOSE_BRACE,
CLOSE_BRACE_REPLACEMENT).replace(COLON, COLON_REPLACEMENT);
+ }
+ }
+
+ public static class PortletNameFormatter implements ObjectFormatter
+ {
+ public static final String SLASH_REPLACEMENT = "-_-";
+ private static final String SLASH = "/";
+
+ public String decodeNodeName(FormatterContext formatterContext, String s)
+ {
+ return decode(s);
+ }
+
+ public static String decode(String s)
+ {
+ return s.replace(SLASH_REPLACEMENT, SLASH);
+ }
+
+ public String encodeNodeName(FormatterContext formatterContext, String s) throws
IllegalArgumentException, NullPointerException
+ {
+ return encode(s);
+ }
+
+ public static String encode(String s)
+ {
+ return s.replace(SLASH, SLASH_REPLACEMENT);
+ }
+ }
+}
Modified:
portal/branches/wsrp-extraction/packaging/module/src/main/javascript/portal.packaging.module.js
===================================================================
---
portal/branches/wsrp-extraction/packaging/module/src/main/javascript/portal.packaging.module.js 2011-02-02
22:48:53 UTC (rev 5851)
+++
portal/branches/wsrp-extraction/packaging/module/src/main/javascript/portal.packaging.module.js 2011-02-02
22:51:10 UTC (rev 5852)
@@ -88,6 +88,7 @@
.addDependency(new Project("org.gatein.wsrp", "wsrp-wsrp1-ws",
"jar", wsrpVersion))
.addDependency(new Project("org.gatein.wsrp", "wsrp-wsrp2-ws",
"jar", wsrpVersion))
.addDependency(new Project("org.gatein.wsrp", "wsrp-consumer",
"jar", wsrpVersion))
+ .addDependency(new Project("org.gatein.wsrp", "wsrp-jcr-impl",
"jar", wsrpVersion))
.addDependency(new Project("org.gatein.wsrp",
"wsrp-integration-api", "jar", wsrpVersion));
module.component.scripting =
Modified: portal/branches/wsrp-extraction/pom.xml
===================================================================
--- portal/branches/wsrp-extraction/pom.xml 2011-02-02 22:48:53 UTC (rev 5851)
+++ portal/branches/wsrp-extraction/pom.xml 2011-02-02 22:51:10 UTC (rev 5852)
@@ -48,7 +48,7 @@
<org.gatein.wci.version>2.1.0-Alpha02</org.gatein.wci.version>
<org.gatein.pc.version>2.3.0-Alpha01</org.gatein.pc.version>
<org.picketlink.idm>1.1.8.CR01</org.picketlink.idm>
- <org.gatein.wsrp.version>2.0.0-GA</org.gatein.wsrp.version>
+
<org.gatein.wsrp.version>2.1.0-Alpha01-SNAPSHOT</org.gatein.wsrp.version>
<org.gatein.mop.version>1.0.3-GA</org.gatein.mop.version>
<org.slf4j.version>1.5.6</org.slf4j.version>
<rhino.version>1.6R5</rhino.version>
@@ -583,8 +583,14 @@
</dependency>
<dependency>
<groupId>org.gatein.wsrp</groupId>
+ <artifactId>wsrp-jcr-impl</artifactId>
+ <version>${org.gatein.wsrp.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.gatein.wsrp</groupId>
<artifactId>wsrp-consumer</artifactId>
<version>${org.gatein.wsrp.version}</version>
+ <!-- TODO: remove -->
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>