package org.gcube.informationsystem.collector.impl.porttypes.wsdaix;
import java.rmi.RemoteException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.axis.message.MessageElement;
import org.apache.axis.types.URI;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
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;
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;
String targetCollection = this.URItoCollection(getDocumentsRequest.getCollectionName());
GetDocumentResponseWrapper[] responseWrapper = new GetDocumentResponseWrapper[size];
for(int i=0;i
//2 -
//3 -
//4 -
//5 -
for(int i=0;i 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());
xmlResource.setNamespace(metadataReader.getNamespace());
xmlResource.setPublicationMode(metadataReader.getPublicationMode());
}
return xmlResource;
}
/**
* Implementation of CollectionAccess::RemoveDocuments
*
* @param removeDocumentsRequest
* @return
* @throws RemoteException
* @throws ServiceBusyFaultType
* @throws InvalidResourceNameFaultType
* @throws InvalidCollectionNameFaultType
*/
public RemoveDocumentsResponse removeDocuments(RemoveDocumentsRequest removeDocumentsRequest)
throws RemoteException, ServiceBusyFaultType, InvalidResourceNameFaultType, InvalidCollectionNameFaultType {
RemoveDocumentsResponse response = new RemoveDocumentsResponse();
RemoveDocumentRequestWrapper[] docs = removeDocumentsRequest.getRemoveDocumentRequestWrapper();
RemoveDocumentResponseWrapper[] responseWrappers = new RemoveDocumentResponseWrapper[docs.length];
String targetCollection = this.URItoCollection(removeDocumentsRequest.getCollectionName());
//response wrapper values
//v1 = Success
//v2 = DocumentNotRemoved-NotAuthorized
//v3 = documentDoesNotExist
for(int i=0;i