minor fixes and patch product thread class to implement
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@135074 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
20193083df
commit
b843a2b551
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
Product Groups:</b:ControlLabel>
|
||||
<b:Controls>
|
||||
<b:ListBox b:id="listboxStatus" alternateSize="LARGE"
|
||||
width="91%" title="Select a new status" enabled="false"
|
||||
width="91%" title="Select a new status" enabled="true"
|
||||
ui:field="listBoxStatus"></b:ListBox>
|
||||
</b:Controls>
|
||||
</b:ControlGroup>
|
||||
|
|
|
@ -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<Boolean>() {
|
||||
|
||||
@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<CkanRole>() {
|
||||
|
||||
|
@ -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<Boolean>() {
|
||||
|
||||
@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.
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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<String, String> 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;
|
||||
|
|
|
@ -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
|
||||
|
||||
}
|
Loading…
Reference in New Issue