Author: chris.laprun(a)jboss.com
Date: 2009-11-27 17:54:02 -0500 (Fri, 27 Nov 2009)
New Revision: 847
Modified:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/JCRPersister.java
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/JCRConsumerRegistry.java
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/ProducerInfoMapping.java
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/ProducerInfosMapping.java
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/RegistrationInfoMapping.java
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/RegistrationPropertyMapping.java
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/JCRProducerConfigurationService.java
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/mapping/ProducerConfigurationMapping.java
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/mapping/RegistrationRequirementsMapping.java
portal/branches/wsrp-integration/web/portal/src/main/webapp/WEB-INF/conf/wsrp/consumers-configuration-nodetypes.xml
portal/branches/wsrp-integration/web/portal/src/main/webapp/WEB-INF/conf/wsrp/producer-configuration-nodetypes.xml
Log:
- Improved mapping classes:
+ Fixed improper use of RelatedMappedBy instead of MappedBy.
+ Create methods have been renamed and take the child name in parameter as it is needed
by JCR.
+ Added QNameFormatter on RegistrationInfoMapping so QNames that are used as
RegistrationProperty names can be persisted in JCR.
+ Children elements must be added to parents before they are initialized as they need to
be attached in JCR.
+ Avoid NPEs by checking that we do have a RegistrationPropertyDescription before doing
anything with it.
+ Re-added name property on RegistrationPropertyMapping as we don't always have a
RegistrationPropertyDescription to get the name from.
- Added explicit defaultPrimaryType declaration on child node definitions for one to one
mappings.
- Auto-create endpoint and registration info in JCR nodetype for ProducerInfo.
- Added closeSession method on JCRPersister to save and close the session when operations
are done and used it where appropriate.
Modified:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/JCRPersister.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/JCRPersister.java 2009-11-27
21:07:48 UTC (rev 846)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/JCRPersister.java 2009-11-27
22:54:02 UTC (rev 847)
@@ -25,6 +25,8 @@
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.services.jcr.RepositoryService;
@@ -88,7 +90,13 @@
return chrome.openSession();
}
+ public void closeSession(ChromatticSession session)
+ {
+ session.save();
+ session.close();
+ }
+
public static class WSRPSessionLifeCycle implements SessionLifeCycle
{
@@ -127,4 +135,41 @@
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 = "_-_";
+
+ 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);
+ }
+
+ private String decode(String s)
+ {
+ return s.replace(CLOSE_BRACE_REPLACEMENT,
"}").replace(OPEN_BRACE_REPLACEMENT, "{").replace(COLON_REPLACEMENT,
":");
+ }
+
+ private String encode(String s)
+ {
+ return s.replace("{", OPEN_BRACE_REPLACEMENT).replace("}",
CLOSE_BRACE_REPLACEMENT).replace(":", COLON_REPLACEMENT);
+ }
+ }
}
Modified:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/JCRConsumerRegistry.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/JCRConsumerRegistry.java 2009-11-27
21:07:48 UTC (rev 846)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/JCRConsumerRegistry.java 2009-11-27
22:54:02 UTC (rev 847)
@@ -68,13 +68,13 @@
ChromatticSession session = persister.getSession();
ProducerInfosMapping pims = getProducerInfosMapping(session);
- ProducerInfoMapping pim = pims.createProducerInfo();
+ ProducerInfoMapping pim = pims.createProducerInfo(info.getId());
pim.initFrom(info);
String key = session.persist(pims, pim, info.getId());
info.setKey(key);
- session.close();
+ persister.closeSession(session);
}
@Override
@@ -83,7 +83,7 @@
ChromatticSession session = persister.getSession();
delete(session, getPathFor(info));
- session.close();
+ persister.closeSession(session);
}
@Override
@@ -103,9 +103,9 @@
throw new IllegalArgumentException("Couldn't find ProducerInfoMapping
associated with key " + key);
}
pim.initFrom(producerInfo);
- session.save();
- session.close();
+ persister.closeSession(session);
+
return null;
}
@@ -117,8 +117,8 @@
List<ProducerInfoMapping> mappings =
producerInfosMapping.getProducerInfos();
- session.save();
- session.close();
+ persister.closeSession(session);
+
return new MappingToProducerInfoIterator(mappings.iterator());
}
@@ -141,11 +141,16 @@
List<WSRPConsumer> consumers = fromXML.getConfiguredConsumers();
for (WSRPConsumer consumer : consumers)
{
- ProducerInfoMapping pim = producerInfosMapping.createProducerInfo();
- pim.initFrom(consumer.getProducerInfo());
+ ProducerInfo info = consumer.getProducerInfo();
+
+ ProducerInfoMapping pim =
producerInfosMapping.createProducerInfo(info.getId());
+
+ // need to add to parent first to attach newly created ProducerInfoMapping
infos.add(pim);
+
+ // init it from ProducerInfo
+ pim.initFrom(info);
}
- session.persist(infos); // todo: is that sufficient?
}
return producerInfosMapping;
Modified:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/ProducerInfoMapping.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/ProducerInfoMapping.java 2009-11-27
21:07:48 UTC (rev 846)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/ProducerInfoMapping.java 2009-11-27
22:54:02 UTC (rev 847)
@@ -24,10 +24,10 @@
package org.gatein.portal.wsrp.state.consumer.mapping;
import org.chromattic.api.annotations.Id;
+import org.chromattic.api.annotations.MappedBy;
import org.chromattic.api.annotations.NodeMapping;
import org.chromattic.api.annotations.OneToOne;
import org.chromattic.api.annotations.Property;
-import org.chromattic.api.annotations.RelatedMappedBy;
import org.gatein.wsrp.consumer.EndpointConfigurationInfo;
import org.gatein.wsrp.consumer.ProducerInfo;
import org.gatein.wsrp.consumer.RegistrationInfo;
@@ -42,11 +42,11 @@
public static final String NODE_NAME = "wsrp:producerinfo";
@OneToOne
- @RelatedMappedBy("endpoint")
+ @MappedBy("endpoint")
public abstract EndpointInfoMapping getEndpointInfo();
@OneToOne
- @RelatedMappedBy("registration")
+ @MappedBy("registration")
public abstract RegistrationInfoMapping getRegistrationInfo();
@Property(name = "producerid")
Modified:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/ProducerInfosMapping.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/ProducerInfosMapping.java 2009-11-27
21:07:48 UTC (rev 846)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/ProducerInfosMapping.java 2009-11-27
22:54:02 UTC (rev 847)
@@ -42,5 +42,5 @@
public abstract List<ProducerInfoMapping> getProducerInfos();
@Create
- public abstract ProducerInfoMapping createProducerInfo();
+ public abstract ProducerInfoMapping createProducerInfo(String producerId);
}
Modified:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/RegistrationInfoMapping.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/RegistrationInfoMapping.java 2009-11-27
21:07:48 UTC (rev 846)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/RegistrationInfoMapping.java 2009-11-27
22:54:02 UTC (rev 847)
@@ -24,10 +24,12 @@
package org.gatein.portal.wsrp.state.consumer.mapping;
import org.chromattic.api.annotations.Create;
+import org.chromattic.api.annotations.FormattedBy;
import org.chromattic.api.annotations.NodeMapping;
import org.chromattic.api.annotations.OneToMany;
import org.chromattic.api.annotations.Property;
import org.exoplatform.commons.utils.Safe;
+import org.gatein.portal.wsrp.state.JCRPersister;
import org.gatein.portal.wsrp.state.mapping.RegistrationPropertyDescriptionMapping;
import org.gatein.wsrp.consumer.RegistrationInfo;
import org.gatein.wsrp.consumer.RegistrationProperty;
@@ -42,6 +44,7 @@
* @version $Revision$
*/
@NodeMapping(name = RegistrationInfoMapping.NODE_NAME)
+(a)FormattedBy(JCRPersister.QNameFormatter.class)
public abstract class RegistrationInfoMapping
{
public static final String NODE_NAME = "wsrp:registrationinfo";
@@ -65,7 +68,7 @@
public abstract List<RegistrationPropertyMapping> getRegistrationProperties();
@Create
- public abstract RegistrationPropertyMapping createRegistrationProperty();
+ public abstract RegistrationPropertyMapping createRegistrationProperty(String
propertyName);
public void initFrom(RegistrationInfo regInfo)
{
@@ -84,13 +87,11 @@
for (RegistrationProperty property : regInfo.getRegistrationProperties().values())
{
// create new RegistrationPropertyMapping for this RegistrationInfoMapping
- RegistrationPropertyMapping rpm = createRegistrationProperty();
+ RegistrationPropertyMapping rpm =
createRegistrationProperty(property.getName());
- // initialize
+ // add newly created RegistrationPropertyMapping to parent then initialize for
JCR
+ rpms.add(rpm);
rpm.initFrom(property);
-
- // add newly created RegistrationPropertyMapping to parent
- rpms.add(rpm);
}
}
@@ -105,14 +106,15 @@
// registration properties
for (RegistrationPropertyMapping rpm : getRegistrationProperties())
{
+ RegistrationProperty prop = regInfo.setRegistrationPropertyValue(rpm.getName(),
rpm.getValue());
+
RegistrationPropertyDescriptionMapping rpdm = rpm.getDescription();
- String name = rpdm.getName();
+ if (rpdm != null)
+ {
+ RegistrationPropertyDescription desc =
rpdm.toRegistrationPropertyDescription();
+ prop.setDescription(desc);
+ }
- RegistrationProperty prop = regInfo.setRegistrationPropertyValue(name,
rpm.getValue());
-
- RegistrationPropertyDescription desc =
rpdm.toRegistrationPropertyDescription();
- prop.setDescription(desc);
-
prop.setStatus(RegistrationProperty.Status.valueOf(rpm.getStatus()));
}
Modified:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/RegistrationPropertyMapping.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/RegistrationPropertyMapping.java 2009-11-27
21:07:48 UTC (rev 846)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/RegistrationPropertyMapping.java 2009-11-27
22:54:02 UTC (rev 847)
@@ -40,6 +40,11 @@
{
public static final String NODE_NAME = "wsrp:registrationproperty";
+ @Property(name = "name")
+ public abstract String getName();
+
+ public abstract void setName(String name);
+
@Property(name = "value")
public abstract String getValue();
@@ -59,12 +64,16 @@
public void initFrom(RegistrationProperty property)
{
// set properties
+ setName(property.getName());
setStatus(property.getStatus().name());
setValue(property.getValue());
// description
- RegistrationPropertyDescriptionMapping rpdm = getDescription();
RegistrationPropertyDescription desc = property.getDescription();
- rpdm.initFrom(desc);
+ if (desc != null)
+ {
+ RegistrationPropertyDescriptionMapping rpdm = getDescription();
+ rpdm.initFrom(desc);
+ }
}
}
Modified:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/JCRProducerConfigurationService.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/JCRProducerConfigurationService.java 2009-11-27
21:07:48 UTC (rev 846)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/JCRProducerConfigurationService.java 2009-11-27
22:54:02 UTC (rev 847)
@@ -80,6 +80,7 @@
configuration = pcm.toProducerConfiguration();
+ persister.closeSession(session);
}
public void saveConfiguration() throws Exception
@@ -87,6 +88,8 @@
ChromatticSession session = persister.getSession();
saveConfiguration(session, session.findByPath(ProducerConfigurationMapping.class,
PRODUCER_CONFIGURATION_PATH), false);
+
+ persister.closeSession(session);
}
private ProducerConfigurationMapping saveConfiguration(ChromatticSession session,
ProducerConfigurationMapping pcm, boolean forceReloadFromXML) throws Exception
@@ -108,8 +111,6 @@
}
pcm.initFrom(configuration);
-
- session.persist(pcm);
}
return pcm;
Modified:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/mapping/ProducerConfigurationMapping.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/mapping/ProducerConfigurationMapping.java 2009-11-27
21:07:48 UTC (rev 846)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/mapping/ProducerConfigurationMapping.java 2009-11-27
22:54:02 UTC (rev 847)
@@ -22,10 +22,10 @@
package org.gatein.portal.wsrp.state.producer.configuration.mapping;
+import org.chromattic.api.annotations.MappedBy;
import org.chromattic.api.annotations.NodeMapping;
import org.chromattic.api.annotations.OneToOne;
import org.chromattic.api.annotations.Property;
-import org.chromattic.api.annotations.RelatedMappedBy;
import org.gatein.wsrp.producer.config.ProducerConfiguration;
import org.gatein.wsrp.producer.config.ProducerRegistrationRequirements;
import org.gatein.wsrp.producer.config.impl.ProducerConfigurationImpl;
@@ -45,7 +45,7 @@
public abstract void setUsingStrictMode(boolean strict);
@OneToOne
- @RelatedMappedBy("registrationrequirements")
+ @MappedBy("registrationrequirements")
public abstract RegistrationRequirementsMapping getRegistrationRequirements();
public void initFrom(ProducerConfiguration configuration)
Modified:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/mapping/RegistrationRequirementsMapping.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/mapping/RegistrationRequirementsMapping.java 2009-11-27
21:07:48 UTC (rev 846)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/configuration/mapping/RegistrationRequirementsMapping.java 2009-11-27
22:54:02 UTC (rev 847)
@@ -56,7 +56,7 @@
public abstract List<RegistrationPropertyDescriptionMapping>
getRegistrationPropertyDescriptions();
@Create
- public abstract RegistrationPropertyDescriptionMapping create();
+ public abstract RegistrationPropertyDescriptionMapping
createRegistrationPropertyDescription(String propertyName);
public void initFrom(ProducerRegistrationRequirements registrationRequirements)
{
@@ -66,11 +66,11 @@
List<RegistrationPropertyDescriptionMapping> rpdms =
getRegistrationPropertyDescriptions();
for (RegistrationPropertyDescription desc :
registrationRequirements.getRegistrationProperties().values())
{
- RegistrationPropertyDescriptionMapping rpdm = create();
+ RegistrationPropertyDescriptionMapping rpdm =
createRegistrationPropertyDescription(desc.getNameAsString());
+ // attach first to parent, then init
+ rpdms.add(rpdm);
rpdm.initFrom(desc);
-
- rpdms.add(rpdm);
}
}
Modified:
portal/branches/wsrp-integration/web/portal/src/main/webapp/WEB-INF/conf/wsrp/consumers-configuration-nodetypes.xml
===================================================================
---
portal/branches/wsrp-integration/web/portal/src/main/webapp/WEB-INF/conf/wsrp/consumers-configuration-nodetypes.xml 2009-11-27
21:07:48 UTC (rev 846)
+++
portal/branches/wsrp-integration/web/portal/src/main/webapp/WEB-INF/conf/wsrp/consumers-configuration-nodetypes.xml 2009-11-27
22:54:02 UTC (rev 847)
@@ -61,13 +61,15 @@
</propertyDefinition>
</propertyDefinitions>
<childNodeDefinitions>
- <childNodeDefinition name="endpoint"
defaultPrimaryType="" autoCreated="false" mandatory="false"
+ <childNodeDefinition name="endpoint"
defaultPrimaryType="wsrp:endpointinfo" autoCreated="true"
+ mandatory="false"
onParentVersion="COPY"
protected="false" sameNameSiblings="false">
<requiredPrimaryTypes>
<requiredPrimaryType>wsrp:endpointinfo</requiredPrimaryType>
</requiredPrimaryTypes>
</childNodeDefinition>
- <childNodeDefinition name="registration"
defaultPrimaryType="" autoCreated="false" mandatory="false"
+ <childNodeDefinition name="registration"
defaultPrimaryType="wsrp:registrationinfo" autoCreated="true"
+ mandatory="false"
onParentVersion="COPY"
protected="false" sameNameSiblings="false">
<requiredPrimaryTypes>
<requiredPrimaryType>wsrp:registrationinfo</requiredPrimaryType>
@@ -125,6 +127,10 @@
<supertype>mix:referenceable</supertype>
</supertypes>
<propertyDefinitions>
+ <propertyDefinition name="name" requiredType="String"
autoCreated="false" mandatory="false"
+ onParentVersion="COPY" protected="false"
multiple="true">
+ <valueConstraints/>
+ </propertyDefinition>
<propertyDefinition name="value" requiredType="String"
autoCreated="false" mandatory="false"
onParentVersion="COPY" protected="false"
multiple="true">
<valueConstraints/>
Modified:
portal/branches/wsrp-integration/web/portal/src/main/webapp/WEB-INF/conf/wsrp/producer-configuration-nodetypes.xml
===================================================================
---
portal/branches/wsrp-integration/web/portal/src/main/webapp/WEB-INF/conf/wsrp/producer-configuration-nodetypes.xml 2009-11-27
21:07:48 UTC (rev 846)
+++
portal/branches/wsrp-integration/web/portal/src/main/webapp/WEB-INF/conf/wsrp/producer-configuration-nodetypes.xml 2009-11-27
22:54:02 UTC (rev 847)
@@ -38,8 +38,9 @@
</propertyDefinition>
</propertyDefinitions>
<childNodeDefinitions>
- <childNodeDefinition name="registrationrequirements"
defaultPrimaryType="" autoCreated="true" mandatory="false"
- onParentVersion="COPY"
protected="false" sameNameSiblings="false">
+ <childNodeDefinition name="registrationrequirements"
defaultPrimaryType="wsrp:registrationrequirements"
+ autoCreated="true" mandatory="false"
onParentVersion="COPY" protected="false"
+ sameNameSiblings="false">
<requiredPrimaryTypes>
<requiredPrimaryType>wsrp:registrationrequirements</requiredPrimaryType>
</requiredPrimaryTypes>