This commit is contained in:
Manuele Simi 2008-04-23 15:25:01 +00:00
parent 988510b4c3
commit 3214fd599f
3 changed files with 24 additions and 30 deletions

View File

@ -32,11 +32,11 @@
type="java.lang.String" type="java.lang.String"
override="false"/> override="false"/>
<environment <!--<environment
name="lifeTime" name="lifeTime"
value="120" value="120"
type="java.lang.Integer" type="java.lang.Integer"
override="false" /> override="false" /> -->
<resource name="publicationProfile" type="org.gcube.common.core.state.GCUBEPublicationProfile"> <resource name="publicationProfile" type="org.gcube.common.core.state.GCUBEPublicationProfile">
<resourceParams> <resourceParams>

View File

@ -64,11 +64,9 @@ public class ProfileResource extends GCUBEWSResource {
StringWriter writer =new StringWriter(); StringWriter writer =new StringWriter();
try { try {
resource.store(writer); resource.store(writer);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder(); DocumentBuilder builder = factory.newDocumentBuilder();
StringReader reader = new StringReader(writer.toString().substring(writer.toString().indexOf("?>")+2, writer.toString().length())); StringReader reader = new StringReader(writer.toString().substring(writer.toString().indexOf("?>")+2, writer.toString().length()));
InputSource source = new InputSource(reader); InputSource source = new InputSource(reader);
dom =builder.parse(source); dom =builder.parse(source);
@ -106,7 +104,7 @@ public class ProfileResource extends GCUBEWSResource {
public void setNotificationProfile(Document profile) { public void setNotificationProfile(Document profile) {
this.getResourcePropertySet().get(NotificationProfileRP).clear(); this.getResourcePropertySet().get(NotificationProfileRP).clear();
this.getResourcePropertySet().get(NotificationProfileRP).add(profile); this.getResourcePropertySet().get(NotificationProfileRP).add(profile);
this.getPersistenceDelegate().store(this); //this.getPersistenceDelegate().store(this);
} }
public Document getNotificationProfile() { public Document getNotificationProfile() {
@ -118,7 +116,7 @@ public class ProfileResource extends GCUBEWSResource {
public void setProfile(Document profile) { public void setProfile(Document profile) {
this.getResourcePropertySet().get(ProfileRP).clear(); this.getResourcePropertySet().get(ProfileRP).clear();
this.getResourcePropertySet().get(ProfileRP).add(profile); this.getResourcePropertySet().get(ProfileRP).add(profile);
this.getPersistenceDelegate().store(this); //this.getPersistenceDelegate().store(this);
} }
public Document getProfile() { public Document getProfile() {
@ -128,7 +126,7 @@ public class ProfileResource extends GCUBEWSResource {
/** /**
* Check if the profile has to live or not * Checks if the profile has to live or not
* return true/false * return true/false
*/ */
private boolean hasToLive(GCUBEResource resource) { private boolean hasToLive(GCUBEResource resource) {
@ -139,8 +137,8 @@ public class ProfileResource extends GCUBEWSResource {
} }
/** /**
* Get the Resource Qname * Gets the Resource QName
* @return the Resource Qname * @return the Resource QName
*/ */
private QName generateQName() { private QName generateQName() {
return QName.valueOf(NotificationProfileRP.toString()+"_"+this.getID()); return QName.valueOf(NotificationProfileRP.toString()+"_"+this.getID());
@ -205,14 +203,13 @@ public class ProfileResource extends GCUBEWSResource {
StringReader reader = new StringReader(writer.toString()); StringReader reader = new StringReader(writer.toString());
InputSource source = new InputSource(reader); InputSource source = new InputSource(reader);
Document dom = builder.parse(source); Document dom = builder.parse(source);
this.setProfile(dom); this.setProfile(dom);
this.setGCubeResource(resource); this.setGCubeResource(resource);
// updates the notification profile too
if (this.hasToLive(resource)) if (this.hasToLive(resource))
this.setNotificationProfile(dom); this.setNotificationProfile(dom);
this.getPersistenceDelegate().store(this);
} }

View File

@ -47,7 +47,6 @@ import org.gcube.informationsystem.registry.stubs.UpdateResourceResponse;
import org.gcube.informationsystem.registry.stubs.UpdateScopeInProfileMessage; import org.gcube.informationsystem.registry.stubs.UpdateScopeInProfileMessage;
import org.gcube.informationsystem.registry.stubs.UpdateStateMessage; import org.gcube.informationsystem.registry.stubs.UpdateStateMessage;
import org.gcube.informationsystem.registry.stubs.service.RegistryServiceAddressingLocator; import org.gcube.informationsystem.registry.stubs.service.RegistryServiceAddressingLocator;
import org.globus.wsrf.ResourceKey;
import org.globus.wsrf.security.SecurityManager; import org.globus.wsrf.security.SecurityManager;
import org.oasis.wsrf.lifetime.Destroy; import org.oasis.wsrf.lifetime.Destroy;
@ -187,7 +186,8 @@ public class RegistryFactory extends GCUBEStartupPortType{
//try to create resource //try to create resource
try { try {
logger.debug("Creating the stateful resource for " + resource.getID()); logger.debug("Creating the stateful resource for " + resource.getID());
ProfileContext.getContext().getWSHome().create(ProfileContext.getContext().makeKey(resource.getID()),resource); ProfileResource presource = (ProfileResource) ProfileContext.getContext().getWSHome().create(ProfileContext.getContext().makeKey(resource.getID()),resource);
presource.getPersistenceDelegate().store(presource);
} }
catch (Exception ex) { catch (Exception ex) {
String msg = "Error creating Resource"; String msg = "Error creating Resource";
@ -208,16 +208,15 @@ public class RegistryFactory extends GCUBEStartupPortType{
} catch (Exception e) { } catch (Exception e) {
logger.error("Persistence failed for " + resource.getID(), e); logger.error("Persistence failed for " + resource.getID(), e);
} }
logger.info("Profile created: " + writer.toString()); logger.info("Profile " + resource.getID() + " created ");
return writer.toString(); return writer.toString();
} }
/** /**
* Updates Resource Profiles ( in case of an update of an ID not present it simply calls the Create resource method) * Updates Resource Profiles (in case of an update of an ID not present it invokes calls the Create resource operation)
* *
* * @param mess Complex Object that contains a String representing the XML profile to update and the diligentID
* @param mess Complex Object that contains a String representing the xml profile to update and the diligentID
* @return UpdateResourceResponse * @return UpdateResourceResponse
* @throws RemoteException Exception * @throws RemoteException Exception
* @throws SchemaValidationException Exception * @throws SchemaValidationException Exception
@ -263,12 +262,12 @@ public class RegistryFactory extends GCUBEStartupPortType{
logger.error("Error updating Counting info for resource with ID " + resource.getID()); logger.error("Error updating Counting info for resource with ID " + resource.getID());
e.printStackTrace(); e.printStackTrace();
} }
logger.info("Profile updated: " + mess.getXmlProfile()); logger.info("Profile " + mess.getUniqueID() + " updated");
return new UpdateResourceResponse(); return new UpdateResourceResponse();
} }
/** /**
* Remove a Resource profile given the ID * Removes a Resource profile identified by the given the resource ID
* *
* *
* @param inputMessage Defined into WSDL file * @param inputMessage Defined into WSDL file
@ -357,21 +356,19 @@ public class RegistryFactory extends GCUBEStartupPortType{
} }
/** /**
* Check if the Resource has been created * Checks if the Resource has been created
* *
* @param id the Resource ID * @param id the Resource ID
* @return the resource ( null if the resource has not been created yet * @return the resource ( null if the resource has not been created yet
*/ */
protected synchronized ProfileResource getProfileResource(String id ){ protected synchronized ProfileResource getProfileResource(String id ){
ProfileResource resource = null;
try { try {
resource = (ProfileResource) ProfileContext.getContext().getWSHome().find(ProfileContext.getContext().makeKey(id)); return (ProfileResource) ProfileContext.getContext().getWSHome().find(ProfileContext.getContext().makeKey(id));
} }
catch (Exception e ){ catch (Exception e ){
logger.debug("A profile with the given id has not been created yet"); logger.debug("A profile with the given id has not been created yet");
return null;
} }
return resource; return null;
} }