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">
|
<Changeset component="data-transfer-model-1.2.0" date="2016-10-09">
|
||||||
<Change>Improved Plugin handling</Change>
|
<Change>Improved Plugin handling</Change>
|
||||||
</Changeset>
|
</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>
|
</ReleaseNotes>
|
12
pom.xml
12
pom.xml
|
@ -1,4 +1,5 @@
|
||||||
<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">
|
<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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.gcube.tools</groupId>
|
<groupId>org.gcube.tools</groupId>
|
||||||
|
@ -7,7 +8,7 @@
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>org.gcube.data.transfer</groupId>
|
<groupId>org.gcube.data.transfer</groupId>
|
||||||
<artifactId>data-transfer-model</artifactId>
|
<artifactId>data-transfer-model</artifactId>
|
||||||
<version>1.2.0-SNAPSHOT</version>
|
<version>1.2.2-SNAPSHOT</version>
|
||||||
<name>Data Transfer Model</name>
|
<name>Data Transfer Model</name>
|
||||||
<description>Common model used by Data Transfer Service facilities</description>
|
<description>Common model used by Data Transfer Service facilities</description>
|
||||||
|
|
||||||
|
@ -44,6 +45,13 @@
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.persistence</groupId>
|
||||||
|
<artifactId>org.eclipse.persistence.moxy</artifactId>
|
||||||
|
<version>2.6.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- lombok -->
|
<!-- lombok -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.gcube.data.transfer.model;
|
||||||
|
|
||||||
public enum DestinationClashPolicy {
|
public enum DestinationClashPolicy {
|
||||||
|
|
||||||
|
|
||||||
FAIL,
|
FAIL,
|
||||||
REWRITE,
|
REWRITE,
|
||||||
ADD_SUFFIX,
|
ADD_SUFFIX,
|
||||||
|
|
|
@ -9,10 +9,26 @@ public class ServiceConstants {
|
||||||
public static final String REQUESTS_SERVLET_NAME="Requests";
|
public static final String REQUESTS_SERVLET_NAME="Requests";
|
||||||
public static final String STATUS_SERVLET_NAME="TransferStatus";
|
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
|
//Params
|
||||||
public static final String TRANSFER_REQUEST_OBJECT="request-object";
|
public static final String TRANSFER_REQUEST_OBJECT="request-object";
|
||||||
public static final String TRANSFER_ID="transfer-id";
|
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;
|
package org.gcube.data.transfer.model;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlAccessType;
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
|
@ -120,6 +121,18 @@ public class TransferCapabilities {
|
||||||
if(!other.availablePlugins.contains(opt))
|
if(!other.availablePlugins.contains(opt))
|
||||||
return false;
|
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 (nodeId == null) {
|
||||||
|
|
|
@ -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{
|
public static enum TransferMethod{
|
||||||
HTTPDownload,
|
HTTPDownload,
|
||||||
DirectTransfer
|
DirectTransfer,
|
||||||
|
FileUpload
|
||||||
}
|
}
|
||||||
|
|
||||||
public static enum Protocol{
|
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
|
@EqualsAndHashCode
|
||||||
@XmlRootElement
|
@XmlRootElement
|
||||||
@XmlAccessorType(XmlAccessType.NONE)
|
@XmlAccessorType(XmlAccessType.NONE)
|
||||||
@XmlSeeAlso({HttpDownloadSettings.class,DirectTransferSettings.class})
|
@XmlSeeAlso({HttpDownloadSettings.class,DirectTransferSettings.class,FileUploadSettings.class})
|
||||||
public abstract class TransferSettings<T extends TransferOptions> {
|
public abstract class TransferSettings<T extends TransferOptions> {
|
||||||
|
|
||||||
public abstract T getOptions();
|
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;
|
||||||
import org.gcube.data.transfer.model.TransferTicket.Status;
|
import org.gcube.data.transfer.model.TransferTicket.Status;
|
||||||
import org.gcube.data.transfer.model.options.DirectTransferOptions;
|
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.HttpDownloadOptions;
|
||||||
import org.gcube.data.transfer.model.options.TransferOptions;
|
import org.gcube.data.transfer.model.options.TransferOptions;
|
||||||
import org.gcube.data.transfer.model.options.TransferOptions.TransferMethod;
|
import org.gcube.data.transfer.model.options.TransferOptions.TransferMethod;
|
||||||
import org.gcube.data.transfer.model.settings.DirectTransferSettings;
|
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.settings.HttpDownloadSettings;
|
||||||
import org.gcube.data.transfer.model.utils.DateWrapper;
|
import org.gcube.data.transfer.model.utils.DateWrapper;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
@ -58,18 +60,22 @@ public class MarshallUnmarshalTest {
|
||||||
public void Marshall() throws MalformedURLException{
|
public void Marshall() throws MalformedURLException{
|
||||||
print(createRequest(TransferMethod.HTTPDownload));
|
print(createRequest(TransferMethod.HTTPDownload));
|
||||||
print(createRequest(TransferMethod.DirectTransfer));
|
print(createRequest(TransferMethod.DirectTransfer));
|
||||||
|
print(createRequest(TransferMethod.FileUpload));
|
||||||
print(createTransferCapabilities());
|
print(createTransferCapabilities());
|
||||||
print(createTicket(createRequest(TransferMethod.HTTPDownload)));
|
print(createTicket(createRequest(TransferMethod.HTTPDownload)));
|
||||||
print(createTicket(createRequest(TransferMethod.DirectTransfer)));
|
print(createTicket(createRequest(TransferMethod.DirectTransfer)));
|
||||||
|
print(createTicket(createRequest(TransferMethod.FileUpload)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void UnMarshall() throws MalformedURLException{
|
public void UnMarshall() throws MalformedURLException{
|
||||||
assertTrue(roundTrip(createRequest(TransferMethod.HTTPDownload)));
|
assertTrue(roundTrip(createRequest(TransferMethod.HTTPDownload)));
|
||||||
assertTrue(roundTrip(createRequest(TransferMethod.DirectTransfer)));
|
assertTrue(roundTrip(createRequest(TransferMethod.DirectTransfer)));
|
||||||
|
assertTrue(roundTrip(createRequest(TransferMethod.FileUpload)));
|
||||||
assertTrue(roundTrip(createTransferCapabilities()));
|
assertTrue(roundTrip(createTransferCapabilities()));
|
||||||
assertTrue(roundTrip(createTicket(createRequest(TransferMethod.HTTPDownload))));
|
assertTrue(roundTrip(createTicket(createRequest(TransferMethod.HTTPDownload))));
|
||||||
assertTrue(roundTrip(createTicket(createRequest(TransferMethod.DirectTransfer))));
|
assertTrue(roundTrip(createTicket(createRequest(TransferMethod.DirectTransfer))));
|
||||||
|
assertTrue(roundTrip(createTicket(createRequest(TransferMethod.FileUpload))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,9 +83,11 @@ public class MarshallUnmarshalTest {
|
||||||
public void toStringTest() throws MalformedURLException{
|
public void toStringTest() throws MalformedURLException{
|
||||||
System.out.println(createRequest(TransferMethod.HTTPDownload));
|
System.out.println(createRequest(TransferMethod.HTTPDownload));
|
||||||
System.out.println(createRequest(TransferMethod.DirectTransfer));
|
System.out.println(createRequest(TransferMethod.DirectTransfer));
|
||||||
|
System.out.println(createRequest(TransferMethod.FileUpload));
|
||||||
System.out.println(createTransferCapabilities());
|
System.out.println(createTransferCapabilities());
|
||||||
System.out.println(createTicket(createRequest(TransferMethod.HTTPDownload)));
|
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) {
|
public static <T extends Result> T marshal(Object resource,T result) {
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JAXBContext context = ctx;
|
// OLD XML MARSHALLING
|
||||||
Marshaller m = context.createMarshaller();
|
// JAXBContext context = ctx;
|
||||||
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
// 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;
|
return result;
|
||||||
}
|
}
|
||||||
catch(Exception e) {
|
catch(Exception e) {
|
||||||
throw new RuntimeException("serialisation error",e);
|
throw new RuntimeException("serialisation error",e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void print(Object resource) {
|
public static void print(Object resource) {
|
||||||
|
|
||||||
marshal(resource,new OutputStreamWriter(System.out));
|
marshal(resource,new OutputStreamWriter(System.out));
|
||||||
|
@ -159,6 +178,7 @@ public class MarshallUnmarshalTest {
|
||||||
public static <T> T unmarshal(Class<T> resourceClass,Source source) {
|
public static <T> T unmarshal(Class<T> resourceClass,Source source) {
|
||||||
try {
|
try {
|
||||||
Unmarshaller um = ctx.createUnmarshaller();
|
Unmarshaller um = ctx.createUnmarshaller();
|
||||||
|
um.setProperty("eclipselink.media-type", "application/json");
|
||||||
return resourceClass.cast(um.unmarshal(source));
|
return resourceClass.cast(um.unmarshal(source));
|
||||||
}
|
}
|
||||||
catch(Exception e) {
|
catch(Exception e) {
|
||||||
|
@ -192,10 +212,18 @@ public class MarshallUnmarshalTest {
|
||||||
switch(toUseMethod){
|
switch(toUseMethod){
|
||||||
case HTTPDownload : return new TransferRequest(UUID.randomUUID().toString(), createHttpSettings(),new Destination("myImportedFile"));
|
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 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;
|
default : return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private FileUploadSettings getFileUploadSettings(){
|
||||||
|
return new FileUploadSettings(getClass().getResourceAsStream("MarshallUnmarhsallTest.java"),getFileUploadOptions());
|
||||||
|
}
|
||||||
|
|
||||||
|
private FileUploadOptions getFileUploadOptions(){
|
||||||
|
return new FileUploadOptions();
|
||||||
|
}
|
||||||
|
|
||||||
private PluginInvocation createPluginInvocation(){
|
private PluginInvocation createPluginInvocation(){
|
||||||
HashMap<String,String> params=new HashMap<>();
|
HashMap<String,String> params=new HashMap<>();
|
||||||
|
|
Loading…
Reference in New Issue