diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/GcubeCkanDataCatalogService.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/GcubeCkanDataCatalogService.java index afe3116..7bb0e5e 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/GcubeCkanDataCatalogService.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/GcubeCkanDataCatalogService.java @@ -91,6 +91,7 @@ public interface GcubeCkanDataCatalogService extends RemoteService { * Get the product bean from the product identifier * @param identifier * @return ManageProductBean + * @throws Exception */ - ManageProductBean getProductBeanById(String identifier); + ManageProductBean getProductBeanById(String identifier) throws Exception; } diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/ui/ManageProductWidget.ui.xml b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/ui/ManageProductWidget.ui.xml index c5b3e17..085132d 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/ui/ManageProductWidget.ui.xml +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/ui/ManageProductWidget.ui.xml @@ -51,7 +51,7 @@ Product Groups: diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/view/GCubeCkanDataCatalogPanel.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/view/GCubeCkanDataCatalogPanel.java index 73dfbf5..22ea516 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/view/GCubeCkanDataCatalogPanel.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/view/GCubeCkanDataCatalogPanel.java @@ -111,6 +111,22 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate { } else { + /** + * Just check if it is enabled.. then we need to listen for dom events coming + */ + GCubeCkanDataCatalog.service.isManageProductEnabled(new AsyncCallback() { + + @Override + public void onSuccess(Boolean result) { + isManageProductEnabled = result; + } + + @Override + public void onFailure(Throwable caught) { + isManageProductEnabled = false; + } + }); + // MANAGE CKAN MANAGEMENT PANEL ACCORDING TO MY ROLE GCubeCkanDataCatalog.service.getMyRole(new AsyncCallback() { @@ -172,22 +188,6 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate { } }); - /** - * Just check if it is enabled.. then we need to listen for dom events coming - */ - GCubeCkanDataCatalog.service.isManageProductEnabled(new AsyncCallback() { - - @Override - public void onSuccess(Boolean result) { - isManageProductEnabled = result; - } - - @Override - public void onFailure(Throwable caught) { - isManageProductEnabled = false; - } - }); - } }); } @@ -356,7 +356,7 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate { GWT.log("Ckan base url: "+ckanAccessPoint.getBaseUrl()); // parsing data.. it is a json bean of the type - printMessage("Incoming message is " + data + " from " + origin); + GWT.log("Incoming message is " + data + " from " + origin); if (ckanAccessPoint.getBaseUrl().indexOf(origin)>=0) { // The data has been sent from your site @@ -367,13 +367,13 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate { try{ JSONValue parsedJSON = JSONParser.parseStrict(data); JSONObject object = parsedJSON.isObject(); - printMessage("Object is " + object); + GWT.log("Object is " + object); if(object != null){ - height = object.get("height").toString(); - productId = object.get("product").toString(); + height = object.get("height").isString().stringValue(); + productId = object.get("product").isString().stringValue(); } }catch(Exception e){ - printMessage("Exception is " + e); + GWT.log("Exception is " + e); } if(height != null) @@ -381,7 +381,7 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate { // show or hide the manage product button latestSelectedProductIdentifier = productId.toString(); - managementPanel.showManageProductButton(productId != null && isManageProductEnabled); + managementPanel.showManageProductButton(productId != null && !productId.isEmpty() && isManageProductEnabled); } else { // The data hasn't been sent from your site! @@ -391,10 +391,6 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate { } - protected native void printMessage(String msg) /*-{ - console.log(msg); - }-*/; - /** * Sets the i frame height. diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GRSFNotificationServices.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GRSFNotificationServices.java index 1290c34..8939659 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GRSFNotificationServices.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GRSFNotificationServices.java @@ -1,7 +1,13 @@ package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.ManageProductBean; import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,7 +64,7 @@ public class GRSFNotificationServices { JSONObject obj = new JSONObject(); obj.put(CATALOGUE_ID, bean.getCatalogueIdentifier()); obj.put(KB_ID, bean.getKnowledgeBaseIdentifier()); - obj.put(PRODUCT_TYPE, bean.getProductType()); + obj.put(PRODUCT_TYPE, bean.getProductType().toLowerCase()); obj.put(STATUS, bean.getNewStatus()); String annotation = bean.getAnnotation(); @@ -68,14 +74,22 @@ public class GRSFNotificationServices { logger.debug("Update request looks like " + obj.toJSONString()); HttpPost request = new HttpPost(serviceUrl + SERVICE_POST_METHOD); + request.setHeader("Accept", "application/json"); + request.setHeader("Content-type", "application/json"); StringEntity params = new StringEntity(obj.toJSONString()); request.setEntity(params); HttpResponse response = httpClient.execute(request); logger.debug("Response code is " + response.getStatusLine().getStatusCode() + " and response message is " + response.getStatusLine().getReasonPhrase()); + String result = convertStreamToString(response.getEntity().getContent()); + JSONParser parser = new JSONParser(); + JSONObject parsedJSON = (JSONObject)parser.parse(result); + if(response.getStatusLine().getStatusCode() > STATUS_SUCCESS) - throw new IllegalArgumentException("Error while performing the update request: " + response.getStatusLine().getReasonPhrase()); + throw new IllegalArgumentException( + "Error while performing the update request: " + response.getStatusLine().getReasonPhrase() + + "and error in the result bean is " + parsedJSON.get("error")); }catch(Exception e){ logger.error("Unable to update this record", e); @@ -85,5 +99,27 @@ public class GRSFNotificationServices { return null; } + private static String convertStreamToString(InputStream is) { + + BufferedReader reader = new BufferedReader(new InputStreamReader(is)); + StringBuilder sb = new StringBuilder(); + + String line = null; + try { + while ((line = reader.readLine()) != null) { + sb.append(line + "\n"); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + is.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return sb.toString(); + } + } diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java index 3a99fbd..6a97278 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java @@ -540,7 +540,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem } @Override - public ManageProductBean getProductBeanById(String identifier) { + public ManageProductBean getProductBeanById(String identifier) throws Exception { ManageProductBean toReturn = null; @@ -555,11 +555,12 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem Map extras = product.getExtrasAsHashMap(); String status = extras.get("Status"); String uuidKB = extras.get("UUID Knowledge Base"); - String productType = extras.get("Product Type"); + String productType = extras.get("Product type"); String title = product.getTitle(); - + if(status == null || uuidKB == null || productType == null) - throw new Exception("Some information is missing"); + throw new Exception("Some information is missing: status = " + status + ", uuid_kb = " + uuidKB + + ", and product type is = " + productType); toReturn = new ManageProductBean(); toReturn.setCatalogueIdentifier(identifier); @@ -571,7 +572,8 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem logger.info("Returning product bean " + toReturn); }catch(Exception e){ - logger.error("Failed to retrieve the information for the product with identifier " + identifier, e); + logger.error("Failed to retrieve the information for the product with identifier " + identifier, e); + throw new Exception("Failed to retrieve the information for the product with identifier " + identifier + ". " + e.getMessage()); } return toReturn; diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/PatchProductThread.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/PatchProductThread.java new file mode 100644 index 0000000..43e45e8 --- /dev/null +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/PatchProductThread.java @@ -0,0 +1,11 @@ +package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server; + +/** + * Thread used to patch a ckan product. + * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) + */ +public class PatchProductThread extends Thread{ + + // TODO + +}