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,11 +398,18 @@ 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) {
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).asText();
storageHubManagement.getPersistedFile(resourceID, mimeType);
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);
@ -417,11 +424,16 @@ public class CKANResource extends CKAN {
*/
}
String ret = super.update(getAsString(resourceNode));
if(storageHubManagement.getPersistedFile()!= null) {
String revisionID = result.get(REVISION_ID_KEY).asText();
storageHubManagement.addRevisionID(resourceID, revisionID);
}
return ret;
}
return previousRepresentation.asText();
}
@Override
public String update(String json) {
try {

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();
}
}