completed StorageManager
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@173687 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
3d734be032
commit
29da3a8dec
|
@ -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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -39,7 +39,7 @@ public class Catalogue {
|
||||||
private String scopeToEncDecr = null;
|
private String scopeToEncDecr = null;
|
||||||
|
|
||||||
ApplicationProfileReaderForCatalogueResolver appPrCatResolver;
|
ApplicationProfileReaderForCatalogueResolver appPrCatResolver;
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{entityContext:ctlg(-(o|g|p|d)?}/{vreName}/{entityName}")
|
@Path("{entityContext:ctlg(-(o|g|p|d)?}/{vreName}/{entityName}")
|
||||||
public Response resolveCatalogue(@PathParam("entityName") String entityName, @PathParam("vreName") String vreName, @PathParam("entityContext") String entityContext) {
|
public Response resolveCatalogue(@PathParam("entityName") String entityName, @PathParam("vreName") String vreName, @PathParam("entityContext") String entityContext) {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.io.InputStream;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.WebApplicationException;
|
import javax.ws.rs.WebApplicationException;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.Response.ResponseBuilder;
|
import javax.ws.rs.core.Response.ResponseBuilder;
|
||||||
|
@ -23,41 +24,64 @@ import org.slf4j.LoggerFactory;
|
||||||
public class StorageManager {
|
public class StorageManager {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(StorageManager.class);
|
private static Logger logger = LoggerFactory.getLogger(StorageManager.class);
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{smpId}")
|
@Path("{(id)?}|{storage-id}")
|
||||||
public Response getFile(@PathParam("smpId") String smpId) {
|
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("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);
|
StorageClient client = new StorageClient("DataTransfer", "UriResolver", "storageid-resolver", AccessType.PUBLIC);
|
||||||
IClient iClient = client.getClient();
|
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);
|
logger.debug("Decoded ID"+" = "+ toSEID);
|
||||||
|
|
||||||
if(toSEID==null){
|
if(toSEID==null){
|
||||||
String error = "Decrypted id is null, thrown exception!";
|
String error = "Decrypted id is null, thrown exception!";
|
||||||
throw new WebApplicationException(error, Status.BAD_REQUEST);
|
throw new WebApplicationException(error, Status.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
long size = iClient.getSize().RFileById(toSEID);
|
long size = iClient.getSize().RFileById(toSEID);
|
||||||
String fileName="download";
|
|
||||||
String contentType=null;
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
MyFile file = client.getClient().getMetaFile().RFile(toSEID);
|
MyFile file = client.getClient().getMetaFile().RFile(toSEID);
|
||||||
logger.debug("MetaFile retrieved from storage? "+ (file!=null));
|
logger.debug("MetaFile retrieved from storage? "+ (file!=null));
|
||||||
|
|
||||||
fileName= file.getName();
|
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) {
|
}catch (Exception e) {
|
||||||
logger.warn("Error when getting file metadata from storage, printing this warning and trying to continue..", 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);
|
logger.info("filename retrieved is {}",fileName);
|
||||||
|
|
||||||
|
//Building the response
|
||||||
InputStream streamToWrite=iClient.get().RFileAsInputStream(toSEID); //input stream
|
InputStream streamToWrite=iClient.get().RFileAsInputStream(toSEID); //input stream
|
||||||
|
|
||||||
StreamingOutput so = new SingleFileStreamingOutput(streamToWrite);
|
StreamingOutput so = new SingleFileStreamingOutput(streamToWrite);
|
||||||
|
|
||||||
ResponseBuilder response = Response
|
ResponseBuilder response = Response
|
||||||
.ok(so)
|
.ok(so)
|
||||||
.header("content-disposition","attachment; filename = \""+fileName+"\"")
|
.header("content-disposition","attachment; filename = \""+fileName+"\"")
|
||||||
|
@ -65,5 +89,5 @@ public class StorageManager {
|
||||||
if (contentType!= null) response.header("Content-Type",contentType);
|
if (contentType!= null) response.header("Content-Type",contentType);
|
||||||
return response.build();
|
return response.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue