diff --git a/src/org/gcube/informationsystem/collector/impl/resources/MetadataRecord.java b/src/org/gcube/informationsystem/collector/impl/resources/MetadataRecord.java
deleted file mode 100644
index 8a2d0e2..0000000
--- a/src/org/gcube/informationsystem/collector/impl/resources/MetadataRecord.java
+++ /dev/null
@@ -1,103 +0,0 @@
-package org.gcube.informationsystem.collector.impl.resources;
-
-import java.util.Calendar;
-
-/**
- *
- * Metadata Record for gCube Profiles and Instance States
- *
- * @author Manuele Simi (ISTI-CNR)
- *
- */
-
-public class MetadataRecord {
-
- private Calendar getTerminationTime;
-
- private String source, key, groupKey, entryKey, type;
-
- /**
- * @return the getTerminationTime
- */
- public Calendar getGetTerminationTime() {
- return getTerminationTime;
- }
-
- /**
- * @param getTerminationTime the getTerminationTime to set
- */
- public void setGetTerminationTime(Calendar getTerminationTime) {
- this.getTerminationTime = getTerminationTime;
- }
-
- /**
- * @return the source
- */
- public String getSource() {
- return source;
- }
-
- /**
- * @param source the source to set
- */
- public void setSource(String source) {
- this.source = source;
- }
-
- /**
- * @return the key
- */
- public String getKey() {
- return key;
- }
-
- /**
- * @param key the key to set
- */
- public void setKey(String key) {
- this.key = key;
- }
-
- /**
- * @return the groupKey
- */
- public String getGroupKey() {
- return groupKey;
- }
-
- /**
- * @param groupKey the groupKey to set
- */
- public void setGroupKey(String groupKey) {
- this.groupKey = groupKey;
- }
-
- /**
- * @return the entryKey
- */
- public String getEntryKey() {
- return entryKey;
- }
-
- /**
- * @param entryKey the entryKey to set
- */
- public void setEntryKey(String entryKey) {
- this.entryKey = entryKey;
- }
-
- /**
- * @return the type
- */
- public String getType() {
- return type;
- }
-
- /**
- * @param type the type to set
- */
- public void setType(String type) {
- this.type = type;
- }
-
-}
diff --git a/src/org/gcube/informationsystem/collector/impl/utils/MetadataReader.java b/src/org/gcube/informationsystem/collector/impl/utils/MetadataReader.java
index 2b2ce95..2d240bf 100644
--- a/src/org/gcube/informationsystem/collector/impl/utils/MetadataReader.java
+++ b/src/org/gcube/informationsystem/collector/impl/utils/MetadataReader.java
@@ -31,7 +31,7 @@ public class MetadataReader {
public Calendar getTerminationTime() {
//value is in seconds
- String value = this.metadata.getElementsByTagName("TerminationTime").item(0).getTextContent();
+ String value = this.metadata.getElementsByTagName("TimeToLive").item(0).getTextContent();
Calendar now = new GregorianCalendar();
now.setTimeZone(TimeZone.getTimeZone("GMT"));
//add seconds to obtain the effective termination time
diff --git a/src/org/gcube/informationsystem/collector/stubs/metadata/MetadataRecord.java b/src/org/gcube/informationsystem/collector/stubs/metadata/MetadataRecord.java
new file mode 100644
index 0000000..8f96cc9
--- /dev/null
+++ b/src/org/gcube/informationsystem/collector/stubs/metadata/MetadataRecord.java
@@ -0,0 +1,180 @@
+package org.gcube.informationsystem.collector.stubs.metadata;
+
+import java.io.IOException;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.TimeZone;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+import com.sun.xml.bind.StringInputStream;
+
+/**
+ *
+ * Metadata Record for gCube Profiles and Instance States
+ *
+ * @author Manuele Simi (ISTI-CNR)
+ *
+ */
+
+public class MetadataRecord {
+
+ public static enum TYPE {INSTANCESTATE("InstanceState"),GCUBERESOURCE("Profile");
+ String name;
+ TYPE(String name) {this.name = name;}
+ public String toString() {return this.name;}
+
+ };
+
+ private Calendar terminationTime;
+
+ private Integer time;
+
+ private String source, key, groupKey, entryKey;
+
+ private TYPE type;
+
+
+ protected MetadataRecord() {}
+
+ /**
+ * @return the getTerminationTime
+ */
+ public Calendar getGetTerminationTime() {
+ return terminationTime;
+ }
+
+ /**
+ * @param time this amount of time (in seconds) will be added to the current time to determine the
+ * resource's termination time
+ */
+ public void setTimeToLive(Integer time) {
+ terminationTime = new GregorianCalendar();
+ terminationTime.setTimeZone(TimeZone.getTimeZone("GMT"));
+ //add seconds to obtain the effective termination time
+ terminationTime.add(Calendar.SECOND, time);
+ this.time = time;
+ }
+
+ /**
+ * @return the source
+ */
+ public String getSource() {
+ return source;
+ }
+
+ /**
+ * @param source the source to set
+ */
+ public void setSource(String source) {
+ this.source = source;
+ }
+
+ /**
+ * @return the key
+ */
+ public String getKey() {
+ return key;
+ }
+
+ /**
+ * @param key the key to set
+ */
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ /**
+ * @return the groupKey
+ */
+ public String getGroupKey() {
+ return groupKey;
+ }
+
+ /**
+ * @param groupKey the groupKey to set
+ */
+ public void setGroupKey(String groupKey) {
+ this.groupKey = groupKey;
+ }
+
+ /**
+ * @return the entryKey
+ */
+ public String getEntryKey() {
+ return entryKey;
+ }
+
+ /**
+ * @param entryKey the entryKey to set
+ */
+ public void setEntryKey(String entryKey) {
+ this.entryKey = entryKey;
+ }
+
+ /**
+ * @return the type
+ */
+ public TYPE getType() {
+ return type;
+ }
+
+ /**
+ * @param type the type to set
+ */
+ public void setType(TYPE type) {
+ this.type = type;
+ }
+
+ /**
+ *
+ * @return the time to live in seconds
+ */
+ public Integer getTimeToLive() {
+ return this.time;
+ }
+
+ /**
+ * Gets a {@link Document} representation of the record
+ * @return a document object representing the record as XML document
+ * @throws SAXException
+ * @throws IOException
+ * @throws ParserConfigurationException
+ */
+ public Document getAsDocument()
+ throws SAXException, IOException, ParserConfigurationException {
+ return DocumentBuilderFactory
+ .newInstance()
+ .newDocumentBuilder()
+ .parse(new StringInputStream(getAsBuilder().toString()));
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String toString() {
+ return getAsBuilder().toString();
+ }
+
+ /**
+ *
+ * @return a {@link StringBuilder} holding the string serialization of the record
+ */
+ private StringBuilder getAsBuilder() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("");
+ builder.append("").append(this.getType().toString()).append("");
+ builder.append("");
+ builder.append("").append(this.getTimeToLive()).append("");
+ builder.append("").append(this.getGroupKey()).append("");
+ builder.append("").append(this.getEntryKey()).append("");
+ builder.append("").append(this.getKey()).append("");
+ builder.append("");
+ return builder;
+ }
+}
diff --git a/src/org/gcube/informationsystem/collector/stubs/metadata/MetadataWriter.java b/src/org/gcube/informationsystem/collector/stubs/metadata/MetadataWriter.java
new file mode 100644
index 0000000..0f7d7df
--- /dev/null
+++ b/src/org/gcube/informationsystem/collector/stubs/metadata/MetadataWriter.java
@@ -0,0 +1,41 @@
+package org.gcube.informationsystem.collector.stubs.metadata;
+
+import org.gcube.informationsystem.collector.stubs.metadata.MetadataRecord.TYPE;
+import org.gcube.informationsystem.collector.stubs.metadata.MetadataRecord;
+
+
+/**
+ *
+ * A metadata writer for IC records
+ *
+ * @author Manuele Simi (ISTI-CNR)
+ *
+ */
+public class MetadataWriter {
+
+ private MetadataRecord metadata;
+
+ /**
+ * Creates a new writer
+ * @param type
+ * @param source
+ * @param timeToLive lifetime in seconds
+ * @param groupkey
+ * @param key
+ * @param entrykey
+ */
+ public MetadataWriter(TYPE type, String source,
+ Integer timeToLive, String groupkey, String key, String entrykey) {
+ this.metadata = new MetadataRecord();
+ this.metadata.setType(type);
+ this.metadata.setSource(source);
+ this.metadata.setEntryKey(entrykey);
+ this.metadata.setGroupKey(groupkey);
+ this.metadata.setTimeToLive(timeToLive);
+ }
+
+ public MetadataRecord getRecord() {
+ return this.metadata;
+ }
+
+ }
diff --git a/src/org/gcube/informationsystem/collector/stubs/testsuite/wsdaix/AddDocumentsTester.java b/src/org/gcube/informationsystem/collector/stubs/testsuite/wsdaix/AddDocumentsTester.java
index 60aea50..7217254 100644
--- a/src/org/gcube/informationsystem/collector/stubs/testsuite/wsdaix/AddDocumentsTester.java
+++ b/src/org/gcube/informationsystem/collector/stubs/testsuite/wsdaix/AddDocumentsTester.java
@@ -1,17 +1,16 @@
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.metadata.MetadataWriter;
+import org.gcube.informationsystem.collector.stubs.metadata.MetadataRecord.TYPE;
import org.gcube.informationsystem.collector.stubs.wsdai.DataResourceUnavailableFaultType;
import org.gcube.informationsystem.collector.stubs.wsdai.InvalidResourceNameFaultType;
import org.gcube.informationsystem.collector.stubs.wsdai.NotAuthorizedFaultType;
@@ -24,9 +23,6 @@ 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;
/**
*
@@ -100,9 +96,10 @@ public class AddDocumentsTester {
XMLWrapperType wrapper = new XMLWrapperType();
MessageElement msgElement = new MessageElement(documents[i].getDocumentElement());
MessageElement msgElement2;
+ MetadataWriter writer = new MetadataWriter(TYPE.INSTANCESTATE, "http://source",
+ 600, "MyGroupKey", "MyKey", "MyEntryKey");
try {
- msgElement2 = new MessageElement(createMetadata(type, "http://source",
- 600, "MyGroupKey", "MyKey", "MyEntryKey").getDocumentElement());
+ msgElement2 = new MessageElement(writer.getRecord().getAsDocument().getDocumentElement());
} catch (Exception e) {
logger.error("Unable to add document " + documentNames[i], e);
continue;
@@ -123,27 +120,5 @@ public class AddDocumentsTester {
return stubs.addDocuments(request);
}
- private static Document createMetadata(String type, String source,
- Integer tt, String groupkey, String key, String entrykey)
- throws SAXException, IOException, ParserConfigurationException {
-
- StringBuilder builder = new StringBuilder();
- builder.append("");
- builder.append("").append(type).append("");
- builder.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("");
-
- System.out.println(builder.toString());
- return DocumentBuilderFactory
- .newInstance()
- .newDocumentBuilder()
- .parse(new StringInputStream(builder.toString()));
-
-
- }
}