Looking for a workaround for a storagehub issue
This commit is contained in:
parent
69fb4eafa0
commit
d5137f8a82
|
@ -10,6 +10,7 @@ import org.gcube.common.authorization.utils.secret.Secret;
|
||||||
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
||||||
import org.gcube.common.storagehub.client.dsl.FileContainer;
|
import org.gcube.common.storagehub.client.dsl.FileContainer;
|
||||||
import org.gcube.common.storagehub.model.Metadata;
|
import org.gcube.common.storagehub.model.Metadata;
|
||||||
|
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
||||||
import org.gcube.gcat.utils.Constants;
|
import org.gcube.gcat.utils.Constants;
|
||||||
import org.gcube.storagehub.StorageHubManagement;
|
import org.gcube.storagehub.StorageHubManagement;
|
||||||
import org.glassfish.jersey.media.multipart.ContentDisposition;
|
import org.glassfish.jersey.media.multipart.ContentDisposition;
|
||||||
|
@ -88,18 +89,27 @@ public class CatalogueStorageHubManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void internalAddRevisionID(String resourceID, String revisionID) throws Exception {
|
protected void internalAddRevisionID(String resourceID, String revisionID) throws Exception {
|
||||||
FileContainer fileContainer = storageHubManagement.getPersistedFile();
|
try {
|
||||||
if(fileContainer != null) {
|
FileContainer fileContainer = null;
|
||||||
Metadata metadata = fileContainer.get().getMetadata();
|
AbstractFileItem fileItem = null;
|
||||||
|
try {
|
||||||
|
fileContainer = storageHubManagement.getPersistedFile();
|
||||||
|
fileItem = fileContainer.get();
|
||||||
|
}catch (Exception e) {
|
||||||
|
fileContainer = storageHubManagement.getPersistedFile(resourceID, mimeType);
|
||||||
|
fileItem = fileContainer.get();
|
||||||
|
}
|
||||||
|
Metadata metadata = fileItem.getMetadata();
|
||||||
Map<String,Object> map = metadata.getMap();
|
Map<String,Object> map = metadata.getMap();
|
||||||
map.put(CatalogueMetadata.CATALOGUE_RESOURCE_ID, resourceID);
|
map.put(CatalogueMetadata.CATALOGUE_RESOURCE_ID, resourceID);
|
||||||
map.put(CatalogueMetadata.CATALOGUE_RESOURCE_REVISION_ID, revisionID);
|
map.put(CatalogueMetadata.CATALOGUE_RESOURCE_REVISION_ID, revisionID);
|
||||||
metadata.setMap(map);
|
metadata.setMap(map);
|
||||||
fileContainer.setMetadata(metadata);
|
fileContainer.setMetadata(metadata);
|
||||||
} else {
|
} catch (Exception e) {
|
||||||
logger.warn(
|
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.",
|
"Unable to set revision id {} to the file of resource with id {} because the file was NOT found on storage-hub.",
|
||||||
revisionID, resourceID);
|
revisionID, resourceID);
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,26 +138,19 @@ public class CatalogueStorageHubManagement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileContainer retrievePersistedFile(String id, String mimeType) throws Exception {
|
public FileContainer retrievePersistedFile(String filename, String mimeType) throws Exception {
|
||||||
SecretManager secretManager = SecretManagerProvider.instance.get();
|
SecretManager secretManager = SecretManagerProvider.instance.get();
|
||||||
Secret secret = Constants.getCatalogueSecret();
|
Secret secret = Constants.getCatalogueSecret();
|
||||||
try {
|
try {
|
||||||
secretManager.startSession(secret);
|
secretManager.startSession(secret);
|
||||||
return storageHubManagement.getPersistedFile(id, mimeType);
|
return storageHubManagement.getPersistedFile(filename, mimeType);
|
||||||
} finally {
|
} finally {
|
||||||
secretManager.endSession();
|
secretManager.endSession();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileContainer getPersistedFile() throws Exception {
|
public FileContainer getPersistedFile() throws Exception {
|
||||||
SecretManager secretManager = SecretManagerProvider.instance.get();
|
return storageHubManagement.getPersistedFile();
|
||||||
Secret secret = Constants.getCatalogueSecret();
|
|
||||||
try {
|
|
||||||
secretManager.startSession(secret);
|
|
||||||
return storageHubManagement.getPersistedFile();
|
|
||||||
} finally {
|
|
||||||
secretManager.endSession();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue