Fixing secret sessions

This commit is contained in:
luca.frosini 2023-07-11 11:09:04 +02:00
parent 3bfbe5ed9b
commit 69fb4eafa0
1 changed files with 13 additions and 20 deletions

View File

@ -63,7 +63,7 @@ public class CatalogueStorageHubManagement {
Metadata metadata = catalogueMetadata.getMetadata(persistedURL, originalFilename, resourceID); Metadata metadata = catalogueMetadata.getMetadata(persistedURL, originalFilename, resourceID);
persistedURL = storageHubManagement.persistFile(httpURLConnection.getInputStream(), resourceID, mimeType, persistedURL = storageHubManagement.persistFile(httpURLConnection.getInputStream(), resourceID, mimeType,
metadata); metadata);
mimeType = storageHubManagement.getMimeType(); // mimeType = storageHubManagement.getMimeType();
return persistedURL; return persistedURL;
} catch (Exception e) { } catch (Exception e) {
logger.error("Error while trying to persists the resource", e); logger.error("Error while trying to persists the resource", e);
@ -88,25 +88,18 @@ public class CatalogueStorageHubManagement {
} }
protected void internalAddRevisionID(String resourceID, String revisionID) throws Exception { protected void internalAddRevisionID(String resourceID, String revisionID) throws Exception {
SecretManager secretManager = SecretManagerProvider.instance.get(); FileContainer fileContainer = storageHubManagement.getPersistedFile();
Secret secret = Constants.getCatalogueSecret(); if(fileContainer != null) {
try { Metadata metadata = fileContainer.get().getMetadata();
secretManager.startSession(secret); Map<String,Object> map = metadata.getMap();
FileContainer fileContainer = storageHubManagement.getPersistedFile(); map.put(CatalogueMetadata.CATALOGUE_RESOURCE_ID, resourceID);
if(fileContainer != null) { map.put(CatalogueMetadata.CATALOGUE_RESOURCE_REVISION_ID, revisionID);
Metadata metadata = fileContainer.get().getMetadata(); metadata.setMap(map);
Map<String,Object> map = metadata.getMap(); fileContainer.setMetadata(metadata);
map.put(CatalogueMetadata.CATALOGUE_RESOURCE_ID, resourceID); } else {
map.put(CatalogueMetadata.CATALOGUE_RESOURCE_REVISION_ID, revisionID); logger.warn(
metadata.setMap(map); "Unable to set revision id {} to the file of resource with id {} because the file was NOT found on storage-hub. This could be related to an item not created via gCat. Skipping it.",
fileContainer.setMetadata(metadata); revisionID, resourceID);
} else {
logger.warn(
"Unable to set revision id {} to the file of resource with id {} because the file was NOT found on storage-hub. This could be related to an item not created via gCat. Skipping it.",
revisionID, resourceID);
}
} finally {
secretManager.endSession();
} }
} }