Author: chris.laprun(a)jboss.com
Date: 2009-11-20 18:20:21 -0500 (Fri, 20 Nov 2009)
New Revision: 747
Modified:
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/pom/spi/wsrp/WSRPContentProvider.java
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/ConsumerRegistry.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/RegistrationInfoMapping.java
Log:
- Finished first pass at ConsumerRegistry implementation.
- Renamed ProducerInfoMapping.producerId property to id and added key property to hold
generated UUID.
- Added create method on RegistrationInfoMapping to be able to create child
RegistrationPropertyMapping elements.
- Use Safe.getBytes in WSRPContentProvider and ConsumerRegistry.
Modified:
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/pom/spi/wsrp/WSRPContentProvider.java
===================================================================
---
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/pom/spi/wsrp/WSRPContentProvider.java 2009-11-20
23:18:15 UTC (rev 746)
+++
portal/branches/wsrp-integration/component/portal/src/main/java/org/exoplatform/portal/pom/spi/wsrp/WSRPContentProvider.java 2009-11-20
23:20:21 UTC (rev 747)
@@ -19,16 +19,14 @@
package org.exoplatform.portal.pom.spi.wsrp;
+import org.exoplatform.commons.utils.Safe;
import org.exoplatform.portal.pom.spi.ContentProviderHelper;
import org.exoplatform.portal.pom.spi.HelpableContentProvider;
-import org.gatein.common.io.IOTools;
import org.gatein.mop.spi.content.ContentProvider;
import org.gatein.mop.spi.content.GetState;
import org.gatein.mop.spi.content.StateContainer;
import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
import java.util.List;
/**
@@ -80,31 +78,10 @@
persistedState.setCloned(updatedState.isCloned());
}
- private byte[] getBytes(InputStream is)
- {
- byte[] bytes;
-
- if (is == null)
- {
- return null;
- }
-
- try
- {
- bytes = IOTools.getBytes(is);
- }
- catch (IOException e)
- {
- throw new RuntimeException("Couldn't get bytes from WSRPState",
e); // todo: log instead?
- }
- IOTools.safeClose(is);
- return bytes;
- }
-
public WSRP getState(WSRPState state)
{
WSRP wsrp = new WSRP();
- byte[] bytes = getBytes(state.getState());
+ byte[] bytes = Safe.getBytes(state.getState());
wsrp.setState(bytes);
wsrp.setPortletId(state.getPortletId());
wsrp.setCloned(state.getCloned());
Modified:
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/ConsumerRegistry.java
===================================================================
---
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/ConsumerRegistry.java 2009-11-20
23:18:15 UTC (rev 746)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/ConsumerRegistry.java 2009-11-20
23:20:21 UTC (rev 747)
@@ -26,6 +26,7 @@
import org.chromattic.api.Chromattic;
import org.chromattic.api.ChromatticBuilder;
import org.chromattic.api.ChromatticSession;
+import org.exoplatform.commons.utils.Safe;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.services.jcr.ext.registry.RegistryService;
import org.gatein.portal.wsrp.state.consumer.mapping.EndpointInfoMapping;
@@ -36,9 +37,15 @@
import org.gatein.portal.wsrp.state.consumer.mapping.RegistrationPropertyMapping;
import org.gatein.wsrp.WSRPConsumer;
import org.gatein.wsrp.consumer.ProducerInfo;
+import org.gatein.wsrp.consumer.RegistrationInfo;
+import org.gatein.wsrp.consumer.RegistrationProperty;
import org.gatein.wsrp.consumer.registry.AbstractConsumerRegistry;
import org.gatein.wsrp.consumer.registry.xml.XMLConsumerRegistry;
+import org.gatein.wsrp.registration.LocalizedString;
+import org.gatein.wsrp.registration.RegistrationPropertyDescription;
+import javax.xml.namespace.QName;
+import java.io.ByteArrayInputStream;
import java.util.Iterator;
import java.util.List;
@@ -78,10 +85,9 @@
String path = getPathFor(info);
ChromatticSession session = chrome.openSession();
- session.persist(toProducerInfoMapping(info), path);
+ String key = session.persist(toProducerInfoMapping(info, session), path);
+ info.setKey(key);
- // todo: find a way to inject JCR Id into ProducerInfo
-
session.close();
}
@@ -97,7 +103,16 @@
@Override
protected String update(ProducerInfo producerInfo)
{
- // todo: need JCR id to be able to find the previous ProducerInfo in case the id
has been modified
+ String key = producerInfo.getKey();
+ if (key == null)
+ {
+ throw new IllegalArgumentException("ProducerInfo '" +
producerInfo.getId()
+ + "' hasn't been persisted and thus cannot be updated.");
+ }
+
+ ChromatticSession session = chrome.openSession();
+ session.persist(toProducerInfoMapping(producerInfo, session),
getPathFor(producerInfo));
+
return null;
}
@@ -124,7 +139,7 @@
List<WSRPConsumer> consumers = fromXML.getConfiguredConsumers();
for (WSRPConsumer consumer : consumers)
{
- infos.add(toProducerInfoMapping(consumer.getProducerInfo()));
+ infos.add(toProducerInfoMapping(consumer.getProducerInfo(), session));
}
session.persist(infos); // todo: is that sufficient?
@@ -151,19 +166,106 @@
}
}
- private String getPathFor(ProducerInfo info)
+ private static String getPathFor(ProducerInfo info)
{
return PRODUCER_INFOS_PATH + "/" + info.getId();
}
- private static ProducerInfoMapping toProducerInfoMapping(ProducerInfo producerInfo)
+ private static ProducerInfoMapping toProducerInfoMapping(ProducerInfo producerInfo,
ChromatticSession session)
{
- return null; // todo: implement
+ ProducerInfoMapping pim = session.findById(ProducerInfoMapping.class,
producerInfo.getKey());
+ if (pim == null)
+ {
+ pim = session.insert(ProducerInfoMapping.class, getPathFor(producerInfo));
+ }
+
+ pim.setActive(producerInfo.isActive());
+ pim.setExpirationCacheSeconds(producerInfo.getExpirationCacheSeconds());
+ pim.setId(producerInfo.getId());
+
+ EndpointInfoMapping eim = pim.getEndpointInfo();
+
eim.setWSDLURL(producerInfo.getEndpointConfigurationInfo().getWsdlDefinitionURL());
+
+ RegistrationInfoMapping rim = pim.getRegistrationInfo();
+ RegistrationInfo regInfo = producerInfo.getRegistrationInfo();
+ rim.setConsumerName(regInfo.getConsumerName());
+ rim.setRegistrationHandle(regInfo.getRegistrationHandle());
+ byte[] bytes = regInfo.getRegistrationState();
+ if (bytes != null && bytes.length > 0)
+ {
+ ByteArrayInputStream is = new ByteArrayInputStream(bytes);
+ rim.setRegistrationState(is);
+ }
+
+ // clear and recreate registration properties
+ List<RegistrationPropertyMapping> rpms = rim.getRegistrationProperties();
+ rpms.clear();
+ for (RegistrationProperty property : regInfo.getRegistrationProperties().values())
+ {
+ // create new RegistrationPropertyMapping for this RegistrationInfoMapping
+ RegistrationPropertyMapping rpm = rim.create();
+
+ // set properties
+ rpm.setStatus(property.getStatus().name());
+ rpm.setValue(property.getValue());
+
+ // description
+ RegistrationPropertyDescriptionMapping rpdm = rpm.getDescription();
+ RegistrationPropertyDescription desc = property.getDescription();
+ rpdm.setDescription(desc.getDescription().getValue()); // todo: should really
persist LocalizedString here...
+ rpdm.setHint(desc.getHint().getValue()); // todo: should really persist
LocalizedString here...
+ rpdm.setLabel(desc.getLabel().getValue()); // todo: should really persist
LocalizedString here...
+
+ // convert QNames to Strings
+ rpdm.setName(desc.getName().toString());
+ rpdm.setType(desc.getType().toString());
+
+ // add newly created RegistrationPropertyMapping to parent
+ rpms.add(rpm);
+ }
+
+ return pim;
}
private static ProducerInfo toProducerInfo(ProducerInfoMapping mapping)
{
- return null; // todo: implement
+ // todo: should probably use a ProducerInfo implementation backed by mapping at
some point
+ ProducerInfo info = new ProducerInfo();
+
+ // basic properties
+ info.setKey(mapping.getKey());
+ info.setId(mapping.getId());
+ info.setActive(mapping.getActive());
+ info.setExpirationCacheSeconds(mapping.getExpirationCacheSeconds());
+
+ // endpoint
+
info.getEndpointConfigurationInfo().setWsdlDefinitionURL(mapping.getEndpointInfo().getWSDLURL());
+
+ // registration
+ RegistrationInfo regInfo = info.getRegistrationInfo();
+ RegistrationInfoMapping rim = mapping.getRegistrationInfo();
+ regInfo.setConsumerName(rim.getConsumerName());
+ regInfo.setRegistrationHandle(rim.getRegistrationHandle());
+ regInfo.setRegistrationState(Safe.getBytes(rim.getRegistrationState()));
+
+ // registration properties
+ for (RegistrationPropertyMapping rpm : rim.getRegistrationProperties())
+ {
+ RegistrationPropertyDescriptionMapping rpdm = rpm.getDescription();
+ String name = rpdm.getName();
+
+ RegistrationProperty prop = regInfo.setRegistrationPropertyValue(name,
rpm.getValue());
+
+ RegistrationPropertyDescription desc = new RegistrationPropertyDescription(name,
QName.valueOf(rpdm.getType()));
+ desc.setDefaultDescription(rpdm.getDescription());
+ desc.setHint(new LocalizedString(rpdm.getHint()));
+ desc.setLabel(new LocalizedString(rpdm.getLabel()));
+ prop.setDescription(desc);
+
+ prop.setStatus(RegistrationProperty.Status.valueOf(rpm.getStatus()));
+ }
+
+ return info;
}
private static class MappingToProducerInfoIterator implements
Iterator<ProducerInfo>
@@ -175,19 +277,16 @@
this.mappings = infoMappingIterator;
}
- @Override
public boolean hasNext()
{
return mappings.hasNext();
}
- @Override
public ProducerInfo next()
{
return toProducerInfo(mappings.next());
}
- @Override
public void remove()
{
throw new UnsupportedOperationException("Remove not supported!");
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-20
23:18:15 UTC (rev 746)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/ProducerInfoMapping.java 2009-11-20
23:20:21 UTC (rev 747)
@@ -23,6 +23,7 @@
package org.gatein.portal.wsrp.state.consumer.mapping;
+import org.chromattic.api.annotations.Id;
import org.chromattic.api.annotations.NodeMapping;
import org.chromattic.api.annotations.OneToOne;
import org.chromattic.api.annotations.Property;
@@ -46,9 +47,9 @@
public abstract RegistrationInfoMapping getRegistrationInfo();
@Property(name = "producerid")
- public abstract String getProducerId();
+ public abstract String getId();
- public abstract void setProducerId(String id);
+ public abstract void setId(String id);
@Property(name = "cache")
public abstract Integer getExpirationCacheSeconds();
@@ -60,8 +61,11 @@
public abstract void setActive(boolean active);
- @Property(name = "available")
- public abstract boolean getAvailable();
+ @Id
+ public abstract String getKey();
- public abstract void setAvailable(boolean available);
+ /* @Property(name = "available")
+public abstract boolean getAvailable();
+
+public abstract void setAvailable(boolean available);*/
}
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-20
23:18:15 UTC (rev 746)
+++
portal/branches/wsrp-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/consumer/mapping/RegistrationInfoMapping.java 2009-11-20
23:20:21 UTC (rev 747)
@@ -23,6 +23,7 @@
package org.gatein.portal.wsrp.state.consumer.mapping;
+import org.chromattic.api.annotations.Create;
import org.chromattic.api.annotations.NodeMapping;
import org.chromattic.api.annotations.OneToMany;
import org.chromattic.api.annotations.Property;
@@ -56,4 +57,7 @@
@OneToMany
public abstract List<RegistrationPropertyMapping> getRegistrationProperties();
+
+ @Create
+ public abstract RegistrationPropertyMapping create();
}
Show replies by date