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="/WEB-INF/classes" source-path="/src/main/java"/>
<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="java-output-path" value="/grsf-manage-widget/target/grsf-manage-widget-1.0.0-SNAPSHOT/WEB-INF/classes"/>
</wb-module>

View File

@ -1,5 +1,7 @@
package org.gcube.datacatalogue.grsf_manage_widget.client;
import java.util.List;
import org.gcube.datacatalogue.grsf_manage_widget.shared.ManageProductBean;
import com.google.gwt.user.client.rpc.RemoteService;
@ -25,7 +27,7 @@ public interface GRSFManageWidgetService extends RemoteService {
/**
* 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

View File

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

View File

@ -93,7 +93,7 @@ public class ManageProductWidget extends Composite{
@UiField
VerticalPanel panelForSimilarGRSFRecords;
@UiField
VerticalPanel panelForFurtherMerges;
@ -244,7 +244,7 @@ public class ManageProductWidget extends Composite{
List<SimilarGRSFRecord> availableGRSFSimilarRecords = bean.getSimilarGrsfRecords();
similarRecordPanel = new SimilarGRSFRecordWidget(availableGRSFSimilarRecords/*, service*/);
panelForSimilarGRSFRecords.add(similarRecordPanel);
// further suggested merges
suggestedMergesPanel = new SuggestMerges(service);
panelForFurtherMerges.add(suggestedMergesPanel);
@ -344,14 +344,6 @@ public class ManageProductWidget extends Composite{
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);
cancelButton.setEnabled(false);
confirmButton.setEnabled(false);
@ -360,8 +352,10 @@ public class ManageProductWidget extends Composite{
// get short name
bean.setShortNameUpdated(shortNameTextBox.getText());
// evaluate the connections and the actions on them
bean.setConnections(connectWidget.getConnectList());
// update similar records and to connect
bean.setConnectTo(connectWidget.getConnectList());
bean.setSimilarGrsfRecords(similarRecordPanel.getSimilarRecords());
bean.getSimilarGrsfRecords().addAll(suggestedMergesPanel.getSimilarRecords());
@ -372,7 +366,7 @@ public class ManageProductWidget extends Composite{
// traceability flag
bean.setTraceabilityFlag(traceabilityFlag.getValue());
service.notifyProductUpdate(bean, new AsyncCallback<String>() {
service.notifyProductUpdate(bean, null, new AsyncCallback<String>() { // TODO add hashtags here
@Override
public void onSuccess(String result) {

View File

@ -102,7 +102,7 @@
</g:VerticalPanel>
</b:Controls>
</b:ControlGroup>
<b:ControlGroup ui:field="suggestFurtherMerges">
<b:ControlLabel title="Suggest merges with other records">
<b>Suggest Merges (Notification will be sent):</b>

View File

@ -36,13 +36,17 @@ import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
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{
private static ConnectToWidgetUiBinder uiBinder = GWT
.create(ConnectToWidgetUiBinder.class);
private static final String REGEX_UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
interface ConnectToWidgetUiBinder extends UiBinder<Widget, ConnectToWidget> {
}
@ -52,31 +56,41 @@ public class ConnectToWidget extends Composite{
@UiField
Button suggestRecord;
//private GRSFManageWidgetServiceAsync service;
private List<Tuple> connectList = new ArrayList<Tuple>(0);
private List<ConnectedBean> connectedRecords = null;
private List<ConnectedBean> currentlyConnected = null;
private List<ConnectedBean> suggestedByKnowledgeBase;
private GRSFManageWidgetServiceAsync service;
public ConnectToWidget(final ManageProductBean bean, GRSFManageWidgetServiceAsync service) {
initWidget(uiBinder.createAndBindUi(this));
this.service = service;
// get already connected beans, if any
connectedRecords = bean.getConnectTo();
// add the one suggested by the knowledge base
suggestedByKnowledgeBase = bean.getSuggestedByKnowledgeBase();
if(connectedRecords != null){
if(suggestedByKnowledgeBase != null){
connectPanel.add(new HTML("<hr style=\"width:100%;\"/>"));
for (ConnectedBean connected : connectedRecords) {
Widget widget = buildWidgetForConnectedRecords(connected);
for (ConnectedBean connected : suggestedByKnowledgeBase) {
Widget widget = buildWidgetForConnected(connected, true);
connectPanel.add(widget);
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
suggestRecord.setTitle("Connect this " + bean.getGrsfDomain() + " record to a " + acceptedDomain + " record ");
suggestRecord.setIcon(IconType.PLUS_SIGN);
@ -89,8 +103,6 @@ public class ConnectToWidget extends Composite{
public void onClick(ClickEvent arg0) {
ConnectedBean cb = new ConnectedBean();
// cb.setExtra(true);
cb.setSourceDomain(bean.getGrsfDomain());
Tuple t = buildWidgetConnect(cb);
connectList.add(t);
connectPanel.add(t.getW());
@ -105,24 +117,25 @@ public class ConnectToWidget extends Composite{
* @param similarGRSFRecord
* @return
*/
public static Widget buildWidgetForConnectedRecords(final ConnectedBean connected){
public static Widget buildWidgetForConnected(final ConnectedBean connected, boolean suggestedByKb){
HorizontalPanel hp = new HorizontalPanel();
hp.setWidth("95%");
VerticalPanel leftPanel = new VerticalPanel();
leftPanel.setWidth("80%");
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);
Paragraph semanticIdentifier = new Paragraph("Semantic Identifier: " +
connected.getDestSemanticIdentifier());
leftPanel.add(semanticIdentifier);
Paragraph identifier = new Paragraph("Record UUID: " +
connected.getDestKnowledgeBaseId());
leftPanel.add(identifier);
Anchor view = new Anchor();
view.setHref(connected.getUrl());
view.setHref(connected.getDestUrl());
view.setText("View");
view.setTitle("Click to view the similar record");
view.setTarget("_blank");
@ -131,19 +144,33 @@ public class ConnectToWidget extends Composite{
VerticalPanel rightPanel = new VerticalPanel();
rightPanel.setWidth("20%");
rightPanel.getElement().getStyle().setFloat(Float.RIGHT);
if(!suggestedByKb){
final CheckBox removeExtra = new CheckBox("Remove");
removeExtra.setTitle("Remove this connections");
removeExtra.addClickHandler(new ClickHandler() {
final CheckBox removeExtra = new CheckBox("Remove");
removeExtra.setTitle("Remove this record among the connected ones");
removeExtra.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent arg0) {
connected.setRemove(removeExtra.getValue());
}
});
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.setToBeKept(!removeExtra.getValue());
connected.setRemove(connect.getValue());
}
});
rightPanel.getElement().getStyle().setFloat(Float.RIGHT);
rightPanel.add(removeExtra);
rightPanel.add(connect);
hp.add(leftPanel);
hp.add(rightPanel);
hp.getElement().getStyle().setPadding(10, Unit.PX);
@ -232,7 +259,7 @@ public class ConnectToWidget extends Composite{
main.add(separator);
return new Tuple(cb, main, box);
}
protected void validateUUID(final TextBox box, final ConnectedBean c, final Icon icon, final Anchor view) {
final String currentText = box.getText().trim();
@ -297,22 +324,25 @@ public class ConnectToWidget extends Composite{
* @return
*/
public List<ConnectedBean> getConnectList() {
if(connectedRecords == null)
connectedRecords = new ArrayList<ConnectedBean>(0);
for (Tuple p : connectList) {
String suggestedIdentifier = ((ConnectedBean)p.getO()).getDestKnowledgeBaseId();
if(suggestedIdentifier == null || suggestedIdentifier.isEmpty())
continue;
else{
ConnectedBean connectedRecord = (ConnectedBean) p.getO();
connectedRecord.setToBeKept(true);
connectedRecords.add((ConnectedBean) p.getO());
}
}
return connectedRecords;
TODO
// List<ConnectedBean> toReturn = new ArrayList<>();
//
// if(currentlyConnected != null)
// currentlyConnected = new ArrayList<ConnectedBean>(0);
//
// for (Tuple p : connectList) {
// String suggestedIdentifier = ((ConnectedBean)p.getO()).getDestKnowledgeBaseId();
// if(suggestedIdentifier == null || suggestedIdentifier.isEmpty())
// continue;
// else{
// ConnectedBean connectedRecord = (ConnectedBean) p.getO();
// connectedRecord.setToBeKept(true);
// currentlyConnected.add((ConnectedBean) p.getO());
// }
// }
//
// return currentlyConnected;
}
}

View File

@ -86,14 +86,13 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
toReturn = new ManageProductBean();
toReturn.setCatalogueIdentifier(UUID.randomUUID().toString());
List<ConnectedBean> connectTo = new ArrayList<>();
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",
"Random title",
"http://data.d4science.org/ctlg/GRSF_Admin/89f1e413-dc9f-3b4e-b1c5-0e8560177254",
"Fishery"
"Fishery",
"ajklsdkad:akljdnajdna"
));
toReturn.setCurrentConnections(connectTo);
toReturn.setGrsfDomain("Stock");
@ -206,7 +205,7 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
for (String connectedBean : connectedBeanUrls) {
if(connectedBean.equals(Constants.NO_CONNECTED_RECORDS)) // stop here if there is a single element with this information
break;
ConnectedBean builtBean = Utils.connectedBeanRecordFromUrl(recordUrl, connectedBean, uuidKB, grsfDomain, catalogue, apiKey);
ConnectedBean builtBean = Utils.connectedBeanRecordFromUrl(connectedBean, catalogue, apiKey, httpSession);
if(builtBean != null)
connectedBeans.add(builtBean);
}
@ -223,7 +222,7 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
if(exploitedResourcesUrls != null && !exploitedResourcesUrls.isEmpty()){
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)
suggestedConnectionsByKnowledgeBase.add(builtBean);
}
@ -282,7 +281,7 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
}
@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");
try{
@ -306,7 +305,7 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
threadRequest.getSession().removeAttribute(sessionProductKey);
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){
logger.error("Unable to update the product", e);

View File

@ -122,9 +122,9 @@ public class GRSFUpdaterServiceClient {
for(ConnectedBean c: connections){
JSONObject cc = new JSONObject();
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.SOURCE_DOMAIN, c.getSourceDomain());
cc.put(Constants.SOURCE_DOMAIN, bean.getGrsfDomain());
cc.put(Constants.CONNECTION_TO_REMOVE, c.isRemove());
}
connectionsJson.add(cc);

View File

@ -1,16 +1,12 @@
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.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.io.StringReader;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -23,10 +19,7 @@ import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.encryption.StringEncrypter;
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.scope.api.ScopeProvider;
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.shared.ex.ApplicationProfileNotFoundException;
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.grsf_manage_widget.server.manage.RevertOperationUrl.Operation;
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.SimilarGRSFRecord;
import org.gcube.portlets.user.urlshortener.UrlShortener;
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.SimpleQuery;
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.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
@ -62,12 +47,8 @@ import org.xml.sax.InputSource;
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.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.CkanPair;
@ -177,7 +158,7 @@ public class Utils {
}
}
logger.debug("Map is " + namespacesMap);
// put them into session for speeding up the operations
httpSession.setAttribute(sessionKey, namespacesMap);
return namespacesMap;
@ -252,8 +233,17 @@ public class Utils {
* @param catalogue
* @return true on success, false otherwise
*/
public static String updateRecord(String serviceUrl, ManageProductBean bean, DataCatalogue catalogue, String username,
String fullName, HttpServletRequest httpServletRequest, long groupId, String context, String token) throws Exception{
public static String updateRecord(
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)
throw new IllegalArgumentException("GRSF Updater service url cannot be null");
@ -272,16 +262,21 @@ public class Utils {
// manage interactions through a separated thread but set there security token and context
new Thread(()->{
ScopeProvider.instance.set(context);
SecurityTokenProvider.instance.set(token);
// send email to Editors and Reviewers
SocialCommunications.sendEmailAdministrators(bean, catalogue, username, fullName, groupId, httpServletRequest, bean.isMergesInvolved());
try{
// send email to Editors and Reviewers
SocialCommunications.sendEmailAdministrators(bean, catalogue, username, fullName, groupId, httpServletRequest, bean.isMergesInvolved());
// create a post about the operation
SocialCommunications.writeProductPost(bean, username, fullName, hashtags, true);
}catch(Exception e){
logger.error("Something failed while alerting editors/reviewers", e);
}
// create a post about the operation
SocialCommunications.createSocialPost(bean, catalogue, username, fullName, hashtags);
}).start();
}catch(Exception e){
@ -401,49 +396,49 @@ public class Utils {
return user;
}
/**
* Given a semantic identifier, check if a record exists and return it
* @param suggestedRecordSemanticIdentifier
* @param catalogue
* @return CkanDataset
* @throws Exception in case no record matches the semantic identifier
*/
public static CkanDataset getRecordBySemanticIdentifier(
String suggestedRecordSemanticIdentifier, DataCatalogue catalogue,
String apiKey) throws Exception {
if(suggestedRecordSemanticIdentifier == null || suggestedRecordSemanticIdentifier.isEmpty())
throw new Exception(Constants.GRSF_SEMANTIC_IDENTIFIER_CUSTOM_KEY + " cannot be null or emtpy");
String query = Constants.GRSF_SEMANTIC_IDENTIFIER_CUSTOM_KEY + "\"" + suggestedRecordSemanticIdentifier+ "\"";
List<CkanDataset> datasets = catalogue.searchForPackageInOrganization(apiKey, query, 0, 10, Constants.GRSF_ADMIN_ORGANIZATION_NAME);
if(datasets == null || datasets.isEmpty()){
String message = "Unable to find dataset with such " + Constants.GRSF_SEMANTIC_IDENTIFIER_CUSTOM_KEY;
logger.warn(message);
throw new Exception(message);
}
logger.info("Result size is " + datasets.size());
if(datasets.size() == 1)
return datasets.get(0);
else{
// worst situation.. we need to check for the right one
for(CkanDataset dataset: datasets)
for(CkanPair extra : dataset.getExtras())
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);
return dataset;
}
}
// in the end ....
throw new Exception("Unable to find record with " + Constants.GRSF_SEMANTIC_IDENTIFIER_CUSTOM_KEY + " equals to " + suggestedRecordSemanticIdentifier);
}
// /**
// * Given a semantic identifier, check if a record exists and return it
// * @param suggestedRecordSemanticIdentifier
// * @param catalogue
// * @return CkanDataset
// * @throws Exception in case no record matches the semantic identifier
// */
// public static CkanDataset getRecordBySemanticIdentifier(
// String suggestedRecordSemanticIdentifier, DataCatalogue catalogue,
// String apiKey) throws Exception {
//
// if(suggestedRecordSemanticIdentifier == null || suggestedRecordSemanticIdentifier.isEmpty())
// throw new Exception(Constants.GRSF_SEMANTIC_IDENTIFIER_CUSTOM_KEY + " cannot be null or emtpy");
//
// String query = Constants.GRSF_SEMANTIC_IDENTIFIER_CUSTOM_KEY + "\"" + suggestedRecordSemanticIdentifier+ "\"";
// List<CkanDataset> datasets = catalogue.searchForPackageInOrganization(apiKey, query, 0, 10, Constants.GRSF_ADMIN_ORGANIZATION_NAME);
//
// if(datasets == null || datasets.isEmpty()){
// String message = "Unable to find dataset with such " + Constants.GRSF_SEMANTIC_IDENTIFIER_CUSTOM_KEY;
// logger.warn(message);
// throw new Exception(message);
// }
//
// logger.info("Result size is " + datasets.size());
//
// if(datasets.size() == 1)
// return datasets.get(0);
// else{
//
// // worst situation.. we need to check for the right one
// for(CkanDataset dataset: datasets)
// for(CkanPair extra : dataset.getExtras())
// 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);
// return dataset;
// }
//
// }
//
// // in the end ....
// 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
@ -567,6 +562,7 @@ public class Utils {
/**
* Get Connected bean from record
* @param httpSession
* @param json
* @param sourceIdentifier
* @param sourceDomain
@ -575,26 +571,31 @@ public class Utils {
* @throws ParseException
*/
public static ConnectedBean connectedBeanRecordFromUrl(
String sourceIdentifier,
String sourceDomain,
String sourceUrl,
String destUrl,
DataCatalogue clg,
String apiKey) throws ParseException {
String apiKey,
HttpSession httpSession
) throws ParseException {
if(destUrl == null)
return null;
String connectedBeanUuid = Utils.getDatasetKnowledgeBaseIdFromUrl(destUrl);
String connectedBeanUuid = getDatasetKnowledgeBaseIdFromUrl(destUrl);
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(
sourceIdentifier,
sourceDomain,
sourceUrl,
connectedBeanUuid,
destDataset.getTitle(),
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{
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 destName;
private String destUrl;
private String destSemanticIdentifier;
private String destDomain; // please note that this MUST be different from sourceDomain
private boolean remove;
private boolean connect;
@ -34,17 +32,18 @@ public class ConnectedBean implements Serializable{
* @param remove
* @param connect
*/
public ConnectedBean(String sourceKnowledgeBaseId, String sourceDomain,
String sourceUrl, String destKnowledgeBaseId, String destName,
String destUrl, String destDomain) {
public ConnectedBean(
String destKnowledgeBaseId,
String destName,
String destUrl,
String destDomain,
String destSemanticIdentifier) {
super();
this.sourceKnowledgeBaseId = sourceKnowledgeBaseId;
this.sourceDomain = sourceDomain;
this.sourceUrl = sourceUrl;
this.destKnowledgeBaseId = destKnowledgeBaseId;
this.destName = destName;
this.destUrl = destUrl;
this.destDomain = destDomain;
this.destSemanticIdentifier = destSemanticIdentifier;
}
public boolean isConnect() {
@ -55,14 +54,6 @@ public class ConnectedBean implements Serializable{
this.connect = connect;
}
public String getSourceKnowledgeBaseId() {
return sourceKnowledgeBaseId;
}
public void setSourceKnowledgeBaseId(String sourceKnowledgeBaseId) {
this.sourceKnowledgeBaseId = sourceKnowledgeBaseId;
}
public String getDestKnowledgeBaseId() {
return destKnowledgeBaseId;
}
@ -71,13 +62,6 @@ public class ConnectedBean implements Serializable{
this.destKnowledgeBaseId = destKnowledgeBaseId;
}
public String getSourceDomain() {
return sourceDomain;
}
public void setSourceDomain(String sourceDomain) {
this.sourceDomain = sourceDomain;
}
public boolean isRemove() {
return remove;
}
@ -86,14 +70,6 @@ public class ConnectedBean implements Serializable{
this.remove = remove;
}
public String getSourceUrl() {
return sourceUrl;
}
public void setSourceUrl(String sourceUrl) {
this.sourceUrl = sourceUrl;
}
public String getDestName() {
return destName;
}
@ -118,12 +94,19 @@ public class ConnectedBean implements Serializable{
this.destDomain = destDomain;
}
public String getDestSemanticIdentifier() {
return destSemanticIdentifier;
}
public void setDestSemanticIdentifier(String destSemanticIdentifier) {
this.destSemanticIdentifier = destSemanticIdentifier;
}
@Override
public String toString() {
return "ConnectedBean [sourceKnowledgeBaseId=" + sourceKnowledgeBaseId
+ ", sourceDomain=" + sourceDomain + ", sourceUrl=" + sourceUrl
+ ", destKnowledgeBaseId=" + destKnowledgeBaseId
return "ConnectedBean [destKnowledgeBaseId=" + destKnowledgeBaseId
+ ", destName=" + destName + ", destUrl=" + destUrl
+ ", destSemanticIdentifier=" + destSemanticIdentifier
+ ", destDomain=" + destDomain + ", remove=" + remove
+ ", connect=" + connect + "]";
}