Adding CreateSubcollection and RemoveSubcollection implementation (plus related testers), removing old invalid testers from the test-suite
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Collector@30455 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
96faf17845
commit
bd6c50f062
|
@ -4,6 +4,7 @@ import java.rmi.RemoteException;
|
|||
import org.apache.axis.message.MessageElement;
|
||||
import org.apache.axis.types.URI;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xmldb.api.base.XMLDBException;
|
||||
import org.gcube.common.core.contexts.GCUBEServiceContext;
|
||||
import org.gcube.common.core.porttypes.GCUBEPortType;
|
||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||
|
@ -87,7 +88,7 @@ public class XMLCollectionAccess extends GCUBEPortType {
|
|||
InvalidCollectionNameFaultType {
|
||||
|
||||
int size = getDocumentsRequest.getGetDocumentRequestWrapper().length;
|
||||
String targetCollection = this.getTargetCollection(getDocumentsRequest.getCollectionName());
|
||||
String targetCollection = this.URItoCollection(getDocumentsRequest.getCollectionName());
|
||||
GetDocumentResponseWrapper[] responseWrapper = new GetDocumentResponseWrapper[size];
|
||||
for(int i=0;i<size;i++) {
|
||||
String resourceName = getDocumentsRequest.getGetDocumentRequestWrapper(i).getDocumentName();
|
||||
|
@ -145,7 +146,7 @@ public class XMLCollectionAccess extends GCUBEPortType {
|
|||
|
||||
AddDocumentRequestWrapper[] docs = addDocumentsRequest.getAddDocumentRequestWrapper();
|
||||
AddDocumentResponseWrapper[] responseWrappers = new AddDocumentResponseWrapper[docs.length];
|
||||
String targetCollection = this.getTargetCollection(addDocumentsRequest.getCollectionName());
|
||||
String targetCollection = this.URItoCollection(addDocumentsRequest.getCollectionName());
|
||||
//response wrapper values
|
||||
//1 - <xsd:enumeration value="Success"/>
|
||||
//2 - <xsd:enumeration value="DocumentNotAdded-DocumentDoesNotValidate"/>
|
||||
|
@ -209,7 +210,7 @@ public class XMLCollectionAccess extends GCUBEPortType {
|
|||
xmlResource.setEntryKey(metadataReader.getEntryKey());
|
||||
xmlResource.setSourceKey(metadataReader.getKey());
|
||||
boolean exist = false;
|
||||
if ( State.getDataManager().checkResource(xmlResource) ) {
|
||||
if ( State.getDataManager().resourceExists(xmlResource) ) {
|
||||
exist = true;
|
||||
}
|
||||
//store/update the new resource
|
||||
|
@ -254,7 +255,7 @@ public class XMLCollectionAccess extends GCUBEPortType {
|
|||
RemoveDocumentsResponse response = new RemoveDocumentsResponse();
|
||||
RemoveDocumentRequestWrapper[] docs = removeDocumentsRequest.getRemoveDocumentRequestWrapper();
|
||||
RemoveDocumentResponseWrapper[] responseWrappers = new RemoveDocumentResponseWrapper[docs.length];
|
||||
String targetCollection = this.getTargetCollection(removeDocumentsRequest.getCollectionName());
|
||||
String targetCollection = this.URItoCollection(removeDocumentsRequest.getCollectionName());
|
||||
//response wrapper values
|
||||
//v1 = Success
|
||||
//v2 = DocumentNotRemoved-NotAuthorized
|
||||
|
@ -268,7 +269,7 @@ public class XMLCollectionAccess extends GCUBEPortType {
|
|||
BaseDAIXResource resource = new BaseDAIXResource(resourceName);
|
||||
resource.setCollectionName(targetCollection);
|
||||
GCUBEXMLResource xmlResource = new GCUBEXMLResource(resource);
|
||||
if ( ! State.getDataManager().checkResource(xmlResource) ) {
|
||||
if ( ! State.getDataManager().resourceExists(xmlResource) ) {
|
||||
responseWrappers[i].setResponse(RemoveDocumentResponseWrapperResponse.value3);
|
||||
continue;
|
||||
}
|
||||
|
@ -306,8 +307,44 @@ public class XMLCollectionAccess extends GCUBEPortType {
|
|||
public CreateSubcollectionResponse createSubcollection(CreateSubcollectionRequest createSubcollectionRequest)
|
||||
throws RemoteException, CollectionAlreadyExistsFaultType, ServiceBusyFaultType, InvalidResourceNameFaultType,
|
||||
InvalidCollectionNameFaultType, NotAuthorizedFaultType, DataResourceUnavailableFaultType {
|
||||
|
||||
throw new NotAuthorizedFaultType();
|
||||
|
||||
String collectionPath = null;
|
||||
if ( createSubcollectionRequest.getCollectionName() != null ) {
|
||||
collectionPath = this.URItoCollection(createSubcollectionRequest.getCollectionName());
|
||||
if (collectionPath != null) {
|
||||
if (! State.getDataManager().collectionExists(collectionPath)) {
|
||||
logger.warn("Invalid collection name");
|
||||
throw new InvalidCollectionNameFaultType();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logger.warn("Collection "+ collectionPath + " does not exist, assuming ROOT collection");
|
||||
}
|
||||
|
||||
if (createSubcollectionRequest.getSubcollectionName() == null) {
|
||||
logger.warn("Invalid subcollection name");
|
||||
throw new InvalidCollectionNameFaultType();
|
||||
}
|
||||
|
||||
String subCollectionName = this.URItoCollection(createSubcollectionRequest.getSubcollectionName());
|
||||
if (collectionPath != null)
|
||||
subCollectionName = collectionPath +"/" + subCollectionName;
|
||||
if (State.getDataManager().collectionExists(subCollectionName)) {
|
||||
logger.warn("Collection "+ subCollectionName + " already exists");
|
||||
throw new CollectionAlreadyExistsFaultType();
|
||||
} else {
|
||||
try {
|
||||
State.getDataManager().createCollection(subCollectionName);
|
||||
} catch (XMLDBException e) {
|
||||
logger.error("Unable to create subcollection", e);
|
||||
throw new ServiceBusyFaultType();
|
||||
} catch (XMLStorageNotAvailableException e) {
|
||||
logger.error("Unable to create subcollection", e);
|
||||
throw new DataResourceUnavailableFaultType();
|
||||
}
|
||||
}
|
||||
|
||||
return new CreateSubcollectionResponse();
|
||||
}
|
||||
|
||||
|
||||
|
@ -326,7 +363,41 @@ public class XMLCollectionAccess extends GCUBEPortType {
|
|||
*/
|
||||
public RemoveSubcollectionResponse removeSubcollection(RemoveSubcollectionRequest removeSubcollectionRequest)
|
||||
throws RemoteException, ServiceBusyFaultType, InvalidResourceNameFaultType, InvalidCollectionNameFaultType, NotAuthorizedFaultType, DataResourceUnavailableFaultType {
|
||||
throw new NotAuthorizedFaultType();
|
||||
|
||||
if (removeSubcollectionRequest.getSubcollectionName() == null)
|
||||
throw new InvalidCollectionNameFaultType();
|
||||
|
||||
String collectionPath = null;
|
||||
if ( removeSubcollectionRequest.getCollectionName() != null ) {
|
||||
collectionPath = this.URItoCollection(removeSubcollectionRequest.getCollectionName());
|
||||
if (collectionPath != null) {
|
||||
if (! State.getDataManager().collectionExists(collectionPath)) {
|
||||
logger.warn("Invalid collection name");
|
||||
throw new InvalidCollectionNameFaultType();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logger.warn("Collection "+ collectionPath + " does not exist, assuming ROOT collection");
|
||||
}
|
||||
|
||||
String subCollectionName = this.URItoCollection(removeSubcollectionRequest.getSubcollectionName());
|
||||
if (collectionPath != null)
|
||||
subCollectionName = collectionPath +"/" + subCollectionName;
|
||||
if (! State.getDataManager().collectionExists(subCollectionName)) {
|
||||
logger.warn("Collection "+ subCollectionName + " does not exist");
|
||||
throw new InvalidCollectionNameFaultType();
|
||||
} else {
|
||||
try {
|
||||
State.getDataManager().deleteCollection(subCollectionName);
|
||||
logger.info("Collection " + subCollectionName + " successfully removed");
|
||||
} catch (XMLStorageNotAvailableException e) {
|
||||
logger.error("Unable to create subcollection", e);
|
||||
throw new DataResourceUnavailableFaultType();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return new RemoveSubcollectionResponse();
|
||||
}
|
||||
|
||||
|
||||
|
@ -404,8 +475,11 @@ public class XMLCollectionAccess extends GCUBEPortType {
|
|||
throw new NotAuthorizedFaultType();
|
||||
}
|
||||
|
||||
private String getTargetCollection(URI collection) {
|
||||
return collection.getHost() + "/" + collection.getPath();
|
||||
private String URItoCollection(URI collection) {
|
||||
if ((collection.getPath() == null) || (collection.getPath().length() == 0) )
|
||||
return collection.getHost();
|
||||
else
|
||||
return collection.getHost() + "/" + collection.getPath();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
|
|
@ -76,7 +76,7 @@ public class DataManager extends XMLStorage {
|
|||
if (Boolean.valueOf((String) ICServiceContext.getContext().getProperty("deleteRPsOnStartup", true))) {
|
||||
// cleanup the RPs collection
|
||||
logger.info("deleting all RPs...");
|
||||
this.deleteAllResourcesFromCollection(new GCUBEInstanceStateResource().getCollectionName());
|
||||
this.deleteCollection(new GCUBEInstanceStateResource().getCollectionName());
|
||||
}
|
||||
logger.info("Restore completed");
|
||||
} catch (Exception e1) {
|
||||
|
|
|
@ -59,7 +59,7 @@ public class State {
|
|||
if (Boolean.valueOf((String) ICServiceContext.getContext().getProperty("deleteRPsOnStartup", true))) {
|
||||
// cleanup the RPs collection
|
||||
logger.info("Deleting all RPs...");
|
||||
State.dataManager.deleteAllResourcesFromCollection(new GCUBEInstanceStateResource().getCollectionName());
|
||||
State.dataManager.deleteCollection(new GCUBEInstanceStateResource().getCollectionName());
|
||||
} else {
|
||||
logger.info("All RPs previously stored are kept in the storage");
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import java.util.List;
|
|||
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||
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.XMLStorage.XMLStorageNotAvailableException;
|
||||
import org.gcube.informationsystem.collector.impl.resources.GCUBEInstanceStateResource;
|
||||
import org.gcube.informationsystem.collector.impl.resources.GCUBEXMLResource;
|
||||
|
||||
|
@ -117,11 +118,12 @@ public class Sweeper implements Runnable {
|
|||
|
||||
/**
|
||||
* Deletes the Properties collection from the storage
|
||||
* @throws XMLStorageNotAvailableException
|
||||
*
|
||||
*/
|
||||
public static void cleanRPs() {
|
||||
public static void cleanRPs() throws XMLStorageNotAvailableException {
|
||||
// cleanup the RPs collection
|
||||
State.getDataManager().deleteAllResourcesFromCollection(new GCUBEInstanceStateResource().getCollectionName());
|
||||
State.getDataManager().deleteCollection(new GCUBEInstanceStateResource().getCollectionName());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,9 +17,6 @@ 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;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
@ -161,7 +158,6 @@ public class XMLStorage {
|
|||
for (String subcollection : subcollections) {
|
||||
Collection child = parent.getChildCollection(subcollection);
|
||||
logger.info("Creating subcollection " + subcollection);
|
||||
System.out.println("Creating subcollection " + subcollection);
|
||||
if (child == null) {
|
||||
child = this.createCollection(parent, subcollection);
|
||||
if (child == null)
|
||||
|
@ -451,7 +447,7 @@ public class XMLStorage {
|
|||
* @throws MalformedXMLResourceException if the input resource is not valid
|
||||
* @throws XMLStorageNotAvailableException
|
||||
*/
|
||||
public boolean checkResource(GCUBEXMLResource resource) throws MalformedXMLResourceException, XMLStorageNotAvailableException {
|
||||
public boolean resourceExists(GCUBEXMLResource resource) throws MalformedXMLResourceException, XMLStorageNotAvailableException {
|
||||
XMLResource res = null;
|
||||
Collection currentCollection = this.loadCollection(resource.getCollectionName());
|
||||
try {
|
||||
|
@ -611,6 +607,28 @@ public class XMLStorage {
|
|||
this.resetCollection(currentCollection);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a collection exists or not
|
||||
* @param collectionName the name of the collection to check
|
||||
* @return true or false, depending if the collection exists or not
|
||||
*/
|
||||
public boolean collectionExists(String collectionName) {
|
||||
String[] subcollections = collectionName.split("/");
|
||||
Collection parent = this.rootCollection;
|
||||
for (String subcollection : subcollections) {
|
||||
try {
|
||||
Collection child = parent.getChildCollection(subcollection);
|
||||
if (child == null) {
|
||||
return false;
|
||||
}
|
||||
parent = child;
|
||||
} catch (XMLDBException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new collection
|
||||
|
@ -635,9 +653,10 @@ public class XMLStorage {
|
|||
}
|
||||
|
||||
/**
|
||||
* Delete the collection named ROOT_COLLECTION_NAME from the storage
|
||||
* Deletes the collection from the storage
|
||||
* @param collectionName the name of the collection to delete
|
||||
*/
|
||||
public void deleteAllResourcesFromCollection(String collectionName) {
|
||||
public void deleteCollection(String collectionName) throws XMLStorageNotAvailableException {
|
||||
|
||||
this.lock();
|
||||
try {
|
||||
|
@ -647,6 +666,7 @@ public class XMLStorage {
|
|||
logger.info("Collection deleted");
|
||||
} catch (XMLDBException edb) {
|
||||
logger.warn("Unable to delete the collection " + collectionName + ": " + edb.toString());
|
||||
throw new XMLStorageNotAvailableException("Unable to delete the collection " + collectionName);
|
||||
} finally {
|
||||
this.unlock();
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ public class AddDocumentsTester {
|
|||
* 3 - document name
|
||||
* 4 - filename
|
||||
* 5 - type (Properties/Profile/Daix)
|
||||
* 6 - collection name
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
@ -57,7 +58,7 @@ public class AddDocumentsTester {
|
|||
try {
|
||||
AddDocumentsResponse r = addDocuments(portTypeURI,GCUBEScope.getScope(args[2]),
|
||||
new org.apache.axis.types.URI ("gcube://testResourceName"),
|
||||
new org.apache.axis.types.URI("gcube://collection"), args[5],
|
||||
new org.apache.axis.types.URI(args[6]), args[5],
|
||||
new String[] { args[3] },
|
||||
new Document[] {TestDocuments.loadDocument(args[4])} );
|
||||
logger.info("Number of response wrappers "+ r.getAddDocumentResponseWrapper().length );
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package org.gcube.informationsystem.collector.stubs.testsuite.wsdaix;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import org.apache.axis.types.URI;
|
||||
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.wsdaix.CreateSubcollectionRequest;
|
||||
import org.gcube.informationsystem.collector.stubs.wsdaix.XMLCollectionAccessPT;
|
||||
import org.gcube.informationsystem.collector.stubs.wsdaix.service.WsdaixServiceAddressingLocator;
|
||||
|
||||
public class CreateSubcollectionTester {
|
||||
|
||||
private static GCUBEClientLog logger = new GCUBEClientLog(CreateSubcollectionTester.class);
|
||||
|
||||
/**
|
||||
* @param args
|
||||
* 0 - host
|
||||
* 1 - port
|
||||
* 2 - scope
|
||||
* 3 - resource name
|
||||
* 4 - collection name
|
||||
* 5 - subcollection name
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
final String portTypeURI = "http://" + args[0] + ":" + args[1] + "/wsrf/services/gcube/informationsystem/collector/wsdaix/XMLCollectionAccess";
|
||||
try {
|
||||
CreateSubcollectionRequest request = new CreateSubcollectionRequest();
|
||||
request.setDataResourceAbstractName(new URI(args[3]));
|
||||
request.setCollectionName(new URI(args[4]));
|
||||
request.setSubcollectionName(new URI(args[5]));
|
||||
XMLCollectionAccessPT stubs = new WsdaixServiceAddressingLocator().getXMLCollectionAccessPTPort(new URL(portTypeURI));
|
||||
stubs = GCUBERemotePortTypeContext.getProxy(stubs, GCUBEScope.getScope(args[2]));
|
||||
stubs.createSubcollection(request);
|
||||
logger.info("Subcollection successfully created");
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to create subcollection " + args[5], e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package org.gcube.informationsystem.collector.stubs.testsuite.wsdaix;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import org.apache.axis.types.URI;
|
||||
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.wsdaix.RemoveSubcollectionRequest;
|
||||
import org.gcube.informationsystem.collector.stubs.wsdaix.XMLCollectionAccessPT;
|
||||
import org.gcube.informationsystem.collector.stubs.wsdaix.service.WsdaixServiceAddressingLocator;
|
||||
|
||||
public class RemoveSubcollectionTester {
|
||||
|
||||
private static GCUBEClientLog logger = new GCUBEClientLog(RemoveSubcollectionTester.class);
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
final String portTypeURI = "http://" + args[0] + ":" + args[1] + "/wsrf/services/gcube/informationsystem/collector/wsdaix/XMLCollectionAccess";
|
||||
try {
|
||||
RemoveSubcollectionRequest request = new RemoveSubcollectionRequest();
|
||||
request.setDataResourceAbstractName(new URI(args[3]));
|
||||
request.setCollectionName(new URI(args[4]));
|
||||
request.setSubcollectionName(new URI(args[5]));
|
||||
XMLCollectionAccessPT stubs = new WsdaixServiceAddressingLocator().getXMLCollectionAccessPTPort(new URL(portTypeURI));
|
||||
stubs = GCUBERemotePortTypeContext.getProxy(stubs, GCUBEScope.getScope(args[2]));
|
||||
stubs.removeSubcollection(request);
|
||||
logger.info("Subcollection successfully removed");
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to create subcollection " + args[5], e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
java -cp .:./lib/org.gcube.informationsystem.collector.testsuite.jar:$CLASSPATH org/gcube/informationsystem/collector/stubs/testsuite/xmlcollectionaccess/GetProfileTester $1 $2 $3 $4 $5
|
|
@ -1 +0,0 @@
|
|||
java -cp .:./lib/org.gcube.informationsystem.collector.testsuite.jar:$CLASSPATH org/gcube/informationsystem/collector/stubs/testsuite/xmlcollectionaccess/GetResourceTester $1 $2 $3 $4
|
Loading…
Reference in New Issue