add identifyId private method

This commit is contained in:
Roberto Cirillo 2021-09-03 11:13:41 +02:00
parent 9d128ce1a0
commit b64bb2fe45
1 changed files with 20 additions and 12 deletions

View File

@ -56,6 +56,7 @@ public class StorageIDResolver {
private static String help = "https://wiki.gcube-system.org/gcube/URI_Resolver#STORAGE-ID_Resolver"; private static String help = "https://wiki.gcube-system.org/gcube/URI_Resolver#STORAGE-ID_Resolver";
protected static IClient storageManagerClient; protected static IClient storageManagerClient;
private static MemoryType memory;
/** /**
* Gets the storage id. * Gets the storage id.
@ -140,9 +141,8 @@ public class StorageIDResolver {
// LOG.error("Storage Client Exception when getting file from storage: ", 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); // 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);
IClient iClient = getStorageClientInstance(storageId);
String toSEID = null; String toSEID = null;
LOG.info("I'm using the storageId {}",storageId); LOG.info("I'm using the storageId {}",storageId);
try{ try{
@ -211,6 +211,9 @@ public class StorageIDResolver {
} }
/** /**
* Http do head. * Http do head.
* *
@ -288,7 +291,8 @@ public class StorageIDResolver {
// } // }
IClient iClient = getStorageClientInstance(storageId); storageId = identifyIdAndMemory(storageId);
IClient iClient = getStorageClientInstance(memory);
String toSEID = null; String toSEID = null;
LOG.info("I'm using the storageId {}",storageId); LOG.info("I'm using the storageId {}",storageId);
try{ try{
@ -394,14 +398,7 @@ public class StorageIDResolver {
* @param storageId the storage id * @param storageId the storage id
* @return the storage client instance * @return the storage client instance
*/ */
protected static IClient getStorageClientInstance(String storageId) { protected static IClient getStorageClientInstance(MemoryType memory) {
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, "");
}else {
memory=MemoryType.PERSISTENT;
}
if ((!Objects.isNull(storageManagerClient)) && (storageManagerClient.getGcubeMemoryType().equals(memory))) if ((!Objects.isNull(storageManagerClient)) && (storageManagerClient.getGcubeMemoryType().equals(memory)))
return storageManagerClient; return storageManagerClient;
else { else {
@ -415,6 +412,17 @@ public class StorageIDResolver {
} }
} }
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");
memory=MemoryType.VOLATILE;
storageId=storageId.replace(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR, "");
}else {
memory=MemoryType.PERSISTENT;
}
return storageId;
}
/** /**
* Gets the storage metadata file. * Gets the storage metadata file.
* *