minor fix at server side

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/grsf-manage-widget@162870 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2018-02-02 16:32:30 +00:00
parent aee48d3ecd
commit f1cb4f058e
10 changed files with 196 additions and 188 deletions

View File

@ -4,9 +4,6 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/> <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="ckan-util-library-2.4.1-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/ckan-util-library/ckan-util-library">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="context-root" value="grsf-manage-widget"/> <property name="context-root" value="grsf-manage-widget"/>
<property name="java-output-path" value="/grsf-manage-widget/target/grsf-manage-widget-1.0.0-SNAPSHOT/WEB-INF/classes"/> <property name="java-output-path" value="/grsf-manage-widget/target/grsf-manage-widget-1.0.0-SNAPSHOT/WEB-INF/classes"/>
</wb-module> </wb-module>

View File

@ -1,5 +1,7 @@
package org.gcube.datacatalogue.grsf_manage_widget.client; package org.gcube.datacatalogue.grsf_manage_widget.client;
import java.util.List;
import org.gcube.datacatalogue.grsf_manage_widget.shared.ManageProductBean; import org.gcube.datacatalogue.grsf_manage_widget.shared.ManageProductBean;
import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteService;
@ -25,7 +27,7 @@ public interface GRSFManageWidgetService extends RemoteService {
/** /**
* Notify product update * Notify product update
*/ */
String notifyProductUpdate(ManageProductBean bean) throws Exception; String notifyProductUpdate(ManageProductBean bean, List<String> hashtags) throws Exception;
// /** // /**
// * Check that a record with such semantic identifier exists // * Check that a record with such semantic identifier exists

View File

@ -3,6 +3,8 @@
*/ */
package org.gcube.datacatalogue.grsf_manage_widget.client; package org.gcube.datacatalogue.grsf_manage_widget.client;
import java.util.List;
import org.gcube.datacatalogue.grsf_manage_widget.shared.ManageProductBean; import org.gcube.datacatalogue.grsf_manage_widget.shared.ManageProductBean;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
@ -13,7 +15,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
*/ */
public interface GRSFManageWidgetServiceAsync { public interface GRSFManageWidgetServiceAsync {
void notifyProductUpdate(ManageProductBean bean, void notifyProductUpdate(ManageProductBean bean, List<String> hashtags,
AsyncCallback<String> callback); AsyncCallback<String> callback);
void getProductBeanById(String identifier, void getProductBeanById(String identifier,

View File

@ -344,14 +344,6 @@ public class ManageProductWidget extends Composite{
return; return;
} }
annotationAreaGroup.setType(ControlGroupType.NONE);
// if(annotationArea.getText() == null || annotationArea.getText().isEmpty()){
// annotationArea.setPlaceholder("An annotation message to send along the update (mandatory)");
// annotationAreaGroup.setType(ControlGroupType.ERROR);
// return;
// }
manageProductModal.setCloseVisible(false); manageProductModal.setCloseVisible(false);
cancelButton.setEnabled(false); cancelButton.setEnabled(false);
confirmButton.setEnabled(false); confirmButton.setEnabled(false);
@ -360,8 +352,10 @@ public class ManageProductWidget extends Composite{
// get short name // get short name
bean.setShortNameUpdated(shortNameTextBox.getText()); bean.setShortNameUpdated(shortNameTextBox.getText());
// evaluate the connections and the actions on them
bean.setConnections(connectWidget.getConnectList());
// update similar records and to connect // update similar records and to connect
bean.setConnectTo(connectWidget.getConnectList());
bean.setSimilarGrsfRecords(similarRecordPanel.getSimilarRecords()); bean.setSimilarGrsfRecords(similarRecordPanel.getSimilarRecords());
bean.getSimilarGrsfRecords().addAll(suggestedMergesPanel.getSimilarRecords()); bean.getSimilarGrsfRecords().addAll(suggestedMergesPanel.getSimilarRecords());
@ -372,7 +366,7 @@ public class ManageProductWidget extends Composite{
// traceability flag // traceability flag
bean.setTraceabilityFlag(traceabilityFlag.getValue()); bean.setTraceabilityFlag(traceabilityFlag.getValue());
service.notifyProductUpdate(bean, new AsyncCallback<String>() { service.notifyProductUpdate(bean, null, new AsyncCallback<String>() { // TODO add hashtags here
@Override @Override
public void onSuccess(String result) { public void onSuccess(String result) {

View File

@ -36,6 +36,10 @@ import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.Widget;
/**
* Connections panel
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class ConnectToWidget extends Composite{ public class ConnectToWidget extends Composite{
private static ConnectToWidgetUiBinder uiBinder = GWT private static ConnectToWidgetUiBinder uiBinder = GWT
@ -52,11 +56,9 @@ public class ConnectToWidget extends Composite{
@UiField @UiField
Button suggestRecord; Button suggestRecord;
//private GRSFManageWidgetServiceAsync service;
private List<Tuple> connectList = new ArrayList<Tuple>(0); private List<Tuple> connectList = new ArrayList<Tuple>(0);
private List<ConnectedBean> currentlyConnected = null;
private List<ConnectedBean> connectedRecords = null; private List<ConnectedBean> suggestedByKnowledgeBase;
private GRSFManageWidgetServiceAsync service; private GRSFManageWidgetServiceAsync service;
public ConnectToWidget(final ManageProductBean bean, GRSFManageWidgetServiceAsync service) { public ConnectToWidget(final ManageProductBean bean, GRSFManageWidgetServiceAsync service) {
@ -64,19 +66,31 @@ public class ConnectToWidget extends Composite{
this.service = service; this.service = service;
// get already connected beans, if any // add the one suggested by the knowledge base
connectedRecords = bean.getConnectTo(); suggestedByKnowledgeBase = bean.getSuggestedByKnowledgeBase();
if(connectedRecords != null){ if(suggestedByKnowledgeBase != null){
connectPanel.add(new HTML("<hr style=\"width:100%;\"/>")); connectPanel.add(new HTML("<hr style=\"width:100%;\"/>"));
for (ConnectedBean connected : connectedRecords) { for (ConnectedBean connected : suggestedByKnowledgeBase) {
Widget widget = buildWidgetForConnectedRecords(connected); Widget widget = buildWidgetForConnected(connected, true);
connectPanel.add(widget); connectPanel.add(widget);
connectPanel.add(new HTML("<hr style=\"width:100%;\"/>")); connectPanel.add(new HTML("<hr style=\"width:100%;\"/>"));
} }
} }
//this.service = service;
// get already connected beans, and suggested ones
currentlyConnected = bean.getCurrentConnections();
if(currentlyConnected != null){
connectPanel.add(new HTML("<hr style=\"width:100%;\"/>"));
for (ConnectedBean connected : currentlyConnected) {
Widget widget = buildWidgetForConnected(connected, false);
connectPanel.add(widget);
connectPanel.add(new HTML("<hr style=\"width:100%;\"/>"));
}
}
// manage the button for manual suggestion
String acceptedDomain = bean.getGrsfDomain().equalsIgnoreCase(Product_Type.STOCK.getOrigName()) ? Product_Type.FISHERY.getOrigName() : Product_Type.STOCK.getOrigName(); // inverted String acceptedDomain = bean.getGrsfDomain().equalsIgnoreCase(Product_Type.STOCK.getOrigName()) ? Product_Type.FISHERY.getOrigName() : Product_Type.STOCK.getOrigName(); // inverted
suggestRecord.setTitle("Connect this " + bean.getGrsfDomain() + " record to a " + acceptedDomain + " record "); suggestRecord.setTitle("Connect this " + bean.getGrsfDomain() + " record to a " + acceptedDomain + " record ");
suggestRecord.setIcon(IconType.PLUS_SIGN); suggestRecord.setIcon(IconType.PLUS_SIGN);
@ -89,8 +103,6 @@ public class ConnectToWidget extends Composite{
public void onClick(ClickEvent arg0) { public void onClick(ClickEvent arg0) {
ConnectedBean cb = new ConnectedBean(); ConnectedBean cb = new ConnectedBean();
// cb.setExtra(true);
cb.setSourceDomain(bean.getGrsfDomain());
Tuple t = buildWidgetConnect(cb); Tuple t = buildWidgetConnect(cb);
connectList.add(t); connectList.add(t);
connectPanel.add(t.getW()); connectPanel.add(t.getW());
@ -105,24 +117,25 @@ public class ConnectToWidget extends Composite{
* @param similarGRSFRecord * @param similarGRSFRecord
* @return * @return
*/ */
public static Widget buildWidgetForConnectedRecords(final ConnectedBean connected){ public static Widget buildWidgetForConnected(final ConnectedBean connected, boolean suggestedByKb){
HorizontalPanel hp = new HorizontalPanel(); HorizontalPanel hp = new HorizontalPanel();
hp.setWidth("95%"); hp.setWidth("95%");
VerticalPanel leftPanel = new VerticalPanel(); VerticalPanel leftPanel = new VerticalPanel();
leftPanel.setWidth("80%"); leftPanel.setWidth("80%");
leftPanel.getElement().getStyle().setMarginLeft(20, Unit.PX); leftPanel.getElement().getStyle().setMarginLeft(20, Unit.PX);
Paragraph name = new Paragraph("Record name: " + (connected.getDestShortName() != null? connected.getDestShortName() : "Unavailable")); Paragraph name = new Paragraph("Record name: " + (connected.getDestName() != null? connected.getDestName() : "Unavailable"));
leftPanel.add(name); leftPanel.add(name);
Paragraph semanticIdentifier = new Paragraph("Semantic Identifier: " + Paragraph semanticIdentifier = new Paragraph("Semantic Identifier: " +
connected.getDestSemanticIdentifier()); connected.getDestSemanticIdentifier());
leftPanel.add(semanticIdentifier); leftPanel.add(semanticIdentifier);
Paragraph identifier = new Paragraph("Record UUID: " + Paragraph identifier = new Paragraph("Record UUID: " +
connected.getDestKnowledgeBaseId()); connected.getDestKnowledgeBaseId());
leftPanel.add(identifier); leftPanel.add(identifier);
Anchor view = new Anchor(); Anchor view = new Anchor();
view.setHref(connected.getUrl()); view.setHref(connected.getDestUrl());
view.setText("View"); view.setText("View");
view.setTitle("Click to view the similar record"); view.setTitle("Click to view the similar record");
view.setTarget("_blank"); view.setTarget("_blank");
@ -131,19 +144,33 @@ public class ConnectToWidget extends Composite{
VerticalPanel rightPanel = new VerticalPanel(); VerticalPanel rightPanel = new VerticalPanel();
rightPanel.setWidth("20%"); rightPanel.setWidth("20%");
rightPanel.getElement().getStyle().setFloat(Float.RIGHT);
if(!suggestedByKb){
final CheckBox removeExtra = new CheckBox("Remove"); final CheckBox removeExtra = new CheckBox("Remove");
removeExtra.setTitle("Remove this record among the connected ones"); removeExtra.setTitle("Remove this connections");
removeExtra.addClickHandler(new ClickHandler() { removeExtra.addClickHandler(new ClickHandler() {
@Override @Override
public void onClick(ClickEvent arg0) { public void onClick(ClickEvent arg0) {
connected.setToBeKept(!removeExtra.getValue()); connected.setRemove(removeExtra.getValue());
} }
}); });
rightPanel.getElement().getStyle().setFloat(Float.RIGHT);
rightPanel.add(removeExtra); rightPanel.add(removeExtra);
}
final CheckBox connect = new CheckBox("Connect");
connect.setValue(suggestedByKb); // automatically check the value
connect.setTitle("Connect this record");
connect.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent arg0) {
connected.setRemove(connect.getValue());
}
});
rightPanel.add(connect);
hp.add(leftPanel); hp.add(leftPanel);
hp.add(rightPanel); hp.add(rightPanel);
hp.getElement().getStyle().setPadding(10, Unit.PX); hp.getElement().getStyle().setPadding(10, Unit.PX);
@ -298,21 +325,24 @@ public class ConnectToWidget extends Composite{
*/ */
public List<ConnectedBean> getConnectList() { public List<ConnectedBean> getConnectList() {
if(connectedRecords == null) TODO
connectedRecords = new ArrayList<ConnectedBean>(0); // List<ConnectedBean> toReturn = new ArrayList<>();
//
for (Tuple p : connectList) { // if(currentlyConnected != null)
String suggestedIdentifier = ((ConnectedBean)p.getO()).getDestKnowledgeBaseId(); // currentlyConnected = new ArrayList<ConnectedBean>(0);
if(suggestedIdentifier == null || suggestedIdentifier.isEmpty()) //
continue; // for (Tuple p : connectList) {
else{ // String suggestedIdentifier = ((ConnectedBean)p.getO()).getDestKnowledgeBaseId();
ConnectedBean connectedRecord = (ConnectedBean) p.getO(); // if(suggestedIdentifier == null || suggestedIdentifier.isEmpty())
connectedRecord.setToBeKept(true); // continue;
connectedRecords.add((ConnectedBean) p.getO()); // else{
} // ConnectedBean connectedRecord = (ConnectedBean) p.getO();
} // connectedRecord.setToBeKept(true);
// currentlyConnected.add((ConnectedBean) p.getO());
return connectedRecords; // }
// }
//
// return currentlyConnected;
} }
} }

View File

@ -86,14 +86,13 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
toReturn = new ManageProductBean(); toReturn = new ManageProductBean();
toReturn.setCatalogueIdentifier(UUID.randomUUID().toString()); toReturn.setCatalogueIdentifier(UUID.randomUUID().toString());
List<ConnectedBean> connectTo = new ArrayList<>(); List<ConnectedBean> connectTo = new ArrayList<>();
connectTo.add(new ConnectedBean( connectTo.add(new ConnectedBean(
"91f1e413-dc9f-3b4e-b1c5-0e8560177253",
"Stock",
"http://data.d4science.org/ctlg/GRSF_Admin/91f1e413-dc9f-3b4e-b1c5-0e8560177253",
"89f1e413-dc9f-3b4e-b1c5-0e8560177254", "89f1e413-dc9f-3b4e-b1c5-0e8560177254",
"Random title", "Random title",
"http://data.d4science.org/ctlg/GRSF_Admin/89f1e413-dc9f-3b4e-b1c5-0e8560177254", "http://data.d4science.org/ctlg/GRSF_Admin/89f1e413-dc9f-3b4e-b1c5-0e8560177254",
"Fishery" "Fishery",
"ajklsdkad:akljdnajdna"
)); ));
toReturn.setCurrentConnections(connectTo); toReturn.setCurrentConnections(connectTo);
toReturn.setGrsfDomain("Stock"); toReturn.setGrsfDomain("Stock");
@ -206,7 +205,7 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
for (String connectedBean : connectedBeanUrls) { for (String connectedBean : connectedBeanUrls) {
if(connectedBean.equals(Constants.NO_CONNECTED_RECORDS)) // stop here if there is a single element with this information if(connectedBean.equals(Constants.NO_CONNECTED_RECORDS)) // stop here if there is a single element with this information
break; break;
ConnectedBean builtBean = Utils.connectedBeanRecordFromUrl(recordUrl, connectedBean, uuidKB, grsfDomain, catalogue, apiKey); ConnectedBean builtBean = Utils.connectedBeanRecordFromUrl(connectedBean, catalogue, apiKey, httpSession);
if(builtBean != null) if(builtBean != null)
connectedBeans.add(builtBean); connectedBeans.add(builtBean);
} }
@ -223,7 +222,7 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
if(exploitedResourcesUrls != null && !exploitedResourcesUrls.isEmpty()){ if(exploitedResourcesUrls != null && !exploitedResourcesUrls.isEmpty()){
for (String exploited : exploitedResourcesUrls) { for (String exploited : exploitedResourcesUrls) {
ConnectedBean builtBean = Utils.connectedBeanRecordFromUrl(recordUrl, exploited, uuidKB, grsfDomain, catalogue, apiKey); ConnectedBean builtBean = Utils.connectedBeanRecordFromUrl(exploited, catalogue, apiKey, httpSession);
if(builtBean != null) if(builtBean != null)
suggestedConnectionsByKnowledgeBase.add(builtBean); suggestedConnectionsByKnowledgeBase.add(builtBean);
} }
@ -282,7 +281,7 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
} }
@Override @Override
public String notifyProductUpdate(ManageProductBean bean) throws Exception{ public String notifyProductUpdate(ManageProductBean bean, List<String> hashtags) throws Exception{
logger.info("Creating notification for the bean " + bean + " to send to the knowledge base"); logger.info("Creating notification for the bean " + bean + " to send to the knowledge base");
try{ try{
@ -306,7 +305,7 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
threadRequest.getSession().removeAttribute(sessionProductKey); threadRequest.getSession().removeAttribute(sessionProductKey);
return Utils.updateRecord(baseUrl, bean, catalogue, username, administratorFullName, threadRequest, return Utils.updateRecord(baseUrl, bean, catalogue, username, administratorFullName, threadRequest,
PortalContext.getConfiguration().getCurrentGroupId(threadRequest), context, token); PortalContext.getConfiguration().getCurrentGroupId(threadRequest), context, token, hashtags);
}catch(Exception e){ }catch(Exception e){
logger.error("Unable to update the product", e); logger.error("Unable to update the product", e);

View File

@ -122,9 +122,9 @@ public class GRSFUpdaterServiceClient {
for(ConnectedBean c: connections){ for(ConnectedBean c: connections){
JSONObject cc = new JSONObject(); JSONObject cc = new JSONObject();
if(c.isRemove() || (c.isConnect() && !c.isRemove())){ // do not send it if it needs to be unconnected but not removed if(c.isRemove() || (c.isConnect() && !c.isRemove())){ // do not send it if it needs to be unconnected but not removed
cc.put(Constants.SOURCE_KNOWLEDGE_BASE_ID, c.getSourceKnowledgeBaseId()); cc.put(Constants.SOURCE_KNOWLEDGE_BASE_ID, bean.getKnowledgeBaseIdentifier());
cc.put(Constants.DEST_KNOWLEDGE_BASE_ID, c.getDestKnowledgeBaseId()); cc.put(Constants.DEST_KNOWLEDGE_BASE_ID, c.getDestKnowledgeBaseId());
cc.put(Constants.SOURCE_DOMAIN, c.getSourceDomain()); cc.put(Constants.SOURCE_DOMAIN, bean.getGrsfDomain());
cc.put(Constants.CONNECTION_TO_REMOVE, c.isRemove()); cc.put(Constants.CONNECTION_TO_REMOVE, c.isRemove());
} }
connectionsJson.add(cc); connectionsJson.add(cc);

View File

@ -1,16 +1,12 @@
package org.gcube.datacatalogue.grsf_manage_widget.server.manage; package org.gcube.datacatalogue.grsf_manage_widget.server.manage;
import static org.gcube.resources.discovery.icclient.ICFactory.client; import static org.gcube.resources.discovery.icclient.ICFactory.client;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.io.StringReader; import java.io.StringReader;
import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -23,10 +19,7 @@ import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.encryption.StringEncrypter;
import org.gcube.common.portal.PortalContext; import org.gcube.common.portal.PortalContext;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.resources.gcore.utils.XPathHelper; import org.gcube.common.resources.gcore.utils.XPathHelper;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datacatalogue.ckanutillibrary.server.ApplicationProfileScopePerUrlReader; import org.gcube.datacatalogue.ckanutillibrary.server.ApplicationProfileScopePerUrlReader;
@ -34,23 +27,15 @@ import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue;
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueRunningCluster; import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueRunningCluster;
import org.gcube.datacatalogue.ckanutillibrary.shared.ex.ApplicationProfileNotFoundException; import org.gcube.datacatalogue.ckanutillibrary.shared.ex.ApplicationProfileNotFoundException;
import org.gcube.datacatalogue.common.Constants; import org.gcube.datacatalogue.common.Constants;
import org.gcube.datacatalogue.common.enums.Product_Type;
import org.gcube.datacatalogue.common.enums.Status; import org.gcube.datacatalogue.common.enums.Status;
import org.gcube.datacatalogue.grsf_manage_widget.server.manage.RevertOperationUrl.Operation;
import org.gcube.datacatalogue.grsf_manage_widget.shared.ConnectedBean; import org.gcube.datacatalogue.grsf_manage_widget.shared.ConnectedBean;
import org.gcube.datacatalogue.grsf_manage_widget.shared.ManageProductBean; import org.gcube.datacatalogue.grsf_manage_widget.shared.ManageProductBean;
import org.gcube.datacatalogue.grsf_manage_widget.shared.SimilarGRSFRecord; import org.gcube.datacatalogue.grsf_manage_widget.shared.SimilarGRSFRecord;
import org.gcube.portlets.user.urlshortener.UrlShortener;
import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.Query; import org.gcube.resources.discovery.client.queries.api.Query;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.resources.discovery.client.queries.impl.QueryBox; import org.gcube.resources.discovery.client.queries.impl.QueryBox;
import org.gcube.vomanagement.usermanagement.RoleManager;
import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.GCubeTeam;
import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser; import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
@ -62,12 +47,8 @@ import org.xml.sax.InputSource;
import com.liferay.portal.service.UserLocalServiceUtil; import com.liferay.portal.service.UserLocalServiceUtil;
import eu.trentorise.opendata.jackan.internal.org.apache.http.HttpResponse;
import eu.trentorise.opendata.jackan.internal.org.apache.http.client.methods.HttpPost;
import eu.trentorise.opendata.jackan.internal.org.apache.http.entity.StringEntity;
import eu.trentorise.opendata.jackan.internal.org.apache.http.impl.client.CloseableHttpClient; import eu.trentorise.opendata.jackan.internal.org.apache.http.impl.client.CloseableHttpClient;
import eu.trentorise.opendata.jackan.internal.org.apache.http.impl.client.HttpClientBuilder; import eu.trentorise.opendata.jackan.internal.org.apache.http.impl.client.HttpClientBuilder;
import eu.trentorise.opendata.jackan.internal.org.apache.http.util.EntityUtils;
import eu.trentorise.opendata.jackan.model.CkanDataset; import eu.trentorise.opendata.jackan.model.CkanDataset;
import eu.trentorise.opendata.jackan.model.CkanPair; import eu.trentorise.opendata.jackan.model.CkanPair;
@ -252,8 +233,17 @@ public class Utils {
* @param catalogue * @param catalogue
* @return true on success, false otherwise * @return true on success, false otherwise
*/ */
public static String updateRecord(String serviceUrl, ManageProductBean bean, DataCatalogue catalogue, String username, public static String updateRecord(
String fullName, HttpServletRequest httpServletRequest, long groupId, String context, String token) throws Exception{ String serviceUrl,
ManageProductBean bean,
DataCatalogue catalogue,
String username,
String fullName,
HttpServletRequest httpServletRequest,
long groupId,
String context,
String token,
List<String> hashtags) throws Exception{
if(serviceUrl == null) if(serviceUrl == null)
throw new IllegalArgumentException("GRSF Updater service url cannot be null"); throw new IllegalArgumentException("GRSF Updater service url cannot be null");
@ -275,12 +265,17 @@ public class Utils {
ScopeProvider.instance.set(context); ScopeProvider.instance.set(context);
SecurityTokenProvider.instance.set(token); SecurityTokenProvider.instance.set(token);
try{
// send email to Editors and Reviewers // send email to Editors and Reviewers
SocialCommunications.sendEmailAdministrators(bean, catalogue, username, fullName, groupId, httpServletRequest, bean.isMergesInvolved()); SocialCommunications.sendEmailAdministrators(bean, catalogue, username, fullName, groupId, httpServletRequest, bean.isMergesInvolved());
// create a post about the operation // create a post about the operation
SocialCommunications.createSocialPost(bean, catalogue, username, fullName, hashtags); SocialCommunications.writeProductPost(bean, username, fullName, hashtags, true);
}catch(Exception e){
logger.error("Something failed while alerting editors/reviewers", e);
}
}).start(); }).start();
@ -401,49 +396,49 @@ public class Utils {
return user; return user;
} }
/** // /**
* Given a semantic identifier, check if a record exists and return it // * Given a semantic identifier, check if a record exists and return it
* @param suggestedRecordSemanticIdentifier // * @param suggestedRecordSemanticIdentifier
* @param catalogue // * @param catalogue
* @return CkanDataset // * @return CkanDataset
* @throws Exception in case no record matches the semantic identifier // * @throws Exception in case no record matches the semantic identifier
*/ // */
public static CkanDataset getRecordBySemanticIdentifier( // public static CkanDataset getRecordBySemanticIdentifier(
String suggestedRecordSemanticIdentifier, DataCatalogue catalogue, // String suggestedRecordSemanticIdentifier, DataCatalogue catalogue,
String apiKey) throws Exception { // String apiKey) throws Exception {
//
if(suggestedRecordSemanticIdentifier == null || suggestedRecordSemanticIdentifier.isEmpty()) // if(suggestedRecordSemanticIdentifier == null || suggestedRecordSemanticIdentifier.isEmpty())
throw new Exception(Constants.GRSF_SEMANTIC_IDENTIFIER_CUSTOM_KEY + " cannot be null or emtpy"); // throw new Exception(Constants.GRSF_SEMANTIC_IDENTIFIER_CUSTOM_KEY + " cannot be null or emtpy");
//
String query = Constants.GRSF_SEMANTIC_IDENTIFIER_CUSTOM_KEY + "\"" + suggestedRecordSemanticIdentifier+ "\""; // String query = Constants.GRSF_SEMANTIC_IDENTIFIER_CUSTOM_KEY + "\"" + suggestedRecordSemanticIdentifier+ "\"";
List<CkanDataset> datasets = catalogue.searchForPackageInOrganization(apiKey, query, 0, 10, Constants.GRSF_ADMIN_ORGANIZATION_NAME); // List<CkanDataset> datasets = catalogue.searchForPackageInOrganization(apiKey, query, 0, 10, Constants.GRSF_ADMIN_ORGANIZATION_NAME);
//
if(datasets == null || datasets.isEmpty()){ // if(datasets == null || datasets.isEmpty()){
String message = "Unable to find dataset with such " + Constants.GRSF_SEMANTIC_IDENTIFIER_CUSTOM_KEY; // String message = "Unable to find dataset with such " + Constants.GRSF_SEMANTIC_IDENTIFIER_CUSTOM_KEY;
logger.warn(message); // logger.warn(message);
throw new Exception(message); // throw new Exception(message);
} // }
//
logger.info("Result size is " + datasets.size()); // logger.info("Result size is " + datasets.size());
//
if(datasets.size() == 1) // if(datasets.size() == 1)
return datasets.get(0); // return datasets.get(0);
else{ // else{
//
// worst situation.. we need to check for the right one // // worst situation.. we need to check for the right one
for(CkanDataset dataset: datasets) // for(CkanDataset dataset: datasets)
for(CkanPair extra : dataset.getExtras()) // for(CkanPair extra : dataset.getExtras())
if(extra.getKey().contains(Constants.GRSF_SEMANTIC_IDENTIFIER_CUSTOM_KEY) && extra.getValue().equals(suggestedRecordSemanticIdentifier)){ // if(extra.getKey().contains(Constants.GRSF_SEMANTIC_IDENTIFIER_CUSTOM_KEY) && extra.getValue().equals(suggestedRecordSemanticIdentifier)){
logger.info("Matching dataset has id " + dataset.getId() + " with value " + Constants.GRSF_SEMANTIC_IDENTIFIER_CUSTOM_KEY); // logger.info("Matching dataset has id " + dataset.getId() + " with value " + Constants.GRSF_SEMANTIC_IDENTIFIER_CUSTOM_KEY);
return dataset; // return dataset;
} // }
//
} // }
//
// in the end .... // // in the end ....
throw new Exception("Unable to find record with " + Constants.GRSF_SEMANTIC_IDENTIFIER_CUSTOM_KEY + " equals to " + suggestedRecordSemanticIdentifier); // throw new Exception("Unable to find record with " + Constants.GRSF_SEMANTIC_IDENTIFIER_CUSTOM_KEY + " equals to " + suggestedRecordSemanticIdentifier);
//
} // }
/** /**
* Exploits the fact that in GRSF the url of a record contains the name (which is unique) of the record itself * Exploits the fact that in GRSF the url of a record contains the name (which is unique) of the record itself
@ -567,6 +562,7 @@ public class Utils {
/** /**
* Get Connected bean from record * Get Connected bean from record
* @param httpSession
* @param json * @param json
* @param sourceIdentifier * @param sourceIdentifier
* @param sourceDomain * @param sourceDomain
@ -575,26 +571,31 @@ public class Utils {
* @throws ParseException * @throws ParseException
*/ */
public static ConnectedBean connectedBeanRecordFromUrl( public static ConnectedBean connectedBeanRecordFromUrl(
String sourceIdentifier,
String sourceDomain,
String sourceUrl,
String destUrl, String destUrl,
DataCatalogue clg, DataCatalogue clg,
String apiKey) throws ParseException { String apiKey,
HttpSession httpSession
) throws ParseException {
if(destUrl == null) if(destUrl == null)
return null; return null;
String connectedBeanUuid = Utils.getDatasetKnowledgeBaseIdFromUrl(destUrl); String connectedBeanUuid = getDatasetKnowledgeBaseIdFromUrl(destUrl);
CkanDataset destDataset = clg.getDataset(connectedBeanUuid, apiKey); CkanDataset destDataset = clg.getDataset(connectedBeanUuid, apiKey);
boolean isStock = destDataset.getExtrasAsHashMap().get(Constants.DOMAIN_CUSTOM_KEY).contains(Product_Type.STOCK.getOrigName());
Map<String, String> fieldsNamespacesMap =
Utils.getFieldToFieldNameSpaceMapping(httpSession, isStock ?
Constants.GENERIC_RESOURCE_NAME_MAP_KEY_NAMESPACES_STOCK : Constants.GENERIC_RESOURCE_NAME_MAP_KEY_NAMESPACES_FISHERY);
Map<String, List<String>> extrasWithoutNamespaces = Utils.replaceFieldsKey(destDataset.getExtras(), fieldsNamespacesMap);
String semanticId = extrasWithoutNamespaces.get(Constants.GRSF_SEMANTIC_IDENTIFIER_CUSTOM_KEY).get(0);
String destDomain = extrasWithoutNamespaces.get(Constants.DOMAIN_CUSTOM_KEY).get(0);
return new ConnectedBean( return new ConnectedBean(
sourceIdentifier,
sourceDomain,
sourceUrl,
connectedBeanUuid, connectedBeanUuid,
destDataset.getTitle(), destDataset.getTitle(),
destUrl, destUrl,
destDataset.getExtrasAsHashMap().get(Constants.DOMAIN_CUSTOM_KEY) destDomain,
semanticId
); );
} }

View File

@ -10,12 +10,10 @@ import java.io.Serializable;
public class ConnectedBean implements Serializable{ public class ConnectedBean implements Serializable{
private static final long serialVersionUID = -4863776727351488790L; private static final long serialVersionUID = -4863776727351488790L;
private String sourceKnowledgeBaseId;
private String sourceDomain; // i.e. Stock or Fishery
private String sourceUrl;
private String destKnowledgeBaseId; // the dest identifier of a Fishery or Stock (the link is from a Stock to a Fishery and vice versa) private String destKnowledgeBaseId; // the dest identifier of a Fishery or Stock (the link is from a Stock to a Fishery and vice versa)
private String destName; private String destName;
private String destUrl; private String destUrl;
private String destSemanticIdentifier;
private String destDomain; // please note that this MUST be different from sourceDomain private String destDomain; // please note that this MUST be different from sourceDomain
private boolean remove; private boolean remove;
private boolean connect; private boolean connect;
@ -34,17 +32,18 @@ public class ConnectedBean implements Serializable{
* @param remove * @param remove
* @param connect * @param connect
*/ */
public ConnectedBean(String sourceKnowledgeBaseId, String sourceDomain, public ConnectedBean(
String sourceUrl, String destKnowledgeBaseId, String destName, String destKnowledgeBaseId,
String destUrl, String destDomain) { String destName,
String destUrl,
String destDomain,
String destSemanticIdentifier) {
super(); super();
this.sourceKnowledgeBaseId = sourceKnowledgeBaseId;
this.sourceDomain = sourceDomain;
this.sourceUrl = sourceUrl;
this.destKnowledgeBaseId = destKnowledgeBaseId; this.destKnowledgeBaseId = destKnowledgeBaseId;
this.destName = destName; this.destName = destName;
this.destUrl = destUrl; this.destUrl = destUrl;
this.destDomain = destDomain; this.destDomain = destDomain;
this.destSemanticIdentifier = destSemanticIdentifier;
} }
public boolean isConnect() { public boolean isConnect() {
@ -55,14 +54,6 @@ public class ConnectedBean implements Serializable{
this.connect = connect; this.connect = connect;
} }
public String getSourceKnowledgeBaseId() {
return sourceKnowledgeBaseId;
}
public void setSourceKnowledgeBaseId(String sourceKnowledgeBaseId) {
this.sourceKnowledgeBaseId = sourceKnowledgeBaseId;
}
public String getDestKnowledgeBaseId() { public String getDestKnowledgeBaseId() {
return destKnowledgeBaseId; return destKnowledgeBaseId;
} }
@ -71,13 +62,6 @@ public class ConnectedBean implements Serializable{
this.destKnowledgeBaseId = destKnowledgeBaseId; this.destKnowledgeBaseId = destKnowledgeBaseId;
} }
public String getSourceDomain() {
return sourceDomain;
}
public void setSourceDomain(String sourceDomain) {
this.sourceDomain = sourceDomain;
}
public boolean isRemove() { public boolean isRemove() {
return remove; return remove;
} }
@ -86,14 +70,6 @@ public class ConnectedBean implements Serializable{
this.remove = remove; this.remove = remove;
} }
public String getSourceUrl() {
return sourceUrl;
}
public void setSourceUrl(String sourceUrl) {
this.sourceUrl = sourceUrl;
}
public String getDestName() { public String getDestName() {
return destName; return destName;
} }
@ -118,12 +94,19 @@ public class ConnectedBean implements Serializable{
this.destDomain = destDomain; this.destDomain = destDomain;
} }
public String getDestSemanticIdentifier() {
return destSemanticIdentifier;
}
public void setDestSemanticIdentifier(String destSemanticIdentifier) {
this.destSemanticIdentifier = destSemanticIdentifier;
}
@Override @Override
public String toString() { public String toString() {
return "ConnectedBean [sourceKnowledgeBaseId=" + sourceKnowledgeBaseId return "ConnectedBean [destKnowledgeBaseId=" + destKnowledgeBaseId
+ ", sourceDomain=" + sourceDomain + ", sourceUrl=" + sourceUrl
+ ", destKnowledgeBaseId=" + destKnowledgeBaseId
+ ", destName=" + destName + ", destUrl=" + destUrl + ", destName=" + destName + ", destUrl=" + destUrl
+ ", destSemanticIdentifier=" + destSemanticIdentifier
+ ", destDomain=" + destDomain + ", remove=" + remove + ", destDomain=" + destDomain + ", remove=" + remove
+ ", connect=" + connect + "]"; + ", connect=" + connect + "]";
} }