From 75305c41697c6630c0aa7bdfd7eb6801cdf46376 Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Mon, 25 Oct 2010 03:15:43 +0000 Subject: [PATCH] Adding new XMLCollectionAccess interface (WS-DAIX compliant), comprehensive reorganization of the internal hierarchy of resources was needed, XMLStorage interface to eXist was remodeled git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Collector@30018 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 2 + build.xml | 93 ++- changelog.xml | 4 + etc/build.properties | 23 +- etc/deploy-jndi-config.xml | 34 +- etc/deploy-server.wsdd | 47 +- etc/profile.xml | 17 +- schema/XMLCollectionAccess.wsdl | 221 ------ schema/previous/DISICService.wsdl | 136 ---- schema/wsdaix/XMLCollectionAccessPT.wsdl | 730 ++++++++++++++++++ schema/wsdaix/types/ws-addressing-0805.xsd | 145 ++++ schema/wsdaix/types/wsdai_core_types.xsd | 219 ++++++ .../types/wsdaix_xmlcollection_types.xsd | 70 ++ schema/wsdaix/wsdai_core_porttypes.wsdl | 319 ++++++++ .../AggregatorPersistentResource.java | 571 -------------- .../impl/persistence/PersistentResource.java | 109 --- .../collector/impl/porttypes/OldService.java | 253 ------ .../collector/impl/porttypes/Sink.java | 3 +- .../impl/porttypes/XMLCollectionAccess.java | 224 ------ .../impl/porttypes/XQueryAccess.java | 2 +- .../porttypes/wsdaix/XMLCollectionAccess.java | 391 ++++++++++ .../impl/resources/BaseDAIXResource.java | 173 +++++ .../impl/resources/DAIXResource.java | 52 ++ .../resources/GCUBEInstanceStateResource.java | 43 ++ .../impl/resources/GCUBEProfileResource.java | 58 ++ .../impl/resources/GCUBEXMLResource.java | 446 +++++++++++ .../state/AggregatorRegisteredResource.java | 22 +- .../state/ICAggregatorRemoveCallback.java | 11 +- .../collector/impl/utils/EntryParser.java | 5 +- .../collector/impl/utils/Identifier.java | 30 + .../collector/impl/utils/MetadataReader.java | 53 ++ .../collector/impl/utils/MsgParser.java | 34 +- .../impl/xmlstorage/exist/DataManager.java | 5 +- .../impl/xmlstorage/exist/QueryManager.java | 2 +- .../impl/xmlstorage/exist/State.java | 24 +- .../impl/xmlstorage/exist/Sweeper.java | 31 +- ...XMLStorageManager.java => XMLStorage.java} | 253 +++--- .../testsuite/wsdaix/AddDocumentsTester.java | 152 ++++ .../wsdaix/RemoveDocumentsTester.java | 13 + .../stubs/testsuite/wsdaix/TestDocuments.java | 39 + .../testsuite/wsdaix/metadataCollection.xml | 31 + .../xmlcollectionaccess/GetProfileTester.java | 60 -- .../GetResourceTester.java | 61 -- .../test/GCUBEInstanceStateResourceTest.java | 72 ++ .../test/GCUBEProfileResourceTest.java | 121 +++ .../collector/test/GCUBEXMLResourceTest.java | 160 ++++ .../collector/test/MetadataReaderTest.java | 77 ++ .../collector/test/XMLStorageManagerTest.java | 165 ++++ 48 files changed, 3857 insertions(+), 1949 deletions(-) delete mode 100755 schema/XMLCollectionAccess.wsdl delete mode 100755 schema/previous/DISICService.wsdl create mode 100644 schema/wsdaix/XMLCollectionAccessPT.wsdl create mode 100644 schema/wsdaix/types/ws-addressing-0805.xsd create mode 100644 schema/wsdaix/types/wsdai_core_types.xsd create mode 100644 schema/wsdaix/types/wsdaix_xmlcollection_types.xsd create mode 100644 schema/wsdaix/wsdai_core_porttypes.wsdl delete mode 100755 src/org/gcube/informationsystem/collector/impl/persistence/AggregatorPersistentResource.java delete mode 100644 src/org/gcube/informationsystem/collector/impl/persistence/PersistentResource.java delete mode 100644 src/org/gcube/informationsystem/collector/impl/porttypes/OldService.java delete mode 100755 src/org/gcube/informationsystem/collector/impl/porttypes/XMLCollectionAccess.java create mode 100644 src/org/gcube/informationsystem/collector/impl/porttypes/wsdaix/XMLCollectionAccess.java create mode 100644 src/org/gcube/informationsystem/collector/impl/resources/BaseDAIXResource.java create mode 100644 src/org/gcube/informationsystem/collector/impl/resources/DAIXResource.java create mode 100644 src/org/gcube/informationsystem/collector/impl/resources/GCUBEInstanceStateResource.java create mode 100644 src/org/gcube/informationsystem/collector/impl/resources/GCUBEProfileResource.java create mode 100644 src/org/gcube/informationsystem/collector/impl/resources/GCUBEXMLResource.java create mode 100644 src/org/gcube/informationsystem/collector/impl/utils/Identifier.java create mode 100644 src/org/gcube/informationsystem/collector/impl/utils/MetadataReader.java rename src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/{XMLStorageManager.java => XMLStorage.java} (70%) create mode 100644 src/org/gcube/informationsystem/collector/stubs/testsuite/wsdaix/AddDocumentsTester.java create mode 100644 src/org/gcube/informationsystem/collector/stubs/testsuite/wsdaix/RemoveDocumentsTester.java create mode 100644 src/org/gcube/informationsystem/collector/stubs/testsuite/wsdaix/TestDocuments.java create mode 100644 src/org/gcube/informationsystem/collector/stubs/testsuite/wsdaix/metadataCollection.xml delete mode 100644 src/org/gcube/informationsystem/collector/stubs/testsuite/xmlcollectionaccess/GetProfileTester.java delete mode 100644 src/org/gcube/informationsystem/collector/stubs/testsuite/xmlcollectionaccess/GetResourceTester.java create mode 100644 src/org/gcube/informationsystem/collector/test/GCUBEInstanceStateResourceTest.java create mode 100644 src/org/gcube/informationsystem/collector/test/GCUBEProfileResourceTest.java create mode 100644 src/org/gcube/informationsystem/collector/test/GCUBEXMLResourceTest.java create mode 100644 src/org/gcube/informationsystem/collector/test/MetadataReaderTest.java create mode 100644 src/org/gcube/informationsystem/collector/test/XMLStorageManagerTest.java diff --git a/.classpath b/.classpath index 77458fa..543fb7f 100644 --- a/.classpath +++ b/.classpath @@ -7,5 +7,7 @@ + + diff --git a/build.xml b/build.xml index e9680b4..8bcc08c 100755 --- a/build.xml +++ b/build.xml @@ -91,7 +91,8 @@ full.stubs: (optional) Set to 'false', it excludes auxiliary stub code plac - + + @@ -164,6 +165,7 @@ full.stubs: (optional) Set to 'false', it excludes auxiliary stub code plac + @@ -171,23 +173,6 @@ full.stubs: (optional) Set to 'false', it excludes auxiliary stub code plac - - - - - - - - - - - - - - - - - - - + + @@ -382,7 +358,23 @@ full.stubs: (optional) Set to 'false', it excludes auxiliary stub code plac - + + + + + + + + + + + + + + + + + @@ -411,7 +403,8 @@ full.stubs: (optional) Set to 'false', it excludes auxiliary stub code plac - + + diff --git a/changelog.xml b/changelog.xml index 638ba9d..c4749ce 100644 --- a/changelog.xml +++ b/changelog.xml @@ -1,4 +1,8 @@ + + WSDAI::XMLCollectionAccess interface + internal refactoring of resources + GetProfileLastModificationTimeMs and GetResourceLastModificationTimeMs operations diff --git a/etc/build.properties b/etc/build.properties index 2eac27c..74c96fe 100755 --- a/etc/build.properties +++ b/etc/build.properties @@ -1,18 +1,19 @@ package = org.gcube.informationsystem.collector -previous-package = org.diligentproject.informationservice.disic +package.6 = wsdai +package.7 = wsdaix lib.dir = Dependencies/ISCollector -wsdl.1 = XMLCollectionAccess -wsdl.2 = Sink_service -wsdl.3 = SinkEntry_service -wsdl.4 = DISICService -wsdl.5 = XQueryAccess -wsdl.6 = XMLStorageAccess +wsdl.1 = Sink_service +wsdl.2 = SinkEntry_service +wsdl.4 = XQueryAccess +wsdl.5 = XMLStorageAccess +wsdl.6 = XMLCollectionAccessPT namespace.1=http://gcube-system.org/namespaces/informationsystem/collector namespace.2=http://gcube-system.org/namespaces/informationsystem/collector/Sink namespace.3=http://mds.globus.org/index/2004/07/12 -namespace.4=http://gcube-system.org/namespaces/informationsystem/collector/XMLCollectionAccess -namespace.5=http://gcube-system.org/namespaces/informationsystem/collector/XQueryAccess -namespace.6=http://gcube-system.org/namespaces/informationsystem/collector/XMLStorageAccess -previous.namespace.1=http://diligentproject.org/namespaces/informationservice/disic/DISICService +namespace.4=http://gcube-system.org/namespaces/informationsystem/collector/XQueryAccess +namespace.5=http://gcube-system.org/namespaces/informationsystem/collector/XMLStorageAccess +namespace.6=http://www.ggf.org/namespaces/2005/12/WS-DAI +namespace.7=http://www.ggf.org/namespaces/2005/12/WS-DAIX + diff --git a/etc/deploy-jndi-config.xml b/etc/deploy-jndi-config.xml index b356bc7..cf11c89 100755 --- a/etc/deploy-jndi-config.xml +++ b/etc/deploy-jndi-config.xml @@ -76,8 +76,7 @@ - - + - - - - - - - - - - factory - - - org.globus.wsrf.jndi.BeanFactory - - - - resourceClass - org.gcube.informationsystem.collector.impl.state.AggregatorRegisteredResource - - - - - - - - diff --git a/etc/deploy-server.wsdd b/etc/deploy-server.wsdd index 542f1be..1094aff 100755 --- a/etc/deploy-server.wsdd +++ b/etc/deploy-server.wsdd @@ -5,16 +5,17 @@ xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> - - + + + - + - share/schema/org.gcube.informationsystem.collector/XMLCollectionAccess_service.wsdl + share/schema/org.gcube.informationsystem.collector/wsdaix/XMLCollectionAccessPT_service.wsdl - + @@ -23,7 +24,7 @@ share/schema/org.gcube.informationsystem.collector/XMLStorageAccess_service.wsdl - + @@ -68,38 +69,4 @@ - - - - - - - - - share/schema/org.gcube.informationsystem.collector/previous/DISICService_service.wsdl - - - - - - - - - - share/schema/org.gcube.informationsystem.collector/Sink_service.wsdl - - - diff --git a/etc/profile.xml b/etc/profile.xml index 2173788..dbc3cad 100644 --- a/etc/profile.xml +++ b/etc/profile.xml @@ -16,11 +16,9 @@ -->
- Information Collector service: it acts at an aggregator - sink by collecting and exposing the information published by the - registered gCube services + Information Collector service: aggregate and make available information published by gCube services IS-Collector-service - 2.2.0 + 3.0.0 @@ -29,7 +27,7 @@ 1.0.0 IS-Collector-stubs - [2.2.0] + [3.0.0] false @@ -62,6 +60,11 @@ + + gcube/informationsystem/collector/wsdaix/XMLCollectionAccess + + + gcube/informationsystem/collector/XQueryAccess @@ -76,7 +79,7 @@ InformationCollector Stubs IS-Collector-stubs - 2.2.0 + 3.0.0 @@ -88,7 +91,7 @@ Test-suite for IS-Collector: provide sample usages of interaction with a IS-Collector instance IS-Collector-test-suite - 2.2.0 + 3.0.0 application diff --git a/schema/XMLCollectionAccess.wsdl b/schema/XMLCollectionAccess.wsdl deleted file mode 100755 index 159c7df..0000000 --- a/schema/XMLCollectionAccess.wsdl +++ /dev/null @@ -1,221 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/schema/previous/DISICService.wsdl b/schema/previous/DISICService.wsdl deleted file mode 100755 index 52ab8dc..0000000 --- a/schema/previous/DISICService.wsdl +++ /dev/null @@ -1,136 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/schema/wsdaix/XMLCollectionAccessPT.wsdl b/schema/wsdaix/XMLCollectionAccessPT.wsdl new file mode 100644 index 0000000..814bf12 --- /dev/null +++ b/schema/wsdaix/XMLCollectionAccessPT.wsdl @@ -0,0 +1,730 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/schema/wsdaix/types/ws-addressing-0805.xsd b/schema/wsdaix/types/ws-addressing-0805.xsd new file mode 100644 index 0000000..d0ac7c7 --- /dev/null +++ b/schema/wsdaix/types/ws-addressing-0805.xsd @@ -0,0 +1,145 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/schema/wsdaix/types/wsdai_core_types.xsd b/schema/wsdaix/types/wsdai_core_types.xsd new file mode 100644 index 0000000..aaa9b2e --- /dev/null +++ b/schema/wsdaix/types/wsdai_core_types.xsd @@ -0,0 +1,219 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/schema/wsdaix/types/wsdaix_xmlcollection_types.xsd b/schema/wsdaix/types/wsdaix_xmlcollection_types.xsd new file mode 100644 index 0000000..a4d94f2 --- /dev/null +++ b/schema/wsdaix/types/wsdaix_xmlcollection_types.xsd @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/schema/wsdaix/wsdai_core_porttypes.wsdl b/schema/wsdaix/wsdai_core_porttypes.wsdl new file mode 100644 index 0000000..6475492 --- /dev/null +++ b/schema/wsdaix/wsdai_core_porttypes.wsdl @@ -0,0 +1,319 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/org/gcube/informationsystem/collector/impl/persistence/AggregatorPersistentResource.java b/src/org/gcube/informationsystem/collector/impl/persistence/AggregatorPersistentResource.java deleted file mode 100755 index d751e93..0000000 --- a/src/org/gcube/informationsystem/collector/impl/persistence/AggregatorPersistentResource.java +++ /dev/null @@ -1,571 +0,0 @@ -package org.gcube.informationsystem.collector.impl.persistence; - -import org.gcube.common.core.utils.logging.GCUBELog; -import org.gcube.informationsystem.collector.impl.persistence.AggregatorPersistentResource; - -import org.xmldb.api.modules.XMLResource; -import org.xmldb.api.base.XMLDBException; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.StringReader; -import java.io.StringWriter; -import java.util.Calendar; -import java.util.GregorianCalendar; -import java.util.TimeZone; - -import java.lang.Exception; - -import org.w3c.dom.*; - -import org.xml.sax.InputSource; - -import javax.xml.parsers.*; -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 javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; -import javax.xml.xpath.*; - -/** - * AggregatorPersistentResource represents a resource in the XML Storage - * repository - * - * @author Manuele Simi (ISTI-CNR) - * - */ - -public class AggregatorPersistentResource extends PersistentResource { - - private String resourceID = null; - - private String resource_string = null; - - // the resource type states if the resource contains a profile or generic - // WS-ResourceProperties - private RESOURCETYPE type = null; - - // the profile type states which kind of profiles the resource contains - // (RunningInstance, Service, etc.) - private String profile_type = null; - - // the various parts of the resource - private String data = null, entryKey, groupKey, source, sourceKey = "", completeSourceKey = ""; - - private Calendar terminationTime = null, lastUpdateTime = null; - - private static GCUBELog logger = new GCUBELog(AggregatorPersistentResource.class); - - // the source XMLResource (if any) - private XMLResource originalSource = null; - - // the XML DOM loaded from the resource string - private Document internalDOM = null; - - // xpath factory to evaluate Xpath expressions - private XPath path = XPathFactory.newInstance().newXPath(); - - /** - * Builds a new empty DISPersinstentresource - * @param key - * @param source - * @throws Exception if it was impossible to extract the ID from the resource - * - */ - public AggregatorPersistentResource(String source, String key, String data, RESOURCETYPE type) throws Exception { - - // defatult termination time is now - Calendar cal = new GregorianCalendar(); - cal.setTimeZone(TimeZone.getTimeZone("GMT")); - this.setTerminationTime(cal); - this.source = source; - this.sourceKey = key; - this.data = data; - this.type = type; - lastUpdateTime = new GregorianCalendar(); - lastUpdateTime.setTimeZone(TimeZone.getTimeZone("GMT")); - this.buildID(); - logger.debug("Resource ID: " + this.resourceID); - } - - - /** - * Builds a DISPersinstentresource starting from an eXist resource - * - * @param resource - * the input eXist resource - * @throws Exception - * if the resource is invalid - */ - public AggregatorPersistentResource(XMLResource resource) throws Exception { - if (resource == null) - throw new Exception("invalid resource"); - try { - this.resourceID = resource.getId(); - this.originalSource = resource; - this.resource_string = resource.getContent().toString(); - this.parseResource(); - logger.debug("Resource ID: " + this.resourceID); - } catch (XMLDBException dbe) { - throw new Exception("invalid resource"); - } - } - - private void buildID() throws Exception { - if ((this.type != null) && (type == RESOURCETYPE.Profile)) { //it's a gCube profile - try { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - StringReader reader = new StringReader(this.toXML()); - InputSource source = new InputSource(reader); - Document internalDOM = builder.parse(source); - // gets the type - XPath path = XPathFactory.newInstance().newXPath(); - this.profile_type = path.evaluate("/Document/Data/child::*[local-name()='Profile']/Resource/Type", internalDOM); - // uses the GCUBEResource ID as local resource ID - this.resourceID = path.evaluate("/Document/Data/child::*[local-name()='Profile']/Resource/ID", internalDOM); - - } catch (Exception e) { - logger.error("Unable to extract the ID from the resource " + e.getMessage()); - throw e; - - } - } else { //it's a RP doc - //we need to replace the schema and colons in order to make it an ID accepted by eXist - this.resourceID = this.source.replace("http://", "").replace(":", "").replace("/", "-") + "-" + this.sourceKey.replace("http://", "").replace(":", "").replace("/", "-"); - } - } - /** - * Sets the content of the resource - * - * @param data the new content - */ - public void setData(String data) { - this.data = data; - } - - /** - * Sets the content of the resource using the content of a file - * - * @param f the file to use as content source - * - * @throws IOException if the access to the given file fails - * - */ - public void setData(File f) throws IOException { - try { - FileInputStream fin = new FileInputStream(f); - this.data = fin.toString(); - } catch (IOException ioe) { - logger.error("Unable to set content from file " + f.getAbsolutePath()); - throw ioe; - } - } - - /** - * Accesses the resource content - * - * @return the content - * @throws MalformedResourceException - */ - public String getData() throws MalformedResourceException { - if (this.data == null) - this.data = this.extractData(); - return this.data; - } - - /** - * @return - * @throws MalformedResourceException - */ - private String extractData() throws MalformedResourceException { - - if (this.internalDOM != null) { - try { - if (this.getType() == RESOURCETYPE.Profile) - return nodeToString(internalDOM.getElementsByTagName("Resource").item(0)); //Data/Profile/Resource - else - return nodeToString(internalDOM.getElementsByTagName("Data").item(0)); //Data/* - } catch (Exception e) { - logger.error("",e); - throw new MalformedResourceException("unable to retrieve data for resource " + this.getID()); - } - } else - throw new MalformedResourceException("unable to retrieve data for resource " + this.getID()); - } - - - /** - * - * @return the original XMLResource from which the resource has been - * generated (if any) - */ - public XMLResource getOriginalXMLResource() { - return this.originalSource; - } - - /** - * Accesses the resource ID - * - * @return the ID - */ - public String getID() { - return this.resourceID; - } - - /** - * Accesses the source GroupKey - * - * @return the ID - */ - public String getGroupKey() { - return this.groupKey; - } - - /** - * Sets the source GroupKey - * - * @param groupKey - * the new group key - * - */ - public void setGroupKey(String groupKey) { - this.groupKey = groupKey; - } - - /** - * Accesses the source EntryKey - * - * @return the ID - */ - public String getEntryKey() { - return this.entryKey; - } - - /** - * Sets the source EntryKey - * - * @param entryKey - * the new entry key - */ - public void setEntryKey(String entryKey) { - this.entryKey = entryKey; - } - - /** - * Sets the source address of the RI that publishes resource as reported in - * the servicegroup entry - * - * @param source - * the new source address - */ - public void setSource(String source) { - this.source = source; - } - - /** - * Accesses the source address of the service that published the data - * - * @return the source - */ - public String getSource() { - return this.source; - } - - /** - * Sets the key of the WS-Resource that published the data - * - * @param key - * the new source key - */ - public void setSourceKey(String key) { - this.sourceKey = key; - } - - /** - * Gets the key of the WS-Resource that published the data - * - * @return the key - */ - public String getSourceKey() { - return this.sourceKey; - } - - /** - * Sets the complete source key - * - * @param completeKey the new complete key - */ - public void setCompleteSourceKey(String completeKey) { - this.completeSourceKey = completeKey; - } - - /** - * Gets the complete source key - * - * @return the complete source key - */ - public String getCompleteSourceKey() { - return this.completeSourceKey; - } - - /** - * Sets the resource type. The actual implementation supports "Profile" and - * "Properties" as type - * - * @param type - * "Profile" or "Properties" - */ - - public void setType(RESOURCETYPE type) { - this.type = type; - } - - /** - * Accesses the resource type. The actual implementation supports "Profile" - * and "Properties" as type - * - * @return the type - */ - public RESOURCETYPE getType() { - if (this.type == null) - this.type = this.extractType(); - return this.type; - } - - /** - * @return - */ - private RESOURCETYPE extractType() { - if (internalDOM.getElementsByTagName("Resource").getLength() > 0) { - logger.trace("The resource is a profile"); - return RESOURCETYPE.Profile; - } - else { - logger.trace("The resource is a RP"); - return RESOURCETYPE.Properties; - } - - } - - - /** - * Updates the resource body - * - * @param data - * the new body - * - */ - public void updateData(String data) { - this.data = data; - } - - /** - * Builds a XML representation of the resource - * - * @return a String in the form of <Document>... <Data> resource - * content </Data> </Document> - */ - private String toXML() { - - StringBuilder resource = new StringBuilder("\n"); - resource.append("" + this.getID() + "\n"); - resource.append("" + this.getSource() + "\n"); - resource.append("" + this.getSourceKey() + "\n"); - resource.append("" + this.getCompleteSourceKey() + "\n"); - resource.append("" + this.getEntryKey() + "\n"); - resource.append("" + this.getGroupKey() + "\n"); - resource.append(""+ this.getTerminationTime().getTimeInMillis()+ "\n"); - resource.append("" + this.getTerminationTime().getTime().toString()+ "\n"); - resource.append("" + this.lastUpdateTime.getTimeInMillis()+ "\n"); - resource.append("" + this.lastUpdateTime.getTime().toString() + "\n"); - try { - resource.append(this.getData() + "\n"); - } catch (MalformedResourceException e) { - logger.warn("Unable to read the resource data",e); - } - resource.append( "\n"); - return resource.toString(); - } - - /** - * - * @return a String representation of the resource - */ - public String toString() { - if (this.resource_string == null) - return this.toXML(); - else - return this.resource_string; - } - - /** - * Accesses the type of resource to which the profile is related to (if any) - * - * @return null if the resource does not contain a profile - */ - public String getProfileType() { - if (this.profile_type != null) { - // the profile type has been already extracted - return this.profile_type; - } - - if ((this.type != null) && (type == RESOURCETYPE.Profile)) { - try { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - StringReader reader = new StringReader(this.toXML()); - InputSource source = new InputSource(reader); - Document internalDOM = builder.parse(source); - // gets the type - XPath path = XPathFactory.newInstance().newXPath(); - this.profile_type = path.evaluate("/Document/Data/child::*[local-name()='Profile']/Resource/Type", internalDOM); - // uses the GCUBEResource ID as local resource ID - this.resourceID = path.evaluate("/Document/Data/child::*[local-name()='Profile']/Resource/ID", internalDOM); - - } catch (Exception e) { - logger.error("Unable to extract the profile type from the resource " + e.getMessage()); - - } - } - return this.profile_type; - } - - /** - * @return the terminationTime of this resource - */ - public Calendar getTerminationTime() { - return terminationTime; - } - - /** - * @param terminationTime - * the terminationTime to set - */ - public void setTerminationTime(Calendar terminationTime) { - this.terminationTime = (Calendar) terminationTime.clone(); - this.terminationTime.setTimeZone(TimeZone.getTimeZone("GMT")); - } - - /** - * Compares two resources - * - * @param o - * the resource to compare - * @return true if the resources have the same ID - */ - public boolean equals(Object o) { - // check the class this object is instance of - if (!(o instanceof AggregatorPersistentResource)) - return false; - // compare the two objects - AggregatorPersistentResource key = (AggregatorPersistentResource) o; - if (key.getID() == this.getID()) - return true; - else - return false; - } - - /** - * @return the lastUpdateTime in milliseconds - * @throws Exception if an error occurs when accessing the LastUpdateMs field - */ - public long getLastUpdateTimeinMills() throws MalformedResourceException { - - if (lastUpdateTime != null) - return lastUpdateTime.getTimeInMillis(); - - if ((lastUpdateTime == null) && (this.internalDOM != null)) { - String value = ""; - try { - value = path.evaluate("Document/LastUpdateMs", this.internalDOM); - } catch (XPathExpressionException xpee) { - logger.error("" + xpee.getMessage()); - logger.error("" + xpee.getStackTrace()); - throw new MalformedResourceException("XPath evaluation error"); - } - try { - return Long.parseLong(value); - } catch (NumberFormatException nfe) { - logger.error("Invalid last update time format found in resource " + this.getID()); - logger.error("Parsed string was " + value); - throw new MalformedResourceException("Unable to retrieve last update time for resource " + this.getID()); - } - - } else - throw new MalformedResourceException("unable to retrieve last update time for resource " + this.getID()); - - } - - /** - * Loads the XML DOM from the resource string - * - */ - private void parseResource() throws MalformedResourceException { - logger.debug("Parsing resource: " + this.resource_string); - try { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - StringReader reader = new StringReader(this.resource_string); - InputSource source = new InputSource(reader); - this.internalDOM = builder.parse(source); - } catch (Exception e) { - throw new MalformedResourceException(e); - } - - } - - /* - * (non-Javadoc) - * - * @see - * org.gcube.informationsystem.collector.impl.persistence.PersistentResource - * #getPublisher() - */ - @Override - public String getPublisher() { - return null; - } - - - /* - * (non-Javadoc) - * - * @see - * org.gcube.informationsystem.collector.impl.persistence.PersistentResource - * #setPublisher(java.lang.String) - */ - @Override - public void setPublisher(String publisher) { - - } - - /** - * Node to String helper - * @param node the source node - * @return the node content serialized as string - * @throws Exception if the serialization fails - */ - private String nodeToString(Node node) 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(node), new StreamResult(buffer)); - return buffer.toString(); - - } catch (TransformerConfigurationException e) { - logger.error("Unable to deserialise content data", e); - throw new Exception("Unable to deserialise content data"); - } catch (TransformerException e) { - logger.error("Unable to deserialise content data", e); - throw new Exception("Unable to deserialise content data"); - } - - } -} diff --git a/src/org/gcube/informationsystem/collector/impl/persistence/PersistentResource.java b/src/org/gcube/informationsystem/collector/impl/persistence/PersistentResource.java deleted file mode 100644 index 5a6fe18..0000000 --- a/src/org/gcube/informationsystem/collector/impl/persistence/PersistentResource.java +++ /dev/null @@ -1,109 +0,0 @@ -package org.gcube.informationsystem.collector.impl.persistence; - -/** - * A resource handled by the XML repository - * - * @author Manuele Simi (ISTI-CNR) - * - */ -public abstract class PersistentResource { - - public enum RESOURCETYPE { - Profile, Properties - } - - protected String id; - - /** - * Gets the resource ID - * - * @return the ID - */ - public abstract String getID(); - - /** - * @return a String representation of the resource - */ - public abstract String toString(); - - /** - * Gets the resource type. - * - * @return the resource type - */ - public abstract RESOURCETYPE getType(); - - /** - * Gets the resource profile type, if any - * - * @return the resource profile type - * @throws Exception - * if the resource has no profile type (i.e. it is not a - * profile) - */ - public abstract String getProfileType() throws MalformedResourceException; - - /** - * Gets the publisher of the resource - * - * @return the publisher - */ - public abstract String getPublisher(); - - /** - * Sets the resource's publisher - * - * @param publisher - * the publisher - */ - public abstract void setPublisher(String publisher); - - /** - * @return - * @throws Exception - */ - public abstract long getLastUpdateTimeinMills() throws MalformedResourceException; - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); - return result; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - PersistentResource other = (PersistentResource) obj; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - return true; - } - /** - * - * Malformed resource exception - * - * @author Manuele Simi (ISTI-CNR) - * - */ - public static class MalformedResourceException extends Exception { - private static final long serialVersionUID = 1L; - public MalformedResourceException(Exception e) {super(e);} - public MalformedResourceException(String message) {super(message);} - } -} diff --git a/src/org/gcube/informationsystem/collector/impl/porttypes/OldService.java b/src/org/gcube/informationsystem/collector/impl/porttypes/OldService.java deleted file mode 100644 index 95df7e8..0000000 --- a/src/org/gcube/informationsystem/collector/impl/porttypes/OldService.java +++ /dev/null @@ -1,253 +0,0 @@ -package org.gcube.informationsystem.collector.impl.porttypes; - -import javax.xml.namespace.QName; - -import org.diligentproject.informationservice.disic.stubs.DeleteProfileParams; -import org.globus.wsrf.utils.FaultHelper; -import org.oasis.wsrf.faults.BaseFaultType; -import org.xmldb.api.base.ResourceSet; -import org.xmldb.api.modules.XMLResource; - -import org.gcube.common.core.contexts.GCUBEServiceContext; -import org.gcube.common.core.porttypes.GCUBEPortType; -import org.gcube.common.core.utils.logging.GCUBELog; -import org.gcube.informationsystem.collector.impl.contexts.ICServiceContext; -import org.gcube.informationsystem.collector.impl.xmlstorage.exist.State; -import org.gcube.informationsystem.collector.impl.xmlstorage.exist.Sweeper; -import org.gcube.informationsystem.collector.impl.xmlstorage.exist.XQuery; - -/** - * An implementation of the diligentproject/informationservice/disic/DISICService portType.
- * This is here to support backward compatibility with the "old" GHN in the infrastructure. - * @deprecated - * - * @author Manuele Simi (ISTI-CNR) - * - */ -public class OldService extends GCUBEPortType { - - private final GCUBELog logger = new GCUBELog(OldService.class); - - /** - * WS Properties namespace - */ - public static final QName RP_SET = new QName( - "http://gcube-system.org/namespaces/informationsystem/collector/XMLCollectionAccess", - "ICRP"); - - /** - * Executes the given XQuery on the embedded eXist DB instance - * - * @param xquery - * - a valid XQuery. It must be compliant with the syntax (with - * the exception of XML Schema-related features) as specified in - * W3C's recommendations outlined in the June 2006 candidate - * recommendation - * @return the result set wrapped in a <Resultset> tag. Each record is - * wrapped with a <Recordt> - * @throws BaseFaultType - * if the XQuery is not valid or the connection to eXist is - * broken - */ - public String executeXQuery(String xquery) throws BaseFaultType { - - StringBuilder response = new StringBuilder(); - try { - - logger.debug("executing XQuery: " + xquery); - - XQuery q = new XQuery(xquery); - ResourceSet result = State.getQueryManager().executeXQuery(q); - logger.debug("number of returned documents: " + result.getSize()); - response.append("\n"); - for (int i = 0; i < (int) result.getSize(); i++) { - XMLResource xmlres = (XMLResource) result.getResource((long) i); - // logger.debug("retrieved resource - " + xmlres.getContent()); - response.append("\n" + xmlres.getContent()+ "\n\n"); - } - response.append(""); - - } catch (Exception e) { - BaseFaultType fault = new BaseFaultType(); - FaultHelper faultHelper = new FaultHelper(fault); - faultHelper.addFaultCause(e); - faultHelper.addDescription("IC service: Exception when executing the requested XQuery"); - throw fault; - } - return response.toString(); - } - - /** - * Removes a profile from the Storage given its DILIGENT Resource ID - * - * @param params - * a stub class including private java.lang.String - * DILIGENTResourceID; the id of the profile to remove private - * java.lang.String profileType; the type of the profile to - * remove (e.g RunningInstance, DHN, Service, etc.); - * @return true if the resource is successfully deleted - * @throws BaseFaultType - * if the type parameter is not valid or an error occurs when - * deleting the profile - */ - - public boolean deleteProfile(DeleteProfileParams params) throws BaseFaultType { - - boolean response = false; - String id = params.getDILIGENTResourceID(); - String type = params.getProfileType(); - - if ((id == "") || (id == null)) { - logger.warn("invalid id"); - BaseFaultType fault = new BaseFaultType(); - FaultHelper faultHelper = new FaultHelper(fault); - faultHelper.addDescription("invalid id"); - throw fault; - } - - if ((type == "") || (type == null)) { - logger.warn("invalid profile type"); - BaseFaultType fault = new BaseFaultType(); - FaultHelper faultHelper = new FaultHelper(fault); - faultHelper.addDescription("invalid profile type"); - throw fault; - } - - try { - logger.debug("deleting profile " + id + " from collection " + type); - State.getDataManager().retrieveAndDeleteProfileFromID(id, type); - if (type.equalsIgnoreCase("RunningInstance")) - Sweeper.cleanResourceForRI(id); - - } catch (Exception e) { - logger.error("unable to remove resource: " + id, e); - BaseFaultType fault = new BaseFaultType(); - FaultHelper faultHelper = new FaultHelper(fault); - faultHelper.addFaultCause(e); - faultHelper - .addDescription("IC service: Exception when deleting the requested resource"); - throw fault; - } - return response; - } - - /** - * Removes a resource from the Storage given its ID - * - * @param id - * - the id of the resoure to remove - * @return true if the resource is successfully deleted - * @throws BaseFaultType - * if the id parameter is null or an error occurs when deleting - * the profile - */ - public boolean deleteResource(String id) throws BaseFaultType { - - boolean response = false; - - if ((id == "") || (id == null)) { - logger.warn("invalid id"); - BaseFaultType fault = new BaseFaultType(); - FaultHelper faultHelper = new FaultHelper(fault); - faultHelper.addDescription("invalid id"); - throw fault; - } - - try { - logger.debug("deleting resource: " + id); - State.getDataManager().retrieveAndDeleteResourceFromID(id); - } catch (Exception e) { - logger.error("unable to remove resource: " + id, e); - BaseFaultType fault = new BaseFaultType(); - FaultHelper faultHelper = new FaultHelper(fault); - faultHelper.addFaultCause(e); - faultHelper - .addDescription("IC service: Exception when deleting the requested resource"); - throw fault; - } - return response; - } - - /** - * Deletes the entire set of registered RPs from the storage - * - * @throws BaseFaultType - * if an error occurs when deleting the resources - */ - public void deleteAllRPs() throws BaseFaultType { - try { - logger.info("DeleteAllRPs operation invoked"); - Sweeper.cleanRPs(); - logger.info("All RPs have been deleted from the storage"); - } catch (Exception e) { - logger.error("unable to clean RPs collction: ", e); - BaseFaultType fault = new BaseFaultType(); - FaultHelper faultHelper = new FaultHelper(fault); - faultHelper.addFaultCause(e); - faultHelper.addDescription("IC service: Exception when deleting the requested resource"); - throw fault; - } - } - - /** - * Disposes the State service - * - * @throws BaseFaultType - * if the shutdown fails - */ - public void dispose() throws BaseFaultType { - try { - logger.info("Dispose operation invoked"); - logger.info("trying to shutdown the storage instances..."); - try { - State.getDataManager().shutdown(true); - State.getQueryManager().shutdown(true); - } catch (NullPointerException se) {/* nothing to do */ - } - // request the interruption of the sweeper thread - State.sweeperT.interrupt(); - logger.info("done"); - } catch (Exception e) { - logger.error("unable to pose the IC with success ", e); - BaseFaultType fault = new BaseFaultType(); - FaultHelper faultHelper = new FaultHelper(fault); - faultHelper.addFaultCause(e); - faultHelper - .addDescription("-IC service: Unable to pose the service"); - throw fault; - } - } - - /** - * Initialized the State service - * - * @throws BaseFaultType - * if the initialization fails - */ - public void initialize() throws BaseFaultType { - - try { - logger.info("Initialize operation invoked"); - State.initialize(); - logger.info("done"); - } catch (Exception e) { - logger.error("Unable to initialize the IC state", e); - BaseFaultType fault = new BaseFaultType(); - FaultHelper faultHelper = new FaultHelper(fault); - faultHelper.addFaultCause(e); - faultHelper.addDescription("-IC service: Unable to initialize the service"); - throw fault; - } - } - - - - /* (non-Javadoc) - * @see org.gcube.common.core.porttypes.GCUBEPortType#getServiceContext() - */ - @Override - protected GCUBEServiceContext getServiceContext() { - return ICServiceContext.getContext(); - } - -} diff --git a/src/org/gcube/informationsystem/collector/impl/porttypes/Sink.java b/src/org/gcube/informationsystem/collector/impl/porttypes/Sink.java index dcfa4b9..535e0ba 100755 --- a/src/org/gcube/informationsystem/collector/impl/porttypes/Sink.java +++ b/src/org/gcube/informationsystem/collector/impl/porttypes/Sink.java @@ -14,6 +14,7 @@ import org.gcube.common.core.contexts.GCUBEServiceContext; import org.gcube.common.core.porttypes.GCUBEPortType; import org.gcube.common.core.utils.logging.GCUBELog; import org.gcube.informationsystem.collector.impl.contexts.ICServiceContext; +import org.gcube.informationsystem.collector.impl.state.AggregatorRegisteredResource; /** * Sink PortType's implementation class. It's the registration PortType @@ -43,7 +44,7 @@ public class Sink extends GCUBEPortType implements ResourceLifetime, ResourcePro * */ public Sink() { - this.propSet = new SimpleResourcePropertySet(XMLCollectionAccess.RP_SET); + this.propSet = new SimpleResourcePropertySet(AggregatorRegisteredResource.RP_SET); ResourceProperty prop = null; try { // ResourceLifeTime properties diff --git a/src/org/gcube/informationsystem/collector/impl/porttypes/XMLCollectionAccess.java b/src/org/gcube/informationsystem/collector/impl/porttypes/XMLCollectionAccess.java deleted file mode 100755 index 7a20dbc..0000000 --- a/src/org/gcube/informationsystem/collector/impl/porttypes/XMLCollectionAccess.java +++ /dev/null @@ -1,224 +0,0 @@ -package org.gcube.informationsystem.collector.impl.porttypes; - - -import javax.xml.namespace.QName; - -import org.oasis.wsrf.faults.BaseFaultType; - -import org.gcube.common.core.contexts.GCUBEServiceContext; -import org.gcube.common.core.porttypes.GCUBEPortType; -import org.gcube.common.core.utils.logging.GCUBELog; -import org.gcube.informationsystem.collector.impl.contexts.ICServiceContext; -import org.gcube.informationsystem.collector.impl.persistence.AggregatorPersistentResource; -import org.gcube.informationsystem.collector.impl.xmlstorage.exist.State; -import org.gcube.informationsystem.collector.impl.xmlstorage.exist.Sweeper; -import org.gcube.informationsystem.collector.stubs.DeleteProfileParams; -import org.gcube.informationsystem.collector.stubs.DocumentNotFoundFaultType; -import org.gcube.informationsystem.collector.stubs.GetProfileCriteria; -import org.gcube.informationsystem.collector.stubs.GetProfileLastModificationTimeMsCriteria; -import org.gcube.informationsystem.collector.stubs.GetResourceCriteria; -import org.gcube.informationsystem.collector.stubs.GetResourceLastModificationTimeMsCriteria; - -import org.globus.wsrf.utils.FaultHelper; - -/** - * State service implementation class - * - * @author Manuele Simi (ISTI-CNR) - * - */ -public class XMLCollectionAccess extends GCUBEPortType { - - /** - * WS Properties namespace - */ - public static final QName RP_SET = new QName( - "http://gcube-system.org/namespaces/informationsystem/collector/XMLCollectionAccess", - "ICRP"); - - private final GCUBELog logger = new GCUBELog(XMLCollectionAccess.class); - - /** - * Removes a profile from the Storage given its DILIGENT Resource ID - * - * @param params - * a stub class including private java.lang.String - * DILIGENTResourceID; the id of the profile to remove private - * java.lang.String profileType; the type of the profile to - * remove (e.g RunningInstance, DHN, Service, etc.); - * @return true if the resource is successfully deleted - * @throws BaseFaultType - * if the type parameter is not valid or an error occurs when - * deleting the profile - */ - - public boolean deleteProfile(DeleteProfileParams params) - throws BaseFaultType { - - boolean response = false; - String id = params.getID(); - String type = params.getProfileType(); - - if ((id == "") || (id == null)) { - logger.warn("invalid id"); - BaseFaultType fault = new BaseFaultType(); - FaultHelper faultHelper = new FaultHelper(fault); - faultHelper.addDescription("invalid id"); - throw fault; - } - - if ((type == "") || (type == null)) { - logger.warn("invalid profile type"); - BaseFaultType fault = new BaseFaultType(); - FaultHelper faultHelper = new FaultHelper(fault); - faultHelper.addDescription("invalid profile type"); - throw fault; - } - - try { - logger.debug("deleting profile " + id + " from collection " + type); - State.getDataManager().retrieveAndDeleteProfileFromID(id, type); - if (type.equalsIgnoreCase("RunningInstance")) - Sweeper.cleanResourceForRI(id); - - } catch (Exception e) { - logger.error("unable to remove resource: " + id, e); - BaseFaultType fault = new BaseFaultType(); - FaultHelper faultHelper = new FaultHelper(fault); - faultHelper.addFaultCause(e); - faultHelper - .addDescription("IC service: Exception when deleting the requested resource"); - throw fault; - } - return response; - } - - /** - * Removes a resource from the Storage given its ID - * - * @param id - * - the id of the resoure to remove - * @return true if the resource is successfully deleted - * @throws BaseFaultType - * if the id parameter is null or an error occurs when deleting - * the profile - */ - public boolean deleteResource(String id) throws BaseFaultType { - - boolean response = false; - - if ((id == "") || (id == null)) { - logger.warn("invalid id"); - BaseFaultType fault = new BaseFaultType(); - FaultHelper faultHelper = new FaultHelper(fault); - faultHelper.addDescription("invalid id"); - throw fault; - } - - try { - logger.debug("deleting resource: " + id); - State.getDataManager().retrieveAndDeleteResourceFromID(id); - } catch (Exception e) { - logger.error("unable to remove resource: " + id, e); - BaseFaultType fault = new BaseFaultType(); - FaultHelper faultHelper = new FaultHelper(fault); - faultHelper.addFaultCause(e); - faultHelper - .addDescription("IC service: Exception when deleting the requested resource"); - throw fault; - } - return response; - } - - /** - * Deletes the entire set of registered RPs from the storage - * - * @throws BaseFaultType if an error occurs when deleting the resources - */ - public void deleteAllRPs() throws BaseFaultType { - try { - logger.info("DeleteAllRPs operation invoked"); - Sweeper.cleanRPs(); - logger.info("All RPs have been deleted from the storage"); - } catch (Exception e) { - logger.error("unable to clean RPs collction: ", e); - BaseFaultType fault = new BaseFaultType(); - FaultHelper faultHelper = new FaultHelper(fault); - faultHelper.addFaultCause(e); - faultHelper.addDescription("IC service: Exception when deleting the requested resource"); - throw fault; - } - } - - /** - * Retrieves the given Resource - * @param criteria the Resource ID - * @return the XML serialization of the Resource - * @throws DocumentNotFoundFaultType if the Resource does not exist - */ - public String getResource(GetResourceCriteria criteria) throws DocumentNotFoundFaultType { - try { - AggregatorPersistentResource aresource = State.getDataManager().retrievePropertyResourceFromID(criteria.getID()); - return aresource.getData(); - } catch (Exception e) { - logger.warn("Unable to find Resource with ID=" + criteria.getID(), e); - throw new DocumentNotFoundFaultType(); - } - - } - - /** - * Retrieves the given Profile - * @param criteria the Profile ID and Type - * @return the XML serialization of the Profile - * @throws DocumentNotFoundFaultType if the Profile does not exist - */ - public String getProfile(GetProfileCriteria criteria) throws DocumentNotFoundFaultType { - try { - AggregatorPersistentResource aresource = State.getDataManager().retrieveProfile(criteria.getID(), criteria.getProfileType()); - return aresource.getData(); - } catch (Exception e) { - logger.warn("Unable to find Profile with ID=" + criteria.getID(), e); - throw new DocumentNotFoundFaultType(); - } - } - - /** - * Gets the last modification time in milliseconds of the given Profile - * @param criteria the Profile ID and Type - * @return the last update time in milliseconds - * @throws DocumentNotFoundFaultType if the Profile does not exist - */ - public long getProfileLastModificationTimeMs(GetProfileLastModificationTimeMsCriteria criteria) throws DocumentNotFoundFaultType { - try { - AggregatorPersistentResource aresource = State.getDataManager().retrieveProfile(criteria.getID(), criteria.getProfileType()); - return aresource.getLastUpdateTimeinMills(); - } catch (Exception e) { - logger.warn("Unable to find Profile with ID=" + criteria.getID(), e); - throw new DocumentNotFoundFaultType(); - } - } - - /** - * Gets the last modification time in milliseconds of the given Resource - * @param criteria the Resource ID - * @return the last update time in milliseconds - * @throws DocumentNotFoundFaultType if the Resource does not exist - */ - public long getResourceLastModificationTimeMs(GetResourceLastModificationTimeMsCriteria criteria) throws DocumentNotFoundFaultType { - try { - AggregatorPersistentResource aresource = State.getDataManager().retrievePropertyResourceFromID(criteria.getID()); - return aresource.getLastUpdateTimeinMills(); - } catch (Exception e) { - logger.warn("Unable to find Resource with ID=" + criteria.getID(), e); - throw new DocumentNotFoundFaultType(); - } - - } - - /** {@inheritDoc} */ - @Override - protected GCUBEServiceContext getServiceContext() { - return ICServiceContext.getContext(); - } -} diff --git a/src/org/gcube/informationsystem/collector/impl/porttypes/XQueryAccess.java b/src/org/gcube/informationsystem/collector/impl/porttypes/XQueryAccess.java index d5ef76e..f374de4 100644 --- a/src/org/gcube/informationsystem/collector/impl/porttypes/XQueryAccess.java +++ b/src/org/gcube/informationsystem/collector/impl/porttypes/XQueryAccess.java @@ -9,7 +9,7 @@ import org.gcube.common.core.utils.logging.GCUBELog; import org.gcube.informationsystem.collector.impl.contexts.ICServiceContext; import org.gcube.informationsystem.collector.impl.xmlstorage.exist.State; import org.gcube.informationsystem.collector.impl.xmlstorage.exist.XQuery; -import org.gcube.informationsystem.collector.impl.xmlstorage.exist.XMLStorageManager.XMLStorageNotAvailableException; +import org.gcube.informationsystem.collector.impl.xmlstorage.exist.XMLStorage.XMLStorageNotAvailableException; import org.gcube.informationsystem.collector.stubs.XQueryExecuteRequest; import org.gcube.informationsystem.collector.stubs.XQueryExecuteResponse; import org.gcube.informationsystem.collector.stubs.XQueryFaultType; diff --git a/src/org/gcube/informationsystem/collector/impl/porttypes/wsdaix/XMLCollectionAccess.java b/src/org/gcube/informationsystem/collector/impl/porttypes/wsdaix/XMLCollectionAccess.java new file mode 100644 index 0000000..d63ea2f --- /dev/null +++ b/src/org/gcube/informationsystem/collector/impl/porttypes/wsdaix/XMLCollectionAccess.java @@ -0,0 +1,391 @@ +package org.gcube.informationsystem.collector.impl.porttypes.wsdaix; + +import java.rmi.RemoteException; +import org.apache.axis.message.MessageElement; +import org.w3c.dom.Document; +import org.gcube.common.core.contexts.GCUBEServiceContext; +import org.gcube.common.core.porttypes.GCUBEPortType; +import org.gcube.common.core.utils.logging.GCUBELog; +import org.gcube.informationsystem.collector.impl.contexts.ICServiceContext; +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.gcube.informationsystem.collector.impl.resources.DAIXResource.MalformedResourceException; +import org.gcube.informationsystem.collector.impl.resources.GCUBEXMLResource.MalformedXMLResourceException; +import org.gcube.informationsystem.collector.impl.utils.MetadataReader; +import org.gcube.informationsystem.collector.impl.xmlstorage.exist.State; +import org.gcube.informationsystem.collector.impl.xmlstorage.exist.XMLStorage.XMLStorageNotAvailableException; +import org.gcube.informationsystem.collector.stubs.wsdai.DataResourceUnavailableFaultType; +import org.gcube.informationsystem.collector.stubs.wsdai.GetDataResourcePropertyDocumentRequest; +import org.gcube.informationsystem.collector.stubs.wsdai.InvalidResourceNameFaultType; +import org.gcube.informationsystem.collector.stubs.wsdai.NotAuthorizedFaultType; +import org.gcube.informationsystem.collector.stubs.wsdai.ServiceBusyFaultType; +import org.gcube.informationsystem.collector.stubs.wsdaix.AddDocumentRequestWrapper; +import org.gcube.informationsystem.collector.stubs.wsdaix.AddDocumentResponseWrapper; +import org.gcube.informationsystem.collector.stubs.wsdaix.AddDocumentResponseWrapperResponse; +import org.gcube.informationsystem.collector.stubs.wsdaix.AddDocumentsRequest; +import org.gcube.informationsystem.collector.stubs.wsdaix.AddDocumentsResponse; +import org.gcube.informationsystem.collector.stubs.wsdaix.AddSchemaRequest; +import org.gcube.informationsystem.collector.stubs.wsdaix.AddSchemaResponse; +import org.gcube.informationsystem.collector.stubs.wsdaix.CollectionAlreadyExistsFaultType; +import org.gcube.informationsystem.collector.stubs.wsdaix.CreateSubcollectionRequest; +import org.gcube.informationsystem.collector.stubs.wsdaix.CreateSubcollectionResponse; +import org.gcube.informationsystem.collector.stubs.wsdaix.GetDocumentResponseWrapper; +import org.gcube.informationsystem.collector.stubs.wsdaix.GetDocumentResponseWrapperResponse; +import org.gcube.informationsystem.collector.stubs.wsdaix.GetDocumentsRequest; +import org.gcube.informationsystem.collector.stubs.wsdaix.GetDocumentsResponse; +import org.gcube.informationsystem.collector.stubs.wsdaix.GetSchemaRequest; +import org.gcube.informationsystem.collector.stubs.wsdaix.GetSchemaResponse; +import org.gcube.informationsystem.collector.stubs.wsdaix.InvalidCollectionNameFaultType; +import org.gcube.informationsystem.collector.stubs.wsdaix.RemoveDocumentRequestWrapper; +import org.gcube.informationsystem.collector.stubs.wsdaix.RemoveDocumentResponseWrapper; +import org.gcube.informationsystem.collector.stubs.wsdaix.RemoveDocumentResponseWrapperResponse; +import org.gcube.informationsystem.collector.stubs.wsdaix.XMLWrapperType; + +import org.gcube.informationsystem.collector.stubs.wsdaix.RemoveDocumentsRequest; +import org.gcube.informationsystem.collector.stubs.wsdaix.RemoveDocumentsResponse; +import org.gcube.informationsystem.collector.stubs.wsdaix.RemoveSchemaRequest; +import org.gcube.informationsystem.collector.stubs.wsdaix.RemoveSchemaResponse; +import org.gcube.informationsystem.collector.stubs.wsdaix.RemoveSubcollectionRequest; +import org.gcube.informationsystem.collector.stubs.wsdaix.RemoveSubcollectionResponse; +import org.gcube.informationsystem.collector.stubs.wsdaix.SchemaAdditionMakesDocumentsInvalidFaultType; +import org.gcube.informationsystem.collector.stubs.wsdaix.SchemaAlreadyExistsFaultType; +import org.gcube.informationsystem.collector.stubs.wsdaix.SchemaDoesNotExistFaultType; +import org.gcube.informationsystem.collector.stubs.wsdaix.SchemaInvalidFaultType; +import org.gcube.informationsystem.collector.stubs.wsdaix.SchemaRemovalMakesDocumentsInvalidFaultType; +import org.gcube.informationsystem.collector.stubs.wsdaix.SchemaRemovalMakesSchemaInvalidFaultType; +import org.gcube.informationsystem.collector.stubs.wsdaix.XMLCollectionPropertyDocumentType; + + +/** + * + * Implementation of the WS-DAIX XMLCollectionAccess port type + * + * @author Manuele Simi (ISTI-CNR) + * + * + */ +public class XMLCollectionAccess extends GCUBEPortType { + + private static GCUBELog logger = new GCUBELog(XMLCollectionAccess.class); + + + /** + * Implementation of CollectionAccess::GetDocuments + * + * @param getDocumentsRequest + * @return + * @throws RemoteException + * @throws ServiceBusyFaultType the service is already processing a request and ConcurrentAccess is false. + * @throws InvalidResourceNameFaultType the supplied resource name is not known to the service. + * @throws InvalidCollectionNameFaultType the supplied collection name is not known to the XML resource. + */ + public GetDocumentsResponse getDocuments(GetDocumentsRequest getDocumentsRequest) + throws RemoteException, ServiceBusyFaultType, InvalidResourceNameFaultType, + InvalidCollectionNameFaultType { + + int size = getDocumentsRequest.getGetDocumentRequestWrapper().length; + GetDocumentResponseWrapper[] responseWrapper = new GetDocumentResponseWrapper[size]; + for(int i=0;i + //2 - + //3 - + //4 - + for(int i=0;i 0 && enveloped[0]) { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + StringReader reader = new StringReader(content); + InputSource source = new InputSource(reader); + Document doc = builder.parse(source); + this.parseEnvelop(doc); + resource.setContent(this.removeEnvelop(doc)); + } + else + resource.setContent(content); + } catch (Exception e) { + + } + + } + + /** + * Extract the resource informantion from the envelop + * @param doc the enveloped content + * @throws MalformedXMLResourceException + */ + private void parseEnvelop(Document doc) throws MalformedXMLResourceException { + String value = ""; + try { + value = path.evaluate("Document/LastUpdateMs", doc); + this.lastUpdateTime.setTimeInMillis(Long.parseLong(value)); + value = path.evaluate("Document/TerminationTime", doc); + this.terminationTime.setTimeInMillis(Long.parseLong(value)); + value = path.evaluate("Document/Source", doc); + this.setSource(value); + value = path.evaluate("Document/SourceKey", doc); + this.setCompleteSourceKey(value); + value = path.evaluate("Document/EntryKey", doc); + this.setEntryKey(value); + value = path.evaluate("Document/GroupKey", doc); + this.setGroupKey(value); + } catch (Exception xpee) { + logger.error("" + xpee.getMessage()); + logger.error("" + xpee.getStackTrace()); + throw new MalformedXMLResourceException("Unable to retrieve last update time for resource"); + } + + } + + public String toString() { + // we do not use an XML parser for performance reasons + StringBuilder resource = new StringBuilder("\n"); + try { + resource.append("" + this.resource.getResourceName() + "\n"); + resource.append("" + this.getSource() + "\n"); + resource.append("" + this.getSourceKey() + "\n"); + resource.append("" + this.getCompleteSourceKey() + "\n"); + resource.append("" + this.getEntryKey() + "\n"); + resource.append("" + this.getGroupKey() + "\n"); + resource.append("" + this.getTerminationTime().getTimeInMillis() + "\n"); + resource.append("" + this.getTerminationTime().getTime().toString() + "\n"); + resource.append("" + this.lastUpdateTime.getTimeInMillis() + "\n"); + resource.append("" + this.lastUpdateTime.getTime().toString() + "\n"); + resource.append("\n"); + resource.append(this.resource.toString() + "\n"); + resource.append("\n"); + resource.append("\n"); + } catch (MalformedResourceException e) { + logger.error("invalid content", e); + + } + return resource.toString(); + } + + /** + * Removes the document envelop from the document + * + * @param doc the content to clean up + * @return the content string without the document envelop + * @throws MalformedResourceException + */ + private String removeEnvelop(Document doc) throws MalformedXMLResourceException { + try { + return this.toStringFromElement(doc, "Data"); // Data/* + } catch (Exception e) { + logger.error("unable to retrieve parse the resource's content ", e); + } + throw new MalformedXMLResourceException("unable to retrieve parse the resource's content"); + } + + /** + * Returns a sub-serialization of the given XML, starting from the element name + * + * @param xml + * the source XML serialization + * @param elementName + * the name of the element + * @return the node content serialized as string + * @throws Exception + * if the serialization fails + */ + private String toStringFromElement(String xml, String elementName) throws MalformedXMLResourceException { + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + StringReader reader = new StringReader(xml); + InputSource source = new InputSource(reader); + return toStringFromElement(builder.parse(source), elementName); + + } catch (Exception e) { + logger.error("Unable to deserialise content data", e); + throw new MalformedXMLResourceException("Unable to deserialise the resource"); + } + + } + + /** + * Returns a sub-serialization of the given XML, starting from the element name + * + * @param xml + * the source XML serialization + * @param elementName + * the name of the element + * @return the node content serialized as string + * @throws Exception + * if the serialization fails + */ + private String toStringFromElement(Document xml, String elementName) throws MalformedXMLResourceException { + + try { + Node targetNode = xml.getElementsByTagName(elementName).item(0); + TransformerFactory transFactory = TransformerFactory.newInstance(); + Transformer transformer = transFactory.newTransformer(); + StringBuilder ret = new StringBuilder(); + transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + int index = 0; + Node node = targetNode.getChildNodes().item(index); + while (node != null) { + StringWriter buffer = new StringWriter(); + transformer.transform(new DOMSource(node), new StreamResult(buffer)); + ret.append(buffer.toString().trim()); + node = targetNode.getChildNodes().item(index++); + } + return ret.toString(); + + } catch (Exception e) { + logger.error("Unable to deserialise content data", e); + throw new MalformedXMLResourceException("Unable to deserialise the resource"); + } + + } + + /** + * + * Malformed XML resource exception + * + * @author Manuele Simi (ISTI-CNR) + * + */ + public static class MalformedXMLResourceException extends Exception { + private static final long serialVersionUID = 1L; + + public MalformedXMLResourceException(Exception e) { + super(e); + } + + public MalformedXMLResourceException(String message) { + super(message); + } + } + + /** + * Gets the wrapped {@link BaseDAIXResource}'s content + * @return + * @throws MalformedXMLResourceException + */ + public Document getContent() throws MalformedXMLResourceException { + try { + try { + return resource.getContent(); + } catch (Exception e) { + //try to wrap with a root element + StringBuilder resource = new StringBuilder("\n"); + resource.append(this.resource.toString() + "\n"); + resource.append("\n"); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + StringReader reader = new StringReader(resource.toString()); + InputSource source = new InputSource(reader); + return builder.parse(source); + } + + } catch (Exception e) { + logger.error("Invalid data", e); + throw new MalformedXMLResourceException("Invalid data"); + } + } + + +} diff --git a/src/org/gcube/informationsystem/collector/impl/state/AggregatorRegisteredResource.java b/src/org/gcube/informationsystem/collector/impl/state/AggregatorRegisteredResource.java index b7561b0..f8a5956 100755 --- a/src/org/gcube/informationsystem/collector/impl/state/AggregatorRegisteredResource.java +++ b/src/org/gcube/informationsystem/collector/impl/state/AggregatorRegisteredResource.java @@ -1,16 +1,15 @@ package org.gcube.informationsystem.collector.impl.state; import java.util.Calendar; - +import javax.xml.namespace.QName; import org.apache.axis.encoding.AnyContentType; import org.gcube.common.core.utils.logging.GCUBELog; -import org.gcube.informationsystem.collector.impl.persistence.AggregatorPersistentResource; 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.porttypes.XMLCollectionAccess; - +import org.gcube.informationsystem.collector.impl.resources.GCUBEInstanceStateResource; +import org.gcube.informationsystem.collector.impl.resources.GCUBEXMLResource; import org.globus.mds.aggregator.impl.AggregatorServiceGroupResource; import org.globus.mds.aggregator.impl.AggregatorServiceGroupEntryResource; import org.globus.mds.aggregator.impl.AggregatorSource; @@ -51,13 +50,15 @@ public class AggregatorRegisteredResource extends AggregatorServiceGroupResource private TopicList topicList; - // private String baseDir; + public static final QName RP_SET = new QName( + "http://gcube-system.org/namespaces/informationsystem/collector/XMLCollectionAccess", + "ICRP"); /** * Builds a new resource */ public AggregatorRegisteredResource() { - super.init(XMLCollectionAccess.RP_SET); + super.init(RP_SET); // this.baseDir = getBaseDirectory(); this.propSet = this.getResourcePropertySet(); @@ -189,12 +190,13 @@ public class AggregatorRegisteredResource extends AggregatorServiceGroupResource // Build the new resource to store logger.debug("Storing the new delivered resource"); - AggregatorPersistentResource res = new AggregatorPersistentResource(entryparser.getSourceURI(), entryparser.getSourceKey(), aentry.getEntryAsString(), entryparser.getType()); - res.setData(aentry.getEntryAsString()); + GCUBEInstanceStateResource instanceState = new GCUBEInstanceStateResource(); + instanceState.setResourceName(Identifier.buildInstanceStateID(entryparser)); + instanceState.setContent(aentry.getEntryAsString()); + GCUBEXMLResource res = new GCUBEXMLResource(instanceState); res.setEntryKey(sinkparser.getEntryKey()); res.setGroupKey(sinkparser.getGroupKey()); res.setTerminationTime(entry.getTerminationTime()); - //res.setType(entryparser.getType()); res.setSource(entryparser.getSourceURI()); res.setSourceKey(entryparser.getSourceKey()); logger.debug("Qualified Source Key: " + entryparser.getQualifiedSourceKey()); @@ -204,7 +206,7 @@ public class AggregatorRegisteredResource extends AggregatorServiceGroupResource synchronized (State.deletedResources) { if (State.deletedResources.contains(res)) { State.deletedResources.remove(res); - throw new Exception("the resource " + res.getID() + " is no longer available"); + throw new Exception("the resource " + res.getResourceName() + " is no longer available"); } } logger.trace("Resource: " + res.toString()); diff --git a/src/org/gcube/informationsystem/collector/impl/state/ICAggregatorRemoveCallback.java b/src/org/gcube/informationsystem/collector/impl/state/ICAggregatorRemoveCallback.java index 8ed7cb6..7501a8a 100755 --- a/src/org/gcube/informationsystem/collector/impl/state/ICAggregatorRemoveCallback.java +++ b/src/org/gcube/informationsystem/collector/impl/state/ICAggregatorRemoveCallback.java @@ -1,11 +1,12 @@ package org.gcube.informationsystem.collector.impl.state; import org.gcube.common.core.utils.logging.GCUBELog; -import org.gcube.informationsystem.collector.impl.persistence.AggregatorPersistentResource; -import org.gcube.informationsystem.collector.impl.persistence.PersistentResource.RESOURCETYPE; import org.gcube.informationsystem.collector.impl.utils.EntryEPRParser; import org.gcube.informationsystem.collector.impl.utils.EntryParser; +import org.gcube.informationsystem.collector.impl.utils.Identifier; import org.gcube.informationsystem.collector.impl.xmlstorage.exist.State; +import org.gcube.informationsystem.collector.impl.resources.GCUBEInstanceStateResource; +import org.gcube.informationsystem.collector.impl.resources.GCUBEXMLResource; import org.globus.mds.aggregator.impl.AggregatorServiceGroupEntryRemovedCallback; import org.globus.mds.aggregator.impl.AggregatorServiceGroupEntryResource; @@ -45,7 +46,9 @@ public class ICAggregatorRemoveCallback implements AggregatorServiceGroupEntryRe logger.debug("Aggregator Sink " + eparser.getSink()); EntryEPRParser parser = eparser.getEPRSinkParser(); - AggregatorPersistentResource res = new AggregatorPersistentResource(eparser.getSourceURI(), eparser.getSourceKey(), "", RESOURCETYPE.Properties); + GCUBEInstanceStateResource instancestate = new GCUBEInstanceStateResource(); + instancestate.setResourceName(Identifier.buildInstanceStateID(eparser)); + GCUBEXMLResource res = new GCUBEXMLResource(instancestate); res.setEntryKey(parser.getEntryKey()); res.setGroupKey(parser.getGroupKey()); res.setSourceKey(eparser.getSourceKey()); @@ -60,7 +63,7 @@ public class ICAggregatorRemoveCallback implements AggregatorServiceGroupEntryRe try { //State.getDataManager().retrieveAndDeleteResourceFromID(res.getID()); } catch (Exception e) { - logger.error("Unable to remove resource: " + res.getID(), e); + logger.error("Unable to remove resource: " + res.getResourceName(), e); } } diff --git a/src/org/gcube/informationsystem/collector/impl/utils/EntryParser.java b/src/org/gcube/informationsystem/collector/impl/utils/EntryParser.java index 6181fde..9139976 100644 --- a/src/org/gcube/informationsystem/collector/impl/utils/EntryParser.java +++ b/src/org/gcube/informationsystem/collector/impl/utils/EntryParser.java @@ -5,7 +5,6 @@ import org.apache.axis.message.addressing.EndpointReferenceType; import org.apache.axis.message.addressing.ReferencePropertiesType; import org.globus.mds.aggregator.impl.AggregatorServiceGroupEntryResource; -import org.gcube.informationsystem.collector.impl.persistence.PersistentResource.RESOURCETYPE; /** * Parser for {@link AggregatorServiceGroupEntryResource} @@ -88,7 +87,7 @@ public class EntryParser { * * @return the {@link RESOURCETYPE} */ - public RESOURCETYPE getType() { + /* public RESOURCETYPE getType() { EndpointReferenceType memberEpr = entry.getMemberEPR(); if (memberEpr.getAddress().toString().endsWith(registryNS)) { return RESOURCETYPE.Profile; @@ -96,7 +95,7 @@ public class EntryParser { return RESOURCETYPE.Properties; } } - +*/ public void getRPSet() { // get RP set from entry // ResourcePropertySet rpSet = entry.getResourcePropertySet(); diff --git a/src/org/gcube/informationsystem/collector/impl/utils/Identifier.java b/src/org/gcube/informationsystem/collector/impl/utils/Identifier.java new file mode 100644 index 0000000..512441c --- /dev/null +++ b/src/org/gcube/informationsystem/collector/impl/utils/Identifier.java @@ -0,0 +1,30 @@ +package org.gcube.informationsystem.collector.impl.utils; + +/** + * + * Build instance state identifiers + * + * @author Manuele Simi (ISTI-CNR) + * + */ +public class Identifier { + + /** + * Builds an instance state identifier + * @param parser the parser of the source entry + * @return the identifier + */ + public static String buildInstanceStateID(EntryParser parser) { + return buildInstanceStateID(parser.getSourceURI(),parser.getSourceKey()); + } + + /** + * Builds an instance state identifier + * @param source the URI of the publisher + * @param id the id related to the piece of state to identify + * @return the identifier + */ + public static String buildInstanceStateID(String source, String id) { + return source.replace("http://", "").replace(":", "").replace("/", "-") + "-" + id.replace("http://", "").replace(":", "").replace("/", "-"); + } +} diff --git a/src/org/gcube/informationsystem/collector/impl/utils/MetadataReader.java b/src/org/gcube/informationsystem/collector/impl/utils/MetadataReader.java new file mode 100644 index 0000000..1aa9157 --- /dev/null +++ b/src/org/gcube/informationsystem/collector/impl/utils/MetadataReader.java @@ -0,0 +1,53 @@ +package org.gcube.informationsystem.collector.impl.utils; + +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.TimeZone; + +import org.w3c.dom.Document; + +/** + * + * Reader for resource's metadata + * + * @author Manuele Simi (ISTI-CNR) + * + */ +public class MetadataReader { + + private Document metadata; + + public MetadataReader(Document metadata) { + this.metadata = metadata; + } + + public String getType(){ + return this.metadata.getElementsByTagName("Type").item(0).getTextContent(); + } + + public String getSource() { + return this.metadata.getElementsByTagName("Source").item(0).getTextContent(); + } + + public Calendar getTerminationTime() { + //value is in seconds + String value = this.metadata.getElementsByTagName("TerminationTime").item(0).getTextContent(); + Calendar now = new GregorianCalendar(); + now.setTimeZone(TimeZone.getTimeZone("GMT")); + //add seconds to obtain the effective termination time + now.add(Calendar.SECOND, Integer.valueOf(value)); + return now; + } + + public String getGroupKey() { + return this.metadata.getElementsByTagName("GroupKey").item(0).getTextContent(); + } + + public String getEntryKey() { + return this.metadata.getElementsByTagName("EntryKey").item(0).getTextContent(); + } + + public String getKey() { + return this.metadata.getElementsByTagName("Key").item(0).getTextContent(); + } +} diff --git a/src/org/gcube/informationsystem/collector/impl/utils/MsgParser.java b/src/org/gcube/informationsystem/collector/impl/utils/MsgParser.java index 47ae28c..5c1ee40 100755 --- a/src/org/gcube/informationsystem/collector/impl/utils/MsgParser.java +++ b/src/org/gcube/informationsystem/collector/impl/utils/MsgParser.java @@ -24,12 +24,10 @@ import java.lang.Exception; /** * - * @author manuele simi - * - * @version 1.0 June 2006 - * - * @link http://www.diligentproject.org * + * + * @author Manuele Simi (ISTI-CNR) + * */ public class MsgParser { @@ -100,7 +98,7 @@ public class MsgParser { logger.warn("The entry does not have a ResourceType"); throw new Exception("Invalid resource (type = Properties)"); } - return this.getDILIGENTProperty("DILIGENTResourceType"); + return this.getGCUBEProperty("DILIGENTResourceType"); } /** @@ -112,7 +110,7 @@ public class MsgParser { */ public String getVOName() throws Exception { - return this.getDILIGENTProperty("VO"); + return this.getGCUBEProperty("VO"); } /** @@ -124,7 +122,7 @@ public class MsgParser { */ public String getServiceName() throws Exception { - return this.getDILIGENTProperty("ServiceName"); + return this.getGCUBEProperty("ServiceName"); } /** @@ -136,7 +134,7 @@ public class MsgParser { */ public String getServiceClass() throws Exception { - return this.getDILIGENTProperty("ServiceClass"); + return this.getGCUBEProperty("ServiceClass"); } /** @@ -148,7 +146,7 @@ public class MsgParser { */ public String getRunningInstanceID() throws Exception { - return this.getDILIGENTProperty("RunningInstanceID"); + return this.getGCUBEProperty("RunningInstanceID"); } /** @@ -160,7 +158,7 @@ public class MsgParser { */ public String getServiceID() throws Exception { - return this.getDILIGENTProperty("ServiceID"); + return this.getGCUBEProperty("ServiceID"); } /** @@ -172,17 +170,17 @@ public class MsgParser { */ public String getDHNID() throws Exception { - return this.getDILIGENTProperty("GHN"); + return this.getGCUBEProperty("GHN"); } /** - * Extracts a given DILIGENT Property - * - * @throws Exception + * Reads a GCUBE Property * * @return the property value + * @throws Exception if the reading fails + * */ - private String getDILIGENTProperty(String propName) throws Exception { + private String getGCUBEProperty(String propName) throws Exception { String value = null; @@ -203,9 +201,7 @@ public class MsgParser { * @return the XML string */ public String getEntryAsString() { - return "<" + rootElement + ">\n" + this.originalMsgString + "\n"; - // return XMLUtils.DocumentToString(this.internalDOM); + return this.originalMsgString ; } /** diff --git a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/DataManager.java b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/DataManager.java index 855a9ea..2ba59d6 100644 --- a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/DataManager.java +++ b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/DataManager.java @@ -8,6 +8,7 @@ import org.exist.storage.ConsistencyCheckTask; import org.gcube.common.core.utils.logging.GCUBELog; import org.gcube.informationsystem.collector.impl.contexts.ICServiceContext; +import org.gcube.informationsystem.collector.impl.resources.GCUBEInstanceStateResource; import org.gcube.informationsystem.collector.impl.xmlstorage.backup.BackupsRootFolder; import org.gcube.informationsystem.collector.impl.xmlstorage.backup.Scheduler; @@ -17,7 +18,7 @@ import org.gcube.informationsystem.collector.impl.xmlstorage.backup.Scheduler; * @author Manuele Simi (ISTI-CNR) * */ -public class DataManager extends XMLStorageManager { +public class DataManager extends XMLStorage { private final static GCUBELog logger = new GCUBELog(DataManager.class); @@ -75,7 +76,7 @@ public class DataManager extends XMLStorageManager { if (Boolean.valueOf((String) ICServiceContext.getContext().getProperty("deleteRPsOnStartup", true))) { // cleanup the RPs collection logger.info("deleting all RPs..."); - this.deleteAllProperties(); + this.deleteAllResourcesFromCollection(new GCUBEInstanceStateResource().getCollectionName()); } logger.info("Restore completed"); } catch (Exception e1) { diff --git a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/QueryManager.java b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/QueryManager.java index ac08de6..dbc5f6d 100644 --- a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/QueryManager.java +++ b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/QueryManager.java @@ -12,7 +12,7 @@ import org.gcube.common.core.utils.logging.GCUBELog; * @author Manuele Simi (ISTI-CNR) * */ -public class QueryManager extends XMLStorageManager { +public class QueryManager extends XMLStorage { private final static GCUBELog logger = new GCUBELog(QueryManager.class); diff --git a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/State.java b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/State.java index 0571559..bc03f58 100755 --- a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/State.java +++ b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/State.java @@ -2,8 +2,9 @@ package org.gcube.informationsystem.collector.impl.xmlstorage.exist; import org.gcube.common.core.utils.logging.GCUBELog; import org.gcube.informationsystem.collector.impl.contexts.ICServiceContext; -import org.gcube.informationsystem.collector.impl.persistence.AggregatorPersistentResource; -import org.gcube.informationsystem.collector.impl.xmlstorage.exist.XMLStorageManager.STATUS; +import org.gcube.informationsystem.collector.impl.xmlstorage.exist.XMLStorage.STATUS; +import org.gcube.informationsystem.collector.impl.resources.GCUBEInstanceStateResource; +import org.gcube.informationsystem.collector.impl.resources.GCUBEXMLResource; import java.util.ArrayList; import java.util.Enumeration; @@ -38,7 +39,7 @@ public class State { * List of recently deleted resources. It is used to avoid the storage of RPs of a deleted * resource */ - public static List deletedResources = Collections.synchronizedList(new ArrayList()); + public static List deletedResources = Collections.synchronizedList(new ArrayList()); private static GCUBELog logger = new GCUBELog(State.class); @@ -52,12 +53,13 @@ public class State { */ public static void initialize() throws Exception { logger.info("Starting IC service initialization..."); - State.initializeDataManager(); - State.initializeQueryManager(); + long maxOperations = Long.valueOf((String) ICServiceContext.getContext().getProperty("maxOperationsPerConnection", true)); + State.initializeDataManager(maxOperations); + State.initializeQueryManager(maxOperations); if (Boolean.valueOf((String) ICServiceContext.getContext().getProperty("deleteRPsOnStartup", true))) { // cleanup the RPs collection logger.info("Deleting all RPs..."); - State.dataManager.deleteAllProperties(); + State.dataManager.deleteAllResourcesFromCollection(new GCUBEInstanceStateResource().getCollectionName()); } else { logger.info("All RPs previously stored are kept in the storage"); } @@ -83,20 +85,20 @@ public class State { logger.info("IC service initialization completed"); } - private static void initializeDataManager() throws Exception { + private static void initializeDataManager(long maxOperations) throws Exception { if (State.dataManager == null) State.dataManager = new DataManager(); if (State.dataManager.getStatus() != STATUS.INITIALISED) - dataManager.initialize(); + dataManager.initialize(maxOperations); else logger.info("DataManager already initalized"); } - private static void initializeQueryManager() throws Exception { + private static void initializeQueryManager(long maxOperations) throws Exception { if (State.queryManager == null) State.queryManager = new QueryManager(); if (State.queryManager.getStatus() != STATUS.INITIALISED) - queryManager.initialize(); + queryManager.initialize(maxOperations); else logger.info("QueryManager already initalized"); } @@ -139,7 +141,7 @@ public class State { /** * @return the deletedResources */ - public static List getDeletedResources() { + public static List getDeletedResources() { return deletedResources; } diff --git a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/Sweeper.java b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/Sweeper.java index 5411839..3f5c5eb 100755 --- a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/Sweeper.java +++ b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/Sweeper.java @@ -11,13 +11,14 @@ import java.util.ArrayList; import java.util.List; import org.gcube.common.core.utils.logging.GCUBELog; -import org.gcube.informationsystem.collector.impl.persistence.PersistentResource; import org.gcube.informationsystem.collector.impl.xmlstorage.exist.State; import org.gcube.informationsystem.collector.impl.xmlstorage.exist.Sweeper; +import org.gcube.informationsystem.collector.impl.resources.GCUBEInstanceStateResource; +import org.gcube.informationsystem.collector.impl.resources.GCUBEXMLResource; /** * This class provides some cleanup procedures to use to maintain a consistent - * content in the XML storage One of them is a thread, activated at RI startup + * content in the XML storage. One of them is a thread, activated at RI startup * time, that periodically drops the out to date resources from the storage * * @author Manuele Simi (ISTI-CNR) @@ -31,7 +32,7 @@ public class Sweeper implements Runnable { private static GCUBELog logger = new GCUBELog(Sweeper.class); - //private static XMLStorageManager storage = null; + //private static XMLStorage storage = null; /** * Initializes a new Sweeper @@ -73,15 +74,19 @@ public class Sweeper implements Runnable { Calendar now = new GregorianCalendar(); now.setTimeZone(TimeZone.getTimeZone("GMT")); - try { - String[] ids = State.getDataManager().listAllPropertiesIDs(); + GCUBEInstanceStateResource fakeresource = new GCUBEInstanceStateResource(); + //get all IDs for Instance States' collection + String[] ids = State.getDataManager().listAllCollectionResourceIDs(fakeresource.getCollectionName()); for (String id : ids) { try { - PersistentResource res = State.getDataManager().retrievePropertyResourceFromID(id); - if (now.getTimeInMillis() - res.getLastUpdateTimeinMills() > Sweeper.resourceExpirationTime) + GCUBEInstanceStateResource tempresource = new GCUBEInstanceStateResource(); + tempresource.setResourceName(id); + GCUBEXMLResource xmlresource = new GCUBEXMLResource(tempresource); + State.getDataManager().retrieveResourceContent(new GCUBEXMLResource(tempresource)); + if (now.getTimeInMillis() - xmlresource.getLastUpdateTimeinMills() > Sweeper.resourceExpirationTime) // removes the resources from the database - State.getDataManager().retrieveAndDeleteResourceFromID(id); + State.getDataManager().deleteResource(xmlresource); // break; } catch (Exception e) { logger.debug("IC sweeper - the resource " + id + " is no longer available in the storage"); @@ -110,8 +115,8 @@ public class Sweeper implements Runnable { * */ public static void cleanRPs() { - // cleanup the RPs collection - State.getDataManager().deleteAllProperties(); + // cleanup the RPs collection + State.getDataManager().deleteAllResourcesFromCollection(new GCUBEInstanceStateResource().getCollectionName()); } /** @@ -124,8 +129,8 @@ public class Sweeper implements Runnable { Calendar now = new GregorianCalendar(); now.setTimeZone(TimeZone.getTimeZone("GMT")); - List toRemove = new ArrayList(); - for (PersistentResource res : State.deletedResources) { + List toRemove = new ArrayList(); + for (GCUBEXMLResource res : State.deletedResources) { try { if (now.getTimeInMillis() - res.getLastUpdateTimeinMills() > Sweeper.resourceExpirationTime) { toRemove.add(res); @@ -135,7 +140,7 @@ public class Sweeper implements Runnable { } }// end loop on deletedResources synchronized (State.deletedResources) { - for (PersistentResource res : toRemove) { + for (GCUBEXMLResource res : toRemove) { State.deletedResources.remove(res); } }// end synch block diff --git a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/XMLStorageManager.java b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/XMLStorage.java similarity index 70% rename from src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/XMLStorageManager.java rename to src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/XMLStorage.java index 5ffff68..cd92471 100755 --- a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/XMLStorageManager.java +++ b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/XMLStorage.java @@ -3,9 +3,7 @@ package org.gcube.informationsystem.collector.impl.xmlstorage.exist; import org.xmldb.api.base.XMLDBException; import org.xmldb.api.base.Collection; import org.xmldb.api.base.Database; - import org.xmldb.api.DatabaseManager; - import org.xmldb.api.modules.XMLResource; import org.xmldb.api.modules.CollectionManagementService; @@ -15,11 +13,10 @@ import org.exist.storage.DBBroker; import org.gcube.common.core.utils.logging.GCUBELog; import org.gcube.informationsystem.collector.impl.contexts.ICServiceContext; -import org.gcube.informationsystem.collector.impl.persistence.AggregatorPersistentResource; -import org.gcube.informationsystem.collector.impl.persistence.PersistentResource; -import org.gcube.informationsystem.collector.impl.persistence.PersistentResource.MalformedResourceException; -import org.gcube.informationsystem.collector.impl.persistence.PersistentResource.RESOURCETYPE; -import org.gcube.informationsystem.collector.impl.xmlstorage.exist.XMLStorageManager; +import org.gcube.informationsystem.collector.impl.xmlstorage.exist.XMLStorage; + +import org.gcube.informationsystem.collector.impl.resources.GCUBEXMLResource; +import org.gcube.informationsystem.collector.impl.resources.GCUBEXMLResource.MalformedXMLResourceException; import java.io.BufferedReader; import java.io.FileReader; @@ -31,10 +28,12 @@ import java.util.concurrent.locks.ReentrantLock; /** * A thread safe manager to interact with the XML Storage repository. * + * RESOURCE the type of the resource to store + * * @author Manuele Simi (ISTI-CNR) * */ -public class XMLStorageManager { +public class XMLStorage { protected static String URI = "xmldb:exist://"; @@ -44,7 +43,7 @@ public class XMLStorageManager { protected static String driver = "org.exist.xmldb.DatabaseImpl"; - private static GCUBELog logger = new GCUBELog(XMLStorageManager.class); + private static GCUBELog logger = new GCUBELog(XMLStorage.class); private Database database; @@ -52,8 +51,6 @@ public class XMLStorageManager { protected Collection rootCollection; - private Collection profilesRootCollection; - protected Lock lock; // lock for writing operations @@ -65,15 +62,15 @@ public class XMLStorageManager { // flag to warn when the DB is locked private boolean locked = false; - private static final String PROPERTIES_COLLECTION_NAME = "Properties"; + //private static final String PROPERTIES_COLLECTION_NAME = "Properties"; - protected static String PROFILES_COLLECTION_NAME = "Profiles"; + //protected static String PROFILES_COLLECTION_NAME = "Profiles"; enum STATUS {INITIALISED, CLOSED, SHUTDOWN}; private STATUS status = STATUS.CLOSED; - protected static long maxOperationsPerConnection = 1000; + protected long maxOperationsPerConnection = 1000; protected long operationsCounter = 0; @@ -82,21 +79,31 @@ public class XMLStorageManager { * Creates a new manager * */ - public XMLStorageManager() { - logger.debug("Creating a new XMLStorageManager"); + public XMLStorage() { + logger.debug("Creating a new XMLStorage"); lock = new ReentrantLock(); writeLock = lock; readLock = lock; } + /** - * Initializes the local XML Storage repository - * @param lock + * Initializes the local XML Storage repository + * @param lock if the storage has to be locked or not during the initalization * - * @throws Exception - * if the connection to eXist or its initialization fail + * @throws Exception if the connection to eXist or its initialization fail */ public void initialize(boolean ... lock) throws XMLStorageNotAvailableException { + this.initialize(this.maxOperationsPerConnection, lock); + } + /** + * Initializes the local XML Storage repository + * @param maxOperationsPerConnection max number of operation per active connection + * @param lock if the storage has to be locked or not during the initalization + * + * @throws Exception if the connection to eXist or its initialization fail + */ + public void initialize(long maxOperationsPerConnection, boolean ... lock) throws XMLStorageNotAvailableException { if (this.getStatus() == STATUS.INITIALISED) { logger.warn("XMLStorage already initialized"); @@ -109,7 +116,7 @@ public class XMLStorageManager { try { logger.info("Initializing XMLStorage..."); // this.printEnv(); - maxOperationsPerConnection = Long.valueOf((String) ICServiceContext.getContext().getProperty("maxOperationsPerConnection", true)); + this.maxOperationsPerConnection = maxOperationsPerConnection;//Long.valueOf((String) ICServiceContext.getContext().getProperty("maxOperationsPerConnection", true)); // register/create the DB instance Class cl = Class.forName(driver); @@ -123,21 +130,9 @@ public class XMLStorageManager { if (this.rootCollection == null) { logger.error("invalid root collection!"); throw new XMLStorageNotAvailableException("unable to load root collection"); - } - logger.info("Initializing the Profiles collection"); - this.profilesRootCollection = this.rootCollection.getChildCollection(XMLStorageManager.PROFILES_COLLECTION_NAME); - if (this.profilesRootCollection == null) { - logger.debug("Creating Profiles collection"); - this.profilesRootCollection = this.createCollection(this.rootCollection, XMLStorageManager.PROFILES_COLLECTION_NAME); - logger.debug("Profiles collection created"); - } - if (this.profilesRootCollection == null) { - throw new XMLStorageNotAvailableException("Unable to load/create Profiles collection"); - } + } this.rootCollection.setProperty("pretty", "true"); - this.rootCollection.setProperty("encoding", "UTF-8"); - this.profilesRootCollection.setProperty("pretty", "true"); - this.profilesRootCollection.setProperty("encoding", "UTF-8"); + this.rootCollection.setProperty("encoding", "UTF-8"); this.setStatus(STATUS.INITIALISED); logger.info("XMLStorage initialized with success"); @@ -158,6 +153,33 @@ public class XMLStorageManager { } + /** + * Creates a collection in the XML storage. If the input includes a full path, collections are created recursively + * @param name the collection to create + * @return the created collection + * @throws XMLDBException + * @throws XMLStorageNotAvailableException + */ + public Collection createCollection(String name) throws XMLDBException, XMLStorageNotAvailableException { + logger.info("Initializing the collection " + name); + String[] subcollections = name.split("/"); + Collection parent = this.rootCollection; + for (String subcollection : subcollections) { + Collection child = parent.getChildCollection(subcollection); + if (child == null) { + child = this.createCollection(parent, subcollection); + if (child == null) + throw new XMLStorageNotAvailableException("unable to create collection " + name); + else { + child.setProperty("pretty", "true"); + child.setProperty("encoding", "UTF-8"); + } + } + parent = child; + } + return parent; + } + /** * Blocks all the writing operations */ @@ -201,6 +223,10 @@ public class XMLStorageManager { return true; } + private Collection loadCollection(String collectionName) { + return this.loadCollection(this.rootCollection, collectionName); + } + /** * Loads a collection. If it does not exist, the collection is created. * @@ -253,10 +279,10 @@ public class XMLStorageManager { * * @return the Collection */ - public Collection loadPropertiesCollection() { + /*public Collection loadPropertiesCollection() { logger.debug("Loading collection Properties... "); - return this.loadCollection(this.rootCollection, XMLStorageManager.PROPERTIES_COLLECTION_NAME); - } + return this.loadCollection(this.rootCollection, XMLStorage.PROPERTIES_COLLECTION_NAME); + } */ /** * Loads from the children of the Profile Collection, the collection identified by the given @@ -266,10 +292,10 @@ public class XMLStorageManager { * the child collection of the Profile collection to load * @return the Collection */ - public Collection loadProfileCollection(String collectionName) { + /* public Collection loadProfileCollection(String collectionName) { logger.debug("Loading collection " + collectionName + "... "); return this.loadCollection(this.profilesRootCollection, collectionName); - } + }*/ /** * Loads the parent collection of all collections containing resources profiles. It must be used @@ -277,10 +303,10 @@ public class XMLStorageManager { * * @return the Collection */ - public Collection loadAllProfilesCollection() { + /*public Collection loadAllProfilesCollection() { logger.debug("Loading all profiles collection... "); - return this.loadCollection(this.rootCollection, XMLStorageManager.PROFILES_COLLECTION_NAME); - } + return this.loadCollection(this.rootCollection, XMLStorage.PROFILES_COLLECTION_NAME); + }*/ /** * Loads the root collection. It must be used when quering all the information maintained by the @@ -293,7 +319,7 @@ public class XMLStorageManager { Collection currentCollection = null; logger.debug("Loading all collections... "); // return this.loadCollection(this.rootCollection, - // XMLStorageManager.PROFILES_COLLECTION_NAME); + // XMLStorage.PROFILES_COLLECTION_NAME); try { currentCollection = DatabaseManager.getCollection(URI + DBBroker.ROOT_COLLECTION, USER, PWD); } catch (XMLDBException edb) { @@ -304,15 +330,16 @@ public class XMLStorageManager { } /** - * Stores a AggregatorPersistentResource in the current collection. If the resource already + * Stores a XMLDBDocument in the current collection. If the resource already * exists in the storage, it is updated. * * @param resource * the resource to store + * @throws MalformedXMLResourceException * @throws Exception * if the storing fails */ - public void storeResource(PersistentResource resource) throws XMLStorageNotAvailableException, MalformedResourceException { + public void storeResource(GCUBEXMLResource resource) throws XMLStorageNotAvailableException, MalformedXMLResourceException { this.lock(); if (status != STATUS.INITIALISED) { @@ -320,14 +347,7 @@ public class XMLStorageManager { throw new XMLStorageNotAvailableException("XMLStorage not initialized"); } - Collection currentCollection = null; - if (resource.getType() == RESOURCETYPE.Profile) { - // the entry contains a gCube resource profile - currentCollection = this.loadProfileCollection(resource.getProfileType()); - } else { - // the entry contains generic properties - currentCollection = this.loadPropertiesCollection(); - } + Collection currentCollection = this.loadCollection(resource.getCollectionName()); if (currentCollection == null) { logger.error("Unable to open the Collection"); @@ -336,13 +356,14 @@ public class XMLStorageManager { } try { - XMLResource document = (XMLResource) currentCollection.createResource(resource.getID(), "XMLResource"); - document.setContent(resource.toString()); + XMLResource document = (XMLResource) currentCollection.createResource(resource.getResourceName(), "XMLResource"); + document.setContent(resource.toString()); logger.debug("Storing/updating resource " + document.getId() + " in collection " + currentCollection.getName() + "..."); + logger.trace("Resource content: " + resource.toString()); currentCollection.storeResource(document); logger.debug("...done"); } catch (XMLDBException edb) { - logger.error("Failed to store resource " + resource.getID()); + logger.error("Failed to store resource " + resource.getResourceName()); logger.error("" + edb.errorCode + " " + edb.getMessage(), edb); } catch (Exception e) { logger.error("" + e.getMessage(), e); @@ -369,9 +390,10 @@ public class XMLStorageManager { * @return * @throws Exception */ - public AggregatorPersistentResource retrieveResourceFromID(String resourceID) throws Exception { + /* public GCUBEXMLResource retrieveResourceFromID(String resourceID) throws Exception { XMLResource res = null; Collection currentCollection = this.loadAllCollections(); + String collectionName = currentCollection.getName(); try { res = (XMLResource) currentCollection.getResource(resourceID); if (res == null) @@ -380,73 +402,83 @@ public class XMLStorageManager { logger.error("Failed to retrieve document " + resourceID); logger.error("" + edb.errorCode + " " + edb.getMessage(), edb); throw new Exception(); - } - return new AggregatorPersistentResource(res); + } + return new GCUBEXMLResource(res, collectionName); } + */ + /** - * Retrieves a resource from the storage given its ID + * Retrieves a resource's content from the storage * - * @param resourceID + * @param resource * @return * @throws Exception */ - synchronized public AggregatorPersistentResource retrievePropertyResourceFromID(String resourceID) throws Exception { + synchronized public void retrieveResourceContent(GCUBEXMLResource resource) throws Exception { XMLResource res = null; - Collection currentCollection = this.loadPropertiesCollection(); + Collection currentCollection = this.loadCollection(resource.getCollectionName()); try { - res = (XMLResource) currentCollection.getResource(resourceID); - if (res == null) - logger.warn("Resource " + resourceID + " not found!"); + res = (XMLResource) currentCollection.getResource(resource.getResourceName()); + if (res == null) { + logger.warn("Resource " + resource.getResourceName() + " not found!"); + throw new Exception("Resource " + resource.getResourceName() + " not found!"); + } + if (res.getContent() == null) { + logger.warn("Resource content for " + resource.getResourceName() + " not found!"); + throw new Exception("Resource content for " + resource.getResourceName() + " not found!"); + } + resource.setContent(res.getContent().toString(), true); } catch (XMLDBException edb) { - logger.error("Failed to retrieve document " + resourceID); + logger.error("Failed to retrieve document " + resource.getResourceName()); logger.error("" + edb.errorCode + " " + edb.getMessage(), edb); throw new Exception(); } finally { this.resetCollection(currentCollection); } - return new AggregatorPersistentResource(res); } - - synchronized public AggregatorPersistentResource retrieveProfile(String profileID, String profileType) throws Exception { - + /** + * Checks if the resource does exist in the storage + * @param resource the resource to check + * @return true if the resource is stored, false otherwise + * @throws MalformedXMLResourceException if the input resource is not valid + */ + public boolean checkResource(GCUBEXMLResource resource) throws MalformedXMLResourceException { XMLResource res = null; - Collection currentCollection = this.loadProfileCollection(profileType); + Collection currentCollection = this.loadCollection(resource.getCollectionName()); try { - res = (XMLResource) currentCollection.getResource(profileID); - if (res == null) - logger.warn("Profile " + profileID + " not found!"); + res = (XMLResource) currentCollection.getResource(resource.getResourceName()); } catch (XMLDBException edb) { - logger.error("Failed to retrieve document " + profileID); - logger.error("" + edb.errorCode + " " + edb.getMessage(), edb); - throw new Exception(); + logger.warn("Resource " + resource.getResourceName() + " not found!"); } finally { this.resetCollection(currentCollection); } - return new AggregatorPersistentResource(res); + return (res == null)? false: true; + } + /** * * @param xpathquery * @return */ - synchronized public AggregatorPersistentResource executeXPathQuery(String xpathquery) { + synchronized public GCUBEXMLResource executeXPathQuery(String xpathquery) { - AggregatorPersistentResource res = null; - // ArrayList results = new - // ArrayList(); + GCUBEXMLResource res = null; + // ArrayList results = new + // ArrayList(); /* * try { // get query-service XPathQueryServiceImpl service = (XPathQueryServiceImpl) * currentCollection.getService("XPathQueryService", "1.0"); // set pretty-printing on * service.setProperty(OutputKeys.INDENT, "yes"); service.setProperty(OutputKeys.ENCODING, * "UTF-8"); ResourceSet set = service.query(xpathquery); logger.debug("number of returned * documents: " + set.getSize()); ResourceIterator i = set.getIterator(); - * while(i.hasMoreResources()) { res = new AggregatorPersistentResource((XMLResource) + * while(i.hasMoreResources()) { res = new XMLDBDocument((BaseDAIXResource) * i.nextResource()); System.out.println("DILIGENT resource " + i + " " + res.toString()); } * * for (int i = 0; i < (int) set.getSize(); i++) { res = new - * AggregatorPersistentResource((XMLResource) set.getResource((long) i)); + * XMLDBDocument((BaseDAIXResource) set.getResource((long) i)); * System.out.println("DILIGENT resource " + i + " " + res.toString()); } } catch * (XMLDBException edb) { logger.error("failed to execute Xpath query " + xpathquery); * edb.printStackTrace(); } catch (Exception e) { logger.error("exception " + xpathquery); @@ -457,30 +489,30 @@ public class XMLStorageManager { } /** - * Deletes a WS-ResourceProperties resource identified by the given ID + * Deletes a resource */ - synchronized public void retrieveAndDeleteResourceFromID(String resourceID) throws Exception { + synchronized public void deleteResource(GCUBEXMLResource resource) throws Exception { - if (resourceID == null) { - logger.warn("Invalid resource ID"); + if (resource.getResourceName() == null) { + logger.warn("Invalid resource name"); return; } this.lock(); - Collection propCollection = this.loadPropertiesCollection(); - - if (propCollection == null) { - logger.error("Unable to load collection Properties!"); - throw new Exception(); + Collection collection = this.loadCollection(resource.getCollectionName()); + if (collection == null) { + //logger.error("Unable to load collection Properties!"); + //throw new Exception(); + collection = this.rootCollection; } try { - logger.info("Trying to remove resource " + resourceID + " from collection " + propCollection.getName()); - deleteResource(resourceID, propCollection, false); + logger.info("Trying to remove resource " + resource.getResourceName() + " from collection " + collection.getName()); + deleteResource(resource.getResourceName(), collection, false); } catch (XMLDBException edb) { logger.error("Failed to remove the resource from the storage! "); logger.error("", edb); throw new Exception(); } finally { - this.resetCollection(propCollection); + this.resetCollection(collection); this.unlock(); } @@ -489,7 +521,7 @@ public class XMLStorageManager { /** * Deletes a Profile resource identified by the given ID */ - synchronized public void retrieveAndDeleteProfileFromID(String profileID, String profileType) throws Exception { + /* synchronized public void retrieveAndDeleteProfileFromID(String profileID, String profileType) throws Exception { if (profileID == null) { logger.warn("Invalid profile ID"); @@ -513,7 +545,7 @@ public class XMLStorageManager { this.unlock(); } - } + }*/ /** * Deletes the resource with the given ID from the local storage @@ -598,23 +630,28 @@ public class XMLStorageManager { /** * Delete the collection named PROPERTIES_COLLECTION_NAME from the storage */ - public void deleteAllProperties() { + public void deleteAllResourcesFromCollection(String collectionName) { this.lock(); try { - logger.info("Trying to delete the collection " + XMLStorageManager.PROPERTIES_COLLECTION_NAME + "..."); + //logger.info("Trying to delete the collection " + XMLStorage.PROPERTIES_COLLECTION_NAME + "..."); CollectionManagementService mgtService = (CollectionManagementService) rootCollection.getService("CollectionManagementService", "1.0"); - mgtService.removeCollection(XMLStorageManager.PROPERTIES_COLLECTION_NAME); + mgtService.removeCollection(collectionName); logger.info("Collection deleted"); } catch (XMLDBException edb) { - logger.warn("Unable to delete the collection " + XMLStorageManager.PROPERTIES_COLLECTION_NAME + ": " + edb.toString()); + logger.warn("Unable to delete the collection " + collectionName + ": " + edb.toString()); } finally { this.unlock(); } } - public String[] listAllPropertiesIDs() { - return listAllColletionIDs(this.loadPropertiesCollection()); + /** + * Lists all the identifiers of the resources belonging the collection + * @param collectionName the collection name + * @return the list of identifiers + */ + public String[] listAllCollectionResourceIDs(String collectionName) { + return listAllCollectionResourceIDs(this.loadCollection(collectionName));//.loadPropertiesCollection()); } /** @@ -634,7 +671,7 @@ public class XMLStorageManager { } - private String[] listAllColletionIDs(Collection collection) { + private String[] listAllCollectionResourceIDs(Collection collection) { String[] ids = null; String collectionName = ""; try { @@ -650,7 +687,7 @@ public class XMLStorageManager { } protected void checkConnection() { - if (this.operationsCounter > XMLStorageManager.maxOperationsPerConnection) { + if (this.operationsCounter > this.maxOperationsPerConnection) { logger.info("It's time to reset the connection..."); this.lock(); this.shutdown(false); diff --git a/src/org/gcube/informationsystem/collector/stubs/testsuite/wsdaix/AddDocumentsTester.java b/src/org/gcube/informationsystem/collector/stubs/testsuite/wsdaix/AddDocumentsTester.java new file mode 100644 index 0000000..cbfc82f --- /dev/null +++ b/src/org/gcube/informationsystem/collector/stubs/testsuite/wsdaix/AddDocumentsTester.java @@ -0,0 +1,152 @@ +package org.gcube.informationsystem.collector.stubs.testsuite.wsdaix; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.rmi.RemoteException; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.axis.message.MessageElement; +import org.gcube.common.core.contexts.GCUBERemotePortTypeContext; +import org.gcube.common.core.scope.GCUBEScope; +import org.gcube.common.core.utils.logging.GCUBEClientLog; +import org.gcube.informationsystem.collector.stubs.wsdai.DataResourceUnavailableFaultType; +import org.gcube.informationsystem.collector.stubs.wsdai.InvalidResourceNameFaultType; +import org.gcube.informationsystem.collector.stubs.wsdai.NotAuthorizedFaultType; +import org.gcube.informationsystem.collector.stubs.wsdai.ServiceBusyFaultType; +import org.gcube.informationsystem.collector.stubs.wsdaix.AddDocumentRequestWrapper; +import org.gcube.informationsystem.collector.stubs.wsdaix.AddDocumentResponseWrapperResponse; +import org.gcube.informationsystem.collector.stubs.wsdaix.AddDocumentsRequest; +import org.gcube.informationsystem.collector.stubs.wsdaix.AddDocumentsResponse; +import org.gcube.informationsystem.collector.stubs.wsdaix.InvalidCollectionNameFaultType; +import org.gcube.informationsystem.collector.stubs.wsdaix.XMLCollectionAccessPT; +import org.gcube.informationsystem.collector.stubs.wsdaix.XMLWrapperType; +import org.gcube.informationsystem.collector.stubs.wsdaix.service.WsdaixServiceAddressingLocator; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; + +import com.sun.xml.bind.StringInputStream; + +/** + * + * Tester for XMLCollectionAccess::addDocuments + * + * @author Manuele Simi (ISTI-CNR) + * + */ +public class AddDocumentsTester { + + + private static GCUBEClientLog logger = new GCUBEClientLog(AddDocumentsTester.class); + + + /** + * @param args + * 0 - host + * 1 - port + * 2 - scope + * 3 - resourcename + * 4 - collection + * 5 - document name + * 6 - filename + */ + public static void main(String[] args) { + + final String portTypeURI = "http://" + args[0] + ":" + args[1] + "/wsrf/services/gcube/informationsystem/collector/wsdaix/XMLCollectionAccess"; + + try { + AddDocumentsResponse r = addDocuments(portTypeURI,GCUBEScope.getScope(args[2]), + new org.apache.axis.types.URI (args[3]), + new org.apache.axis.types.URI(args[4]), + new String[] { args[5] }, + new Document[] {TestDocuments.loadDocument(args[6])} ); + logger.info("Number of response wrappers "+ r.getAddDocumentResponseWrapper().length ); + String response = null; + for(int i=0;i"); + builder.append("").append(type).append(""); + builder.append("").append(source).append(""); + builder.append("").append(String.valueOf(tt)).append(""); + builder.append("").append(groupkey).append(""); + builder.append("").append(entrykey).append(""); + builder.append("").append(key).append(""); + builder.append(""); + builder.toString(); + + return DocumentBuilderFactory + .newInstance() + .newDocumentBuilder() + .parse(new StringInputStream(builder.toString())); + + + } + +} diff --git a/src/org/gcube/informationsystem/collector/stubs/testsuite/wsdaix/RemoveDocumentsTester.java b/src/org/gcube/informationsystem/collector/stubs/testsuite/wsdaix/RemoveDocumentsTester.java new file mode 100644 index 0000000..1c37a1f --- /dev/null +++ b/src/org/gcube/informationsystem/collector/stubs/testsuite/wsdaix/RemoveDocumentsTester.java @@ -0,0 +1,13 @@ +package org.gcube.informationsystem.collector.stubs.testsuite.wsdaix; + +public class RemoveDocumentsTester { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +} diff --git a/src/org/gcube/informationsystem/collector/stubs/testsuite/wsdaix/TestDocuments.java b/src/org/gcube/informationsystem/collector/stubs/testsuite/wsdaix/TestDocuments.java new file mode 100644 index 0000000..c0fbc79 --- /dev/null +++ b/src/org/gcube/informationsystem/collector/stubs/testsuite/wsdaix/TestDocuments.java @@ -0,0 +1,39 @@ +package org.gcube.informationsystem.collector.stubs.testsuite.wsdaix; + +import java.io.File; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.apache.log4j.Logger; +import org.w3c.dom.*; + +/** + * + * Loads the XML documents used in tests. + * + * @author Manuele Simi (ISTI-CNR) + * + */ +public class TestDocuments { + + private static Logger mLog = Logger.getLogger(TestDocuments.class); + + /** + * Loads an XML document with the specified filename + */ + protected static Document loadDocument(String filename) { + try { + File file = new File(filename); + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + return db.parse(file); + + } catch ( Exception e ) { + mLog.error("Unable to load document: " + filename); + } + return null; + } + + +} diff --git a/src/org/gcube/informationsystem/collector/stubs/testsuite/wsdaix/metadataCollection.xml b/src/org/gcube/informationsystem/collector/stubs/testsuite/wsdaix/metadataCollection.xml new file mode 100644 index 0000000..c9c564d --- /dev/null +++ b/src/org/gcube/informationsystem/collector/stubs/testsuite/wsdaix/metadataCollection.xml @@ -0,0 +1,31 @@ + + 3bb6e850-94d2-11df-8d06-8e825c7c7b8d + MetadataCollection + + /d4science.research-infrastructures.eu/FARM/FCPPS + + + + Annotations_Collection + + + + 2010-07-21T15:14:13+01:00 + unknown + 0 + 2010-07-21T15:14:29+01:00 + 2010-07-21T15:14:29+01:00 + unknown + 5ec18cb0-94d2-11df-b077-8e28f9a7444e + + d14baeb0-f162-11dd-96f7-b87cc0f0b075 + is-annotated-by + + + http://gcube.org/AnnotationFrontEnd/AFEAnnotationV2 + + en + Annotations + + + diff --git a/src/org/gcube/informationsystem/collector/stubs/testsuite/xmlcollectionaccess/GetProfileTester.java b/src/org/gcube/informationsystem/collector/stubs/testsuite/xmlcollectionaccess/GetProfileTester.java deleted file mode 100644 index d9cd61d..0000000 --- a/src/org/gcube/informationsystem/collector/stubs/testsuite/xmlcollectionaccess/GetProfileTester.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.gcube.informationsystem.collector.stubs.testsuite.xmlcollectionaccess; - -import java.net.URL; -import java.rmi.RemoteException; - -import org.gcube.common.core.contexts.GCUBERemotePortTypeContext; -import org.gcube.common.core.scope.GCUBEScope; -import org.gcube.common.core.utils.logging.GCUBEClientLog; -import org.gcube.informationsystem.collector.stubs.DocumentNotFoundFaultType; -import org.gcube.informationsystem.collector.stubs.GetProfileCriteria; -import org.gcube.informationsystem.collector.stubs.XMLCollectionAccessPortType; -import org.gcube.informationsystem.collector.stubs.service.XMLCollectionAccessServiceLocator; - -/** - * Tester for GetProfile operation of the - * gcube/informationsystem/collector/XMLCollectionAccess portType - * - * @author Manuele Simi (ISTI-CNR) - * - */ -public class GetProfileTester { - - private static GCUBEClientLog logger = new GCUBEClientLog(GetProfileTester.class); - - /** - * @param args - */ - public static void main(String[] args) { - if (args.length != 5) { - logger.fatal("Usage: GetProfileTester "); - return; - } - final String portTypeURI = "http://" + args[0] + ":" + args[1] + "/wsrf/services/gcube/informationsystem/collector/XMLCollectionAccess"; - - - XMLCollectionAccessPortType port = null; - try { - port = new XMLCollectionAccessServiceLocator().getXMLCollectionAccessPortTypePort(new URL(portTypeURI)); - port = GCUBERemotePortTypeContext.getProxy(port, GCUBEScope.getScope(args[2])); - } catch (Exception e) { - logger.error("",e); - } - - logger.info("Submitting the request..."); - - String profile; - try { - GetProfileCriteria criteria = new GetProfileCriteria(); - criteria.setID(args[3]); - criteria.setProfileType(args[4]); - profile = port.getProfile(criteria); - logger.info("Retrieved profile: \n" + profile); - } catch (DocumentNotFoundFaultType e) { - logger.error("",e); - } catch (RemoteException e) { - logger.error("",e); - } - } - -} diff --git a/src/org/gcube/informationsystem/collector/stubs/testsuite/xmlcollectionaccess/GetResourceTester.java b/src/org/gcube/informationsystem/collector/stubs/testsuite/xmlcollectionaccess/GetResourceTester.java deleted file mode 100644 index f3b257a..0000000 --- a/src/org/gcube/informationsystem/collector/stubs/testsuite/xmlcollectionaccess/GetResourceTester.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.gcube.informationsystem.collector.stubs.testsuite.xmlcollectionaccess; - -import java.net.URL; -import java.rmi.RemoteException; - -import org.gcube.common.core.contexts.GCUBERemotePortTypeContext; -import org.gcube.common.core.scope.GCUBEScope; -import org.gcube.common.core.utils.logging.GCUBEClientLog; -import org.gcube.informationsystem.collector.stubs.DocumentNotFoundFaultType; -import org.gcube.informationsystem.collector.stubs.GetResourceCriteria; -import org.gcube.informationsystem.collector.stubs.XMLCollectionAccessPortType; -import org.gcube.informationsystem.collector.stubs.service.XMLCollectionAccessServiceLocator; - -/** - * Tester for GetResource operation of the - * gcube/informationsystem/collector/XMLCollectionAccess portType - * - * @author Manuele Simi (ISTI-CNR) - * - */ -public class GetResourceTester { - - private static GCUBEClientLog logger = new GCUBEClientLog(GetResourceTester.class); - - /** - * @param args - */ - public static void main(String[] args) { - if (args.length != 4) { - logger.fatal("Usage: GetResourceTester "); - return; - } - final String portTypeURI = "http://" + args[0] + ":" + args[1] + "/wsrf/services/gcube/informationsystem/collector/XMLCollectionAccess"; - - - XMLCollectionAccessPortType port = null; - try { - port = new XMLCollectionAccessServiceLocator().getXMLCollectionAccessPortTypePort(new URL(portTypeURI)); - port = GCUBERemotePortTypeContext.getProxy(port, GCUBEScope.getScope(args[2])); - } catch (Exception e) { - logger.error("",e); - } - - logger.info("Submitting the request..."); - - String resource; - try { - GetResourceCriteria criteria = new GetResourceCriteria(); - criteria.setID(args[3]); - resource = port.getResource(criteria); - logger.info("Retrieved resource: \n" + resource); - } catch (DocumentNotFoundFaultType e) { - logger.error("",e); - } catch (RemoteException e) { - logger.error("",e); - } - - - } - -} diff --git a/src/org/gcube/informationsystem/collector/test/GCUBEInstanceStateResourceTest.java b/src/org/gcube/informationsystem/collector/test/GCUBEInstanceStateResourceTest.java new file mode 100644 index 0000000..eb64c6e --- /dev/null +++ b/src/org/gcube/informationsystem/collector/test/GCUBEInstanceStateResourceTest.java @@ -0,0 +1,72 @@ +package org.gcube.informationsystem.collector.test; + +import org.gcube.informationsystem.collector.impl.resources.GCUBEInstanceStateResource; +import org.gcube.informationsystem.collector.impl.resources.DAIXResource.MalformedResourceException; + +import junit.framework.TestCase; + +public class GCUBEInstanceStateResourceTest extends TestCase { + + private GCUBEInstanceStateResource resource; + + protected void setUp() throws Exception { + super.setUp(); + resource = new GCUBEInstanceStateResource(); + + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + + public void testSetContentString() { + try { + resource.setContent(" "); + } catch (MalformedResourceException e) { + e.printStackTrace(); + } + } + + public void testGetCollectionName() { + assertTrue(resource.getCollectionName() == "Properties"); + } + + public void testSetCollectionName() { + fail("Not yet implemented"); + } + + public void testGetContent() { + fail("Not yet implemented"); + } + + public void testSetContentDocument() { + //resource.setContent(null); + } + + + public void testSetResourceName() { + resource.setResourceName("InstanceStateTest"); + } + + public void testGetResourceName() { + this.testSetResourceName(); + System.out.println("Resource name is " + resource.getResourceName()); + } + + + public void testGetResourceURI() { + fail("Not yet implemented"); + } + + public void testSetResourceURI() { + fail("Not yet implemented"); + } + + + public void testToString() { + this.testSetContentString(); + System.out.println("Resource content is " + resource.toString()); + } + +} diff --git a/src/org/gcube/informationsystem/collector/test/GCUBEProfileResourceTest.java b/src/org/gcube/informationsystem/collector/test/GCUBEProfileResourceTest.java new file mode 100644 index 0000000..82be2ce --- /dev/null +++ b/src/org/gcube/informationsystem/collector/test/GCUBEProfileResourceTest.java @@ -0,0 +1,121 @@ +package org.gcube.informationsystem.collector.test; + +import java.io.StringReader; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import junit.framework.TestCase; + +import org.gcube.informationsystem.collector.impl.resources.GCUBEProfileResource; +import org.gcube.informationsystem.collector.impl.resources.DAIXResource.MalformedResourceException; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.xml.sax.InputSource; + +public class GCUBEProfileResourceTest extends TestCase { + + private GCUBEProfileResource resource; + + @Before + public void setUp() throws Exception { + resource = new GCUBEProfileResource(); + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void testSetContentString() { + StringBuilder builder = new StringBuilder(); + builder.append(""); + builder.append("3bb6e850-94d2-11df-8d06-8e825c7c7b8d"); + builder.append("MetadataCollection"); + builder.append(""); + builder.append("/d4science.research-infrastructures.eu/FARM/FCPPS"); + builder.append(""); + builder.append(""); + builder.append(""); + builder.append(""); + builder.append(""); + + try { + resource.setContent(builder.toString()); + } catch (MalformedResourceException e) { + e.printStackTrace(); + } + } + + + @Test + public void testBaseDAIXResource() { + //fail("Not yet implemented"); + } + + @Test + public void testGetResourceName() { + //fail("Not yet implemented"); + } + + @Test + public void testSetResourceName() { + resource.setResourceName("TestResouceName"); + } + + @Test + public void testGetResourceURI() { + //fail("Not yet implemented"); + } + + @Test + public void testSetResourceURI() { + //fail("Not yet implemented"); + } + + @Test + public void testGetContent() { + //fail("Not yet implemented"); + } + + @Test + public void testSetContentDocument() { + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + StringReader reader = new StringReader("GHN"); + InputSource source = new InputSource(reader); + resource.setContent(builder.parse(source)); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + @Test + public void testSetCollectionName() { + resource.setResourceType("testCollection"); + } + + @Test + public void testGetCollectionName() { + this.testSetContentString(); + try { + System.out.println("Resource collection is " + resource.getCollectionName()); + } catch (MalformedResourceException e) { + e.printStackTrace(); + } + } + + @Test + public void testToString() { + this.testSetContentDocument(); + System.out.println("Resource from DOM is: " + resource.toString()); + //resource.setContent(null); + this.testSetContentString(); + System.out.println("Resource from String is: " + resource.toString()); + } + +} diff --git a/src/org/gcube/informationsystem/collector/test/GCUBEXMLResourceTest.java b/src/org/gcube/informationsystem/collector/test/GCUBEXMLResourceTest.java new file mode 100644 index 0000000..f212e2f --- /dev/null +++ b/src/org/gcube/informationsystem/collector/test/GCUBEXMLResourceTest.java @@ -0,0 +1,160 @@ +package org.gcube.informationsystem.collector.test; + +import junit.framework.TestCase; + +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.gcube.informationsystem.collector.impl.resources.GCUBEXMLResource.MalformedXMLResourceException; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class GCUBEXMLResourceTest extends TestCase { + + private GCUBEXMLResource XMLiresource; + private GCUBEXMLResource XMLpresource; + private GCUBEInstanceStateResource iresource; + private GCUBEProfileResource presource; + + + @Before + public void setUp() throws Exception { + iresource = new GCUBEInstanceStateResource(); + iresource.setResourceName("Instance"); + iresource.setContent(" "); + presource = new GCUBEProfileResource(); + presource.setResourceName("Profile"); + presource.setContent("GHN"); + XMLiresource = new GCUBEXMLResource(iresource); + XMLpresource = new GCUBEXMLResource(presource); + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testGCUBEXMLResourceBaseDAIXResource() { + try { + XMLiresource = new GCUBEXMLResource(iresource); + XMLpresource = new GCUBEXMLResource(presource); + } catch (MalformedXMLResourceException e) { + Assert.fail("failed to create GCUBEXMLResources"); + } + + } + + @Test + public void testGCUBEXMLResourceXMLResourceString() { + //fail("Not yet implemented"); + } + + @Test + public void testGetCollectionName() { + try { + System.out.println("Instance collection Name " + XMLiresource.getCollectionName() ); + System.out.println("Profile collection Name " + XMLpresource.getCollectionName() ); + } catch (MalformedXMLResourceException e) { + e.printStackTrace(); + } + } + + @Test + public void testSetContentWithEnvelop() { + try { + String content = XMLpresource.toString(); + System.out.println("Profile Content with envelop " + content); + GCUBEXMLResource temp = new GCUBEXMLResource(new BaseDAIXResource("name")); + temp.setContent(content, true); + System.out.println("New Profile Content with envelop " + temp.toString()); + + String content2 = XMLiresource.toString(); + System.out.println("Instance State Content with envelop " + content2); + GCUBEXMLResource temp2 = new GCUBEXMLResource(new BaseDAIXResource("name")); + temp2.setContent(content2, true); + System.out.println("New Instance State Content with envelop " + temp2.toString()); + } catch (MalformedXMLResourceException e) { + Assert.fail("failed to create GCUBEXMLResources"); + } + } + + @Test + public void testGetResourceName() { + //fail("Not yet implemented"); + } + + @Test + public void testGetTerminationTime() { + //fail("Not yet implemented"); + } + + @Test + public void testGetLastUpdateTime() { + //fail("Not yet implemented"); + } + + @Test + public void testSetTerminationTime() { + //fail("Not yet implemented"); + } + + @Test + public void testGetLastUpdateTimeinMills() { + //fail("Not yet implemented"); + } + + @Test + public void testSetGroupKey() { + //fail("Not yet implemented"); + } + + @Test + public void testGetEntryKey() { + //fail("Not yet implemented"); + } + + @Test + public void testSetEntryKey() { + //fail("Not yet implemented"); + } + + @Test + public void testSetSource() { + //fail("Not yet implemented"); + } + + @Test + public void testGetSource() { + //fail("Not yet implemented"); + } + + @Test + public void testSetSourceKey() { + //fail("Not yet implemented"); + } + + @Test + public void testGetSourceKey() { + //fail("Not yet implemented"); + } + + @Test + public void testSetCompleteSourceKey() { + //fail("Not yet implemented"); + } + + @Test + public void testGetCompleteSourceKey() { + //fail("Not yet implemented"); + } + + @Test + public void testToString() { + System.out.println("Instance to string " + XMLiresource.toString() ); + System.out.println("Profile to string " + XMLpresource.toString() ); + } + +} diff --git a/src/org/gcube/informationsystem/collector/test/MetadataReaderTest.java b/src/org/gcube/informationsystem/collector/test/MetadataReaderTest.java new file mode 100644 index 0000000..263d886 --- /dev/null +++ b/src/org/gcube/informationsystem/collector/test/MetadataReaderTest.java @@ -0,0 +1,77 @@ +package org.gcube.informationsystem.collector.test; + +import java.io.IOException; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.gcube.informationsystem.collector.impl.utils.MetadataReader; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; + +import com.sun.xml.bind.StringInputStream; + +import junit.framework.TestCase; + +public class MetadataReaderTest extends TestCase { + + MetadataReader reader; + + protected void setUp() throws Exception { + Document metadata = this.createMetadata("Profile", "MySource", "600", "MyGroup", "MyKey", + "MyEntry"); + reader = new MetadataReader(metadata); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testGetType() { + System.out.println("Type: " + reader.getType()); + } + + public void testGetSource() { + System.out.println("Source: " + reader.getSource()); + } + + public void testGetTerminationTime() { + System.out.println("Termination time: " + reader.getTerminationTime().getTime().toString()); + } + + public void testGetGroupKey() { + System.out.println("Group Key: " + reader.getGroupKey()); + } + + public void testGetEntryKey() { + System.out.println("Entry Key: " + reader.getEntryKey()); + } + + public void testGetKey() { + System.out.println("Key: " + reader.getKey()); + } + + private Document createMetadata(String type, String source, + String tt, String groupkey, String key, String entrykey) + throws SAXException, IOException, ParserConfigurationException { + + StringBuilder builder = new StringBuilder(); + builder.append(""); + builder.append("").append(type).append(""); + builder.append("").append(source).append(""); + builder.append("").append(tt).append(""); + builder.append("").append(groupkey).append(""); + builder.append("").append(entrykey).append(""); + builder.append("").append(key).append(""); + builder.append(""); + builder.toString(); + + return DocumentBuilderFactory + .newInstance() + .newDocumentBuilder() + .parse(new StringInputStream(builder.toString())); + + + } + +} diff --git a/src/org/gcube/informationsystem/collector/test/XMLStorageManagerTest.java b/src/org/gcube/informationsystem/collector/test/XMLStorageManagerTest.java new file mode 100644 index 0000000..a4323b6 --- /dev/null +++ b/src/org/gcube/informationsystem/collector/test/XMLStorageManagerTest.java @@ -0,0 +1,165 @@ +package org.gcube.informationsystem.collector.test; + +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.gcube.informationsystem.collector.impl.resources.DAIXResource.MalformedResourceException; +import org.gcube.informationsystem.collector.impl.resources.GCUBEXMLResource.MalformedXMLResourceException; +import org.gcube.informationsystem.collector.impl.xmlstorage.exist.XMLStorage; +import org.gcube.informationsystem.collector.impl.xmlstorage.exist.XMLStorage.XMLStorageNotAvailableException; +import org.junit.Assert; +import org.xmldb.api.base.XMLDBException; + +import junit.framework.TestCase; + +public class XMLStorageManagerTest extends TestCase { + + private static final String resourceProfileName = "profileName"; + + private static final String resourceInstanceStateName = "instanceStateName"; + + XMLStorage storage; + + protected void setUp() throws Exception { + super.setUp(); + + storage = new XMLStorage(); + storage.initialize(1000); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testCreateCollection() { + try { + storage.createCollection("Profiles/RunningInstance"); + } catch (XMLDBException e) { + Assert.fail("XMLDB failure" + e.getMessage()); + } catch (XMLStorageNotAvailableException e) { + Assert.fail("Storage not available " + e.getMessage()); + } + } + + public void testShutdown() { + //fail("Not yet implemented"); + } + + public void testLoadAllCollections() { + + } + + public void testStoreResource() { + + try { + GCUBEXMLResource XMLpresource; + GCUBEProfileResource presource = new GCUBEProfileResource(); + presource.setResourceName(resourceProfileName); + presource.setContent("GHN"); + XMLpresource = new GCUBEXMLResource(presource); + storage.storeResource(XMLpresource); + System.out.println("testStoreResource : profile "+ XMLpresource.getResourceName()+ " successfully stored"); + GCUBEInstanceStateResource iresource = new GCUBEInstanceStateResource(); + iresource.setResourceName(resourceInstanceStateName); + iresource.setContent(" "); + GCUBEXMLResource XMLiresource = new GCUBEXMLResource(iresource); + storage.storeResource(XMLiresource); + System.out.println("testStoreResource : instance state "+ XMLiresource.getResourceName()+ " successfully stored"); + } catch (MalformedResourceException e) { + Assert.fail("Malformed Profile resource"); + } catch (XMLStorageNotAvailableException e) { + Assert.fail("Storage not available " + e.getMessage()); + } catch (MalformedXMLResourceException e) { + Assert.fail("Malformed XML resource"); + } + + } + + public void testIsLocked() { + } + + public void testRetrieveResourceContent() { + //this.testStoreResource(); + GCUBEXMLResource XMLresource; + GCUBEProfileResource presource = new GCUBEProfileResource(); + presource.setResourceName(resourceProfileName); + presource.setResourceType("GHN"); + try { + XMLresource = new GCUBEXMLResource(presource); + storage.retrieveResourceContent(XMLresource); + System.out.println("testRetrieveResourceContent: Retrieved content " + XMLresource.toString()); + } catch (Exception e) { + e.printStackTrace(); + Assert.fail("Failed to retrieve resource's content"); + } + GCUBEInstanceStateResource iresource = new GCUBEInstanceStateResource(); + iresource.setResourceName(resourceInstanceStateName); + try { + XMLresource = new GCUBEXMLResource(iresource); + storage.retrieveResourceContent(XMLresource); + System.out.println("testRetrieveResourceContent: Retrieved content " + XMLresource.toString()); + } catch (Exception e) { + e.printStackTrace(); + Assert.fail("Failed to retrieve resource's content"); + } + } + + public void testExecuteXPathQuery() { + + } + + + public void testListAllCollectionResourceIDs() { + GCUBEProfileResource presource = new GCUBEProfileResource(); + presource.setResourceType("GHN"); + try { + System.out.println("testListAllCollectionResourceIDs: Looking in collection " + presource.getCollectionName()); + for (String id : storage.listAllCollectionResourceIDs(presource.getCollectionName())) + System.out.println("\ttestListAllCollectionResourceIDs: Found Resource ID " + id); + + System.out.println("testListAllCollectionResourceIDs: Looking in collection " + new GCUBEInstanceStateResource().getCollectionName()); + for (String id : storage.listAllCollectionResourceIDs(new GCUBEInstanceStateResource().getCollectionName())) + System.out.println("\ttestListAllCollectionResourceIDs: Found Resource ID " + id); + + } catch (MalformedResourceException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + } + + public void testDeleteResource() { + GCUBEProfileResource presource = new GCUBEProfileResource(); + presource.setResourceType("GHN"); + try { + for (String id : storage.listAllCollectionResourceIDs(presource.getCollectionName())) { + presource.setResourceName(id); + storage.deleteResource(new GCUBEXMLResource(presource)); + System.out.println("testDeleteResource: resource " + id + " deleted"); + } + this.testListAllCollectionResourceIDs(); + } catch (MalformedResourceException e) { + e.printStackTrace(); + } catch (Exception e) { + + e.printStackTrace(); + } + + + } + + public void testDeleteAllResourcesFromCollection() { + + } + + + public void testGetStatus() { + + } + + public void testSetStatus() { + + } + +}