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";
protected static IClient storageManagerClient;
private static MemoryType memory;
/**
* Gets the storage id.
@ -140,9 +141,8 @@ 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);
// }
IClient iClient = getStorageClientInstance(storageId);
storageId = identifyIdAndMemory(storageId);
IClient iClient = getStorageClientInstance(memory);
String toSEID = null;
LOG.info("I'm using the storageId {}",storageId);
try{
@ -209,6 +209,9 @@ public class StorageIDResolver {
return response.build();
}
/**
@ -288,7 +291,8 @@ public class StorageIDResolver {
// }
IClient iClient = getStorageClientInstance(storageId);
storageId = identifyIdAndMemory(storageId);
IClient iClient = getStorageClientInstance(memory);
String toSEID = null;
LOG.info("I'm using the storageId {}",storageId);
try{
@ -394,14 +398,7 @@ public class StorageIDResolver {
* @param storageId the storage id
* @return the storage client instance
*/
protected static IClient getStorageClientInstance(String storageId) {
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;
}
protected static IClient getStorageClientInstance(MemoryType memory) {
if ((!Objects.isNull(storageManagerClient)) && (storageManagerClient.getGcubeMemoryType().equals(memory)))
return storageManagerClient;
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.
*