Fixings for generic WSDAIX resources
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Collector@34099 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
63bbd342ff
commit
b4b00b2e08
|
@ -1,5 +1,15 @@
|
||||||
#Wed Aug 12 09:49:59 EDT 2009
|
#Wed Dec 22 09:55:30 EST 2010
|
||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=1.5
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.source=1.5
|
||||||
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
|
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
|
||||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
|
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
|
||||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
|
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
|
||||||
|
|
|
@ -160,9 +160,8 @@ public class XMLCollectionAccess extends GCUBEPortType {
|
||||||
logger.info("Storing resource " + resourceName);
|
logger.info("Storing resource " + resourceName);
|
||||||
//String output = "AddDocument-" + UniqueName.getInstance().getName();
|
//String output = "AddDocument-" + UniqueName.getInstance().getName();
|
||||||
MessageElement elem = docs[i].getData().get_any()[0];
|
MessageElement elem = docs[i].getData().get_any()[0];
|
||||||
MessageElement elem2 = docs[i].getData().get_any()[1];
|
|
||||||
Document doc = null;
|
Document doc = null;
|
||||||
MetadataReader metadataReader = null;
|
BaseDAIXResource resource;
|
||||||
try {
|
try {
|
||||||
Object o = elem.getAsDocument();
|
Object o = elem.getAsDocument();
|
||||||
if (! (o instanceof Document))
|
if (! (o instanceof Document))
|
||||||
|
@ -173,18 +172,10 @@ public class XMLCollectionAccess extends GCUBEPortType {
|
||||||
responseWrappers[i].setResponse(AddDocumentResponseWrapperResponse.value2);
|
responseWrappers[i].setResponse(AddDocumentResponseWrapperResponse.value2);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
MetadataReader metadataReader = null;
|
||||||
try {
|
try {
|
||||||
Object o = elem2.getAsDocument();
|
//check if there exists a metadata record for this resource
|
||||||
if (! (o instanceof Document))
|
metadataReader = this.getMetadata(docs[i].getData().get_any(), resourceName);
|
||||||
throw new Exception("Unable to add resource " + resourceName + " because of a problem deserializing the metadata");
|
|
||||||
metadataReader = new MetadataReader((Document) o);
|
|
||||||
} catch ( Exception e ) {
|
|
||||||
logger.error("Unable to read resource's metadata", e);
|
|
||||||
responseWrappers[i].setResponse(AddDocumentResponseWrapperResponse.value2);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
BaseDAIXResource resource;
|
|
||||||
if (metadataReader.getType().compareToIgnoreCase(GCUBEProfileResource.TYPE) == 0) {
|
if (metadataReader.getType().compareToIgnoreCase(GCUBEProfileResource.TYPE) == 0) {
|
||||||
resource = new GCUBEProfileResource();
|
resource = new GCUBEProfileResource();
|
||||||
} else if (metadataReader.getType().compareToIgnoreCase(GCUBEInstanceStateResource.TYPE) == 0) {
|
} else if (metadataReader.getType().compareToIgnoreCase(GCUBEInstanceStateResource.TYPE) == 0) {
|
||||||
|
@ -193,6 +184,12 @@ public class XMLCollectionAccess extends GCUBEPortType {
|
||||||
resource = new BaseDAIXResource();
|
resource = new BaseDAIXResource();
|
||||||
resource.setCollectionName(targetCollection);
|
resource.setCollectionName(targetCollection);
|
||||||
}
|
}
|
||||||
|
} catch (Exception e2) {
|
||||||
|
resource = new BaseDAIXResource();
|
||||||
|
resource.setCollectionName(targetCollection);
|
||||||
|
metadataReader = null;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
resource.setResourceName(resourceName);
|
resource.setResourceName(resourceName);
|
||||||
resource.setContent(doc);
|
resource.setContent(doc);
|
||||||
|
@ -201,14 +198,9 @@ public class XMLCollectionAccess extends GCUBEPortType {
|
||||||
responseWrappers[i].setResponse(AddDocumentResponseWrapperResponse.value2);
|
responseWrappers[i].setResponse(AddDocumentResponseWrapperResponse.value2);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
GCUBEXMLResource xmlResource;
|
|
||||||
try {
|
try {
|
||||||
xmlResource = new GCUBEXMLResource(resource);
|
GCUBEXMLResource xmlResource = wrap(resource, metadataReader);
|
||||||
xmlResource.setSource(metadataReader.getSource());
|
|
||||||
xmlResource.setTerminationTime(metadataReader.getTerminationTime());
|
|
||||||
xmlResource.setGroupKey(metadataReader.getGroupKey());
|
|
||||||
xmlResource.setEntryKey(metadataReader.getEntryKey());
|
|
||||||
xmlResource.setSourceKey(metadataReader.getKey());
|
|
||||||
boolean exist = false;
|
boolean exist = false;
|
||||||
if ( State.getDataManager().resourceExists(xmlResource) ) {
|
if ( State.getDataManager().resourceExists(xmlResource) ) {
|
||||||
exist = true;
|
exist = true;
|
||||||
|
@ -237,6 +229,47 @@ public class XMLCollectionAccess extends GCUBEPortType {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the metadata reader from the given soap elements, if any
|
||||||
|
* @param elements the elements received as part of the SOAP message
|
||||||
|
* @param resourceName the related resource name
|
||||||
|
* @return the metadata reader
|
||||||
|
* @throws Exception if the reader does not exist or is invalid
|
||||||
|
*/
|
||||||
|
private MetadataReader getMetadata(MessageElement[] elements, String resourceName) throws Exception {
|
||||||
|
if (elements.length > 1){
|
||||||
|
MessageElement elem2 = elements[1];
|
||||||
|
try {
|
||||||
|
Object o = elem2.getAsDocument();
|
||||||
|
if (! (o instanceof Document))
|
||||||
|
throw new Exception("Unable to add resource " + resourceName + " because of a problem deserializing the metadata");
|
||||||
|
return new MetadataReader((Document) o);
|
||||||
|
} catch ( Exception e ) {
|
||||||
|
logger.error("Unable to read resource's metadata", e);
|
||||||
|
throw new Exception("Unable to read resource "+ resourceName + " metadata", e);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
throw new Exception("Unable to find any resource's metadata record for " + resourceName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wraps a {@link BaseDAIXResource} into a {@link GCUBEXMLResource}
|
||||||
|
* @param resource the resource to wrap
|
||||||
|
* @param metadataReader the related reader, if any
|
||||||
|
* @return the wrapped resource
|
||||||
|
* @throws MalformedXMLResourceException
|
||||||
|
*/
|
||||||
|
private GCUBEXMLResource wrap(BaseDAIXResource resource, MetadataReader metadataReader) throws MalformedXMLResourceException {
|
||||||
|
GCUBEXMLResource xmlResource = new GCUBEXMLResource(resource);
|
||||||
|
if (metadataReader != null) {
|
||||||
|
xmlResource.setSource(metadataReader.getSource());
|
||||||
|
xmlResource.setTerminationTime(metadataReader.getTerminationTime());
|
||||||
|
xmlResource.setGroupKey(metadataReader.getGroupKey());
|
||||||
|
xmlResource.setEntryKey(metadataReader.getEntryKey());
|
||||||
|
xmlResource.setSourceKey(metadataReader.getKey());
|
||||||
|
}
|
||||||
|
return xmlResource;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of CollectionAccess::RemoveDocuments
|
* Implementation of CollectionAccess::RemoveDocuments
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.gcube.informationsystem.collector.stubs.metadata;
|
package org.gcube.informationsystem.collector.stubs.metadata;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
@ -11,8 +12,6 @@ import javax.xml.parsers.ParserConfigurationException;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import com.sun.xml.bind.StringInputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Metadata Record for gCube Profiles and Instance States
|
* Metadata Record for gCube Profiles and Instance States
|
||||||
|
@ -150,7 +149,7 @@ public class MetadataRecord {
|
||||||
return DocumentBuilderFactory
|
return DocumentBuilderFactory
|
||||||
.newInstance()
|
.newInstance()
|
||||||
.newDocumentBuilder()
|
.newDocumentBuilder()
|
||||||
.parse(new StringInputStream(getAsBuilder().toString()));
|
.parse(new ByteArrayInputStream(getAsBuilder().toString().getBytes("UTF-8")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.gcube.informationsystem.collector;
|
package org.gcube.informationsystem.collector;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
@ -9,7 +10,6 @@ import org.gcube.informationsystem.collector.impl.utils.MetadataReader;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import com.sun.xml.bind.StringInputStream;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ public class MetadataReaderTest extends TestCase {
|
||||||
return DocumentBuilderFactory
|
return DocumentBuilderFactory
|
||||||
.newInstance()
|
.newInstance()
|
||||||
.newDocumentBuilder()
|
.newDocumentBuilder()
|
||||||
.parse(new StringInputStream(builder.toString()));
|
.parse(new ByteArrayInputStream(builder.toString().getBytes("UTF-8")));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue