add some costants and comments to the code
This commit is contained in:
parent
b64bb2fe45
commit
3ec3a05cfc
|
@ -50,7 +50,8 @@ public class StorageIDResolver {
|
|||
*/
|
||||
protected static final String STORAGEID_RESOLVER = "storageid-resolver";
|
||||
private static final String STORAGE_ID = "storage-id";
|
||||
|
||||
private static final AccessType STORAGE_ACCESS_TYPE=AccessType.PUBLIC;
|
||||
private static final BackendType STORAGE_BACKEND_TYPE=BackendType.MongoDB;
|
||||
private static final Logger LOG = LoggerFactory.getLogger(StorageIDResolver.class);
|
||||
|
||||
private static String help = "https://wiki.gcube-system.org/gcube/URI_Resolver#STORAGE-ID_Resolver";
|
||||
|
@ -127,20 +128,6 @@ public class StorageIDResolver {
|
|||
LOG.error("storageId not found");
|
||||
throw ExceptionManager.badRequestException(httpRequest, "Missing mandatory path parameter "+STORAGE_ID, StorageIDResolver.class, help);
|
||||
}
|
||||
/** START PATCH 2.6.1-SNAPSHOT **/
|
||||
// StorageClientInstance scInstance = buildStorageClientInstance(storageId);
|
||||
// String toSEID = null;
|
||||
// IClient iClient = null;
|
||||
// storageId = scInstance.getStorageId(); //IT SHOULD BE CHANGED es. removing the suffix '-VLT'
|
||||
// LOG.info("I'm using the storageId {}",storageId);
|
||||
// try{
|
||||
// iClient = scInstance.getStorageClient().getClient();
|
||||
// toSEID = iClient.getId(storageId); //to Storage Encrypted ID
|
||||
// LOG.info("Decoded ID"+" = "+ toSEID);
|
||||
// }catch(Exception e){
|
||||
// LOG.error("Storage Client Exception when getting file from storage: ", e);
|
||||
// throw ExceptionManager.notFoundException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help);
|
||||
// }
|
||||
storageId = identifyIdAndMemory(storageId);
|
||||
IClient iClient = getStorageClientInstance(memory);
|
||||
String toSEID = null;
|
||||
|
@ -152,10 +139,6 @@ public class StorageIDResolver {
|
|||
LOG.error("Storage Client Exception when getting file from storage: ", e);
|
||||
throw ExceptionManager.notFoundException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help);
|
||||
}
|
||||
|
||||
/** END PATCH 2.6.1-SNAPSHOT **/
|
||||
|
||||
|
||||
if(toSEID==null || toSEID.isEmpty()){
|
||||
LOG.error("Decrypted id for storageId: "+storageId +" is null or empty!");
|
||||
throw ExceptionManager.notFoundException(httpRequest, "Error on decrypting the "+STORAGE_ID+ " '"+storageId+"'. Is it a valid id?", StorageIDResolver.class, help);
|
||||
|
@ -274,23 +257,7 @@ public class StorageIDResolver {
|
|||
if (storageId == null || storageId.isEmpty()) {
|
||||
LOG.warn("storageId not found");
|
||||
throw ExceptionManager.badRequestException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, this.getClass(), help);
|
||||
}
|
||||
/** START PATCH 2.6.1-SNAPSHOT **/
|
||||
// StorageClientInstance scInstance = buildStorageClientInstance(storageId);
|
||||
// String toSEID = null;
|
||||
// IClient iClient = null;
|
||||
// storageId = scInstance.getStorageId(); //IT SHOULD BE CHANGED es. removing the suffix '-VLT'
|
||||
// LOG.info("I'm using the storageId {}",storageId);
|
||||
// try{
|
||||
// iClient = scInstance.getStorageClient().getClient();
|
||||
// toSEID = iClient.getId(storageId); //to Storage Encrypted ID
|
||||
// LOG.info("Decoded ID"+" = "+ toSEID);
|
||||
// }catch(Exception e){
|
||||
// LOG.error("Storage Client Exception when getting file from storage: ", e);
|
||||
// throw ExceptionManager.notFoundException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help);
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
storageId = identifyIdAndMemory(storageId);
|
||||
IClient iClient = getStorageClientInstance(memory);
|
||||
String toSEID = null;
|
||||
|
@ -302,14 +269,10 @@ public class StorageIDResolver {
|
|||
LOG.error("Storage Client Exception when getting file from storage: ", e);
|
||||
throw ExceptionManager.notFoundException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help);
|
||||
}
|
||||
|
||||
/** END PATCH 2.6.1-SNAPSHOT **/
|
||||
|
||||
if(toSEID==null || toSEID.isEmpty()){
|
||||
LOG.error("Decrypted id for storageId: "+storageId +" is null or empty!");
|
||||
throw ExceptionManager.notFoundException(httpRequest, "Error on decrypting the "+STORAGE_ID+ " '"+storageId+"'. Is it a valid id?", StorageIDResolver.class, help);
|
||||
}
|
||||
|
||||
//SETTING DEFAULT METADATA
|
||||
String fileName = ConstantsResolver.DEFAULT_FILENAME_FROM_STORAGE_MANAGER;
|
||||
String contentType = ConstantsResolver.DEFAULT_CONTENTTYPE_UNKNOWN_UNKNOWN;
|
||||
|
@ -368,34 +331,12 @@ public class StorageIDResolver {
|
|||
return response.build();
|
||||
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * Builds the storage client instance.
|
||||
// *
|
||||
// * @param storageId the storage id
|
||||
// * @return the storage client instance
|
||||
// * @throws Exception the exception
|
||||
// */
|
||||
// protected static StorageClientInstance buildStorageClientInstance(String storageId) throws Exception{
|
||||
//
|
||||
// MemoryType memory=null;
|
||||
// if(storageId.endsWith(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR)){
|
||||
// memory=MemoryType.VOLATILE;
|
||||
// storageId=storageId.replace(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR, "");
|
||||
// }
|
||||
//
|
||||
// StorageClient client;
|
||||
// if(memory==null)
|
||||
// memory=MemoryType.PERSISTENT;
|
||||
// client=new StorageClient(StorageIDResolver.class.getName(), StorageIDResolver.class.getSimpleName(), STORAGEID_RESOLVER, AccessType.PUBLIC, memory, BackendType.MongoDB);
|
||||
// return new StorageClientInstance(client, memory, storageId);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Get a storage client instance.
|
||||
* Get a storage-manager client instance. A new storage instance will be instantied only if the memory type is not the same of the previous one.
|
||||
* In this case the old connection will be closed.
|
||||
*
|
||||
* @param storageId the storage id
|
||||
* @param memoryType indicates the memory type (Persistent, Volatile or whatever)
|
||||
* @return the storage client instance
|
||||
*/
|
||||
protected static IClient getStorageClientInstance(MemoryType memory) {
|
||||
|
@ -407,11 +348,16 @@ public class StorageIDResolver {
|
|||
storageManagerClient.forceClose();
|
||||
}
|
||||
LOG.debug("initializing a new storage-client instance");
|
||||
storageManagerClient=new StorageClient(StorageIDResolver.class.getName(), StorageIDResolver.class.getSimpleName(), STORAGEID_RESOLVER, AccessType.PUBLIC, memory, BackendType.MongoDB).getClient();
|
||||
storageManagerClient=new StorageClient(StorageIDResolver.class.getName(), StorageIDResolver.class.getSimpleName(), STORAGEID_RESOLVER, STORAGE_ACCESS_TYPE, memory, STORAGE_BACKEND_TYPE).getClient();
|
||||
return storageManagerClient;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the right memory type extrapolated from the storageid
|
||||
* @param storageId storageid with backend type specification (if present)
|
||||
* @return storageId without backend type specification
|
||||
*/
|
||||
private static String identifyIdAndMemory(String storageId) {
|
||||
if(storageId.endsWith(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR)){
|
||||
LOG.info("identificated a VOLATILE url");
|
||||
|
|
Loading…
Reference in New Issue