Fixed bug on resource update

This commit is contained in:
Luca Frosini 2020-01-22 17:35:48 +01:00
parent 4a4055fced
commit 62a852ca40
7 changed files with 41 additions and 9 deletions

View File

@ -12,7 +12,7 @@
<groupId>org.gcube.data-publishing</groupId>
<artifactId>gcat</artifactId>
<packaging>war</packaging>
<version>1.4.1</version>
<version>1.4.2-SNAPSHOT</version>
<name>gCube Catalogue (gCat) Service</name>
<description>
This service allows any client to publish on the gCube Catalogue.
@ -163,7 +163,6 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -297,7 +297,7 @@ public class CKANResource extends CKAN {
urlToCheck = getFinalURL(url);
} catch(Exception e) {
// TODO Evaluate if we want to validate the URL. If the URL does not exists the service
// could decide refuse the Resource Creation
// could decide to refuse the Resource Creation
}
if(urlToCheck.getHost().compareTo(URI_RESOLVER_STORAGE_HUB_HOST) == 0) {
if(urlToCheck.getPath().startsWith(URI_RESOLVER_STORAGE_HUB_PATH)) {
@ -400,6 +400,9 @@ public class CKANResource extends CKAN {
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);

View File

@ -67,8 +67,9 @@ public class HTTPCall {
|| responseCode == HttpURLConnection.HTTP_SEE_OTHER
|| responseCode == Status.TEMPORARY_REDIRECT.getStatusCode() || responseCode == 308) {
finalURL = getURL(connection.getHeaderField("Location"));
finalURL = getFinalURL(finalURL);
URL newURL = getURL(connection.getHeaderField("Location"));
connection.disconnect();
finalURL = getFinalURL(newURL);
}
return finalURL;

View File

@ -75,7 +75,7 @@ public class CatalogueStorageHubManagement {
}
protected void internalAddRevisionID(String resourceID, String revisionID) throws Exception {
FileContainer fileContainer = storageHubManagement.getCreatedFile();
FileContainer fileContainer = storageHubManagement.getPersistedFile();
Metadata metadata = fileContainer.get().getMetadata();
Map<String,Object> map = metadata.getMap();
map.put(CatalogueMetadata.CATALOGUE_RESOURCE_ID, resourceID);
@ -88,7 +88,7 @@ public class CatalogueStorageHubManagement {
ApplicationMode applicationMode = new ApplicationMode(Constants.getCatalogueApplicationToken());
try {
applicationMode.start();
FileContainer createdfile = storageHubManagement.getCreatedFile();
FileContainer createdfile = storageHubManagement.getPersistedFile();
createdfile.rename(resourceID);
internalAddRevisionID(resourceID, revisionID);
} finally {
@ -106,5 +106,15 @@ public class CatalogueStorageHubManagement {
applicationMode.end();
}
}
public void getPersistedFile(String id, String mimeType) throws Exception {
ApplicationMode applicationMode = new ApplicationMode(Constants.getCatalogueApplicationToken());
try {
applicationMode.start();
storageHubManagement.getPersistedFile(id, mimeType);
} finally {
applicationMode.end();
}
}
}

View File

@ -45,7 +45,7 @@ public class ContextTest {
}
//DEFAULT_TEST_SCOPE_NAME = "/pred4s/preprod/preVRE";
DEFAULT_TEST_SCOPE_NAME = "/gcube/devNext/NextNext";
DEFAULT_TEST_SCOPE_NAME = "/gcube/devsec/devVRE";
}
public static String getCurrentScope(String token) throws ObjectNotFound, Exception {

View File

@ -73,6 +73,25 @@ public class CKANResourceTest extends ContextTest {
ckanResource.create(objectNode);
}
@Test
public void testCreateUpdate() throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode objectNode = objectMapper.createObjectNode();
objectNode.put(CKANResource.NAME_KEY, "MyTestTy_rest_upload");
objectNode.put(CKANResource.URL_KEY, "https://data-dev.d4science.net/C1G2");
objectNode.put("description", "File uploaded using the REST API");
// objectNode.put(CKANResource.ID_KEY, "ba7ab7e8-c268-4219-98cd-c73470870999");
String id = "5795a7ce-4444-439e-b77d-1df3beaa8a42"; // name = my_restful
CKANResource ckanResource = new CKANResource(id);
String json = ckanResource.getAsString(objectNode);
logger.debug("Going to create Resource {}", json);
String createdJson = ckanResource.create(objectNode);
ckanResource = new CKANResource(id);
ckanResource.update(createdJson);
}
// @Test
public void testDelete() throws Exception {
CKANResource ckanResource = new CKANResource("f0326fec-d8ac-42c7-abff-c7905b4d938e");

View File

@ -102,7 +102,7 @@ public class CatalogueStorageHubManagementTest extends ContextTest {
Assert.assertTrue(catalogueStorageHubManagement.getMimeType().compareTo(MIME_TYPE) == 0);
FileContainer createdFileContainer = storageHubManagement.getCreatedFile();
FileContainer createdFileContainer = storageHubManagement.getPersistedFile();
String version = "2";
catalogueStorageHubManagement.renameFile(RESOURCE_ID, version);