Fabio Sinibaldi 2017-12-05 15:03:12 +00:00
parent 01620ea943
commit 598f433134
7 changed files with 68 additions and 40 deletions

View File

@ -22,16 +22,16 @@
<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"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</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"/>
</classpath>

View File

@ -1,8 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.7"/>
<installed facet="wst.jsdt.web" version="1.0"/>
<installed facet="jst.web" version="3.0"/>
<installed facet="jst.jaxrs" version="2.0"/>
<installed facet="java" version="1.8"/>
</faceted-project>

View File

@ -9,6 +9,7 @@ import java.util.Set;
import javax.activation.MimetypesFileTypeMap;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
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.Status;
import org.gcube.data.transfer.model.DeletionReport;
import org.gcube.data.transfer.model.Destination;
import org.gcube.data.transfer.model.DestinationClashPolicy;
import org.gcube.data.transfer.model.PluginInvocation;
@ -157,7 +159,7 @@ public class REST {
}
// @Path("/{destinationId}/{subPath : \\S*}")
@GET
@Produces("*/*")
public Response getFile(@PathParam("destinationId") String destinationId,
@ -179,17 +181,18 @@ public class REST {
}
}
// // @Path("/{destinationId}/{subPath : \\\\S*}")
// @HEAD
// @Produces(MediaType.APPLICATION_JSON)
// public RemoteFileDescriptor getFileDescriptor(@PathParam("destinationId") String destinationId,
// @PathParam("subPath") String subPath ) {
// String pathString="<"+destinationID+">/"+subPath;
// log.info("Received HEAD request at {} ",pathString);
// try{
// return persistence.getDescriptor(destinationId, subPath);
// }catch(DestinationAccessException e) {
// throw new WebApplicationException("Unable to access selected path "+pathString,Status.INTERNAL_SERVER_ERROR);
// }
// }
@DELETE
@Produces(MediaType.APPLICATION_JSON)
public DeletionReport deleteFile(@PathParam("destinationId") String destinationId,
@PathParam("subPath") String subPath) {
String pathString="<"+destinationID+">/"+subPath;
log.info("Received DELETE request at {}",pathString);
try{
return persistence.delete(destinationId, subPath);
}catch(DestinationAccessException e) {
throw new WebApplicationException("Unable to access selected path "+pathString,e,Status.INTERNAL_SERVER_ERROR);
}
}
}

View File

@ -3,6 +3,7 @@ package org.gcube.data.transfer.service.transfers.engine;
import java.io.File;
import java.util.Set;
import org.gcube.data.transfer.model.DeletionReport;
import org.gcube.data.transfer.model.Destination;
import org.gcube.data.transfer.model.RemoteFileDescriptor;
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 DeletionReport delete(String persistenceId,String subPath) throws DestinationAccessException;
}

View File

@ -10,6 +10,7 @@ import java.util.Set;
import javax.inject.Singleton;
import org.gcube.data.transfer.model.DeletionReport;
import org.gcube.data.transfer.model.Destination;
import org.gcube.data.transfer.model.DestinationClashPolicy;
import org.gcube.data.transfer.model.RemoteFileDescriptor;
@ -32,8 +33,8 @@ public class PersistenceProviderImpl implements PersistenceProvider {
File persistenceFolder=getPersistenceFolderById(persistenceId);
return new File(persistenceFolder.getAbsolutePath()+"/"+subPath);
}
@Override
public RemoteFileDescriptor getDescriptor(String persistenceId, String subPath) throws DestinationAccessException {
File file=getPersistedFile(persistenceId, subPath);
@ -48,7 +49,7 @@ public class PersistenceProviderImpl implements PersistenceProvider {
}catch(Throwable t) {
log.warn("Unable to access attributes for {} ",file.getAbsolutePath(),t);
}
toReturn.setAbsolutePath(file.getAbsolutePath());
toReturn.setDirectory(file.isDirectory());
toReturn.setFilename(file.getName());
@ -57,9 +58,9 @@ public class PersistenceProviderImpl implements PersistenceProvider {
log.debug("Returning descriptor {} ",toReturn);
return toReturn;
}
@Override
public File getPersistenceFolderById(String persistenceId) throws DestinationAccessException {
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.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.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()+" .");
return toReturn;
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.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()+" .");
return toReturn;
}
@ -148,9 +149,9 @@ public class PersistenceProviderImpl implements PersistenceProvider {
String clashingName=clashing.getName();
String clashingBaseName=(!dir&&clashingName.contains("."))?clashingName.substring(0, clashingName.lastIndexOf(".")):clashingName;
String destinationExtension=(!dir&&clashingName.contains("."))?clashingName.substring(clashingName.lastIndexOf(".")):"";
int counter=1;
while(clashing.exists()){
clashing=new File(clashing.getParentFile(),clashingBaseName+"("+counter+")"+destinationExtension);
@ -173,9 +174,21 @@ public class PersistenceProviderImpl implements PersistenceProvider {
}
return clashing;
}
private static final void deleteRecursively(File toDelete) throws IOException {
@Override
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());
if(toDelete.isDirectory()) {
for(File child:toDelete.listFiles())

View File

@ -10,6 +10,7 @@ import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Application;
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.RemoteFileDescriptor;
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));
}
@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));
}
}