2017-01-26 18:21:33 +01:00
|
|
|
package org.gcube.datacatalogue.grsf_manage_widget.server.manage;
|
|
|
|
|
2017-11-09 14:49:07 +01:00
|
|
|
import java.util.ArrayList;
|
2017-01-26 18:21:33 +01:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2017-12-12 18:54:45 +01:00
|
|
|
import java.util.UUID;
|
2017-01-26 18:21:33 +01:00
|
|
|
|
|
|
|
import org.gcube.common.portal.PortalContext;
|
|
|
|
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue;
|
|
|
|
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueFactory;
|
|
|
|
import org.gcube.datacatalogue.ckanutillibrary.server.utils.UtilMethods;
|
2017-10-27 17:30:56 +02:00
|
|
|
import org.gcube.datacatalogue.common.Constants;
|
2017-11-15 19:22:20 +01:00
|
|
|
import org.gcube.datacatalogue.common.enums.Product_Type;
|
2017-11-09 14:49:07 +01:00
|
|
|
import org.gcube.datacatalogue.common.enums.Sources;
|
2017-10-27 17:30:56 +02:00
|
|
|
import org.gcube.datacatalogue.common.enums.Status;
|
2017-11-09 14:49:07 +01:00
|
|
|
import org.gcube.datacatalogue.grsf_manage_widget.client.GRSFManageWidgetService;
|
2017-12-12 18:54:45 +01:00
|
|
|
import org.gcube.datacatalogue.grsf_manage_widget.shared.ConnectedBean;
|
2017-01-26 18:21:33 +01:00
|
|
|
import org.gcube.datacatalogue.grsf_manage_widget.shared.ManageProductBean;
|
2017-11-09 14:49:07 +01:00
|
|
|
import org.gcube.datacatalogue.grsf_manage_widget.shared.SimilarGRSFRecord;
|
|
|
|
import org.gcube.datacatalogue.grsf_manage_widget.shared.SourceRecord;
|
2017-01-26 18:21:33 +01:00
|
|
|
import org.gcube.datacatalogue.grsf_manage_widget.shared.ex.NoGRSFRecordException;
|
2017-11-09 14:49:07 +01:00
|
|
|
import org.gcube.vomanagement.usermanagement.RoleManager;
|
2017-02-16 18:32:19 +01:00
|
|
|
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
|
2017-11-09 14:49:07 +01:00
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
|
2017-03-03 18:26:35 +01:00
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeTeam;
|
2017-11-09 14:49:07 +01:00
|
|
|
import org.gcube.vomanagement.usermanagement.model.GatewayRolesNames;
|
2017-11-14 18:37:07 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2017-01-26 18:21:33 +01:00
|
|
|
|
|
|
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
|
|
|
|
|
|
|
import eu.trentorise.opendata.jackan.model.CkanDataset;
|
|
|
|
import eu.trentorise.opendata.jackan.model.CkanPair;
|
2017-11-09 14:49:07 +01:00
|
|
|
import eu.trentorise.opendata.jackan.model.CkanResource;
|
2017-01-26 18:21:33 +01:00
|
|
|
|
|
|
|
/**
|
2017-11-09 14:49:07 +01:00
|
|
|
* Endpoint for sending update records information to GRSF KnowledgeBase.
|
2017-01-26 18:21:33 +01:00
|
|
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
|
|
|
*/
|
|
|
|
public class GRSFNotificationService extends RemoteServiceServlet implements GRSFManageWidgetService{
|
|
|
|
|
|
|
|
private static final long serialVersionUID = -4534905087994875893L;
|
2017-11-14 18:37:07 +01:00
|
|
|
//private static final Log logger = LogFactoryUtil.getLog(GRSFNotificationService.class);
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(GRSFNotificationService.class);
|
2017-11-15 19:22:20 +01:00
|
|
|
|
2017-01-26 18:21:33 +01:00
|
|
|
/**
|
|
|
|
* Instanciate the ckan util library.
|
|
|
|
* Since it needs the scope, we need to check if it is null or not
|
|
|
|
* @param discoverScope if you want to the discover the utils library in this specified scope
|
2017-11-09 14:49:07 +01:00
|
|
|
* @return DataCatalogue object
|
|
|
|
* @throws Exception
|
2017-01-26 18:21:33 +01:00
|
|
|
*/
|
2017-11-09 14:49:07 +01:00
|
|
|
public DataCatalogue getCatalogue(String discoverScope) throws Exception{
|
2017-11-14 18:37:07 +01:00
|
|
|
String currentScope = Utils.getCurrentContext(getThreadLocalRequest(), true);
|
2017-01-26 18:21:33 +01:00
|
|
|
DataCatalogue instance = null;
|
|
|
|
try{
|
|
|
|
String scopeInWhichDiscover = discoverScope != null && !discoverScope.isEmpty() ? discoverScope : currentScope;
|
|
|
|
logger.debug("Discovering ckan utils library into scope " + scopeInWhichDiscover);
|
|
|
|
instance = DataCatalogueFactory.getFactory().getUtilsPerScope(scopeInWhichDiscover);
|
|
|
|
}catch(Exception e){
|
|
|
|
logger.error("Unable to retrieve ckan utils. Error was " + e.toString());
|
2017-11-09 14:49:07 +01:00
|
|
|
throw e;
|
2017-01-26 18:21:33 +01:00
|
|
|
}
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-12-12 18:54:45 +01:00
|
|
|
public ManageProductBean getProductBeanById(String productIdentifier) throws Exception {
|
2017-01-26 18:21:33 +01:00
|
|
|
|
|
|
|
|
2017-12-12 18:54:45 +01:00
|
|
|
ManageProductBean toReturn = null;
|
2017-01-26 18:21:33 +01:00
|
|
|
|
2017-12-12 18:54:45 +01:00
|
|
|
if(!Utils.isIntoPortal()){
|
|
|
|
|
|
|
|
toReturn = new ManageProductBean();
|
|
|
|
toReturn.setCatalogueIdentifier(UUID.randomUUID().toString());
|
|
|
|
List<ConnectedBean> connectTo = new ArrayList<>();
|
|
|
|
connectTo.add(new ConnectedBean("asfis:WRO+fao:67;FAO", "Stock", "aksldsam asd", "asdasjnk:fas", UUID.randomUUID().toString()));
|
|
|
|
toReturn.setConnectTo(connectTo);
|
|
|
|
toReturn.setGrsfDomain("Stock");
|
|
|
|
toReturn.setGrsfType("Assessment Unit");
|
|
|
|
toReturn.setKnowledgeBaseIdentifier("91f1e413-dc9f-3b4e-b1c5-0e8560177253");
|
|
|
|
toReturn.setShortName("Widow rockfish - US West Coast");
|
|
|
|
toReturn.setShortNameUpdated("Widow rockfish - US West Coast");
|
|
|
|
toReturn.setGrsfName("sebastes entomelas FAO 77 FAO 67");
|
|
|
|
toReturn.setTraceabilityFlag(true);
|
|
|
|
toReturn.setCurrentStatus(Status.Pending);
|
|
|
|
toReturn.setSemanticIdentifier("asfis:WRO+fao:67;FAO");
|
|
|
|
ArrayList<SourceRecord> sources = new ArrayList<SourceRecord>();
|
|
|
|
sources.add(new SourceRecord("RAM", "http://www.google.it"));
|
|
|
|
toReturn.setSources(sources);
|
|
|
|
List<SimilarGRSFRecord> similarGrsfRecords = new ArrayList<SimilarGRSFRecord>();
|
|
|
|
similarGrsfRecords.add(new SimilarGRSFRecord("same species overlapping water areas",
|
|
|
|
Utils.getDatasetKnowledgeBaseIdFromUrl("http://data.d4science.org/ctlg/GRSF_Admin/1a03d6d8-002d-39b9-9255-a954c8ee2bf0")
|
|
|
|
,"unknown:ONCORHYNCHUS GORBUSCHA+unknown:USA-AKSTATE-KELPB",
|
|
|
|
"Pink Salmon Kelp By (District112)",
|
|
|
|
"http://data.d4science.org/ctlg/GRSF_Admin/1a03d6d8-002d-39b9-9255-a954c8ee2bf0"));
|
|
|
|
similarGrsfRecords.add(new SimilarGRSFRecord("same species overlapping water areas 2",
|
|
|
|
Utils.getDatasetKnowledgeBaseIdFromUrl("http://data.d4science.org/ctlg/GRSF_Admin/1a03d6d8-002d-39b9-9255-a954c8ee2bf0"),
|
|
|
|
"unknown:ONCORHYNCHUS GORBUSCHA+unknown:USA-AKSTATE-KELPB",
|
|
|
|
"Pink Salmon Kelp By (District112) 2",
|
|
|
|
"http://data.d4science.org/ctlg/GRSF_Admin/1a03d6d8-002d-39b9-9255-a954c8ee2bf0"));
|
|
|
|
toReturn.setSimilarGrsfRecords(similarGrsfRecords);
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
// retrieve scope per current portlet url
|
|
|
|
String scopePerCurrentUrl = Utils.getScopeFromClientUrl(getThreadLocalRequest());
|
|
|
|
DataCatalogue catalogue = getCatalogue(scopePerCurrentUrl);
|
|
|
|
String username = Utils.getCurrentUser(getThreadLocalRequest()).getUsername();
|
|
|
|
CkanDataset record = catalogue.getDataset(productIdentifier, catalogue.getApiKeyFromUsername(username));
|
|
|
|
|
|
|
|
// it cannot be enabled in this case ...
|
|
|
|
if(record == null)
|
|
|
|
throw new Exception("Unable to retrieve information for the selected record, sorry");
|
|
|
|
else{
|
2017-01-26 18:21:33 +01:00
|
|
|
|
2017-12-12 18:54:45 +01:00
|
|
|
logger.debug("Trying to fetch record....");
|
|
|
|
|
|
|
|
// check it is a grsf record (Source records have a different System Type)
|
|
|
|
String systemType = record.getExtrasAsHashMap().get(Constants.SYSTEM_TYPE_CUSTOM_KEY);
|
|
|
|
if(systemType == null || systemType.isEmpty() || systemType.equals(Constants.SYSTEM_TYPE_FOR_SOURCES_VALUE))
|
|
|
|
throw new NoGRSFRecordException("This is not a GRSF Record");
|
|
|
|
|
|
|
|
// get extras as hashmap and pairs
|
|
|
|
List<CkanPair> extrasAsPairs = record.getExtras();
|
|
|
|
|
|
|
|
// fetch map for namespaces
|
|
|
|
Map<String, String> fieldsNamespacesMap = Utils.getFieldToFieldNameSpaceMapping(getThreadLocalRequest().getSession(),
|
|
|
|
record.getExtrasAsHashMap().get(Constants.DOMAIN_CUSTOM_KEY).contains(Product_Type.STOCK.getOrigName()) ? Constants.GENERIC_RESOURCE_NAME_MAP_KEY_NAMESPACES_STOCK
|
|
|
|
: Constants.GENERIC_RESOURCE_NAME_MAP_KEY_NAMESPACES_FISHERY);
|
|
|
|
|
|
|
|
Map<String, List<String>> extrasWithoutNamespaces = Utils.replaceFieldsKey(extrasAsPairs, fieldsNamespacesMap);
|
|
|
|
// get extras fields (wrt the mandatory ones) to show in the management panel TODO
|
|
|
|
// Utils.getExtrasToShow();
|
|
|
|
String catalogueIdentifier = record.getId();
|
|
|
|
String status = extrasWithoutNamespaces.get(Constants.STATUS_OF_THE_GRSF_RECORD_CUSTOM_KEY).get(0);
|
|
|
|
String uuidKB = extrasWithoutNamespaces.get(Constants.UUID_KB_CUSTOM_KEY).get(0);
|
|
|
|
String grsfDomain = extrasWithoutNamespaces.get(Constants.DOMAIN_CUSTOM_KEY).get(0);
|
|
|
|
|
|
|
|
logger.debug(Constants.DOMAIN_CUSTOM_KEY + " is " + grsfDomain);
|
|
|
|
|
|
|
|
if(status == null || uuidKB == null)
|
|
|
|
throw new Exception("Some information is missing in this record: Status = " + status + ", knowledge base uuid = " + uuidKB +
|
|
|
|
", and grsf domain is = " + grsfDomain);
|
|
|
|
|
|
|
|
String semanticId = extrasWithoutNamespaces.get(Constants.GRSF_SEMANTIC_IDENTIFIER_CUSTOM_KEY).get(0);
|
|
|
|
String shortName = extrasWithoutNamespaces.get(Constants.SHORT_NAME_CUSTOM_KEY).get(0);
|
|
|
|
String grsfType = extrasWithoutNamespaces.get(Constants.GRSF_TYPE_CUSTOM_KEY).get(0);
|
|
|
|
String grsfName = extrasWithoutNamespaces.get(grsfDomain.contains(Product_Type.STOCK.getOrigName()) ?
|
|
|
|
Constants.STOCK_NAME_CUSTOM_KEY : Constants.FISHERY_NAME_CUSTOM_KEY).get(0);
|
|
|
|
boolean traceabilityFlag = extrasWithoutNamespaces.get(Constants.TRACEABILITY_FLAG_CUSTOM_KEY).get(0).equalsIgnoreCase("true");
|
|
|
|
|
|
|
|
// Get similar GRSF records, if any (each of which should have name, description, url and id(i.e semantic identifier))
|
|
|
|
List<String> similarGrsfRecordsAsStrings = extrasWithoutNamespaces.containsKey(Constants.SIMILAR_GRSF_RECORDS_CUSTOM_KEY) ? extrasWithoutNamespaces.get(Constants.SIMILAR_GRSF_RECORDS_CUSTOM_KEY): null;
|
|
|
|
|
|
|
|
List<SimilarGRSFRecord> similarRecords = new ArrayList<SimilarGRSFRecord>(0);
|
|
|
|
if(similarGrsfRecordsAsStrings != null){
|
|
|
|
for (String similarGRSFRecord : similarGrsfRecordsAsStrings) {
|
|
|
|
similarRecords.add(Utils.similarGRSFRecordFromJson(similarGRSFRecord));
|
|
|
|
}
|
|
|
|
}
|
2017-01-26 18:21:33 +01:00
|
|
|
|
2017-12-12 18:54:45 +01:00
|
|
|
logger.debug("SimilarGRSFRecords are " + similarRecords);
|
2017-01-26 18:21:33 +01:00
|
|
|
|
2017-12-12 18:54:45 +01:00
|
|
|
// get connected records
|
|
|
|
List<String> connectedBeansAsStrings = extrasWithoutNamespaces.containsKey(Constants.CONNECTED_CUSTOM_KEY) ? extrasWithoutNamespaces.get(Constants.CONNECTED_CUSTOM_KEY): null;
|
2017-01-26 18:21:33 +01:00
|
|
|
|
2017-12-12 18:54:45 +01:00
|
|
|
List<ConnectedBean> connectedBeans = new ArrayList<ConnectedBean>(0);
|
|
|
|
if(connectedBeansAsStrings != null){
|
|
|
|
for (String connectedBean : connectedBeansAsStrings) {
|
|
|
|
connectedBeans.add(Utils.connectedBeanRecordFromJson(connectedBean, uuidKB, grsfDomain));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.debug("Connected records are " + connectedBeans);
|
|
|
|
|
|
|
|
// Get sources
|
|
|
|
List<CkanResource> resources = record.getResources();
|
|
|
|
List<SourceRecord> sources = new ArrayList<SourceRecord>(3);
|
|
|
|
for (CkanResource ckanResource : resources) {
|
|
|
|
if(Sources.getListNames().contains(ckanResource.getName()))
|
|
|
|
sources.add(new SourceRecord(ckanResource.getName(), ckanResource.getUrl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the values
|
|
|
|
toReturn = new ManageProductBean(semanticId, catalogueIdentifier, uuidKB, grsfType,
|
|
|
|
grsfDomain, grsfName, shortName, traceabilityFlag, Status.fromString(status), null,
|
|
|
|
null, null, sources, similarRecords, connectedBeans);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2017-01-26 18:21:33 +01:00
|
|
|
}
|
2017-12-12 18:54:45 +01:00
|
|
|
|
|
|
|
logger.info("Returning item bean " + toReturn);
|
|
|
|
return toReturn;
|
2017-01-26 18:21:33 +01:00
|
|
|
}
|
|
|
|
|
2017-02-16 18:32:19 +01:00
|
|
|
@Override
|
|
|
|
public boolean isAdminUser() {
|
|
|
|
try{
|
|
|
|
|
2017-08-01 18:00:19 +02:00
|
|
|
Boolean inSession = (Boolean)getThreadLocalRequest().getSession().getAttribute(Constants.GRSF_ADMIN_SESSION_KEY);
|
2017-11-15 19:22:20 +01:00
|
|
|
|
2017-02-16 18:32:19 +01:00
|
|
|
if(inSession != null)
|
|
|
|
return inSession;
|
|
|
|
else{
|
2017-11-15 19:22:20 +01:00
|
|
|
|
2017-11-14 18:37:07 +01:00
|
|
|
if(!Utils.isIntoPortal()){
|
|
|
|
getThreadLocalRequest().getSession().setAttribute(Constants.GRSF_ADMIN_SESSION_KEY, true);
|
|
|
|
return true;
|
|
|
|
}
|
2017-11-15 19:22:20 +01:00
|
|
|
|
2017-02-16 18:32:19 +01:00
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
2017-11-09 14:49:07 +01:00
|
|
|
RoleManager roleManager = new LiferayRoleManager();
|
|
|
|
String username = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
|
|
|
|
long userId = pContext.getCurrentUser(getThreadLocalRequest()).getUserId();
|
|
|
|
long groupId = pContext.getCurrentGroupId(getThreadLocalRequest());
|
|
|
|
List<GCubeRole> vreRoles = roleManager.listRolesByUserAndGroup(userId, groupId);
|
|
|
|
List<GCubeTeam> teamRoles = new LiferayRoleManager().listTeamsByUserAndGroup(userId, groupId);
|
2017-02-16 18:32:19 +01:00
|
|
|
boolean toSetInSession = false;
|
2017-03-03 18:26:35 +01:00
|
|
|
for (GCubeTeam team : teamRoles) {
|
2017-08-01 18:00:19 +02:00
|
|
|
if(team.getTeamName().equals(Constants.GRSF_CATALOGUE_MANAGER_ROLE)){
|
2017-11-09 14:49:07 +01:00
|
|
|
logger.info("User " + username + " is " + Constants.GRSF_CATALOGUE_MANAGER_ROLE);
|
2017-02-16 18:32:19 +01:00
|
|
|
toSetInSession = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-11-09 14:49:07 +01:00
|
|
|
|
|
|
|
if(!toSetInSession)
|
|
|
|
for (GCubeRole gCubeTeam : vreRoles) {
|
|
|
|
if(gCubeTeam.getRoleName().equals(GatewayRolesNames.VRE_MANAGER.getRoleName())){
|
|
|
|
logger.info("User " + username + " is " + GatewayRolesNames.VRE_MANAGER.getRoleName());
|
|
|
|
toSetInSession = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-01 18:00:19 +02:00
|
|
|
getThreadLocalRequest().getSession().setAttribute(Constants.GRSF_ADMIN_SESSION_KEY, toSetInSession);
|
2017-02-16 18:32:19 +01:00
|
|
|
return toSetInSession;
|
|
|
|
}
|
|
|
|
}catch(Exception e){
|
2017-11-09 14:49:07 +01:00
|
|
|
logger.error("Failed to check if the user has team " + Constants.GRSF_CATALOGUE_MANAGER_ROLE
|
|
|
|
+ " or " + GatewayRolesNames.VRE_MANAGER.getRoleName() +"!", e);
|
2017-02-16 18:32:19 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2017-11-09 14:49:07 +01:00
|
|
|
|
2017-11-23 20:04:47 +01:00
|
|
|
@Override
|
|
|
|
public boolean checkSemanticIdentifierExists(String semanticIdentifier)
|
|
|
|
throws Exception {
|
|
|
|
|
|
|
|
return getDataset(semanticIdentifier) != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean checkSemanticIdentifierExistsInDomain(String semanticIdentifier, String domain)
|
|
|
|
throws Exception {
|
|
|
|
|
|
|
|
|
|
|
|
CkanDataset dataset = getDataset(semanticIdentifier);
|
2017-12-07 12:37:21 +01:00
|
|
|
|
2017-11-23 20:04:47 +01:00
|
|
|
// look for the right domain this time
|
|
|
|
List<CkanPair> extrasAsPairs = dataset.getExtras();
|
|
|
|
|
|
|
|
for (CkanPair ckanPair : extrasAsPairs) {
|
|
|
|
if(ckanPair.getKey().contains(Constants.DOMAIN_CUSTOM_KEY)){
|
|
|
|
return ckanPair.getValue().equalsIgnoreCase(domain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private CkanDataset getDataset(String semanticIdentifier) throws Exception{
|
|
|
|
|
|
|
|
String scopePerCurrentUrl = Utils.getScopeFromClientUrl(getThreadLocalRequest());
|
|
|
|
DataCatalogue catalogue = getCatalogue(scopePerCurrentUrl);
|
|
|
|
String username = Utils.getCurrentUser(getThreadLocalRequest()).getUsername();
|
|
|
|
CkanDataset dataset = Utils.getRecordBySemanticIdentifier(semanticIdentifier, catalogue, catalogue.getApiKeyFromUsername(username));
|
|
|
|
return dataset;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-12-07 12:37:21 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean checkIdentifierExists(String id)
|
|
|
|
throws Exception {
|
|
|
|
String scopePerCurrentUrl = Utils.getScopeFromClientUrl(getThreadLocalRequest());
|
|
|
|
DataCatalogue catalogue = getCatalogue(scopePerCurrentUrl);
|
|
|
|
String username = Utils.getCurrentUser(getThreadLocalRequest()).getUsername();
|
|
|
|
return catalogue.getDataset(id, catalogue.getApiKeyFromUsername(username)) != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean checkIdentifierExistsInDomain(String id,
|
|
|
|
String domain) throws Exception {
|
|
|
|
String scopePerCurrentUrl = Utils.getScopeFromClientUrl(getThreadLocalRequest());
|
|
|
|
DataCatalogue catalogue = getCatalogue(scopePerCurrentUrl);
|
|
|
|
String username = Utils.getCurrentUser(getThreadLocalRequest()).getUsername();
|
|
|
|
CkanDataset dataset = catalogue.getDataset(id, catalogue.getApiKeyFromUsername(username));
|
|
|
|
if(dataset == null)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
List<CkanPair> extrasAsPairs = dataset.getExtras();
|
|
|
|
|
|
|
|
for (CkanPair ckanPair : extrasAsPairs) {
|
|
|
|
if(ckanPair.getKey().contains(Constants.DOMAIN_CUSTOM_KEY)){
|
|
|
|
return ckanPair.getValue().equalsIgnoreCase(domain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-12 18:54:45 +01:00
|
|
|
@Override
|
|
|
|
public String notifyProductUpdate(ManageProductBean bean) throws Exception{
|
|
|
|
|
|
|
|
logger.info("Creating notification for the bean " + bean + " to send to the knowledge base");
|
|
|
|
try{
|
|
|
|
|
|
|
|
String context = Utils.getScopeFromClientUrl(getThreadLocalRequest());
|
|
|
|
DataCatalogue catalogue = getCatalogue(context);
|
|
|
|
|
|
|
|
// check if the base url of the service is in session
|
|
|
|
String keyPerContext = UtilMethods.concatenateSessionKeyScope(Constants.GRSF_UPDATER_SERVICE, context);
|
|
|
|
String baseUrl = (String)getThreadLocalRequest().getSession().getAttribute(keyPerContext);
|
|
|
|
if(baseUrl == null || baseUrl.isEmpty()){
|
|
|
|
baseUrl = Utils.discoverEndPoint(context);
|
|
|
|
getThreadLocalRequest().getSession().setAttribute(keyPerContext, baseUrl);
|
|
|
|
}
|
|
|
|
return Utils.updateCatalogueRecord(baseUrl, bean, catalogue, Utils.getCurrentUser(getThreadLocalRequest()).getUsername());
|
|
|
|
|
|
|
|
}catch(Exception e){
|
|
|
|
logger.error("Unable to update the product.." + e.getMessage());
|
|
|
|
return e.getMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-26 18:21:33 +01:00
|
|
|
}
|