#23561 Fixing Merging Request throws a Null Pointer exception
This commit is contained in:
parent
0335ac8b9c
commit
72fd24fc61
|
@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
#### Bug fixes
|
||||
|
||||
- [#23549] Fixed serialization issue on the GRSFRecordAlreadyManagedStatusException
|
||||
- [#23561] Fixed Merging Request throws a Null Pointer exception
|
||||
|
||||
## [v1.6.0] - 2022-05-25
|
||||
|
||||
|
|
|
@ -587,17 +587,17 @@ public class GRSFNotificationService extends RemoteServiceServlet implements GRS
|
|||
@Override
|
||||
public String checkIdentifierExistsInDomain(String id, String acceptedDomain) throws Exception {
|
||||
|
||||
if (!Utils.isIntoPortal()) {
|
||||
boolean throwException = Math.random() > 0.5;
|
||||
|
||||
// simulate some delay...
|
||||
Thread.sleep(2500);
|
||||
|
||||
if (throwException)
|
||||
throw new Exception("The suggested record is not a GRSF record");
|
||||
|
||||
return "http://data.d4science.org/catalogue/grsf_admin/" + id;
|
||||
}
|
||||
// if (!Utils.isIntoPortal()) {
|
||||
// boolean throwException = Math.random() > 0.5;
|
||||
//
|
||||
// // simulate some delay...
|
||||
// Thread.sleep(2500);
|
||||
//
|
||||
// if (throwException)
|
||||
// throw new Exception("The suggested record is not a GRSF record");
|
||||
//
|
||||
// return "http://data.d4science.org/catalogue/grsf_admin/" + id;
|
||||
// }
|
||||
|
||||
String scopePerCurrentUrl = Utils.getScopeFromClientUrl(getThreadLocalRequest());
|
||||
DataCatalogue catalogue = getCatalogue(scopePerCurrentUrl);
|
||||
|
|
|
@ -51,6 +51,7 @@ import com.liferay.portal.service.UserLocalServiceUtil;
|
|||
|
||||
/**
|
||||
* Utility methods for GRSF Management panel widget.
|
||||
*
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class Utils {
|
||||
|
@ -59,34 +60,36 @@ public class Utils {
|
|||
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}";
|
||||
|
||||
/**
|
||||
* Return a map for converting a key to a namespace:key format by reading a generic resource.
|
||||
* @param httpSession
|
||||
* Return a map for converting a key to a namespace:key format by reading a
|
||||
* generic resource.
|
||||
*
|
||||
* @param httpSession
|
||||
* @return a map
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Map<String, String> getFieldToFieldNameSpaceMapping(HttpSession httpSession, String resourceName){
|
||||
public static Map<String, String> getFieldToFieldNameSpaceMapping(HttpSession httpSession, String resourceName) {
|
||||
|
||||
// check if this information is available in session
|
||||
String sessionKey = ScopeProvider.instance.get() + resourceName;
|
||||
if(httpSession.getAttribute(sessionKey) != null)
|
||||
if (httpSession.getAttribute(sessionKey) != null)
|
||||
return (Map<String, String>) httpSession.getAttribute(sessionKey);
|
||||
|
||||
Map<String, String> namespacesMap = new HashMap<String, String>(); // e.g. fishery_identity:Short Title -> Short Title
|
||||
Map<String, String> namespacesMap = new HashMap<String, String>(); // e.g. fishery_identity:Short Title -> Short
|
||||
// Title
|
||||
try {
|
||||
Query q = new QueryBox("for $profile in collection('/db/Profiles/GenericResource')//Resource " +
|
||||
"where $profile/Profile/SecondaryType/string() eq '"+ "ApplicationProfile" + "' and $profile/Profile/Name/string() " +
|
||||
" eq '" + resourceName + "'" +
|
||||
"return $profile");
|
||||
Query q = new QueryBox("for $profile in collection('/db/Profiles/GenericResource')//Resource "
|
||||
+ "where $profile/Profile/SecondaryType/string() eq '" + "ApplicationProfile"
|
||||
+ "' and $profile/Profile/Name/string() " + " eq '" + resourceName + "'" + "return $profile");
|
||||
|
||||
DiscoveryClient<String> client = client();
|
||||
List<String> appProfile = client.submit(q);
|
||||
|
||||
if (appProfile == null || appProfile.size() == 0)
|
||||
if (appProfile == null || appProfile.size() == 0)
|
||||
throw new Exception("Your applicationProfile is not registered in the infrastructure");
|
||||
else {
|
||||
|
||||
String elem = appProfile.get(0);
|
||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Node node = docBuilder.parse(new InputSource(new StringReader(elem))).getDocumentElement();
|
||||
XPathHelper helper = new XPathHelper(node);
|
||||
|
||||
|
@ -94,17 +97,18 @@ public class Utils {
|
|||
NodeList nodeListModifiedKeys = helper.evaluateForNodes("//modifiedKey");
|
||||
int sizeKeys = nodeListKeys != null ? nodeListKeys.getLength() : 0;
|
||||
int sizeKeysModifed = nodeListModifiedKeys != null ? nodeListModifiedKeys.getLength() : 0;
|
||||
if(sizeKeys != sizeKeysModifed)
|
||||
if (sizeKeys != sizeKeysModifed)
|
||||
throw new Exception("Malformed XML");
|
||||
logger.debug("Size is " + sizeKeys);
|
||||
for (int i = 0; i < sizeKeys; i++) {
|
||||
namespacesMap.put(nodeListModifiedKeys.item(i).getTextContent(), nodeListKeys.item(i).getTextContent());
|
||||
namespacesMap.put(nodeListModifiedKeys.item(i).getTextContent(),
|
||||
nodeListKeys.item(i).getTextContent());
|
||||
}
|
||||
}
|
||||
logger.debug("Map is " + namespacesMap);
|
||||
|
||||
// put them into session for speeding up the operations
|
||||
httpSession.setAttribute(sessionKey, namespacesMap);
|
||||
httpSession.setAttribute(sessionKey, namespacesMap);
|
||||
return namespacesMap;
|
||||
} catch (Exception e) {
|
||||
logger.error("Error while trying to fetch applicationProfile profile from the infrastructure", e);
|
||||
|
@ -113,7 +117,9 @@ public class Utils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Replace the extras' keys if needed, e.g. fishery_identity:Short Title -> Short Title
|
||||
* Replace the extras' keys if needed, e.g. fishery_identity:Short Title ->
|
||||
* Short Title
|
||||
*
|
||||
* @param extrasAsPairs
|
||||
* @param namespaces
|
||||
* @return a map with replaced key value pairs
|
||||
|
@ -129,7 +135,7 @@ public class Utils {
|
|||
String replacedKey = namespaces.containsKey(pairKey) ? namespaces.get(pairKey) : pairKey;
|
||||
|
||||
List<String> values = null;
|
||||
if(toReturn.containsKey(replacedKey))
|
||||
if (toReturn.containsKey(replacedKey))
|
||||
values = toReturn.get(replacedKey);
|
||||
else
|
||||
values = new ArrayList<String>(1);
|
||||
|
@ -143,10 +149,11 @@ public class Utils {
|
|||
|
||||
/**
|
||||
* Get the extras of this dataset as hashmap
|
||||
*
|
||||
* @param extrasAsPairs
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, List<String>> getExtrasAsHashMap(List<CkanPair> extrasAsPairs){
|
||||
public static Map<String, List<String>> getExtrasAsHashMap(List<CkanPair> extrasAsPairs) {
|
||||
|
||||
Map<String, List<String>> toReturn = new HashMap<String, List<String>>();
|
||||
|
||||
|
@ -155,7 +162,7 @@ public class Utils {
|
|||
String pairValue = ckanPair.getValue();
|
||||
|
||||
List<String> values = null;
|
||||
if(toReturn.containsKey(pairKey))
|
||||
if (toReturn.containsKey(pairKey))
|
||||
values = toReturn.get(pairKey);
|
||||
else
|
||||
values = new ArrayList<String>(1);
|
||||
|
@ -169,68 +176,66 @@ public class Utils {
|
|||
|
||||
/**
|
||||
* Send an update for this bean
|
||||
*
|
||||
* @param baseUrl
|
||||
* @param bean
|
||||
* @param username
|
||||
* @param catalogue
|
||||
* @param username
|
||||
* @param catalogue
|
||||
* @return true on success, false otherwise
|
||||
*/
|
||||
public static void updateRecord(
|
||||
String serviceUrl,
|
||||
final ManageProductBean bean,
|
||||
final DataCatalogue catalogue,
|
||||
final String username,
|
||||
final String fullName,
|
||||
final HttpServletRequest httpServletRequest,
|
||||
final long groupId,
|
||||
final String context,
|
||||
final String token) throws Exception{
|
||||
public static void updateRecord(String serviceUrl, final ManageProductBean bean, final DataCatalogue catalogue,
|
||||
final String username, final String fullName, final HttpServletRequest httpServletRequest,
|
||||
final long groupId, final String context, final String token) throws Exception {
|
||||
|
||||
if(serviceUrl == null)
|
||||
if (serviceUrl == null)
|
||||
throw new IllegalArgumentException("GRSF Updater service url cannot be null");
|
||||
|
||||
if(bean == null)
|
||||
if (bean == null)
|
||||
throw new IllegalArgumentException("Item bean to manage cannot be null");
|
||||
|
||||
try(CloseableHttpClient httpClient = HttpClientBuilder.create().build();){
|
||||
|
||||
//ADDED BY FRANCESCO
|
||||
if(Utils.isIntoPortal()) {
|
||||
try (CloseableHttpClient httpClient = HttpClientBuilder.create().build();) {
|
||||
|
||||
// ADDED BY FRANCESCO
|
||||
if (Utils.isIntoPortal()) {
|
||||
|
||||
// send update to the knowledge base
|
||||
GRSFUpdaterServiceClient.updateKB(httpClient, serviceUrl, bean, catalogue, username, fullName);
|
||||
|
||||
|
||||
// if there are merges, update the status of the other involved records
|
||||
if(bean.isMergesInvolved())
|
||||
updateStatusInvolvedRecords(bean, catalogue);
|
||||
|
||||
if (bean.isMergesInvolved())
|
||||
updateStatusInvolvedRecords(bean, username, catalogue);
|
||||
|
||||
}
|
||||
|
||||
// require social networking url
|
||||
final String baseUrlSocial = SocialCommunications.getBaseUrlSocialService(httpServletRequest);
|
||||
|
||||
// and the user current browser url
|
||||
final String currentBrowserUrl = Utils.getCurrentClientUrl(httpServletRequest).split("\\?")[0]; // ignore other parameters
|
||||
final String currentBrowserUrl = Utils.getCurrentClientUrl(httpServletRequest).split("\\?")[0]; // ignore
|
||||
// other
|
||||
// parameters
|
||||
|
||||
// manage interactions through a separated thread but set there security token and context (and then reset them)
|
||||
// manage interactions through a separated thread but set there security token
|
||||
// and context (and then reset them)
|
||||
Thread t = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ScopeProvider.instance.set(context);
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
try{
|
||||
try {
|
||||
|
||||
// send email to Editors and Reviewers
|
||||
SocialCommunications.sendEmailAdministrators(baseUrlSocial, bean, catalogue, username, fullName,
|
||||
SocialCommunications.sendEmailAdministrators(baseUrlSocial, bean, catalogue, username, fullName,
|
||||
groupId, currentBrowserUrl, bean.isMergesInvolved());
|
||||
|
||||
// create a post about the operation
|
||||
SocialCommunications.writeProductPost(baseUrlSocial, bean, username, fullName, false, currentBrowserUrl);
|
||||
// create a post about the operation
|
||||
SocialCommunications.writeProductPost(baseUrlSocial, bean, username, fullName, false,
|
||||
currentBrowserUrl);
|
||||
|
||||
}catch(Exception e){
|
||||
} catch (Exception e) {
|
||||
logger.error("Something failed while alerting editors/reviewers", e);
|
||||
}finally{
|
||||
} finally {
|
||||
ScopeProvider.instance.reset();
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
|
@ -238,7 +243,7 @@ public class Utils {
|
|||
});
|
||||
t.start();
|
||||
|
||||
}catch(Exception e){
|
||||
} catch (Exception e) {
|
||||
logger.error("Unable to update this Item ", e);
|
||||
throw e;
|
||||
}
|
||||
|
@ -246,14 +251,16 @@ public class Utils {
|
|||
|
||||
/**
|
||||
* Revert operation and alert admins/vre users
|
||||
*
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
* @param httpClient
|
||||
* @param baseUrl
|
||||
* @param fullName
|
||||
* @param uuid
|
||||
*/
|
||||
public static void revertOperation(CloseableHttpClient httpClient, String baseUrl, HttpServletRequest httpServletRequest,
|
||||
final RevertableOperationInfo rInfo, final String token, final String context, final long groupId) throws Exception{
|
||||
public static void revertOperation(CloseableHttpClient httpClient, String baseUrl,
|
||||
HttpServletRequest httpServletRequest, final RevertableOperationInfo rInfo, final String token,
|
||||
final String context, final long groupId) throws Exception {
|
||||
|
||||
GRSFUpdaterServiceClient.revertOperation(httpClient, baseUrl, rInfo.getFullNameCurrentAdmin(), rInfo.getUuid());
|
||||
|
||||
|
@ -261,16 +268,18 @@ public class Utils {
|
|||
final String baseUrlSocial = SocialCommunications.getBaseUrlSocialService(httpServletRequest);
|
||||
|
||||
// and the user current browser url
|
||||
final String currentBrowserUrl = Utils.getCurrentClientUrl(httpServletRequest).split("\\?")[0]; // ignore other parameters
|
||||
|
||||
// manage interactions through a separated thread but set there security token and context (and then reset them)
|
||||
final String currentBrowserUrl = Utils.getCurrentClientUrl(httpServletRequest).split("\\?")[0]; // ignore other
|
||||
// parameters
|
||||
|
||||
// manage interactions through a separated thread but set there security token
|
||||
// and context (and then reset them)
|
||||
Thread t = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ScopeProvider.instance.set(context);
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
try{
|
||||
try {
|
||||
|
||||
// write post about this
|
||||
SocialCommunications.writePostOnRevert(baseUrlSocial, rInfo, false, currentBrowserUrl);
|
||||
|
@ -278,9 +287,9 @@ public class Utils {
|
|||
// alert who's involved
|
||||
SocialCommunications.sendEmailAdministratorsOnOperationReverted(baseUrlSocial, rInfo, groupId);
|
||||
|
||||
}catch(Exception e){
|
||||
} catch (Exception e) {
|
||||
logger.error("Something failed while alerting editors/reviewers", e);
|
||||
}finally{
|
||||
} finally {
|
||||
ScopeProvider.instance.reset();
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
|
@ -292,23 +301,26 @@ public class Utils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Update the status of the involved records to "to be merged"
|
||||
* @param bean
|
||||
* @param catalogue
|
||||
* @param username
|
||||
* @param fullName
|
||||
* @throws Exception
|
||||
* Update the status of the involved records to "to be merged".
|
||||
*
|
||||
* @param bean the bean
|
||||
* @param username the username
|
||||
* @param catalogue the catalogue
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
private static void updateStatusInvolvedRecords(ManageProductBean bean, DataCatalogue catalogue) throws Exception {
|
||||
private static void updateStatusInvolvedRecords(ManageProductBean bean, String username, DataCatalogue catalogue)
|
||||
throws Exception {
|
||||
|
||||
String context = ScopeProvider.instance.get();
|
||||
String sysApi = fetchSysAPI(context);
|
||||
for(SimilarGRSFRecord s: bean.getSimilarGrsfRecords()){
|
||||
if(s.isSuggestedMerge()){
|
||||
// String context = ScopeProvider.instance.get();
|
||||
// String sysApi = fetchSysAPI(context);
|
||||
for (SimilarGRSFRecord s : bean.getSimilarGrsfRecords()) {
|
||||
if (s.isSuggestedMerge()) {
|
||||
String productId = s.getKnowledgeBaseId();
|
||||
Map<String, List<String>> updateStatus = new HashMap<String, List<String>>(1);
|
||||
updateStatus.put(Constants.STATUS_OF_THE_GRSF_RECORD_CUSTOM_KEY, Arrays.asList(Status.To_be_Merged.getOrigName()));
|
||||
catalogue.patchProductCustomFields(productId, sysApi, updateStatus, true);
|
||||
updateStatus.put(Constants.STATUS_OF_THE_GRSF_RECORD_CUSTOM_KEY,
|
||||
Arrays.asList(Status.To_be_Merged.getOrigName()));
|
||||
// Fixing bug #23561, passing username (instead of sysAPI)
|
||||
catalogue.patchProductCustomFields(productId, username, updateStatus, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -316,45 +328,48 @@ public class Utils {
|
|||
|
||||
/**
|
||||
* Get the scope in which ckan information needs to be discovered from the url
|
||||
*
|
||||
* @param httpServletRequest
|
||||
* @return
|
||||
*/
|
||||
public static String getScopeFromClientUrl(HttpServletRequest httpServletRequest){
|
||||
public static String getScopeFromClientUrl(HttpServletRequest httpServletRequest) {
|
||||
|
||||
if(httpServletRequest == null)
|
||||
if (httpServletRequest == null)
|
||||
throw new IllegalArgumentException("HttpServletRequest is null!");
|
||||
|
||||
String scopeToReturn = null;
|
||||
try{
|
||||
try {
|
||||
String clientUrl = getCurrentClientUrl(httpServletRequest).split("\\?")[0];
|
||||
logger.debug("Client url is " + clientUrl);
|
||||
|
||||
// check if this information is in session, otherwise set it and return
|
||||
HttpSession session = httpServletRequest.getSession();
|
||||
|
||||
if((scopeToReturn = (String) session.getAttribute(clientUrl)) != null){
|
||||
if ((scopeToReturn = (String) session.getAttribute(clientUrl)) != null) {
|
||||
logger.debug("Scope to return is " + scopeToReturn);
|
||||
}else{
|
||||
} else {
|
||||
// ask to the ckan library and set it
|
||||
scopeToReturn = ApplicationProfileScopePerUrlReader.getScopePerUrl(clientUrl);
|
||||
logger.debug("Scope to return is " + scopeToReturn);
|
||||
session.setAttribute(clientUrl, scopeToReturn);
|
||||
}
|
||||
}catch(Exception e){
|
||||
} catch (Exception e) {
|
||||
scopeToReturn = getCurrentContext(httpServletRequest, true);
|
||||
logger.warn("Failed to determine the scope from the client url, returning the current one: " + scopeToReturn);
|
||||
logger.warn(
|
||||
"Failed to determine the scope from the client url, returning the current one: " + scopeToReturn);
|
||||
}
|
||||
return scopeToReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Needed to get the url of the client
|
||||
*
|
||||
* @param httpServletRequest the httpServletRequest object
|
||||
* @return the instance of the user
|
||||
* @return the instance of the user
|
||||
* @see the url at client side
|
||||
*/
|
||||
public static String getCurrentClientUrl(HttpServletRequest httpServletRequest) {
|
||||
if(httpServletRequest == null)
|
||||
if (httpServletRequest == null)
|
||||
throw new IllegalArgumentException("HttpServletRequest is null!");
|
||||
|
||||
return httpServletRequest.getHeader(Constants.GCUBE_REQUEST_URL);
|
||||
|
@ -362,19 +377,20 @@ public class Utils {
|
|||
|
||||
/**
|
||||
* Retrieve the current scope by using the portal manager
|
||||
* @param b
|
||||
*
|
||||
* @param b
|
||||
* @return a GcubeUser object
|
||||
*/
|
||||
public static String getCurrentContext(HttpServletRequest request, boolean setInThread){
|
||||
public static String getCurrentContext(HttpServletRequest request, boolean setInThread) {
|
||||
|
||||
if(request == null)
|
||||
if (request == null)
|
||||
throw new IllegalArgumentException("HttpServletRequest is null!");
|
||||
|
||||
PortalContext pContext = PortalContext.getConfiguration();
|
||||
String context = pContext.getCurrentScope(request);
|
||||
logger.debug("Returning context " + context);
|
||||
|
||||
if(context != null && setInThread)
|
||||
if (context != null && setInThread)
|
||||
ScopeProvider.instance.set(context);
|
||||
|
||||
return context;
|
||||
|
@ -382,11 +398,12 @@ public class Utils {
|
|||
|
||||
/**
|
||||
* Retrieve the current user by using the portal manager
|
||||
*
|
||||
* @return a GcubeUser object
|
||||
*/
|
||||
public static GCubeUser getCurrentUser(HttpServletRequest request){
|
||||
public static GCubeUser getCurrentUser(HttpServletRequest request) {
|
||||
|
||||
if(request == null)
|
||||
if (request == null)
|
||||
throw new IllegalArgumentException("HttpServletRequest is null!");
|
||||
|
||||
PortalContext pContext = PortalContext.getConfiguration();
|
||||
|
@ -396,17 +413,18 @@ public class Utils {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param url the url
|
||||
* @param clg the clg
|
||||
* @param url the url
|
||||
* @param clg the clg
|
||||
* @param username the username
|
||||
* @return the dataset from url
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public static CkanDataset getDatasetFromUrl(String url, DataCatalogue clg, String username) throws Exception{
|
||||
public static CkanDataset getDatasetFromUrl(String url, DataCatalogue clg, String username) throws Exception {
|
||||
|
||||
if(url == null || url.isEmpty())
|
||||
if (url == null || url.isEmpty())
|
||||
return null;
|
||||
|
||||
// Parse url
|
||||
|
@ -425,14 +443,16 @@ public class Utils {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @param url
|
||||
* @param clg
|
||||
* @return
|
||||
*/
|
||||
public static String getDatasetKnowledgeBaseIdFromUrl(String url){
|
||||
public static String getDatasetKnowledgeBaseIdFromUrl(String url) {
|
||||
|
||||
if(url == null || url.isEmpty())
|
||||
if (url == null || url.isEmpty())
|
||||
return null;
|
||||
|
||||
// Parse url
|
||||
|
@ -450,39 +470,38 @@ public class Utils {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a {@link SimilarGRSFRecord} from a json string
|
||||
*
|
||||
* @param json
|
||||
* @return {@link SimilarGRSFRecord}
|
||||
* @throws ParseException
|
||||
* @throws ParseException
|
||||
*/
|
||||
public static SimilarGRSFRecord similarGRSFRecordFromJson(String json, DataCatalogue ctl, String username, HttpSession httpSession) throws ParseException{
|
||||
public static SimilarGRSFRecord similarGRSFRecordFromJson(String json, DataCatalogue ctl, String username,
|
||||
HttpSession httpSession) throws ParseException {
|
||||
|
||||
if(json == null)
|
||||
if (json == null)
|
||||
return null;
|
||||
|
||||
JSONParser parser = new JSONParser();
|
||||
JSONObject object = (JSONObject)parser.parse(json);
|
||||
JSONObject object = (JSONObject) parser.parse(json);
|
||||
|
||||
String uuid = getDatasetKnowledgeBaseIdFromUrl((String)object.get(Constants.SIMILAR_RECORDS_BEAN_FIELD_URL));
|
||||
CkanDataset dataset = ctl.getDataset(uuid,username);
|
||||
|
||||
boolean isStock = dataset.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(dataset.getExtras(), fieldsNamespacesMap);
|
||||
String uuid = getDatasetKnowledgeBaseIdFromUrl((String) object.get(Constants.SIMILAR_RECORDS_BEAN_FIELD_URL));
|
||||
CkanDataset dataset = ctl.getDataset(uuid, username);
|
||||
|
||||
return new SimilarGRSFRecord(
|
||||
uuid,
|
||||
(String)object.get(Constants.SIMILAR_RECORDS_BEAN_FIELD_DESCRIPTION),
|
||||
(String)object.get(Constants.SIMILAR_RECORDS_BEAN_FIELD_NAME),
|
||||
dataset.getTitle(),
|
||||
(String)object.get(Constants.SIMILAR_RECORDS_BEAN_FIELD_URL),
|
||||
boolean isStock = dataset.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(dataset.getExtras(),
|
||||
fieldsNamespacesMap);
|
||||
|
||||
return new SimilarGRSFRecord(uuid, (String) object.get(Constants.SIMILAR_RECORDS_BEAN_FIELD_DESCRIPTION),
|
||||
(String) object.get(Constants.SIMILAR_RECORDS_BEAN_FIELD_NAME), dataset.getTitle(),
|
||||
(String) object.get(Constants.SIMILAR_RECORDS_BEAN_FIELD_URL),
|
||||
extrasWithoutNamespaces.get(Constants.GRSF_SEMANTIC_IDENTIFIER_CUSTOM_KEY).get(0),
|
||||
extrasWithoutNamespaces.get(Constants.DOMAIN_CUSTOM_KEY).get(0)
|
||||
);
|
||||
extrasWithoutNamespaces.get(Constants.DOMAIN_CUSTOM_KEY).get(0));
|
||||
|
||||
}
|
||||
|
||||
|
@ -495,7 +514,7 @@ public class Utils {
|
|||
try {
|
||||
UserLocalServiceUtil.getService();
|
||||
return true;
|
||||
}catch (Exception ex) {
|
||||
} catch (Exception ex) {
|
||||
logger.debug("Development Mode ON");
|
||||
return false;
|
||||
}
|
||||
|
@ -504,53 +523,45 @@ public class Utils {
|
|||
/**
|
||||
* Get Connected bean from record.
|
||||
*
|
||||
* @param destUrl the dest url
|
||||
* @param clg the clg
|
||||
* @param username the username
|
||||
* @param destUrl the dest url
|
||||
* @param clg the clg
|
||||
* @param username the username
|
||||
* @param httpSession the http session
|
||||
* @return the connected bean
|
||||
* @throws ParseException the parse exception
|
||||
*/
|
||||
public static ConnectedBean connectedBeanRecordFromUrl(
|
||||
String destUrl,
|
||||
DataCatalogue clg,
|
||||
String username,
|
||||
HttpSession httpSession
|
||||
) throws ParseException {
|
||||
public static ConnectedBean connectedBeanRecordFromUrl(String destUrl, DataCatalogue clg, String username,
|
||||
HttpSession httpSession) throws ParseException {
|
||||
|
||||
if(destUrl == null)
|
||||
if (destUrl == null)
|
||||
return null;
|
||||
|
||||
String connectedBeanUuid = getDatasetKnowledgeBaseIdFromUrl(destUrl);
|
||||
CkanDataset destDataset = clg.getDataset(connectedBeanUuid,username);
|
||||
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);
|
||||
CkanDataset destDataset = clg.getDataset(connectedBeanUuid, username);
|
||||
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);
|
||||
String shortName = extrasWithoutNamespaces.get(Constants.SHORT_NAME_CUSTOM_KEY).get(0);
|
||||
String description = destDataset.getNotes();
|
||||
|
||||
return new ConnectedBean(
|
||||
connectedBeanUuid,
|
||||
description,
|
||||
shortName,
|
||||
destDataset.getTitle(),
|
||||
destUrl,
|
||||
semanticId,
|
||||
destDomain
|
||||
);
|
||||
return new ConnectedBean(connectedBeanUuid, description, shortName, destDataset.getTitle(), destUrl, semanticId,
|
||||
destDomain);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the sysadmin key from the IS for this catalogue
|
||||
*
|
||||
* @return
|
||||
* @throws Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String fetchSysAPI(String context) throws Exception{
|
||||
public static String fetchSysAPI(String context) throws Exception {
|
||||
DataCatalogueRunningCluster catalogueRunningInstance = new DataCatalogueRunningCluster(context);
|
||||
return catalogueRunningInstance.getSysAdminToken();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue