release 4.2
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/data-transfer/data-transfer-model/1.2@134512 82a268e6-3cf1-43bd-a215-b396298e98cfmaster
commit
0b7fd994a4
@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>data-transfer-model</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -0,0 +1,6 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF-8
|
||||
encoding//src/main/resources=UTF-8
|
||||
encoding//src/test/java=UTF-8
|
||||
encoding//src/test/resources=UTF-8
|
||||
encoding/<project>=UTF-8
|
@ -0,0 +1,5 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=false
|
||||
version=1
|
@ -0,0 +1 @@
|
||||
${gcube.license}
|
@ -0,0 +1,65 @@
|
||||
The gCube System - ${name}
|
||||
--------------------------------------------------
|
||||
|
||||
${description}
|
||||
|
||||
|
||||
${gcube.description}
|
||||
|
||||
${gcube.funding}
|
||||
|
||||
|
||||
Version
|
||||
--------------------------------------------------
|
||||
|
||||
${version} (${buildDate})
|
||||
|
||||
Please see the file named "changelog.xml" in this directory for the release notes.
|
||||
|
||||
|
||||
|
||||
Authors
|
||||
--------------------------------------------------
|
||||
|
||||
* Fabio Sinibaldi (fabio.sinibaldi-AT-isti.cnr.it) Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" - CNR, Pisa (Italy).
|
||||
|
||||
Maintainers
|
||||
-----------
|
||||
|
||||
* Fabio Sinibaldi (fabio.sinibaldi-AT-isti.cnr.it) Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" - CNR, Pisa (Italy).
|
||||
|
||||
|
||||
Download information
|
||||
--------------------------------------------------
|
||||
|
||||
Source code is available from SVN:
|
||||
${scm.url}
|
||||
|
||||
Binaries can be downloaded from the gCube website:
|
||||
${gcube.website}
|
||||
|
||||
Installation
|
||||
--------------------------------------------------
|
||||
|
||||
Installation documentation is available on-line in the gCube Wiki:
|
||||
${gcube.wikiRoot}/Data_Transfer_2
|
||||
|
||||
Documentation
|
||||
--------------------------------------------------
|
||||
|
||||
Documentation is available on-line in the gCube Wiki:
|
||||
${gcube.wikiRoot}/Data_Transfer_2
|
||||
${gcube.wikiRoot}/How_to_use_Data_Transfer_2
|
||||
|
||||
|
||||
Support
|
||||
--------------------------------------------------
|
||||
|
||||
Bugs and support requests can be reported in the gCube issue tracking tool:
|
||||
${gcube.issueTracking}
|
||||
|
||||
|
||||
Licensing
|
||||
--------------------------------------------------
|
||||
|
||||
This software is licensed under the terms you may find in the file named "LICENSE" in this directory.
|
@ -0,0 +1,12 @@
|
||||
<ReleaseNotes>
|
||||
<Changeset component="data-transfer-model-1.0.0" date="2016-02-22">
|
||||
<Change>First Release</Change>
|
||||
</Changeset>
|
||||
<Changeset component="data-transfer-model-1.1.0" date="2016-09-09">
|
||||
<Change>Added Destination</Change>
|
||||
<Change>Added Plugin</Change>
|
||||
</Changeset>
|
||||
<Changeset component="data-transfer-model-1.2.0" date="2016-10-09">
|
||||
<Change>Improved Plugin handling</Change>
|
||||
</Changeset>
|
||||
</ReleaseNotes>
|
@ -0,0 +1,30 @@
|
||||
<assembly
|
||||
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
|
||||
<id>servicearchive</id>
|
||||
<formats>
|
||||
<format>tar.gz</format>
|
||||
</formats>
|
||||
<baseDirectory>/</baseDirectory>
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>${distroDirectory}</directory>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<useDefaultExcludes>true</useDefaultExcludes>
|
||||
<includes>
|
||||
<include>README</include>
|
||||
<include>LICENSE</include>
|
||||
<include>changelog.xml</include>
|
||||
</includes>
|
||||
<fileMode>755</fileMode>
|
||||
<filtered>true</filtered>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
<files>
|
||||
<file>
|
||||
<source>target/${build.finalName}.${project.packaging}</source>
|
||||
<outputDirectory>/${artifactId}</outputDirectory>
|
||||
</file>
|
||||
</files>
|
||||
</assembly>
|
@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Resource>
|
||||
<ID></ID>
|
||||
<Type>Service</Type>
|
||||
<Profile>
|
||||
<Description>${description}</Description>
|
||||
<Class>DataTransfer</Class>
|
||||
<Name>${artifactId}</Name>
|
||||
<Version>1.0.0</Version>
|
||||
<Packages>
|
||||
<Software>
|
||||
<Description>${description}</Description>
|
||||
<Name>${artifactId}</Name>
|
||||
<Version>${version}</Version>
|
||||
<MavenCoordinates>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${artifactId}</artifactId>
|
||||
<version>${version}</version>
|
||||
</MavenCoordinates>
|
||||
<Type>library</Type>
|
||||
<Files>
|
||||
<File>${build.finalName}.jar</File>
|
||||
</Files>
|
||||
</Software>
|
||||
</Packages>
|
||||
</Profile>
|
||||
</Resource>
|
||||
|
||||
|
@ -0,0 +1,114 @@
|
||||
<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>
|
||||
<distroDirectory>${project.basedir}/distro</distroDirectory>
|
||||
<svnBaseUrl>http://svn.research-infrastructures.eu/d4science/gcube/trunk/data-transfer/${project.artifactId}</svnBaseUrl>
|
||||
</properties>
|
||||
|
||||
|
||||
<scm>
|
||||
<connection>scm:svn:${svnBaseUrl}/${project.artifactId}</connection>
|
||||
<developerConnection>scm:svn:${svnBaseUrl}/${project.artifactId}</developerConnection>
|
||||
<url>${svnBaseUrl}/${project.artifactId}</url>
|
||||
</scm>
|
||||
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-bom</artifactId>
|
||||
<version>LATEST</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.10</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.14.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.5</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-profile</id>
|
||||
<phase>install</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>target</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${distroDirectory}</directory>
|
||||
<filtering>true</filtering>
|
||||
<includes>
|
||||
<include>*</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<descriptor>${distroDirectory}/descriptor.xml</descriptor>
|
||||
</descriptors>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>servicearchive</id>
|
||||
<phase>install</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
@ -0,0 +1,50 @@
|
||||
package org.gcube.data.transfer.model;
|
||||
|
||||
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 lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
public class Destination {
|
||||
|
||||
public static final String DEFAULT_PERSISTENCE_ID="DEFAULT";
|
||||
|
||||
|
||||
@XmlElement
|
||||
private String persistenceId=DEFAULT_PERSISTENCE_ID;
|
||||
@XmlElement
|
||||
private String subFolder=null;
|
||||
@NonNull
|
||||
@XmlElement
|
||||
private String destinationFileName=null;
|
||||
@XmlElement
|
||||
private Boolean createSubfolders=false;
|
||||
@XmlElement
|
||||
private DestinationClashPolicy onExistingFileName=DestinationClashPolicy.ADD_SUFFIX;
|
||||
@XmlElement
|
||||
private DestinationClashPolicy onExistingSubFolder=DestinationClashPolicy.APPEND;
|
||||
|
||||
public Destination(String destinationFileName) {
|
||||
super();
|
||||
this.destinationFileName = destinationFileName;
|
||||
}
|
||||
|
||||
public Destination(String subFolder, String destinationFileName) {
|
||||
super();
|
||||
this.subFolder = subFolder;
|
||||
this.destinationFileName = destinationFileName;
|
||||
this.createSubfolders=true;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package org.gcube.data.transfer.model;
|
||||
|
||||
public enum DestinationClashPolicy {
|
||||
|
||||
FAIL,
|
||||
REWRITE,
|
||||
ADD_SUFFIX,
|
||||
APPEND
|
||||
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package org.gcube.data.transfer.model;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlID;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
public class PluginDescription {
|
||||
|
||||
@XmlID
|
||||
private String id;
|
||||
@XmlElement
|
||||
private String description;
|
||||
@XmlElement
|
||||
private Map<String,String> parameters;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
PluginDescription other = (PluginDescription) obj;
|
||||
if (id == null) {
|
||||
if (other.id != null)
|
||||
return false;
|
||||
} else if (!id.equals(other.id))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package org.gcube.data.transfer.model;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlID;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
public class PluginInvocation {
|
||||
|
||||
|
||||
public static final String DESTINATION_FILE_PATH="*******USE_DESTINATION_FILE_PATH*********";
|
||||
|
||||
@XmlID
|
||||
private String pluginId;
|
||||
@XmlElement
|
||||
private Map<String,String> parameters;
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package org.gcube.data.transfer.model;
|
||||
|
||||
public class ServiceConstants {
|
||||
|
||||
public static final String APPLICATION_PATH="/gcube/service/";
|
||||
|
||||
//Servlets
|
||||
public static final String CAPABILTIES_SERVLET_NAME="Capabilities";
|
||||
public static final String REQUESTS_SERVLET_NAME="Requests";
|
||||
public static final String STATUS_SERVLET_NAME="TransferStatus";
|
||||
|
||||
//Params
|
||||
public static final String TRANSFER_REQUEST_OBJECT="request-object";
|
||||
public static final String TRANSFER_ID="transfer-id";
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,148 @@
|
||||
package org.gcube.data.transfer.model;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementRef;
|
||||
import javax.xml.bind.annotation.XmlElementRefs;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlID;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.Synchronized;
|
||||
import lombok.ToString;
|
||||
|
||||
import org.gcube.data.transfer.model.options.DirectTransferOptions;
|
||||
import org.gcube.data.transfer.model.options.HttpDownloadOptions;
|
||||
import org.gcube.data.transfer.model.options.TransferOptions;
|
||||
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
public class TransferCapabilities {
|
||||
|
||||
@XmlID
|
||||
private String nodeId;
|
||||
@XmlElement
|
||||
private String hostName;
|
||||
@XmlElement
|
||||
private Integer port;
|
||||
|
||||
@XmlElementWrapper
|
||||
@XmlElementRefs({
|
||||
@XmlElementRef(type = DirectTransferOptions.class),
|
||||
@XmlElementRef(type = HttpDownloadOptions.class),
|
||||
})
|
||||
private Set<TransferOptions> availableMeans;
|
||||
|
||||
@XmlElementWrapper
|
||||
private Set<PluginDescription> availablePlugins;
|
||||
|
||||
@XmlElementWrapper
|
||||
private Set<String> availablePersistenceIds;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
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
|
||||
+ ((hostName == null) ? 0 : hostName.hashCode());
|
||||
result = prime * result
|
||||
+ ((port == null) ? 0 : port.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
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))
|
||||
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;
|
||||
|
||||
|
||||
|
||||
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,111 @@
|
||||
package org.gcube.data.transfer.model;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementRef;
|
||||
import javax.xml.bind.annotation.XmlElementRefs;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlID;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.gcube.data.transfer.model.options.TransferOptions;
|
||||
import org.gcube.data.transfer.model.settings.DirectTransferSettings;
|
||||
import org.gcube.data.transfer.model.settings.HttpDownloadSettings;
|
||||
import org.gcube.data.transfer.model.settings.TransferSettings;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
public class TransferRequest{
|
||||
|
||||
|
||||
@XmlID
|
||||
private String id;
|
||||
@XmlElementRefs({
|
||||
@XmlElementRef(type = DirectTransferSettings.class),
|
||||
@XmlElementRef(type = HttpDownloadSettings.class),
|
||||
})
|
||||
private TransferSettings settings;
|
||||
|
||||
@XmlElement
|
||||
private Destination destinationSettings;
|
||||
|
||||
@XmlElementWrapper
|
||||
private Set<PluginInvocation> pluginInvocations;
|
||||
|
||||
|
||||
public TransferRequest(String id, TransferSettings settings, Destination destinationSettings) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.settings = settings;
|
||||
this.destinationSettings = destinationSettings;
|
||||
this.pluginInvocations=Collections.emptySet();
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
TransferRequest other = (TransferRequest) obj;
|
||||
if (destinationSettings == null) {
|
||||
if (other.destinationSettings != null)
|
||||
return false;
|
||||
} else if (!destinationSettings.equals(other.destinationSettings))
|
||||
return false;
|
||||
if (id == null) {
|
||||
if (other.id != null)
|
||||
return false;
|
||||
} else if (!id.equals(other.id))
|
||||
return false;
|
||||
|
||||
|
||||
//Check plugins
|
||||
if ((pluginInvocations == null || pluginInvocations.isEmpty()))
|
||||
if(other.pluginInvocations!=null&& (!other.pluginInvocations.isEmpty()))
|
||||
return false;
|
||||
else if(pluginInvocations!=null && (!pluginInvocations.isEmpty()))
|
||||
if(other.pluginInvocations==null || other.pluginInvocations.isEmpty())
|
||||
return false;
|
||||
else if(pluginInvocations.size()!=other.pluginInvocations.size())
|
||||
return false;
|
||||
else for(PluginInvocation opt:pluginInvocations)
|
||||
if(!other.pluginInvocations.contains(opt))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((destinationSettings == null) ? 0 : destinationSettings.hashCode());
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
if(pluginInvocations!=null){
|
||||
for(PluginInvocation opt:pluginInvocations)
|
||||
result=prime*result+((opt==null)?0:opt.hashCode());
|
||||
}
|
||||
result = prime * result + ((settings == null) ? 0 : settings.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
package org.gcube.data.transfer.model;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlEnum;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import org.gcube.data.transfer.model.utils.DateWrapper;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
public class TransferTicket extends TransferRequest{
|
||||
|
||||
|
||||
@XmlEnum
|
||||
public static enum Status{
|
||||
PENDING,
|
||||
WAITING, // transfer ready, waiting for sender
|
||||
TRANSFERRING,
|
||||
SUCCESS,
|
||||
ERROR,
|
||||
STOPPED,
|
||||
PLUGIN_EXECUTION
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
private Status status;
|
||||
@XmlElement
|
||||
private long transferredBytes;
|
||||
@XmlElement
|
||||
private double percent;
|
||||
@XmlElement
|
||||
private long averageTransferSpeed;
|
||||
@XmlElement
|
||||
private DateWrapper submissionTime;
|
||||
@XmlElement
|
||||
private String destinationFileName;
|
||||
@XmlElement
|
||||
private String message;
|
||||
|
||||
//
|
||||
// public TransferTicket(String id, TransferOptions options, Status status,
|
||||
// long transferredBytes, double percent, long averageTransferSpeed,
|
||||
// DateWrapper submissionTime,String destinationFileName) {
|
||||
// super(id, options);
|
||||
// this.status = status;
|
||||
// this.transferredBytes = transferredBytes;
|
||||
// this.percent = percent;
|
||||
// this.averageTransferSpeed = averageTransferSpeed;
|
||||
// this.submissionTime = submissionTime;
|
||||
// this.destinationFileName=destinationFileName;
|
||||
// }
|
||||
|
||||
public TransferTicket(TransferRequest request, Status status,
|
||||
long transferredBytes, double percent, long averageTransferSpeed,
|
||||
DateWrapper submissionTime,String destinationFileName,String message) {
|
||||
super(request.getId(), request.getSettings(),request.getDestinationSettings(),request.getPluginInvocations());
|
||||
this.status = status;
|
||||
this.transferredBytes = transferredBytes;
|
||||
this.percent = percent;
|
||||
this.averageTransferSpeed = averageTransferSpeed;
|
||||
this.submissionTime = submissionTime;
|
||||
this.destinationFileName=destinationFileName;
|
||||
}
|
||||
|
||||
|
||||
public TransferTicket(TransferRequest request){
|
||||
super(request.getId(),request.getSettings(),request.getDestinationSettings(),request.getPluginInvocations());
|
||||
this.status=Status.PENDING;
|
||||
this.transferredBytes=0l;
|
||||
this.averageTransferSpeed=0l;
|
||||
this.destinationFileName="/dev/null";
|
||||
this.percent=0d;
|
||||
this.submissionTime=DateWrapper.getInstance();
|
||||
this.message="";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package org.gcube.data.transfer.model.options;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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 lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
public class DirectTransferOptions extends TransferOptions {
|
||||
|
||||
@XmlElement
|
||||
private String source;
|
||||
|
||||
@Override
|
||||
public List<Protocol> getAvailableProtocols() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Range getAvailableRange() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TransferMethod getMethod() {
|
||||
return TransferMethod.DirectTransfer;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package org.gcube.data.transfer.model.options;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
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 lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
public class HttpDownloadOptions extends TransferOptions {
|
||||
|
||||
|
||||
public static final HttpDownloadOptions DEFAULT=new HttpDownloadOptions(Range.ONLY_80);
|
||||
|
||||
@XmlElement
|
||||
private Range range;
|
||||
|
||||
@Override
|
||||
public TransferMethod getMethod() {
|
||||
return TransferOptions.TransferMethod.HTTPDownload;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Protocol> getAvailableProtocols() {
|
||||
return Arrays.asList(new Protocol[]{
|
||||
Protocol.HTTP
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Range getAvailableRange() {
|
||||
return range;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package org.gcube.data.transfer.model.options;
|
||||
|
||||
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 lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
public class Range {
|
||||
|
||||
public final static Range ONLY_80=new Range(80,80);
|
||||
|
||||
|
||||
@XmlElement
|
||||
private int min;
|
||||
@XmlElement
|
||||
private int max;
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package org.gcube.data.transfer.model.options;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlSeeAlso;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode
|
||||
@XmlRootElement
|
||||
@XmlSeeAlso({HttpDownloadOptions.class,DirectTransferOptions.class})
|
||||
public abstract class TransferOptions {
|
||||
|
||||
public static enum TransferMethod{
|
||||
HTTPDownload,
|
||||
DirectTransfer
|
||||
}
|
||||
|
||||
public static enum Protocol{
|
||||
HTTP,
|
||||
TCP,
|
||||
UDP,
|
||||
SMP
|
||||
}
|
||||
|
||||
|
||||
public abstract TransferMethod getMethod();
|
||||
|
||||
|
||||
public abstract List<Protocol> getAvailableProtocols();
|
||||
|
||||
|
||||
|
||||
public abstract Range getAvailableRange();
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package org.gcube.data.transfer.model.settings;
|
||||
|
||||
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 lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import org.gcube.data.transfer.model.options.DirectTransferOptions;
|
||||
import org.gcube.data.transfer.model.options.Range;
|
||||
import org.gcube.data.transfer.model.options.TransferOptions.Protocol;
|
||||
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
public class DirectTransferSettings extends TransferSettings<DirectTransferOptions> {
|
||||
|
||||
|
||||
|
||||
@XmlElement
|
||||
private DirectTransferOptions options;
|
||||
|
||||
|
||||
@Override
|
||||
public Range getToUseRange() {
|
||||
return Range.ONLY_80;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DirectTransferOptions getOptions() {
|
||||
return options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Protocol getToUseProtocol() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package org.gcube.data.transfer.model.settings;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
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 lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import org.gcube.data.transfer.model.options.HttpDownloadOptions;
|
||||
import org.gcube.data.transfer.model.options.Range;
|
||||
import org.gcube.data.transfer.model.options.TransferOptions.Protocol;
|
||||
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
public class HttpDownloadSettings extends TransferSettings<HttpDownloadOptions> {
|
||||
|
||||
|
||||
|
||||
@XmlElement
|
||||
private URL source;
|
||||
|
||||
@XmlElement
|
||||
private HttpDownloadOptions options;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Protocol getToUseProtocol() {
|
||||
return Protocol.HTTP;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public HttpDownloadOptions getOptions() {
|
||||
return options;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Range getToUseRange() {
|
||||
return Range.ONLY_80;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package org.gcube.data.transfer.model.settings;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlSeeAlso;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import org.gcube.data.transfer.model.options.Range;
|
||||
import org.gcube.data.transfer.model.options.TransferOptions;
|
||||
import org.gcube.data.transfer.model.options.TransferOptions.Protocol;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
@XmlSeeAlso({HttpDownloadSettings.class,DirectTransferSettings.class})
|
||||
public abstract class TransferSettings<T extends TransferOptions> {
|
||||
|
||||
public abstract T getOptions();
|
||||
|
||||
public abstract Protocol getToUseProtocol();
|
||||
|
||||
public abstract Range getToUseRange();
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package org.gcube.data.transfer.model.utils;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.data.transfer.model.options.HttpDownloadOptions;
|
||||
import org.gcube.data.transfer.model.options.TransferOptions;
|
||||
|
||||
public class CapabilitiesUtils {
|
||||
|
||||
|
||||
|
||||
|
||||
public static Set<TransferOptions> scanSystem(){
|
||||
Set<TransferOptions> availableMeans=new HashSet<>();
|
||||
availableMeans.add(HttpDownloadOptions.DEFAULT);
|
||||
return availableMeans;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package org.gcube.data.transfer.model.utils;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
import javax.xml.bind.annotation.adapters.XmlAdapter;
|
||||
import javax.xml.datatype.DatatypeFactory;
|
||||
import javax.xml.datatype.XMLGregorianCalendar;
|
||||
|
||||
public class DateFormatterAdapter extends XmlAdapter<String, Calendar> {
|
||||
|
||||
@Override
|
||||
public String marshal(Calendar cal) throws Exception {
|
||||
GregorianCalendar c = new GregorianCalendar();
|
||||
c.setTime(cal.getTime());
|
||||
XMLGregorianCalendar date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
|
||||
return date2.toXMLFormat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Calendar unmarshal(String date) throws Exception {
|
||||
XMLGregorianCalendar gregorianDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(date);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(gregorianDate.toGregorianCalendar().getTime());
|
||||
return cal;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package org.gcube.data.transfer.model.utils;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
import javax.xml.datatype.DatatypeFactory;
|
||||
import javax.xml.datatype.XMLGregorianCalendar;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Setter
|
||||
@Getter
|
||||
@Slf4j
|
||||
public class DateWrapper {
|
||||
|
||||
static DatatypeFactory factory=null;
|
||||
|
||||
static {
|
||||
try{
|
||||
factory=DatatypeFactory.newInstance();
|
||||
}catch(Exception e){
|
||||
log.error("Unexpected exception ",e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static DateWrapper getInstance(){
|
||||
return new DateWrapper(Calendar.getInstance());
|
||||
}
|
||||
|
||||
|
||||
// static SimpleDateFormat dateFormat = new SimpleDateFormat();
|
||||
|
||||
|
||||
@XmlJavaTypeAdapter(DateFormatterAdapter.class)
|
||||
@XmlElement
|
||||
public Calendar value;
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
// not all the date are mandatory, if a date is optional the value is null
|
||||
if(value != null){
|
||||
GregorianCalendar c = new GregorianCalendar();
|
||||
c.setTime(value.getTime());
|
||||
XMLGregorianCalendar date2 = factory.newXMLGregorianCalendar(c);
|
||||
return date2.toXMLFormat();
|
||||
}
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((value == null) ? 0 : value.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
DateWrapper other = (DateWrapper) obj;
|
||||
if (value == null) {
|
||||
if (other.value != null)
|
||||
return false;
|
||||
} else if (!value.equals(other.value))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,215 @@
|
||||
package org.gcube.data.transfer.test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.gcube.data.transfer.model.Destination;
|
||||
import org.gcube.data.transfer.model.PluginDescription;
|
||||
import org.gcube.data.transfer.model.PluginInvocation;
|
||||
import org.gcube.data.transfer.model.TransferCapabilities;
|
||||
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.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.HttpDownloadSettings;
|
||||
import org.gcube.data.transfer.model.utils.DateWrapper;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MarshallUnmarshalTest {
|
||||
|
||||
static JAXBContext ctx =null;
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws JAXBException{
|
||||
ctx = JAXBContext.newInstance(
|
||||
TransferRequest.class,
|
||||
TransferTicket.class,
|
||||
TransferCapabilities.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void Marshall() throws MalformedURLException{
|
||||
print(createRequest(TransferMethod.HTTPDownload));
|
||||
print(createRequest(TransferMethod.DirectTransfer));
|
||||
print(createTransferCapabilities());
|
||||
print(createTicket(createRequest(TransferMethod.HTTPDownload)));
|
||||
print(createTicket(createRequest(TransferMethod.DirectTransfer)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void UnMarshall() throws MalformedURLException{
|
||||
assertTrue(roundTrip(createRequest(TransferMethod.HTTPDownload)));
|
||||
assertTrue(roundTrip(createRequest(TransferMethod.DirectTransfer)));
|
||||
assertTrue(roundTrip(createTransferCapabilities()));
|
||||
assertTrue(roundTrip(createTicket(createRequest(TransferMethod.HTTPDownload))));
|
||||
assertTrue(roundTrip(createTicket(createRequest(TransferMethod.DirectTransfer))));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void toStringTest() throws MalformedURLException{
|
||||
System.out.println(createRequest(TransferMethod.HTTPDownload));
|
||||
System.out.println(createRequest(TransferMethod.DirectTransfer));
|
||||
System.out.println(createTransferCapabilities());
|
||||
System.out.println(createTicket(createRequest(TransferMethod.HTTPDownload)));
|
||||
System.out.println(createTicket(createRequest(TransferMethod.DirectTransfer)));
|
||||
}
|
||||
|
||||
|
||||
public static boolean roundTrip(Object obj){
|
||||
Object roundTripResult=unmarshal(obj.getClass(), new StringReader(marshal(obj,new StringWriter()).toString()));
|
||||
return obj.equals(roundTripResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the serialisation of a given resource to a {@link Result}.
|
||||
* @param resource the resource
|
||||
* @param stream the result
|
||||
* @return the result in input
|
||||
*/
|
||||
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);
|
||||
|
||||
m.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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the serialisation of a given resource to a given character stream.
|
||||
* @param resource the resource
|
||||
* @param stream the stream in input
|
||||
*/
|
||||
public static <T extends Writer> T marshal(Object resource,T stream) {
|
||||
|
||||
marshal(resource,new StreamResult(stream));
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates a resource of given class from its serialisation in a given {@link Reader}.
|
||||
* @param resourceClass the class of the resource
|
||||
* @param reader the reader
|
||||
* @return the resource
|
||||
*/
|
||||
public static <T> T unmarshal(Class<T> resourceClass, Reader reader) {
|
||||
return unmarshal(resourceClass,new StreamSource(reader));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a resource of given class from its serialisation in a given {@link InputStream}.
|
||||
* @param resourceClass the class of the resource
|
||||
* @param stream the stream
|
||||
* @return the resource
|
||||
*/
|
||||
public static <T> T unmarshal(Class<T> resourceClass, InputStream stream) {
|
||||
return unmarshal(resourceClass,new StreamSource(stream));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a resource of given class from its serialisation in a given {@link Source}.
|
||||
* @param resourceClass the class of the resource
|
||||
* @param source the source
|
||||
* @return the resource
|
||||
*/
|
||||
public static <T> T unmarshal(Class<T> resourceClass,Source source) {
|
||||
try {
|
||||
Unmarshaller um = ctx.createUnmarshaller();
|
||||
return resourceClass.cast(um.unmarshal(source));
|
||||
}
|
||||
catch(Exception e) {
|
||||
throw new RuntimeException("deserialisation error",e);
|
||||
}
|
||||
}
|
||||
|
||||
private HttpDownloadSettings createHttpSettings()throws MalformedURLException{
|
||||
return new HttpDownloadSettings(new URL("http://some.where.com"),createHttpOptions());
|
||||
}
|
||||
|
||||
private HttpDownloadOptions createHttpOptions() {
|
||||
return HttpDownloadOptions.DEFAULT;
|
||||
}
|
||||
|
||||
private DirectTransferSettings createDirectTransferSettings(){
|
||||
return new DirectTransferSettings(createDirectTransferOptions());
|
||||
}
|
||||
|
||||
private DirectTransferOptions createDirectTransferOptions(){
|
||||
return new DirectTransferOptions("mySource");
|
||||
}
|
||||
|
||||
|
||||
private TransferCapabilities createTransferCapabilities(){
|
||||
return new TransferCapabilities("12345", "localhost", 80,
|
||||
Collections.singleton((TransferOptions)createHttpOptions()),Collections.singleton(createPluginDescriptor()),Collections.singleton("DT DUMMY"));
|
||||
}
|
||||
|
||||
private TransferRequest createRequest(TransferOptions.TransferMethod toUseMethod) throws MalformedURLException{
|
||||
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"));
|
||||
default : return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private PluginInvocation createPluginInvocation(){
|
||||
HashMap<String,String> params=new HashMap<>();
|
||||
params.put("First param", PluginInvocation.DESTINATION_FILE_PATH);
|
||||
return new PluginInvocation("Dummy Plugin", params);
|
||||
}
|
||||
|
||||
private TransferTicket createTicket(TransferRequest request){
|
||||
return new TransferTicket(request, Status.STOPPED, 1005467l, .57d, 123345, DateWrapper.getInstance(),"/dev/null","bona");
|
||||
}
|
||||
|
||||
private PluginDescription createPluginDescriptor(){
|
||||
HashMap<String,String> params=new HashMap<>();
|
||||
params.put("First param", "Useful param for a no op plugin");
|
||||
return new PluginDescription("Dummy plugin","This thing does nothing",params);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue