git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/data-transfer/data-transfer-model/1.2@148845 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
0b7fd994a4
commit
bdc40fd104
|
@ -9,4 +9,10 @@
|
|||
<Changeset component="data-transfer-model-1.2.0" date="2016-10-09">
|
||||
<Change>Improved Plugin handling</Change>
|
||||
</Changeset>
|
||||
<Changeset component="data-transfer-model-1.2.1" date="2017-02-19">
|
||||
<Change>REST Constants</Change>
|
||||
</Changeset>
|
||||
<Changeset component="data-transfer-model-1.2.2" date="2017-05-18">
|
||||
<Change>Improved marshal checks JSON</Change>
|
||||
</Changeset>
|
||||
</ReleaseNotes>
|
54
pom.xml
54
pom.xml
|
@ -1,29 +1,30 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
<version>LATEST</version>
|
||||
</parent>
|
||||
<groupId>org.gcube.data.transfer</groupId>
|
||||
<artifactId>data-transfer-model</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<name>Data Transfer Model</name>
|
||||
<description>Common model used by Data Transfer Service facilities</description>
|
||||
|
||||
<properties>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
<version>LATEST</version>
|
||||
</parent>
|
||||
<groupId>org.gcube.data.transfer</groupId>
|
||||
<artifactId>data-transfer-model</artifactId>
|
||||
<version>1.2.2-SNAPSHOT</version>
|
||||
<name>Data Transfer Model</name>
|
||||
<description>Common model used by Data Transfer Service facilities</description>
|
||||
|
||||
<properties>
|
||||
<distroDirectory>${project.basedir}/distro</distroDirectory>
|
||||
<svnBaseUrl>http://svn.research-infrastructures.eu/d4science/gcube/trunk/data-transfer/${project.artifactId}</svnBaseUrl>
|
||||
</properties>
|
||||
|
||||
|
||||
<scm>
|
||||
|
||||
|
||||
<scm>
|
||||
<connection>scm:svn:${svnBaseUrl}/${project.artifactId}</connection>
|
||||
<developerConnection>scm:svn:${svnBaseUrl}/${project.artifactId}</developerConnection>
|
||||
<url>${svnBaseUrl}/${project.artifactId}</url>
|
||||
</scm>
|
||||
|
||||
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -35,7 +36,7 @@
|
|||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
@ -43,7 +44,14 @@
|
|||
<version>4.10</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.persistence</groupId>
|
||||
<artifactId>org.eclipse.persistence.moxy</artifactId>
|
||||
<version>2.6.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
|
@ -54,7 +62,7 @@
|
|||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -109,6 +117,6 @@
|
|||
</plugins>
|
||||
|
||||
</build>
|
||||
|
||||
|
||||
|
||||
|
||||
</project>
|
|
@ -2,6 +2,7 @@ package org.gcube.data.transfer.model;
|
|||
|
||||
public enum DestinationClashPolicy {
|
||||
|
||||
|
||||
FAIL,
|
||||
REWRITE,
|
||||
ADD_SUFFIX,
|
||||
|
|
|
@ -9,10 +9,26 @@ public class ServiceConstants {
|
|||
public static final String REQUESTS_SERVLET_NAME="Requests";
|
||||
public static final String STATUS_SERVLET_NAME="TransferStatus";
|
||||
|
||||
public static final String REST_SERVLET_NAME="REST";
|
||||
|
||||
// Methods
|
||||
public static final String REST_HTTP_DOWNLOAD="HttpDownload";
|
||||
public static final String REST_DIRECT_TRANSFER="DirectTransfer";
|
||||
public static final String REST_FILE_UPLOAD="FileUpload";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//Params
|
||||
public static final String TRANSFER_REQUEST_OBJECT="request-object";
|
||||
public static final String TRANSFER_ID="transfer-id";
|
||||
|
||||
|
||||
|
||||
public static final String DESTINATION_FILE_NAME="destination-file-name";
|
||||
public static final String CREATE_DIRS="create-dirs";
|
||||
public static final String ON_EXISTING_FILE="on-existing-file";
|
||||
public static final String ON_EXISTING_DIR="on-existing-dir";
|
||||
public static final String SOURCE_ID="source-id";
|
||||
public static final String MULTIPART_FILE="uploadedFile";
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.gcube.data.transfer.model;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
|
@ -38,17 +39,17 @@ public class TransferCapabilities {
|
|||
private String hostName;
|
||||
@XmlElement
|
||||
private Integer port;
|
||||
|
||||
|
||||
@XmlElementWrapper
|
||||
@XmlElementRefs({
|
||||
@XmlElementRef(type = DirectTransferOptions.class),
|
||||
@XmlElementRef(type = HttpDownloadOptions.class),
|
||||
})
|
||||
@XmlElementRef(type = DirectTransferOptions.class),
|
||||
@XmlElementRef(type = HttpDownloadOptions.class),
|
||||
})
|
||||
private Set<TransferOptions> availableMeans;
|
||||
|
||||
|
||||
@XmlElementWrapper
|
||||
private Set<PluginDescription> availablePlugins;
|
||||
|
||||
|
||||
@XmlElementWrapper
|
||||
private Set<String> availablePersistenceIds;
|
||||
|
||||
|
@ -59,17 +60,17 @@ public class TransferCapabilities {
|
|||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
|
||||
|
||||
if(availableMeans!=null){
|
||||
for(TransferOptions opt:availableMeans)
|
||||
result=prime*result+((opt==null)?0:opt.hashCode());
|
||||
}
|
||||
|
||||
|
||||
if(availablePlugins!=null){
|
||||
for(PluginDescription opt:availablePlugins)
|
||||
result=prime*result+((opt==null)?0:opt.hashCode());
|
||||
}
|
||||
|
||||
|
||||
result = prime * result
|
||||
+ ((nodeId == null) ? 0 : nodeId.hashCode());
|
||||
result = prime * result
|
||||
|
@ -91,58 +92,70 @@ public class TransferCapabilities {
|
|||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
TransferCapabilities other = (TransferCapabilities) obj;
|
||||
|
||||
|
||||
|
||||
|
||||
//Check capabilities
|
||||
if ((availableMeans == null || availableMeans.isEmpty()))
|
||||
if(other.availableMeans!=null&& (!other.availableMeans.isEmpty()))
|
||||
return false;
|
||||
else if(availableMeans!=null && (!availableMeans.isEmpty()))
|
||||
if(other.availableMeans==null || other.availableMeans.isEmpty())
|
||||
return false;
|
||||
else if(availableMeans.size()!=other.availableMeans.size())
|
||||
return false;
|
||||
else for(TransferOptions opt:availableMeans)
|
||||
if(!other.availableMeans.contains(opt))
|
||||
if(other.availableMeans!=null&& (!other.availableMeans.isEmpty()))
|
||||
return false;
|
||||
|
||||
|
||||
else if(availableMeans!=null && (!availableMeans.isEmpty()))
|
||||
if(other.availableMeans==null || other.availableMeans.isEmpty())
|
||||
return false;
|
||||
else if(availableMeans.size()!=other.availableMeans.size())
|
||||
return false;
|
||||
else for(TransferOptions opt:availableMeans)
|
||||
if(!other.availableMeans.contains(opt))
|
||||
return false;
|
||||
|
||||
|
||||
//Check plugins
|
||||
if ((availablePlugins == null || availablePlugins.isEmpty()))
|
||||
if(other.availablePlugins!=null&& (!other.availablePlugins.isEmpty()))
|
||||
return false;
|
||||
else if(availablePlugins!=null && (!availablePlugins.isEmpty()))
|
||||
if(other.availablePlugins==null || other.availablePlugins.isEmpty())
|
||||
return false;
|
||||
else if(availablePlugins.size()!=other.availablePlugins.size())
|
||||
return false;
|
||||
else for(PluginDescription opt:availablePlugins)
|
||||
if(!other.availablePlugins.contains(opt))
|
||||
return false;
|
||||
|
||||
|
||||
|
||||
else if(availablePlugins!=null && (!availablePlugins.isEmpty()))
|
||||
if(other.availablePlugins==null || other.availablePlugins.isEmpty())
|
||||
return false;
|
||||
else if(availablePlugins.size()!=other.availablePlugins.size())
|
||||
return false;
|
||||
else for(PluginDescription opt:availablePlugins)
|
||||
if(!other.availablePlugins.contains(opt))
|
||||
return false;
|
||||
|
||||
//TODO Check persistences
|
||||
if ((availablePersistenceIds == null || availablePersistenceIds.isEmpty()))
|
||||
if(other.availablePersistenceIds!=null&& (!other.availablePersistenceIds.isEmpty()))
|
||||
return false;
|
||||
else if(availablePersistenceIds!=null && (!availablePersistenceIds.isEmpty()))
|
||||
if(other.availablePersistenceIds==null || other.availablePersistenceIds.isEmpty())
|
||||
return false;
|
||||
else if(availablePersistenceIds.size()!=other.availablePersistenceIds.size())
|
||||
return false;
|
||||
else for(String opt:availablePersistenceIds)
|
||||
if(!other.availablePersistenceIds.contains(opt))
|
||||
return false;
|
||||
|
||||
|
||||
if (nodeId == null) {
|
||||
if (other.nodeId != null)
|
||||
return false;
|
||||
} else if (!nodeId.equals(other.nodeId))
|
||||
return false;
|
||||
|
||||
|
||||
if (hostName == null) {
|
||||
if (other.hostName != null)
|
||||
return false;
|
||||
} else if (!hostName.equals(other.hostName))
|
||||
return false;
|
||||
|
||||
|
||||
if (port == null) {
|
||||
if (other.port != null)
|
||||
return false;
|
||||
} else if (!port.equals(other.port))
|
||||
return false;
|
||||
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package org.gcube.data.transfer.model.options;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
public class FileUploadOptions extends TransferOptions{
|
||||
|
||||
private static final List<Protocol> protocol=Collections.singletonList(Protocol.HTTP);
|
||||
|
||||
|
||||
@Override
|
||||
public TransferMethod getMethod() {
|
||||
return TransferMethod.FileUpload;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Protocol> getAvailableProtocols() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Range getAvailableRange() {
|
||||
return Range.ONLY_80;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -16,7 +16,8 @@ public abstract class TransferOptions {
|
|||
|
||||
public static enum TransferMethod{
|
||||
HTTPDownload,
|
||||
DirectTransfer
|
||||
DirectTransfer,
|
||||
FileUpload
|
||||
}
|
||||
|
||||
public static enum Protocol{
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
package org.gcube.data.transfer.model.settings;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.gcube.data.transfer.model.options.FileUploadOptions;
|
||||
import org.gcube.data.transfer.model.options.Range;
|
||||
import org.gcube.data.transfer.model.options.TransferOptions.Protocol;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
public class FileUploadSettings extends TransferSettings<FileUploadOptions> {
|
||||
|
||||
private InputStream passedStream;
|
||||
|
||||
@XmlElement
|
||||
private FileUploadOptions options;
|
||||
|
||||
@Override
|
||||
public FileUploadOptions getOptions() {
|
||||
return options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Protocol getToUseProtocol() {
|
||||
return Protocol.HTTP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Range getToUseRange() {
|
||||
return Range.ONLY_80;
|
||||
}
|
||||
|
||||
}
|
|
@ -16,7 +16,7 @@ import org.gcube.data.transfer.model.options.TransferOptions.Protocol;
|
|||
@EqualsAndHashCode
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
@XmlSeeAlso({HttpDownloadSettings.class,DirectTransferSettings.class})
|
||||
@XmlSeeAlso({HttpDownloadSettings.class,DirectTransferSettings.class,FileUploadSettings.class})
|
||||
public abstract class TransferSettings<T extends TransferOptions> {
|
||||
|
||||
public abstract T getOptions();
|
||||
|
|
|
@ -31,10 +31,12 @@ import org.gcube.data.transfer.model.TransferRequest;
|
|||
import org.gcube.data.transfer.model.TransferTicket;
|
||||
import org.gcube.data.transfer.model.TransferTicket.Status;
|
||||
import org.gcube.data.transfer.model.options.DirectTransferOptions;
|
||||
import org.gcube.data.transfer.model.options.FileUploadOptions;
|
||||
import org.gcube.data.transfer.model.options.HttpDownloadOptions;
|
||||
import org.gcube.data.transfer.model.options.TransferOptions;
|
||||
import org.gcube.data.transfer.model.options.TransferOptions.TransferMethod;
|
||||
import org.gcube.data.transfer.model.settings.DirectTransferSettings;
|
||||
import org.gcube.data.transfer.model.settings.FileUploadSettings;
|
||||
import org.gcube.data.transfer.model.settings.HttpDownloadSettings;
|
||||
import org.gcube.data.transfer.model.utils.DateWrapper;
|
||||
import org.junit.BeforeClass;
|
||||
|
@ -58,18 +60,22 @@ public class MarshallUnmarshalTest {
|
|||
public void Marshall() throws MalformedURLException{
|
||||
print(createRequest(TransferMethod.HTTPDownload));
|
||||
print(createRequest(TransferMethod.DirectTransfer));
|
||||
print(createRequest(TransferMethod.FileUpload));
|
||||
print(createTransferCapabilities());
|
||||
print(createTicket(createRequest(TransferMethod.HTTPDownload)));
|
||||
print(createTicket(createRequest(TransferMethod.DirectTransfer)));
|
||||
print(createTicket(createRequest(TransferMethod.DirectTransfer)));
|
||||
print(createTicket(createRequest(TransferMethod.FileUpload)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void UnMarshall() throws MalformedURLException{
|
||||
assertTrue(roundTrip(createRequest(TransferMethod.HTTPDownload)));
|
||||
assertTrue(roundTrip(createRequest(TransferMethod.DirectTransfer)));
|
||||
assertTrue(roundTrip(createRequest(TransferMethod.FileUpload)));
|
||||
assertTrue(roundTrip(createTransferCapabilities()));
|
||||
assertTrue(roundTrip(createTicket(createRequest(TransferMethod.HTTPDownload))));
|
||||
assertTrue(roundTrip(createTicket(createRequest(TransferMethod.DirectTransfer))));
|
||||
assertTrue(roundTrip(createTicket(createRequest(TransferMethod.FileUpload))));
|
||||
}
|
||||
|
||||
|
||||
|
@ -77,9 +83,11 @@ public class MarshallUnmarshalTest {
|
|||
public void toStringTest() throws MalformedURLException{
|
||||
System.out.println(createRequest(TransferMethod.HTTPDownload));
|
||||
System.out.println(createRequest(TransferMethod.DirectTransfer));
|
||||
System.out.println(createRequest(TransferMethod.FileUpload));
|
||||
System.out.println(createTransferCapabilities());
|
||||
System.out.println(createTicket(createRequest(TransferMethod.HTTPDownload)));
|
||||
System.out.println(createTicket(createRequest(TransferMethod.DirectTransfer)));
|
||||
System.out.println(createTicket(createRequest(TransferMethod.DirectTransfer)));
|
||||
System.out.println(createTicket(createRequest(TransferMethod.FileUpload)));
|
||||
}
|
||||
|
||||
|
||||
|
@ -96,22 +104,33 @@ public class MarshallUnmarshalTest {
|
|||
*/
|
||||
public static <T extends Result> T marshal(Object resource,T result) {
|
||||
|
||||
|
||||
try {
|
||||
JAXBContext context = ctx;
|
||||
Marshaller m = context.createMarshaller();
|
||||
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
||||
// OLD XML MARSHALLING
|
||||
// JAXBContext context = ctx;
|
||||
// Marshaller m = context.createMarshaller();
|
||||
// m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
||||
//
|
||||
// m.marshal(resource,result);
|
||||
//
|
||||
// return result;
|
||||
|
||||
m.marshal(resource,result);
|
||||
|
||||
JAXBContext jaxbContext = ctx;
|
||||
Marshaller marshaller = jaxbContext.createMarshaller();
|
||||
marshaller.setProperty("eclipselink.media-type", "application/json");
|
||||
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
||||
marshaller.marshal(resource, result);
|
||||
return result;
|
||||
}
|
||||
catch(Exception e) {
|
||||
throw new RuntimeException("serialisation error",e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void print(Object resource) {
|
||||
|
||||
marshal(resource,new OutputStreamWriter(System.out));
|
||||
|
@ -159,6 +178,7 @@ public class MarshallUnmarshalTest {
|
|||
public static <T> T unmarshal(Class<T> resourceClass,Source source) {
|
||||
try {
|
||||
Unmarshaller um = ctx.createUnmarshaller();
|
||||
um.setProperty("eclipselink.media-type", "application/json");
|
||||
return resourceClass.cast(um.unmarshal(source));
|
||||
}
|
||||
catch(Exception e) {
|
||||
|
@ -192,10 +212,18 @@ public class MarshallUnmarshalTest {
|
|||
switch(toUseMethod){
|
||||
case HTTPDownload : return new TransferRequest(UUID.randomUUID().toString(), createHttpSettings(),new Destination("myImportedFile"));
|
||||
case DirectTransfer : return new TransferRequest(UUID.randomUUID().toString(), createDirectTransferSettings(),new Destination("myImportedFile"));
|
||||
case FileUpload : return new TransferRequest(UUID.randomUUID().toString(),getFileUploadSettings(),new Destination("myImportedFile"));
|
||||
default : return null;
|
||||
}
|
||||
}
|
||||
|
||||
private FileUploadSettings getFileUploadSettings(){
|
||||
return new FileUploadSettings(getClass().getResourceAsStream("MarshallUnmarhsallTest.java"),getFileUploadOptions());
|
||||
}
|
||||
|
||||
private FileUploadOptions getFileUploadOptions(){
|
||||
return new FileUploadOptions();
|
||||
}
|
||||
|
||||
private PluginInvocation createPluginInvocation(){
|
||||
HashMap<String,String> params=new HashMap<>();
|
||||
|
|
Loading…
Reference in New Issue