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> <dependency>
<groupId>org.gcube.common</groupId> <groupId>org.gcube.common</groupId>
<artifactId>gxRest</artifactId> <artifactId>gxHTTP</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version> <version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency> </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 // 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"; 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"; protected static final String URL_KEY = "url";
private static final String RESOURCES_KEY = "resources"; 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]*$"; 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 { static {
String context = ContextUtility.getCurrentContext(); String context = ContextUtility.getCurrentContext();
if(context.startsWith("/gcube")) { if(context.startsWith("/gcube")) {
@ -247,8 +247,10 @@ public class CKANResource extends CKAN {
} }
protected boolean isStorageFile(URL url) { protected boolean isStorageFile(URL url) {
if(url.getHost().compareTo(URI_RESOLVER_STORAGE_HUB_HOST) == 0) { URL urlToCheck = getFinalURL(url);
if(url.getPath().startsWith(URI_RESOLVER_STORAGE_HUB_PATH)) { if(urlToCheck.getHost().compareTo(URI_RESOLVER_STORAGE_HUB_HOST) == 0) {
if(urlToCheck.getPath().startsWith(URI_RESOLVER_STORAGE_HUB_PATH)) {
persistedURL = urlToCheck;
return true; 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 * @return the public URL of the copied resource if any. It return the original URL otherwise
*/ */
protected URL copyStorageResource(URL url) { protected URL copyStorageResource(URL url) {
persistedURL = getFinalURL(url); if(isStorageFile(url)) {
if(isStorageFile(persistedURL)) {
storageHubManagement = new CatalogueStorageHubManagement(); storageHubManagement = new CatalogueStorageHubManagement();
try { try {
persistedURL = storageHubManagement.ensureResourcePersistence(persistedURL, itemID, resourceID); persistedURL = storageHubManagement.ensureResourcePersistence(persistedURL, itemID, resourceID);
@ -278,10 +279,9 @@ public class CKANResource extends CKAN {
} }
protected void deleteStorageResource(URL url, String resourceID, String mimetype) { protected void deleteStorageResource(URL url, String resourceID, String mimetype) {
persistedURL = getFinalURL(url); if(isStorageFile(url)) {
if(isStorageFile(persistedURL)) {
try { try {
GXHTTPStringRequest gxhttpStringRequest = GXHTTPStringRequest.newRequest(url.toString()); GXHTTPStringRequest gxhttpStringRequest = GXHTTPStringRequest.newRequest(persistedURL.toString());
HttpURLConnection httpURLConnection = gxhttpStringRequest.from(Constants.CATALOGUE_NAME).head(); HttpURLConnection httpURLConnection = gxhttpStringRequest.from(Constants.CATALOGUE_NAME).head();
String storageHubContentType = httpURLConnection.getContentType().split(";")[0]; String storageHubContentType = httpURLConnection.getContentType().split(";")[0];
if(mimetype.compareTo(storageHubContentType) != 0) { if(mimetype.compareTo(storageHubContentType) != 0) {
@ -334,7 +334,6 @@ public class CKANResource extends CKAN {
return sendGetRequest(READ, getMapWithID(resourceID)); return sendGetRequest(READ, getMapWithID(resourceID));
} }
protected String update(JsonNode jsonNode) { protected String update(JsonNode jsonNode) {
ObjectNode resourceNode = (ObjectNode) jsonNode; ObjectNode resourceNode = (ObjectNode) jsonNode;
// This cannot be moved outside otherwise we don't // This cannot be moved outside otherwise we don't
@ -347,7 +346,8 @@ public class CKANResource extends CKAN {
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);
} else { } 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); resourceNode = persistStorageFile(resourceNode);
/* /*
try { try {
@ -418,7 +418,8 @@ public class CKANResource extends CKAN {
mimeType = previousRepresentation.get(MIME_TYPE_KEY).asText(); mimeType = previousRepresentation.get(MIME_TYPE_KEY).asText();
deleteStorageResource(url, resourceID, mimeType); deleteStorageResource(url, resourceID, mimeType);
} catch(Exception e) { } 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 { try {
applicationMode.start(); applicationMode.start();
GXHTTPStringRequest gxhttpStringRequest = GXHTTPStringRequest.newRequest(persistedURL.toString()); GXHTTPStringRequest gxhttpStringRequest = GXHTTPStringRequest.newRequest(persistedURL.toString());
gxhttpStringRequest.from(Constants.CATALOGUE_NAME);
gxhttpStringRequest.isExternalCall(true); gxhttpStringRequest.isExternalCall(true);
HttpURLConnection httpURLConnection = gxhttpStringRequest.get(); HttpURLConnection httpURLConnection = gxhttpStringRequest.get();
mimeType = httpURLConnection.getContentType().split(";")[0]; mimeType = httpURLConnection.getContentType().split(";")[0];