Various fixings on resource management

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Collector@30174 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Manuele Simi 2010-10-27 21:46:26 +00:00
parent 105a17a0e8
commit 5062fdb339
6 changed files with 25 additions and 22 deletions

View File

@ -94,7 +94,7 @@ public class XMLCollectionAccess extends GCUBEPortType {
responseWrapper[i] = new GetDocumentResponseWrapper();
responseWrapper[i].setDocumentName(resourceName);
try {
logger.trace("Retrieving resource " + resourceName + " from collection " + getDocumentsRequest.getCollectionName().getPath());
logger.trace("Retrieving resource " + resourceName + " from collection " + targetCollection);
BaseDAIXResource resource = new BaseDAIXResource(resourceName);
resource.setCollectionName(targetCollection);
GCUBEXMLResource xmlResource = new GCUBEXMLResource(resource);

View File

@ -153,27 +153,25 @@ public class BaseDAIXResource implements DAIXResource {
* if the serialization fails
*/
public String toStringFromElement(String elementName) throws MalformedResourceException {
Document doc;
try {
doc = this.getContent(); //maybe there exists only a string content
} catch (Exception e) {
} catch (Exception e) {
//let's try to return the string content
return this.toString();
}
try {
try {
NodeList nodelist = doc.getElementsByTagName(elementName);
//if the element is not present, the entire content is returned
if (nodelist == null || nodelist.getLength() == 0)
return this.toString();
Node targetNode = nodelist.item(0);
TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer transformer = transFactory.newTransformer();
StringBuilder ret = new StringBuilder();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
int index = 0;
int index = 0;
Node node = targetNode.getChildNodes().item(index);
while (node != null) {
StringWriter buffer = new StringWriter();

View File

@ -291,12 +291,17 @@ public class GCUBEXMLResource {
resource.append("<LastUpdateMs>" + this.lastUpdateTime.getTimeInMillis() + "</LastUpdateMs>\n");
resource.append("<LastUpdateHuman>" + this.lastUpdateTime.getTime().toString() + "</LastUpdateHuman>\n");
resource.append("<Data>\n");
if (this.resource instanceof GCUBEInstanceStateResource)
resource.append(this.resource.toStringFromElement(GCUBEInstanceStateResource.INSTANCESTATE_ROOT_ELEMENT) + "\n");
if (this.resource instanceof GCUBEInstanceStateResource) {
//this check is to avoid a stupid message ("[Fatal Error] :1:83: The markup in the document following the root element must be well-formed.") in the nohup.out from the sax parser
if (this.resource.toString().startsWith("<"+GCUBEInstanceStateResource.INSTANCESTATE_ROOT_ELEMENT))
resource.append(this.resource.toStringFromElement(GCUBEInstanceStateResource.INSTANCESTATE_ROOT_ELEMENT) + "\n");
else
resource.append(this.resource.toString() + "\n");
}
else
resource.append(this.resource.toString() + "\n");
resource.append("</Data>\n");
resource.append("</Document>\n");
resource.append("</Document>");
} catch (MalformedResourceException e) {
logger.error("invalid content", e);
throw new RuntimeException("invalid content");

View File

@ -12,7 +12,6 @@ import org.exist.xmldb.DatabaseInstanceManager;
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.xmlstorage.exist.XMLStorage;
import org.gcube.informationsystem.collector.impl.resources.GCUBEXMLResource;
@ -359,7 +358,7 @@ public class XMLStorage {
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());
logger.trace("Resource content: " + document.getContent().toString());
currentCollection.storeResource(document);
logger.debug("...done");
} catch (XMLDBException edb) {

View File

@ -24,7 +24,7 @@ public class GCUBEXMLResourceTest extends TestCase {
public void setUp() throws Exception {
iresource = new GCUBEInstanceStateResource();
iresource.setResourceName("Instance");
iresource.setContent("<ResourceProperties><ns1:Task xmlns:ns1=\"http://gcube-system.org/namespaces/vremanagement/executor\"/> <ns9:Task xmlns:ns9=\"http://gcube-system.org/namespaces/vremanagement/executor\"/></ResourceProperties>");
iresource.setContent("<"+ GCUBEInstanceStateResource.INSTANCESTATE_ROOT_ELEMENT + "><ns1:Task xmlns:ns1=\"http://gcube-system.org/namespaces/vremanagement/executor\"/> <ns9:Task xmlns:ns9=\"http://gcube-system.org/namespaces/vremanagement/executor\"/></"+ GCUBEInstanceStateResource.INSTANCESTATE_ROOT_ELEMENT + ">");
presource = new GCUBEProfileResource();
presource.setResourceName("Profile");
presource.setContent("<Profile><Resource><ID/><Type>GHN</Type></Resource></Profile>");

View File

@ -29,6 +29,7 @@ public class XMLStorageManagerTest extends TestCase {
protected void tearDown() throws Exception {
super.tearDown();
storage.shutdown(true);
}
public void testCreateCollection() {
@ -49,20 +50,22 @@ public class XMLStorageManagerTest extends TestCase {
}
public void testStoreResource() {
public void testStoreResource() {
try {
GCUBEXMLResource XMLpresource;
GCUBEProfileResource presource = new GCUBEProfileResource();
presource.setResourceName(resourceProfileName);
presource.setContent("<Profile><Resource><ID/><Type>GHN</Type></Resource></Profile>");
presource.setContent("<Resource><ID/><Type>GHN</Type><Profile></Profile></Resource>");
XMLpresource = new GCUBEXMLResource(presource);
System.out.println("testStoreResource : storing \n"+ XMLpresource.toString()+ "\n in collection " + XMLpresource.getCollectionName());
storage.storeResource(XMLpresource);
System.out.println("testStoreResource : profile "+ XMLpresource.getResourceName()+ " successfully stored");
GCUBEInstanceStateResource iresource = new GCUBEInstanceStateResource();
iresource.setResourceName(resourceInstanceStateName);
iresource.setContent("<ns1:Task xmlns:ns1=\"http://gcube-system.org/namespaces/vremanagement/executor\"/> <ns9:Task xmlns:ns9=\"http://gcube-system.org/namespaces/vremanagement/executor\"/>");
iresource.setContent("<"+ GCUBEInstanceStateResource.INSTANCESTATE_ROOT_ELEMENT + "><ns1:Task xmlns:ns1=\"http://gcube-system.org/namespaces/vremanagement/executor\"/> <ns9:Task xmlns:ns9=\"http://gcube-system.org/namespaces/vremanagement/executor\"/> </"+ GCUBEInstanceStateResource.INSTANCESTATE_ROOT_ELEMENT + ">");
GCUBEXMLResource XMLiresource = new GCUBEXMLResource(iresource);
System.out.println("testStoreResource : storing \n"+ XMLiresource.toString()+ "\n in collection " + XMLiresource.getCollectionName());
storage.storeResource(XMLiresource);
System.out.println("testStoreResource : instance state "+ XMLiresource.getResourceName()+ " successfully stored");
} catch (MalformedResourceException e) {
@ -73,7 +76,7 @@ public class XMLStorageManagerTest extends TestCase {
Assert.fail("Malformed XML resource");
}
}
}
public void testIsLocked() {
}
@ -129,7 +132,7 @@ public class XMLStorageManagerTest extends TestCase {
}
public void testDeleteResource() {
public void testDeleteResource() {
GCUBEProfileResource presource = new GCUBEProfileResource();
presource.setResourceType("GHN");
try {
@ -144,11 +147,9 @@ public class XMLStorageManagerTest extends TestCase {
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void testDeleteAllResourcesFromCollection() {
}