Fabio Sinibaldi 2017-05-25 13:12:13 +00:00
parent bdc40fd104
commit 89457330b8
5 changed files with 155 additions and 12 deletions

View File

@ -0,0 +1,41 @@
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 org.gcube.data.transfer.model.TransferTicket.Status;
import org.gcube.data.transfer.model.utils.DateWrapper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
@Data
@EqualsAndHashCode(callSuper=false)
@NoArgsConstructor
@AllArgsConstructor
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
public class ExecutionReport {
@XmlEnum
public static enum ExecutionReportFlag{
SUCCESS,
WRONG_PARAMETER,
UNABLE_TO_EXECUTE,
FAILED_EXECUTION,
FAILED_CLEANUP
}
@XmlElement
private PluginInvocation invocation;
@XmlElement
private String message;
@XmlElement
private ExecutionReportFlag flag;
}

View File

@ -121,7 +121,7 @@ public class TransferCapabilities {
if(!other.availablePlugins.contains(opt))
return false;
//TODO Check persistences
//Check persistence ids
if ((availablePersistenceIds == null || availablePersistenceIds.isEmpty()))
if(other.availablePersistenceIds!=null&& (!other.availablePersistenceIds.isEmpty()))
return false;

View File

@ -1,20 +1,26 @@
package org.gcube.data.transfer.model;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
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)
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@XmlRootElement
@ -48,6 +54,9 @@ public class TransferTicket extends TransferRequest{
@XmlElement
private String message;
@XmlElement
private Map<String,ExecutionReport> executionReports;
//
// public TransferTicket(String id, TransferOptions options, Status status,
// long transferredBytes, double percent, long averageTransferSpeed,
@ -63,7 +72,7 @@ public class TransferTicket extends TransferRequest{
public TransferTicket(TransferRequest request, Status status,
long transferredBytes, double percent, long averageTransferSpeed,
DateWrapper submissionTime,String destinationFileName,String message) {
DateWrapper submissionTime,String destinationFileName,String message, Map<String,ExecutionReport> executionReports) {
super(request.getId(), request.getSettings(),request.getDestinationSettings(),request.getPluginInvocations());
this.status = status;
this.transferredBytes = transferredBytes;
@ -71,6 +80,7 @@ public class TransferTicket extends TransferRequest{
this.averageTransferSpeed = averageTransferSpeed;
this.submissionTime = submissionTime;
this.destinationFileName=destinationFileName;
this.executionReports=executionReports;
}
@ -83,8 +93,91 @@ public class TransferTicket extends TransferRequest{
this.percent=0d;
this.submissionTime=DateWrapper.getInstance();
this.message="";
this.executionReports=new HashMap<String,ExecutionReport>();
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
TransferTicket other = (TransferTicket) obj;
if (averageTransferSpeed != other.averageTransferSpeed)
return false;
if (destinationFileName == null) {
if (other.destinationFileName != null)
return false;
} else if (!destinationFileName.equals(other.destinationFileName))
return false;
//Check reports map
if ((executionReports == null || executionReports.isEmpty()))
if(other.executionReports!=null&& (!other.executionReports.isEmpty()))
return false;
else if(executionReports!=null && (!executionReports.isEmpty()))
if(other.executionReports==null || other.executionReports.isEmpty())
return false;
else if(executionReports.size()!=other.executionReports.size())
return false;
else for(String key:executionReports.keySet())
if(!other.executionReports.containsKey(key)||
(!executionReports.get(key).equals(other.executionReports.get(key))))
return false;
if (message == null) {
if (other.message != null)
return false;
} else if (!message.equals(other.message))
return false;
if (Double.doubleToLongBits(percent) != Double.doubleToLongBits(other.percent))
return false;
if (status != other.status)
return false;
if (submissionTime == null) {
if (other.submissionTime != null)
return false;
} else if (!submissionTime.equals(other.submissionTime))
return false;
if (transferredBytes != other.transferredBytes)
return false;
return true;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + (int) (averageTransferSpeed ^ (averageTransferSpeed >>> 32));
result = prime * result + ((destinationFileName == null) ? 0 : destinationFileName.hashCode());
if(executionReports!=null){
for(Entry<String,ExecutionReport> entry:executionReports.entrySet())
result=prime*result+(entry.getKey().hashCode()+entry.getValue().hashCode());
}
result = prime * result + ((executionReports == null) ? 0 : executionReports.hashCode());
result = prime * result + ((message == null) ? 0 : message.hashCode());
long temp;
temp = Double.doubleToLongBits(percent);
result = prime * result + (int) (temp ^ (temp >>> 32));
result = prime * result + ((status == null) ? 0 : status.hashCode());
result = prime * result + ((submissionTime == null) ? 0 : submissionTime.hashCode());
result = prime * result + (int) (transferredBytes ^ (transferredBytes >>> 32));
return result;
}
}

View File

@ -0,0 +1 @@
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory

View File

@ -24,11 +24,13 @@ 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.ExecutionReport;
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.ExecutionReport.ExecutionReportFlag;
import org.gcube.data.transfer.model.TransferTicket.Status;
import org.gcube.data.transfer.model.options.DirectTransferOptions;
import org.gcube.data.transfer.model.options.FileUploadOptions;
@ -42,6 +44,8 @@ import org.gcube.data.transfer.model.utils.DateWrapper;
import org.junit.BeforeClass;
import org.junit.Test;
import junit.framework.Assert;
public class MarshallUnmarshalTest {
static JAXBContext ctx =null;
@ -90,7 +94,6 @@ public class MarshallUnmarshalTest {
System.out.println(createTicket(createRequest(TransferMethod.FileUpload)));
}
public static boolean roundTrip(Object obj){
Object roundTripResult=unmarshal(obj.getClass(), new StringReader(marshal(obj,new StringWriter()).toString()));
return obj.equals(roundTripResult);
@ -232,7 +235,8 @@ public class MarshallUnmarshalTest {
}
private TransferTicket createTicket(TransferRequest request){
return new TransferTicket(request, Status.STOPPED, 1005467l, .57d, 123345, DateWrapper.getInstance(),"/dev/null","bona");
ExecutionReport report=createExecutionReport();
return new TransferTicket(request, Status.STOPPED, 1005467l, .57d, 123345, DateWrapper.getInstance(),"/dev/null","bona", Collections.singletonMap(report.getInvocation().getPluginId(), report));
}
private PluginDescription createPluginDescriptor(){
@ -240,4 +244,8 @@ public class MarshallUnmarshalTest {
params.put("First param", "Useful param for a no op plugin");
return new PluginDescription("Dummy plugin","This thing does nothing",params);
}
private ExecutionReport createExecutionReport(){
return new ExecutionReport(createPluginInvocation(), "Executed", ExecutionReportFlag.SUCCESS);
}
}