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