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:
parent
c419c056a1
commit
e1e7a413ba
2
pom.xml
2
pom.xml
|
@ -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>
|
||||
|
||||
|
|
|
@ -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")) {
|
||||
|
@ -90,7 +90,7 @@ public class CKANResource extends CKAN {
|
|||
protected JsonNode previousRepresentation;
|
||||
|
||||
protected CatalogueStorageHubManagement storageHubManagement;
|
||||
|
||||
|
||||
public URL getPersistedURL() {
|
||||
return persistedURL;
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ public class CKANResource extends CKAN {
|
|||
}
|
||||
|
||||
public String getResourceID() {
|
||||
if(resourceID==null && previousRepresentation!=null) {
|
||||
if(resourceID == null && previousRepresentation != null) {
|
||||
resourceID = CKANResource.extractResourceID(previousRepresentation);
|
||||
}
|
||||
return resourceID;
|
||||
|
@ -120,7 +120,7 @@ public class CKANResource extends CKAN {
|
|||
}
|
||||
|
||||
public JsonNode getPreviousRepresentation() {
|
||||
if(previousRepresentation==null && resourceID!=null) {
|
||||
if(previousRepresentation == null && resourceID != null) {
|
||||
sendGetRequest(READ, getMapWithID(resourceID));
|
||||
validate(result);
|
||||
previousRepresentation = result;
|
||||
|
@ -170,11 +170,11 @@ public class CKANResource extends CKAN {
|
|||
|
||||
url = copyStorageResource(url);
|
||||
|
||||
if(name!=null) {
|
||||
if(name != null) {
|
||||
objectNode.put(NAME_KEY, name);
|
||||
}
|
||||
|
||||
if(mimeType!=null) {
|
||||
if(mimeType != null) {
|
||||
objectNode.put(MIME_TYPE_KEY, mimeType);
|
||||
}
|
||||
|
||||
|
@ -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,15 +264,14 @@ 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);
|
||||
name = FilenameUtils.removeExtension(storageHubManagement.getOriginalFilename());
|
||||
mimeType = storageHubManagement.getMimeType();
|
||||
persisted = true;
|
||||
}catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
throw new InternalServerErrorException(e);
|
||||
}
|
||||
}
|
||||
|
@ -278,17 +279,16 @@ 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) {
|
||||
if(mimetype.compareTo(storageHubContentType) != 0) {
|
||||
mimetype = storageHubContentType;
|
||||
// Using storage hub mimetype
|
||||
}
|
||||
}catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
// using provided mimetype
|
||||
}
|
||||
storageHubManagement = new CatalogueStorageHubManagement();
|
||||
|
@ -307,7 +307,7 @@ public class CKANResource extends CKAN {
|
|||
String ret = super.create(getAsString(objectNode));
|
||||
if(persisted) {
|
||||
String gotResourceID = result.get(ID_KEY).asText();
|
||||
if(gotResourceID!=null && gotResourceID.compareTo(resourceID)!=0) {
|
||||
if(gotResourceID != null && gotResourceID.compareTo(resourceID) != 0) {
|
||||
resourceID = gotResourceID;
|
||||
String revisionID = result.get(REVISION_ID_KEY).asText();
|
||||
storageHubManagement.renameFile(resourceID, revisionID);
|
||||
|
@ -333,7 +333,6 @@ public class CKANResource extends CKAN {
|
|||
public String read() {
|
||||
return sendGetRequest(READ, getMapWithID(resourceID));
|
||||
}
|
||||
|
||||
|
||||
protected String update(JsonNode jsonNode) {
|
||||
ObjectNode resourceNode = (ObjectNode) jsonNode;
|
||||
|
@ -344,10 +343,11 @@ 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(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);
|
||||
} else {
|
||||
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 {
|
||||
|
@ -405,7 +405,7 @@ public class CKANResource extends CKAN {
|
|||
ObjectNode resourceNode = (ObjectNode) jsonNode;
|
||||
if(resourceNode.has(ID_KEY)) {
|
||||
update(resourceNode);
|
||||
}else {
|
||||
} else {
|
||||
create(resourceNode);
|
||||
}
|
||||
return result;
|
||||
|
@ -418,14 +418,15 @@ 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) : "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void rollback() {
|
||||
if(previousRepresentation!=null) {
|
||||
if(previousRepresentation != null) {
|
||||
update(previousRepresentation);
|
||||
}else {
|
||||
} else {
|
||||
delete();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
|
|
Loading…
Reference in New Issue