diff --git a/src/main/java/org/gcube/datatransfer/resolver/CopyOfGeonetworkRequestCriteria.java b/src/main/java/org/gcube/datatransfer/resolver/CopyOfGeonetworkRequestCriteria.java deleted file mode 100644 index c35af80..0000000 --- a/src/main/java/org/gcube/datatransfer/resolver/CopyOfGeonetworkRequestCriteria.java +++ /dev/null @@ -1,109 +0,0 @@ -/** - * - */ -package org.gcube.datatransfer.resolver; - - -/** - * The Class GeonetworkRequestCriteria. - * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Jun 15, 2016 - */ -public class CopyOfGeonetworkRequestCriteria { - - private String scope; - private boolean valueOfFilterPublicIds; - private boolean authOnGeonetwork; - private boolean noAuthOnGeonetwork; - - /** - * Instantiates a new geonetwork request criteria. - * - * @param scope the scope - * @param valueOfFilterPublicIds the value of filter public ids - * @param noAuthOnGeonetowrk the no auth on geonetowrk - */ - public CopyOfGeonetworkRequestCriteria(String scope, boolean valueOfFilterPublicIds, boolean noAuthOnGeonetowrk){ - this.scope = scope; - this.valueOfFilterPublicIds = valueOfFilterPublicIds; - this.noAuthOnGeonetwork = noAuthOnGeonetowrk; - } - - - /** - * Checks if is no auth on geonetwork. - * - * @return the noAuthOnGeonetwork - */ - public boolean isNoAuthOnGeonetwork() { - - return noAuthOnGeonetwork; - } - - - /** - * Gets the scope. - * - * @return the scope - */ - public String getScope() { - - return scope; - } - - - /** - * Checks if is value of filter public ids. - * - * @return the valueOfFilterPublicIds - */ - public boolean isValueOfFilterPublicIds() { - - return valueOfFilterPublicIds; - } - - - /** - * Sets the scope. - * - * @param scope the scope to set - */ - public void setScope(String scope) { - - this.scope = scope; - } - - - /** - * Sets the value of filter public ids. - * - * @param valueOfFilterPublicIds the valueOfFilterPublicIds to set - */ - public void setValueOfFilterPublicIds(boolean valueOfFilterPublicIds) { - - this.valueOfFilterPublicIds = valueOfFilterPublicIds; - } - - - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - - StringBuilder builder = new StringBuilder(); - builder.append("GeonetworkRequestCriteria [scope="); - builder.append(scope); - builder.append(", valueOfFilterPublicIds="); - builder.append(valueOfFilterPublicIds); - builder.append(", authOnGeonetwork="); - builder.append(authOnGeonetwork); - builder.append(", noAuthOnGeonetwork="); - builder.append(noAuthOnGeonetwork); - builder.append("]"); - return builder.toString(); - } - -} diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/Catalogue.java b/src/main/java/org/gcube/datatransfer/resolver/services/Catalogue.java index b11a7a3..febd7d9 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/Catalogue.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/Catalogue.java @@ -39,7 +39,7 @@ public class Catalogue { private String scopeToEncDecr = null; ApplicationProfileReaderForCatalogueResolver appPrCatResolver; - + @GET @Path("{entityContext:ctlg(-(o|g|p|d)?}/{vreName}/{entityName}") public Response resolveCatalogue(@PathParam("entityName") String entityName, @PathParam("vreName") String vreName, @PathParam("entityContext") String entityContext) { diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/StorageManager.java b/src/main/java/org/gcube/datatransfer/resolver/services/StorageManager.java index 6f47553..1b66c18 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/StorageManager.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/StorageManager.java @@ -5,6 +5,7 @@ import java.io.InputStream; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; +import javax.ws.rs.QueryParam; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.ResponseBuilder; @@ -23,41 +24,64 @@ import org.slf4j.LoggerFactory; public class StorageManager { private static Logger logger = LoggerFactory.getLogger(StorageManager.class); - + @GET - @Path("{smpId}") - public Response getFile(@PathParam("smpId") String smpId) { + @Path("{(id)?}|{storage-id}") + public Response getFile(@PathParam("storage-id") String storageId, @QueryParam("smp-id") String smpId, @QueryParam("fileName") String fileName, @QueryParam("contentType") String contentType, @QueryParam("validation") String validation) { logger.info("resolve Storage Id called"); + logger.info("storage-id: "+storageId); + logger.info("smp-id: "+smpId); + logger.info("fileName: "+fileName); + logger.info("contentType: "+contentType); + + //Checking to STORAGE-ID Resolver + boolean storageIdFound = true; + if (storageId == null || storageId.isEmpty()) { + logger.warn("storageId not found"); + storageIdFound = false; + } + + //If storageId not found, Checking to SMP-ID Resolver + if(!storageIdFound){ + if(smpId==null || smpId.isEmpty()){ + logger.warn("smp-id not found"); + throw new WebApplicationException("Missing mandatory parameter 'smp-id' or 'storage-id'", Status.BAD_REQUEST); + } + } + StorageClient client = new StorageClient("DataTransfer", "UriResolver", "storageid-resolver", AccessType.PUBLIC); IClient iClient = client.getClient(); - String toSEID = iClient.getId(smpId); //to Storage Encrypted ID + String toSEID = iClient.getId(storageId); //to Storage Encrypted ID logger.debug("Decoded ID"+" = "+ toSEID); if(toSEID==null){ String error = "Decrypted id is null, thrown exception!"; throw new WebApplicationException(error, Status.BAD_REQUEST); } - + long size = iClient.getSize().RFileById(toSEID); - String fileName="download"; - String contentType=null; + try{ + MyFile file = client.getClient().getMetaFile().RFile(toSEID); logger.debug("MetaFile retrieved from storage? "+ (file!=null)); fileName= file.getName(); - contentType = file.getMimeType(); + + //Reading the contentType from Storage Metadata only if the passed contentType is null + if(contentType==null) + contentType = file.getMimeType(); }catch (Exception e) { logger.warn("Error when getting file metadata from storage, printing this warning and trying to continue..", e); } - + + fileName = fileName==null || fileName.isEmpty()?"download":fileName; logger.info("filename retrieved is {}",fileName); - + + //Building the response InputStream streamToWrite=iClient.get().RFileAsInputStream(toSEID); //input stream - StreamingOutput so = new SingleFileStreamingOutput(streamToWrite); - ResponseBuilder response = Response .ok(so) .header("content-disposition","attachment; filename = \""+fileName+"\"") @@ -65,5 +89,5 @@ public class StorageManager { if (contentType!= null) response.header("Content-Type",contentType); return response.build(); } - + }