From 08269012227e2f708cfad22553e16207cfe5afde Mon Sep 17 00:00:00 2001 From: Lucio Lelii Date: Thu, 13 Nov 2008 17:56:41 +0000 Subject: [PATCH] git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Registry@6484 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../registry/impl/RegistryFactory.java | 26 +++++++++-- .../registry/impl/state/ProfileResource.java | 46 +++++++++++++++++-- 2 files changed, 64 insertions(+), 8 deletions(-) diff --git a/src/org/gcube/informationsystem/registry/impl/RegistryFactory.java b/src/org/gcube/informationsystem/registry/impl/RegistryFactory.java index e6fb17c..37ab5e3 100644 --- a/src/org/gcube/informationsystem/registry/impl/RegistryFactory.java +++ b/src/org/gcube/informationsystem/registry/impl/RegistryFactory.java @@ -141,7 +141,7 @@ public class RegistryFactory{ String [] scopes = mess.getScopes(); if (scopes != null) { for (String scope : scopes) { - logger.debug("Adding Scopes to Profile "+ scope); + logger.debug(resource.getID()+" Adding Scopes to Profile "+ scope); resource.addScope(GCUBEScope.getScope(scope)); } @@ -167,7 +167,7 @@ public class RegistryFactory{ } else { //try to create resource try { - logger.debug("Creating the stateful resource for " + resource.getID()); + logger.debug(resource.getID()+" Creating the stateful resource for " + resource.getID()); ProfileResource presource = (ProfileResource) ProfileContext.getContext().getWSHome().create(ProfileContext.getContext().makeKey(resource.getID()),resource); presource.getPersistenceDelegate().store(presource); } @@ -177,10 +177,10 @@ public class RegistryFactory{ throw new RemoteException(msg); } try { + updateCounterInfo (resource.getID(), ResourceType.valueOf(mess.getType()), OperationType.create, Calendar.getInstance()); GCUBEEvent event = new GCUBEEvent(); event.setPayload(resource); ServiceContext.getContext().getTopicProducer().notify(ServiceContext.RegistryTopic.CREATE, event); - updateCounterInfo (resource.getID(), ResourceType.valueOf(mess.getType()), OperationType.create, Calendar.getInstance()); } catch (Exception e) { logger.warn("Error updating Counting info for resource with ID " + resource.getID(), e); } @@ -403,7 +403,7 @@ public class RegistryFactory{ /** * return the resource * - * @return NotifierResource + * @return NotifierResource resource * @throws RemoteException Exception */ private RegistryFactoryResource getResource() throws RemoteException { @@ -418,10 +418,28 @@ public class RegistryFactory{ return factoryResource; } + /** + * + * @param message UpdateScopeInProfileMessage + * @return String + * @throws GCUBEFault - + */ public String updateScopeInProfile(UpdateScopeInProfileMessage message)throws GCUBEFault{return null;} + /** + * + * @param message RemoveScopeInProfileMessage + * @return String + * @throws GCUBEFault - + */ public String removeScopeInProfile(RemoveScopeInProfileMessage message)throws GCUBEFault{return null;} + /** + * + * @param message UpdateStateMessage + * @return + * @throws GCUBEFault - + */ public String updateState(UpdateStateMessage message)throws GCUBEFault{return null;} } diff --git a/src/org/gcube/informationsystem/registry/impl/state/ProfileResource.java b/src/org/gcube/informationsystem/registry/impl/state/ProfileResource.java index 4d99f53..3c0ccdd 100644 --- a/src/org/gcube/informationsystem/registry/impl/state/ProfileResource.java +++ b/src/org/gcube/informationsystem/registry/impl/state/ProfileResource.java @@ -7,6 +7,10 @@ import java.util.ArrayList; import javax.xml.namespace.QName; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; import org.gcube.common.core.informationsystem.notifier.ISNotifier; import org.gcube.common.core.informationsystem.publisher.ISPublisher; @@ -66,7 +70,7 @@ public class ProfileResource extends GCUBEWSResource { @Override public void initialise(Object... params) throws ResourceException { GCUBEResource resource = (GCUBEResource) params[0]; - + logger.debug("initializing resource "+resource.getID()); Document dom = null; StringWriter writer =new StringWriter(); @@ -75,6 +79,7 @@ public class ProfileResource extends GCUBEWSResource { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); + DocumentBuilder builder = factory.newDocumentBuilder(); StringReader reader = new StringReader(writer.toString().substring(writer.toString().indexOf("?>")+2, writer.toString().length())); @@ -82,6 +87,8 @@ public class ProfileResource extends GCUBEWSResource { InputSource source = new InputSource(reader); dom =builder.parse(source); + + } catch (Exception e1) { throw new ResourceException(e1); } @@ -91,6 +98,8 @@ public class ProfileResource extends GCUBEWSResource { this.setNotificationProfile(dom); this.setGCubeResource(resource); + + if (hasToLive(resource)) this.setTerminationTime(null); if (hasToLive(resource)) { @@ -115,24 +124,43 @@ public class ProfileResource extends GCUBEWSResource { } + /** + * set notification Profile + * + * @param profile Document + */ public void setNotificationProfile(Document profile) { this.getResourcePropertySet().get(NotificationProfileRP).clear(); this.getResourcePropertySet().get(NotificationProfileRP).add(profile); //this.getPersistenceDelegate().store(this); } + /** + * get notification Profile + * + * @return Document profile + */ public Document getNotificationProfile() { return (Document)this.getResourcePropertySet().get(NotificationProfileRP).get(0); } - + /** + * set Profile + * + * @param profile Document + */ public void setProfile(Document profile) { this.getResourcePropertySet().get(ProfileRP).clear(); this.getResourcePropertySet().get(ProfileRP).add(profile); //this.getPersistenceDelegate().store(this); } + /** + * get Profile + * + * @return Document profile + */ public Document getProfile() { return (Document)this.getResourcePropertySet().get(ProfileRP).get(0); } @@ -141,7 +169,9 @@ public class ProfileResource extends GCUBEWSResource { /** * Checks if the profile has to live or not - * return true/false + * + * @param GCUBEReosurce resource + * @return true/false */ private boolean hasToLive(GCUBEResource resource) { if (resource.getType().compareTo(GCUBERunningInstance.TYPE)==0 || @@ -158,11 +188,19 @@ public class ProfileResource extends GCUBEWSResource { return new QName(ProfileContext.getContext().getNamespace(), NotificationProfileRP+this.getID().getValue()); } + /** + * returns the Resource + * + * @return resource GCUBEReosurce + */ public GCUBEResource getGCubeResource() { return this.gCubeResource; } - + /** + * sets the resource + * @param resource GCUBEReosurce + */ public void setGCubeResource(GCUBEResource resource) { this.gCubeResource = resource; }