Merged from branch of release 4.13.0

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-publishing/gcat@177043 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2019-02-08 10:10:59 +00:00
parent c419c056a1
commit e1e7a413ba
3 changed files with 35 additions and 33 deletions

View File

@ -131,7 +131,7 @@
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>gxRest</artifactId>
<artifactId>gxHTTP</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>

View File

@ -45,13 +45,6 @@ public class CKANResource extends CKAN {
// see http://docs.ckan.org/en/latest/api/#ckan.logic.action.delete.resource_delete
public static final String RESOURCE_DELETE = CKAN.CKAN_API_PATH + "resource_delete";
/* TODO Remove this code ASAP. It requires a function from Storage HUB */
private static final String URI_RESOLVER_STORAGE_HUB_HOST_PROD = "data.d4science.org";
private static final String URI_RESOLVER_STORAGE_HUB_HOST_DEV = "data1-d.d4science.org";
public static final String URI_RESOLVER_STORAGE_HUB_HOST;
public static final String URI_RESOLVER_STORAGE_HUB_PATH = "/shub/";
protected static final String URL_KEY = "url";
private static final String RESOURCES_KEY = "resources";
@ -63,6 +56,13 @@ public class CKANResource extends CKAN {
public final static String RESOURCE_NAME_REGEX = "^[\\s\\S]*$";
/* TODO Remove this code ASAP. It requires a function from Storage HUB */
private static final String URI_RESOLVER_STORAGE_HUB_HOST_PROD = "data.d4science.org";
private static final String URI_RESOLVER_STORAGE_HUB_HOST_DEV = "data1-d.d4science.org";
public static final String URI_RESOLVER_STORAGE_HUB_HOST;
public static final String URI_RESOLVER_STORAGE_HUB_PATH = "/shub/";
static {
String context = ContextUtility.getCurrentContext();
if(context.startsWith("/gcube")) {
@ -247,8 +247,10 @@ public class CKANResource extends CKAN {
}
protected boolean isStorageFile(URL url) {
if(url.getHost().compareTo(URI_RESOLVER_STORAGE_HUB_HOST) == 0) {
if(url.getPath().startsWith(URI_RESOLVER_STORAGE_HUB_PATH)) {
URL urlToCheck = getFinalURL(url);
if(urlToCheck.getHost().compareTo(URI_RESOLVER_STORAGE_HUB_HOST) == 0) {
if(urlToCheck.getPath().startsWith(URI_RESOLVER_STORAGE_HUB_PATH)) {
persistedURL = urlToCheck;
return true;
}
}
@ -262,8 +264,7 @@ public class CKANResource extends CKAN {
* @return the public URL of the copied resource if any. It return the original URL otherwise
*/
protected URL copyStorageResource(URL url) {
persistedURL = getFinalURL(url);
if(isStorageFile(persistedURL)) {
if(isStorageFile(url)) {
storageHubManagement = new CatalogueStorageHubManagement();
try {
persistedURL = storageHubManagement.ensureResourcePersistence(persistedURL, itemID, resourceID);
@ -278,10 +279,9 @@ public class CKANResource extends CKAN {
}
protected void deleteStorageResource(URL url, String resourceID, String mimetype) {
persistedURL = getFinalURL(url);
if(isStorageFile(persistedURL)) {
if(isStorageFile(url)) {
try {
GXHTTPStringRequest gxhttpStringRequest = GXHTTPStringRequest.newRequest(url.toString());
GXHTTPStringRequest gxhttpStringRequest = GXHTTPStringRequest.newRequest(persistedURL.toString());
HttpURLConnection httpURLConnection = gxhttpStringRequest.from(Constants.CATALOGUE_NAME).head();
String storageHubContentType = httpURLConnection.getContentType().split(";")[0];
if(mimetype.compareTo(storageHubContentType) != 0) {
@ -334,7 +334,6 @@ public class CKANResource extends CKAN {
return sendGetRequest(READ, getMapWithID(resourceID));
}
protected String update(JsonNode jsonNode) {
ObjectNode resourceNode = (ObjectNode) jsonNode;
// This cannot be moved outside otherwise we don't
@ -347,7 +346,8 @@ public class CKANResource extends CKAN {
if(oldURL.compareTo(newURL) == 0) {
logger.trace("The URL of the resource with id {} was not changed", resourceID);
} else {
logger.trace("The URL of resource with id {} has been changed the old URL was {}, the new URL is {}", resourceID, oldURL, newURL);
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 {
@ -418,7 +418,8 @@ public class CKANResource extends CKAN {
mimeType = previousRepresentation.get(MIME_TYPE_KEY).asText();
deleteStorageResource(url, resourceID, mimeType);
} catch(Exception e) {
logger.error("Unable to delete resource {}", previousRepresentation!=null ? getAsString(previousRepresentation) : "");
logger.error("Unable to delete resource {}",
previousRepresentation != null ? getAsString(previousRepresentation) : "");
}
}

View File

@ -44,6 +44,7 @@ public class CatalogueStorageHubManagement {
try {
applicationMode.start();
GXHTTPStringRequest gxhttpStringRequest = GXHTTPStringRequest.newRequest(persistedURL.toString());
gxhttpStringRequest.from(Constants.CATALOGUE_NAME);
gxhttpStringRequest.isExternalCall(true);
HttpURLConnection httpURLConnection = gxhttpStringRequest.get();
mimeType = httpURLConnection.getContentType().split(";")[0];