git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/data-transfer/data-transfer-service/2.0@160077 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
01620ea943
commit
598f433134
10
.classpath
10
.classpath
|
@ -22,16 +22,16 @@
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</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">
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
|
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||||
org.eclipse.jdt.core.compiler.source=1.7
|
org.eclipse.jdt.core.compiler.source=1.8
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<faceted-project>
|
<faceted-project>
|
||||||
<fixed facet="wst.jsdt.web"/>
|
<fixed facet="wst.jsdt.web"/>
|
||||||
<installed facet="java" version="1.7"/>
|
|
||||||
<installed facet="wst.jsdt.web" version="1.0"/>
|
<installed facet="wst.jsdt.web" version="1.0"/>
|
||||||
<installed facet="jst.web" version="3.0"/>
|
<installed facet="jst.web" version="3.0"/>
|
||||||
<installed facet="jst.jaxrs" version="2.0"/>
|
<installed facet="jst.jaxrs" version="2.0"/>
|
||||||
|
<installed facet="java" version="1.8"/>
|
||||||
</faceted-project>
|
</faceted-project>
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.util.Set;
|
||||||
import javax.activation.MimetypesFileTypeMap;
|
import javax.activation.MimetypesFileTypeMap;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.DELETE;
|
||||||
import javax.ws.rs.DefaultValue;
|
import javax.ws.rs.DefaultValue;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
|
@ -21,6 +22,7 @@ import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
|
import org.gcube.data.transfer.model.DeletionReport;
|
||||||
import org.gcube.data.transfer.model.Destination;
|
import org.gcube.data.transfer.model.Destination;
|
||||||
import org.gcube.data.transfer.model.DestinationClashPolicy;
|
import org.gcube.data.transfer.model.DestinationClashPolicy;
|
||||||
import org.gcube.data.transfer.model.PluginInvocation;
|
import org.gcube.data.transfer.model.PluginInvocation;
|
||||||
|
@ -157,7 +159,7 @@ public class REST {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// @Path("/{destinationId}/{subPath : \\S*}")
|
|
||||||
@GET
|
@GET
|
||||||
@Produces("*/*")
|
@Produces("*/*")
|
||||||
public Response getFile(@PathParam("destinationId") String destinationId,
|
public Response getFile(@PathParam("destinationId") String destinationId,
|
||||||
|
@ -179,17 +181,18 @@ public class REST {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// // @Path("/{destinationId}/{subPath : \\\\S*}")
|
|
||||||
// @HEAD
|
@DELETE
|
||||||
// @Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
// public RemoteFileDescriptor getFileDescriptor(@PathParam("destinationId") String destinationId,
|
public DeletionReport deleteFile(@PathParam("destinationId") String destinationId,
|
||||||
// @PathParam("subPath") String subPath ) {
|
@PathParam("subPath") String subPath) {
|
||||||
// String pathString="<"+destinationID+">/"+subPath;
|
String pathString="<"+destinationID+">/"+subPath;
|
||||||
// log.info("Received HEAD request at {} ",pathString);
|
log.info("Received DELETE request at {}",pathString);
|
||||||
// try{
|
try{
|
||||||
// return persistence.getDescriptor(destinationId, subPath);
|
return persistence.delete(destinationId, subPath);
|
||||||
// }catch(DestinationAccessException e) {
|
}catch(DestinationAccessException e) {
|
||||||
// throw new WebApplicationException("Unable to access selected path "+pathString,Status.INTERNAL_SERVER_ERROR);
|
throw new WebApplicationException("Unable to access selected path "+pathString,e,Status.INTERNAL_SERVER_ERROR);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.data.transfer.service.transfers.engine;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.gcube.data.transfer.model.DeletionReport;
|
||||||
import org.gcube.data.transfer.model.Destination;
|
import org.gcube.data.transfer.model.Destination;
|
||||||
import org.gcube.data.transfer.model.RemoteFileDescriptor;
|
import org.gcube.data.transfer.model.RemoteFileDescriptor;
|
||||||
import org.gcube.data.transfer.service.transfers.engine.faults.DestinationAccessException;
|
import org.gcube.data.transfer.service.transfers.engine.faults.DestinationAccessException;
|
||||||
|
@ -19,4 +20,5 @@ public interface PersistenceProvider {
|
||||||
|
|
||||||
public RemoteFileDescriptor getDescriptor(String persistenceId,String subPath) throws DestinationAccessException;
|
public RemoteFileDescriptor getDescriptor(String persistenceId,String subPath) throws DestinationAccessException;
|
||||||
|
|
||||||
|
public DeletionReport delete(String persistenceId,String subPath) throws DestinationAccessException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import java.util.Set;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.gcube.data.transfer.model.DeletionReport;
|
||||||
import org.gcube.data.transfer.model.Destination;
|
import org.gcube.data.transfer.model.Destination;
|
||||||
import org.gcube.data.transfer.model.DestinationClashPolicy;
|
import org.gcube.data.transfer.model.DestinationClashPolicy;
|
||||||
import org.gcube.data.transfer.model.RemoteFileDescriptor;
|
import org.gcube.data.transfer.model.RemoteFileDescriptor;
|
||||||
|
@ -32,8 +33,8 @@ public class PersistenceProviderImpl implements PersistenceProvider {
|
||||||
File persistenceFolder=getPersistenceFolderById(persistenceId);
|
File persistenceFolder=getPersistenceFolderById(persistenceId);
|
||||||
return new File(persistenceFolder.getAbsolutePath()+"/"+subPath);
|
return new File(persistenceFolder.getAbsolutePath()+"/"+subPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RemoteFileDescriptor getDescriptor(String persistenceId, String subPath) throws DestinationAccessException {
|
public RemoteFileDescriptor getDescriptor(String persistenceId, String subPath) throws DestinationAccessException {
|
||||||
File file=getPersistedFile(persistenceId, subPath);
|
File file=getPersistedFile(persistenceId, subPath);
|
||||||
|
@ -48,7 +49,7 @@ public class PersistenceProviderImpl implements PersistenceProvider {
|
||||||
}catch(Throwable t) {
|
}catch(Throwable t) {
|
||||||
log.warn("Unable to access attributes for {} ",file.getAbsolutePath(),t);
|
log.warn("Unable to access attributes for {} ",file.getAbsolutePath(),t);
|
||||||
}
|
}
|
||||||
|
|
||||||
toReturn.setAbsolutePath(file.getAbsolutePath());
|
toReturn.setAbsolutePath(file.getAbsolutePath());
|
||||||
toReturn.setDirectory(file.isDirectory());
|
toReturn.setDirectory(file.isDirectory());
|
||||||
toReturn.setFilename(file.getName());
|
toReturn.setFilename(file.getName());
|
||||||
|
@ -57,9 +58,9 @@ public class PersistenceProviderImpl implements PersistenceProvider {
|
||||||
log.debug("Returning descriptor {} ",toReturn);
|
log.debug("Returning descriptor {} ",toReturn);
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getPersistenceFolderById(String persistenceId) throws DestinationAccessException {
|
public File getPersistenceFolderById(String persistenceId) throws DestinationAccessException {
|
||||||
File toReturn=null;
|
File toReturn=null;
|
||||||
|
@ -79,11 +80,11 @@ public class PersistenceProviderImpl implements PersistenceProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(toReturn== null) throw new DestinationAccessException("Persistence ID "+persistenceId+" not found.");
|
if(toReturn== null) throw new DestinationAccessException("Persistence ID "+persistenceId+" not found.");
|
||||||
if(!toReturn.exists()) throw new DestinationAccessException("Persistence ID "+persistenceId+", location "+toReturn.getAbsolutePath()+" location doesn't exists.");
|
if(!toReturn.exists()) throw new DestinationAccessException("Persistence ID "+persistenceId+", location "+toReturn.getAbsolutePath()+" location doesn't exists.");
|
||||||
if(!toReturn.canWrite()) throw new DestinationAccessException("Cannot write to Persistence ID "+persistenceId+", location "+toReturn.getAbsolutePath()+" .");
|
if(!toReturn.canWrite()) throw new DestinationAccessException("Cannot write to Persistence ID "+persistenceId+", location "+toReturn.getAbsolutePath()+" .");
|
||||||
if(!toReturn.isDirectory()) throw new DestinationAccessException("Persistence ID "+persistenceId+", location "+toReturn.getAbsolutePath()+" is a directory.");
|
if(!toReturn.isDirectory()) throw new DestinationAccessException("Persistence ID "+persistenceId+", location "+toReturn.getAbsolutePath()+" is a directory.");
|
||||||
if(!toReturn.canWrite()) throw new DestinationAccessException("Cannot write to Persistence ID "+persistenceId+", location "+toReturn.getAbsolutePath()+" .");
|
if(!toReturn.canWrite()) throw new DestinationAccessException("Cannot write to Persistence ID "+persistenceId+", location "+toReturn.getAbsolutePath()+" .");
|
||||||
return toReturn;
|
return toReturn;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,9 +149,9 @@ public class PersistenceProviderImpl implements PersistenceProvider {
|
||||||
String clashingName=clashing.getName();
|
String clashingName=clashing.getName();
|
||||||
String clashingBaseName=(!dir&&clashingName.contains("."))?clashingName.substring(0, clashingName.lastIndexOf(".")):clashingName;
|
String clashingBaseName=(!dir&&clashingName.contains("."))?clashingName.substring(0, clashingName.lastIndexOf(".")):clashingName;
|
||||||
String destinationExtension=(!dir&&clashingName.contains("."))?clashingName.substring(clashingName.lastIndexOf(".")):"";
|
String destinationExtension=(!dir&&clashingName.contains("."))?clashingName.substring(clashingName.lastIndexOf(".")):"";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int counter=1;
|
int counter=1;
|
||||||
while(clashing.exists()){
|
while(clashing.exists()){
|
||||||
clashing=new File(clashing.getParentFile(),clashingBaseName+"("+counter+")"+destinationExtension);
|
clashing=new File(clashing.getParentFile(),clashingBaseName+"("+counter+")"+destinationExtension);
|
||||||
|
@ -173,9 +174,21 @@ public class PersistenceProviderImpl implements PersistenceProvider {
|
||||||
}
|
}
|
||||||
return clashing;
|
return clashing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
private static final void deleteRecursively(File toDelete) throws IOException {
|
public DeletionReport delete(String persistenceId, String subPath) throws DestinationAccessException {
|
||||||
|
String toDeletePublicPath=persistenceId+"/"+subPath;
|
||||||
|
File toDelete=getPersistedFile(persistenceId, subPath);
|
||||||
|
try{
|
||||||
|
log.warn("Going to DELETE {} aka {} ",toDelete.getAbsolutePath(),toDeletePublicPath);
|
||||||
|
deleteRecursively(toDelete);
|
||||||
|
return new DeletionReport(toDeletePublicPath,toDelete.getAbsolutePath());
|
||||||
|
}catch(Throwable t) {
|
||||||
|
throw new DestinationAccessException("Unable to delete "+toDeletePublicPath,t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final void deleteRecursively(File toDelete) throws IOException {
|
||||||
log.warn("Recursively deleting {} ",toDelete.getAbsolutePath());
|
log.warn("Recursively deleting {} ",toDelete.getAbsolutePath());
|
||||||
if(toDelete.isDirectory()) {
|
if(toDelete.isDirectory()) {
|
||||||
for(File child:toDelete.listFiles())
|
for(File child:toDelete.listFiles())
|
||||||
|
|
|
@ -10,6 +10,7 @@ import javax.ws.rs.client.WebTarget;
|
||||||
import javax.ws.rs.core.Application;
|
import javax.ws.rs.core.Application;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
import org.gcube.data.transfer.model.DeletionReport;
|
||||||
import org.gcube.data.transfer.model.Destination;
|
import org.gcube.data.transfer.model.Destination;
|
||||||
import org.gcube.data.transfer.model.RemoteFileDescriptor;
|
import org.gcube.data.transfer.model.RemoteFileDescriptor;
|
||||||
import org.gcube.data.transfer.model.ServiceConstants;
|
import org.gcube.data.transfer.model.ServiceConstants;
|
||||||
|
@ -143,4 +144,13 @@ public class TestCall extends JerseyTest {
|
||||||
System.out.println(target(ServiceConstants.REST_SERVLET_NAME).path("data-transfer-service/some/folder/inside/temp.txt").request(MediaType.APPLICATION_JSON).head().readEntity(RemoteFileDescriptor.class));
|
System.out.println(target(ServiceConstants.REST_SERVLET_NAME).path("data-transfer-service/some/folder/inside/temp.txt").request(MediaType.APPLICATION_JSON).head().readEntity(RemoteFileDescriptor.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDELETE() {
|
||||||
|
System.out.println(target(ServiceConstants.REST_SERVLET_NAME).path("data-transfer-service/temp.txt").request(MediaType.APPLICATION_JSON).head().readEntity(RemoteFileDescriptor.class));
|
||||||
|
System.out.println(target(ServiceConstants.REST_SERVLET_NAME).path("data-transfer-service/some/folder/inside/temp.txt").request(MediaType.APPLICATION_JSON).head().readEntity(RemoteFileDescriptor.class));
|
||||||
|
|
||||||
|
System.out.println(target(ServiceConstants.REST_SERVLET_NAME).path("data-transfer-service/temp.txt").request(MediaType.APPLICATION_JSON).delete().readEntity(DeletionReport.class));
|
||||||
|
System.out.println(target(ServiceConstants.REST_SERVLET_NAME).path("data-transfer-service/some/folder/inside/temp.txt").request(MediaType.APPLICATION_JSON).delete().readEntity(DeletionReport.class));
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue