Catching situation where the file was not persisted by gcat

This commit is contained in:
Luca Frosini 2020-02-03 15:50:58 +01:00
parent 4a1b20c1d5
commit e9e1539e16
2 changed files with 38 additions and 22 deletions

View File

@ -398,28 +398,40 @@ public class CKANResource extends CKAN {
String oldURL = previousRepresentation.get(CKANResource.URL_KEY).asText();
String newURL = resourceNode.get(CKANResource.URL_KEY).asText();
if(oldURL.compareTo(newURL) == 0) {
logger.trace("The URL of the resource with id {} was not changed", resourceID);
storageHubManagement = new CatalogueStorageHubManagement();
this.mimeType = previousRepresentation.get(CKANResource.MIME_TYPE_KEY).asText();
storageHubManagement.getPersistedFile(resourceID, mimeType);
} else {
logger.trace("The URL of resource with id {} has been changed the old URL was {}, the new URL is {}",
resourceID, oldURL, newURL);
resourceNode = persistStorageFile(resourceNode);
/*
try {
URL urlOLD = new URL(oldURL);
deleteStorageResource(urlOLD);
}catch (Exception e) {
logger.error("Unable to remove old file at URL {}", oldURL);
if(!previousRepresentation.equals(resourceNode)) {
if(oldURL.compareTo(newURL) != 0) {
logger.trace("The URL of the resource with id {} was not changed", resourceID);
storageHubManagement = new CatalogueStorageHubManagement();
this.mimeType = previousRepresentation.get(CKANResource.MIME_TYPE_KEY)!= null ? previousRepresentation.get(CKANResource.MIME_TYPE_KEY).asText() : null;
try {
storageHubManagement.retrievePersistedFile(resourceID, mimeType);
}catch (Exception e) {
}
} else {
logger.trace("The URL of resource with id {} has been changed the old URL was {}, the new URL is {}",
resourceID, oldURL, newURL);
resourceNode = persistStorageFile(resourceNode);
/*
try {
URL urlOLD = new URL(oldURL);
deleteStorageResource(urlOLD);
}catch (Exception e) {
logger.error("Unable to remove old file at URL {}", oldURL);
}
*/
}
*/
String ret = super.update(getAsString(resourceNode));
if(storageHubManagement.getPersistedFile()!= null) {
String revisionID = result.get(REVISION_ID_KEY).asText();
storageHubManagement.addRevisionID(resourceID, revisionID);
}
return ret;
}
String ret = super.update(getAsString(resourceNode));
String revisionID = result.get(REVISION_ID_KEY).asText();
storageHubManagement.addRevisionID(resourceID, revisionID);
return ret;
return previousRepresentation.asText();
}
@Override

View File

@ -117,14 +117,18 @@ public class CatalogueStorageHubManagement {
}
}
public void getPersistedFile(String id, String mimeType) throws Exception {
public FileContainer retrievePersistedFile(String id, String mimeType) throws Exception {
ApplicationMode applicationMode = new ApplicationMode(Constants.getCatalogueApplicationToken());
try {
applicationMode.start();
storageHubManagement.getPersistedFile(id, mimeType);
return storageHubManagement.getPersistedFile(id, mimeType);
} finally {
applicationMode.end();
}
}
public FileContainer getPersistedFile() {
return storageHubManagement.getPersistedFile();
}
}