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