Fixing some backward compatibility problems with profiles registered via AF
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Collector@30238 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
f182095fef
commit
7ca1e0dfc4
|
@ -8,7 +8,9 @@ import org.gcube.common.core.utils.logging.GCUBELog;
|
|||
import org.gcube.informationsystem.collector.impl.state.AggregatorRegisteredResource;
|
||||
import org.gcube.informationsystem.collector.impl.utils.*;
|
||||
import org.gcube.informationsystem.collector.impl.xmlstorage.exist.State;
|
||||
import org.gcube.informationsystem.collector.impl.resources.BaseDAIXResource;
|
||||
import org.gcube.informationsystem.collector.impl.resources.GCUBEInstanceStateResource;
|
||||
import org.gcube.informationsystem.collector.impl.resources.GCUBEProfileResource;
|
||||
import org.gcube.informationsystem.collector.impl.resources.GCUBEXMLResource;
|
||||
import org.globus.mds.aggregator.impl.AggregatorServiceGroupResource;
|
||||
import org.globus.mds.aggregator.impl.AggregatorServiceGroupEntryResource;
|
||||
|
@ -178,13 +180,23 @@ public class AggregatorRegisteredResource extends AggregatorServiceGroupResource
|
|||
|
||||
// Build the new resource to store
|
||||
logger.debug("Storing the new delivered resource");
|
||||
BaseDAIXResource resource;
|
||||
if (entryparser.getType().compareToIgnoreCase(GCUBEProfileResource.TYPE) == 0) {
|
||||
//TODO: this will be removed after all the gHNs have the ISPublisher 2.0 installed
|
||||
// and all the profiles arrive via the XMLCollectionAccess PT
|
||||
resource = new GCUBEProfileResource();
|
||||
String profile = aentry.getProfile();
|
||||
//logger.debug("Received profile: " + profile);
|
||||
resource.setResourceName(Identifier.buildProfileID(profile));
|
||||
resource.setContent(profile);
|
||||
} else {
|
||||
resource = new GCUBEInstanceStateResource();
|
||||
resource.setResourceName(Identifier.buildInstanceStateID(entryparser));
|
||||
resource.setContent(aentry.getEntryAsString());
|
||||
}
|
||||
|
||||
//TODO: check if it's a profile or an RP, by relying on the publisher (registry or not)
|
||||
|
||||
GCUBEInstanceStateResource instanceState = new GCUBEInstanceStateResource();
|
||||
instanceState.setResourceName(Identifier.buildInstanceStateID(entryparser));
|
||||
instanceState.setContent(aentry.getEntryAsString());
|
||||
GCUBEXMLResource res = new GCUBEXMLResource(instanceState);
|
||||
GCUBEXMLResource res = new GCUBEXMLResource(resource);
|
||||
res.setEntryKey(sinkparser.getEntryKey());
|
||||
res.setGroupKey(sinkparser.getGroupKey());
|
||||
res.setTerminationTime(entry.getTerminationTime());
|
||||
|
|
|
@ -16,6 +16,12 @@ public class EntryParser {
|
|||
|
||||
private AggregatorServiceGroupEntryResource entry = null;
|
||||
|
||||
private static final String registryNS = "gcube/informationsystem/registry/Registry";
|
||||
|
||||
public enum RESOURCETYPE {
|
||||
Profile, Properties
|
||||
}
|
||||
|
||||
public EntryParser(AggregatorServiceGroupEntryResource entry) {
|
||||
this.entry = entry;
|
||||
}
|
||||
|
@ -83,17 +89,17 @@ public class EntryParser {
|
|||
|
||||
/**
|
||||
*
|
||||
* @return the {@link RESOURCETYPE}
|
||||
* @return the type of the resource (Profile or Properties)
|
||||
*/
|
||||
/* public RESOURCETYPE getType() {
|
||||
public String getType() {
|
||||
EndpointReferenceType memberEpr = entry.getMemberEPR();
|
||||
if (memberEpr.getAddress().toString().endsWith(registryNS)) {
|
||||
return RESOURCETYPE.Profile;
|
||||
return "Profile";
|
||||
} else {
|
||||
return RESOURCETYPE.Properties;
|
||||
return "Properties";
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
public void getRPSet() {
|
||||
// get RP set from entry
|
||||
// ResourcePropertySet rpSet = entry.getResourcePropertySet();
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
package org.gcube.informationsystem.collector.impl.utils;
|
||||
|
||||
import java.io.StringReader;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.xpath.XPath;
|
||||
import javax.xml.xpath.XPathFactory;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
/**
|
||||
*
|
||||
* Build instance state identifiers
|
||||
|
@ -27,4 +37,28 @@ public class Identifier {
|
|||
public static String buildInstanceStateID(String source, String id) {
|
||||
return source.replace("http://", "").replace(":", "").replace("/", "-") + "-" + id.replace("http://", "").replace(":", "").replace("/", "-");
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a profile ID starting from the message (a string serialization of the profile)
|
||||
* @param message the message
|
||||
* @return the ID of the profile
|
||||
* @throws Exception if the profile is not well-formed
|
||||
*/
|
||||
public static String buildProfileID(String message) throws Exception {
|
||||
Document internalDOM;
|
||||
try {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
StringReader reader = new StringReader(message);
|
||||
InputSource source = new InputSource(reader);
|
||||
internalDOM = builder.parse(source);
|
||||
XPath path = XPathFactory.newInstance().newXPath();
|
||||
// uses the GCUBEResource ID as local resource ID
|
||||
return path.evaluate("/Resource/ID", internalDOM);
|
||||
} catch (Exception e) {
|
||||
throw new Exception("Unable to extract the ID from the resource " + e.getMessage());
|
||||
} finally {
|
||||
internalDOM = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,10 @@ import javax.xml.parsers.*;
|
|||
import javax.xml.xpath.*;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.OutputKeys;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
@ -86,31 +89,15 @@ public class MsgParser {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the entry type if the entry is a profile
|
||||
* Returns the Scope Name included in the entry
|
||||
*
|
||||
* @throws Exception
|
||||
*
|
||||
* @return the entry type
|
||||
* @return the Scope name
|
||||
*/
|
||||
public String getResourceType() throws Exception {
|
||||
public String getScopeName() throws Exception {
|
||||
|
||||
if (this.type.equalsIgnoreCase("Profile")) {
|
||||
logger.warn("The entry does not have a ResourceType");
|
||||
throw new Exception("Invalid resource (type = Properties)");
|
||||
}
|
||||
return this.getGCUBEProperty("DILIGENTResourceType");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the VO Name included in the entry
|
||||
*
|
||||
* @throws Exception
|
||||
*
|
||||
* @return the VO name
|
||||
*/
|
||||
public String getVOName() throws Exception {
|
||||
|
||||
return this.getGCUBEProperty("VO");
|
||||
return this.getGCUBEProperty("Scope");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -168,11 +155,31 @@ public class MsgParser {
|
|||
*
|
||||
* @return the DHN ID
|
||||
*/
|
||||
public String getDHNID() throws Exception {
|
||||
public String getGHNID() throws Exception {
|
||||
|
||||
return this.getGCUBEProperty("GHN");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the profile, it any
|
||||
* @throws Exception
|
||||
*/
|
||||
public String getProfile() throws Exception {
|
||||
try {
|
||||
TransformerFactory transFactory = TransformerFactory.newInstance();
|
||||
Transformer transformer = transFactory.newTransformer();
|
||||
StringWriter buffer = new StringWriter();
|
||||
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||
transformer.transform(new DOMSource(this.internalDOM.getElementsByTagName("Resource").item(0)), new StreamResult(buffer));
|
||||
return buffer.toString();
|
||||
} catch (Exception e) {
|
||||
throw new Exception("Unable to deserialise content data");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads a GCUBE Property
|
||||
*
|
||||
|
@ -182,17 +189,14 @@ public class MsgParser {
|
|||
*/
|
||||
private String getGCUBEProperty(String propName) throws Exception {
|
||||
|
||||
String value = null;
|
||||
|
||||
try {
|
||||
value = path.evaluate("//" + rootElement
|
||||
return path.evaluate("//" + rootElement
|
||||
+ "/child::*[local-name() = '" + propName + "']",
|
||||
internalDOM);
|
||||
} catch (XPathExpressionException xpee) {
|
||||
logger.error("", xpee);
|
||||
throw new Exception("XPath evaluation error");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue