Fixed bug on resource update
This commit is contained in:
parent
4a4055fced
commit
62a852ca40
3
pom.xml
3
pom.xml
|
@ -12,7 +12,7 @@
|
||||||
<groupId>org.gcube.data-publishing</groupId>
|
<groupId>org.gcube.data-publishing</groupId>
|
||||||
<artifactId>gcat</artifactId>
|
<artifactId>gcat</artifactId>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
<version>1.4.1</version>
|
<version>1.4.2-SNAPSHOT</version>
|
||||||
<name>gCube Catalogue (gCat) Service</name>
|
<name>gCube Catalogue (gCat) Service</name>
|
||||||
<description>
|
<description>
|
||||||
This service allows any client to publish on the gCube Catalogue.
|
This service allows any client to publish on the gCube Catalogue.
|
||||||
|
@ -163,7 +163,6 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ch.qos.logback</groupId>
|
<groupId>ch.qos.logback</groupId>
|
||||||
<artifactId>logback-classic</artifactId>
|
<artifactId>logback-classic</artifactId>
|
||||||
<version>1.2.3</version>
|
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
|
@ -297,7 +297,7 @@ public class CKANResource extends CKAN {
|
||||||
urlToCheck = getFinalURL(url);
|
urlToCheck = getFinalURL(url);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
// TODO Evaluate if we want to validate the URL. If the URL does not exists the service
|
// 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.getHost().compareTo(URI_RESOLVER_STORAGE_HUB_HOST) == 0) {
|
||||||
if(urlToCheck.getPath().startsWith(URI_RESOLVER_STORAGE_HUB_PATH)) {
|
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();
|
String newURL = resourceNode.get(CKANResource.URL_KEY).asText();
|
||||||
if(oldURL.compareTo(newURL) == 0) {
|
if(oldURL.compareTo(newURL) == 0) {
|
||||||
logger.trace("The URL of the resource with id {} was not changed", resourceID);
|
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 {
|
} else {
|
||||||
logger.trace("The URL of resource with id {} has been changed the old URL was {}, the new URL is {}",
|
logger.trace("The URL of resource with id {} has been changed the old URL was {}, the new URL is {}",
|
||||||
resourceID, oldURL, newURL);
|
resourceID, oldURL, newURL);
|
||||||
|
|
|
@ -67,8 +67,9 @@ public class HTTPCall {
|
||||||
|| responseCode == HttpURLConnection.HTTP_SEE_OTHER
|
|| responseCode == HttpURLConnection.HTTP_SEE_OTHER
|
||||||
|| responseCode == Status.TEMPORARY_REDIRECT.getStatusCode() || responseCode == 308) {
|
|| responseCode == Status.TEMPORARY_REDIRECT.getStatusCode() || responseCode == 308) {
|
||||||
|
|
||||||
finalURL = getURL(connection.getHeaderField("Location"));
|
URL newURL = getURL(connection.getHeaderField("Location"));
|
||||||
finalURL = getFinalURL(finalURL);
|
connection.disconnect();
|
||||||
|
finalURL = getFinalURL(newURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return finalURL;
|
return finalURL;
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class CatalogueStorageHubManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void internalAddRevisionID(String resourceID, String revisionID) throws Exception {
|
protected void internalAddRevisionID(String resourceID, String revisionID) throws Exception {
|
||||||
FileContainer fileContainer = storageHubManagement.getCreatedFile();
|
FileContainer fileContainer = storageHubManagement.getPersistedFile();
|
||||||
Metadata metadata = fileContainer.get().getMetadata();
|
Metadata metadata = fileContainer.get().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);
|
||||||
|
@ -88,7 +88,7 @@ public class CatalogueStorageHubManagement {
|
||||||
ApplicationMode applicationMode = new ApplicationMode(Constants.getCatalogueApplicationToken());
|
ApplicationMode applicationMode = new ApplicationMode(Constants.getCatalogueApplicationToken());
|
||||||
try {
|
try {
|
||||||
applicationMode.start();
|
applicationMode.start();
|
||||||
FileContainer createdfile = storageHubManagement.getCreatedFile();
|
FileContainer createdfile = storageHubManagement.getPersistedFile();
|
||||||
createdfile.rename(resourceID);
|
createdfile.rename(resourceID);
|
||||||
internalAddRevisionID(resourceID, revisionID);
|
internalAddRevisionID(resourceID, revisionID);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -106,5 +106,15 @@ public class CatalogueStorageHubManagement {
|
||||||
applicationMode.end();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class ContextTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
//DEFAULT_TEST_SCOPE_NAME = "/pred4s/preprod/preVRE";
|
//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 {
|
public static String getCurrentScope(String token) throws ObjectNotFound, Exception {
|
||||||
|
|
|
@ -73,6 +73,25 @@ public class CKANResourceTest extends ContextTest {
|
||||||
ckanResource.create(objectNode);
|
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
|
// @Test
|
||||||
public void testDelete() throws Exception {
|
public void testDelete() throws Exception {
|
||||||
CKANResource ckanResource = new CKANResource("f0326fec-d8ac-42c7-abff-c7905b4d938e");
|
CKANResource ckanResource = new CKANResource("f0326fec-d8ac-42c7-abff-c7905b4d938e");
|
||||||
|
|
|
@ -102,7 +102,7 @@ public class CatalogueStorageHubManagementTest extends ContextTest {
|
||||||
|
|
||||||
Assert.assertTrue(catalogueStorageHubManagement.getMimeType().compareTo(MIME_TYPE) == 0);
|
Assert.assertTrue(catalogueStorageHubManagement.getMimeType().compareTo(MIME_TYPE) == 0);
|
||||||
|
|
||||||
FileContainer createdFileContainer = storageHubManagement.getCreatedFile();
|
FileContainer createdFileContainer = storageHubManagement.getPersistedFile();
|
||||||
|
|
||||||
String version = "2";
|
String version = "2";
|
||||||
catalogueStorageHubManagement.renameFile(RESOURCE_ID, version);
|
catalogueStorageHubManagement.renameFile(RESOURCE_ID, version);
|
||||||
|
|
Loading…
Reference in New Issue