|
|
|
@ -16,8 +16,8 @@ import javax.servlet.http.HttpSession;
|
|
|
|
|
|
|
|
|
|
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue;
|
|
|
|
|
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueFactory;
|
|
|
|
|
import org.gcube.datacatalogue.ckanutillibrary.server.utils.SessionCatalogueAttributes;
|
|
|
|
|
import org.gcube.datacatalogue.ckanutillibrary.server.utils.CatalogueUtilMethods;
|
|
|
|
|
import org.gcube.datacatalogue.ckanutillibrary.server.utils.SessionCatalogueAttributes;
|
|
|
|
|
import org.gcube.datacatalogue.ckanutillibrary.shared.ResourceBean;
|
|
|
|
|
import org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg;
|
|
|
|
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherService;
|
|
|
|
@ -79,7 +79,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|
|
|
|
DataCatalogue instance = null;
|
|
|
|
|
String scopeInWhichDiscover = null;
|
|
|
|
|
try{
|
|
|
|
|
scopeInWhichDiscover = (scope != null && !scope.isEmpty()) ? scope : GenericUtils.getCurrentContext(getThreadLocalRequest(), false);
|
|
|
|
|
scopeInWhichDiscover = scope != null && !scope.isEmpty() ? scope : GenericUtils.getCurrentContext(getThreadLocalRequest(), false);
|
|
|
|
|
logger.debug("Discovering ckan instance into scope " + scopeInWhichDiscover);
|
|
|
|
|
instance = DataCatalogueFactory.getFactory().getUtilsPerScope(scopeInWhichDiscover);
|
|
|
|
|
}catch(Exception e){
|
|
|
|
@ -92,8 +92,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|
|
|
|
* Retrieve the list of organizations in which the user can publish (roles ADMIN/EDITOR)
|
|
|
|
|
* @param username
|
|
|
|
|
* @return the list of organizations
|
|
|
|
|
* @throws GroupRetrievalFault
|
|
|
|
|
* @throws UserManagementSystemException
|
|
|
|
|
* @throws GroupRetrievalFault
|
|
|
|
|
* @throws UserManagementSystemException
|
|
|
|
|
*/
|
|
|
|
|
private List<OrganizationBean> getUserOrganizationsListAdmin(String username, String scope) throws UserManagementSystemException, GroupRetrievalFault {
|
|
|
|
|
|
|
|
|
@ -124,11 +124,11 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|
|
|
|
try {
|
|
|
|
|
UserLocalServiceUtil.getService();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (com.liferay.portal.kernel.bean.BeanLocatorException ex) {
|
|
|
|
|
}
|
|
|
|
|
catch (com.liferay.portal.kernel.bean.BeanLocatorException ex) {
|
|
|
|
|
logger.trace("Development Mode ON");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -136,7 +136,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|
|
|
|
* @param chosenLicense
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private String findLicenseIdByLicense(String chosenLicense) {
|
|
|
|
|
private String findLicenseIdByLicense(String chosenLicense) {
|
|
|
|
|
|
|
|
|
|
// get scope from client url
|
|
|
|
|
String scope = GenericUtils.getScopeFromClientUrl(getThreadLocalRequest());
|
|
|
|
@ -259,12 +259,12 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|
|
|
|
/**
|
|
|
|
|
* Discover from the IS the vocabulary of tags for this scope, if present
|
|
|
|
|
* @return a list of tags vocabulary
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
private List<String> discoverTagsVocabulary(String context){
|
|
|
|
|
|
|
|
|
|
logger.debug("Looking for vocabulary of tags in this context " + context);
|
|
|
|
|
String keyPerVocabulary = CatalogueUtilMethods.concatenateSessionKeyScope(TAGS_VOCABULARY_KEY, context);
|
|
|
|
|
String keyPerVocabulary = CatalogueUtilMethods.concatenateSessionKeyScope(TAGS_VOCABULARY_KEY, context);
|
|
|
|
|
|
|
|
|
|
List<String> vocabulary = (List<String>) getThreadLocalRequest().getSession().getAttribute(keyPerVocabulary);
|
|
|
|
|
if(vocabulary == null){
|
|
|
|
@ -323,7 +323,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|
|
|
|
String userApiKey = utils.getApiKeyFromUsername(userName);
|
|
|
|
|
|
|
|
|
|
String datasetId = utils.createCKanDatasetMultipleCustomFields
|
|
|
|
|
(userApiKey, title, null, organizationNameOrId, author, authorMail, maintainer,
|
|
|
|
|
(userApiKey, title, null, organizationNameOrId, author, authorMail, maintainer,
|
|
|
|
|
maintainerMail, version, description, licenseId, listOfTags, customFields, resources, setPublic);
|
|
|
|
|
|
|
|
|
|
if(datasetId != null){
|
|
|
|
@ -343,7 +343,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|
|
|
|
// start a thread that will associate this dataset with the group
|
|
|
|
|
if(/*toCreate.getChosenType() != null ||*/ toCreate.getGroups() != null){
|
|
|
|
|
|
|
|
|
|
AssociationToGroupAndNotifyThread threadAssociationToGroup =
|
|
|
|
|
AssociationToGroupAndNotifyThread threadAssociationToGroup =
|
|
|
|
|
new AssociationToGroupAndNotifyThread(
|
|
|
|
|
toCreate.getGroups(),
|
|
|
|
|
toCreate.getGroupsForceCreation(),
|
|
|
|
@ -352,8 +352,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|
|
|
|
datasetId,
|
|
|
|
|
toCreate.getTitle(),
|
|
|
|
|
GenericUtils.getCurrentUser(getThreadLocalRequest()).getFullname(),
|
|
|
|
|
userName,
|
|
|
|
|
utils,
|
|
|
|
|
userName,
|
|
|
|
|
utils,
|
|
|
|
|
organizationNameOrId,
|
|
|
|
|
getThreadLocalRequest()
|
|
|
|
|
);
|
|
|
|
@ -362,14 +362,14 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// launch notification thread
|
|
|
|
|
WritePostCatalogueManagerThread threadWritePost =
|
|
|
|
|
WritePostCatalogueManagerThread threadWritePost =
|
|
|
|
|
new WritePostCatalogueManagerThread(
|
|
|
|
|
userName,
|
|
|
|
|
scope,
|
|
|
|
|
toCreate.getTitle(),
|
|
|
|
|
datasetUrl,
|
|
|
|
|
false, // send notification to other people
|
|
|
|
|
toCreate.getTags(),
|
|
|
|
|
scope,
|
|
|
|
|
toCreate.getTitle(),
|
|
|
|
|
datasetUrl,
|
|
|
|
|
false, // send notification to other people
|
|
|
|
|
toCreate.getTags(),
|
|
|
|
|
GenericUtils.getCurrentUser(getThreadLocalRequest()).getFullname(),
|
|
|
|
|
GenericUtils.getCurrentClientUrl(getThreadLocalRequest())
|
|
|
|
|
);
|
|
|
|
@ -405,11 +405,11 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ResourceBean resourceBean = new ResourceBean(
|
|
|
|
|
resource.getUrl(),
|
|
|
|
|
resource.getName(),
|
|
|
|
|
resource.getDescription(),
|
|
|
|
|
null,
|
|
|
|
|
username,
|
|
|
|
|
resource.getUrl(),
|
|
|
|
|
resource.getName(),
|
|
|
|
|
resource.getDescription(),
|
|
|
|
|
null,
|
|
|
|
|
username,
|
|
|
|
|
datasetId,
|
|
|
|
|
null);
|
|
|
|
|
|
|
|
|
@ -546,17 +546,26 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|
|
|
|
logger.info("Found user's groups in session " + toReturn);
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
|
|
DataCatalogue catalogue = getCatalogue(scope);
|
|
|
|
|
String apiKey = catalogue.getApiKeyFromUsername(username);
|
|
|
|
|
Map<String, Map<CkanGroup, RolesCkanGroupOrOrg>> mapRoleGroup = catalogue.getUserRoleByGroup(username, apiKey);
|
|
|
|
|
Set<Entry<String, Map<CkanGroup, RolesCkanGroupOrOrg>>> set = mapRoleGroup.entrySet();
|
|
|
|
|
for (Entry<String, Map<CkanGroup, RolesCkanGroupOrOrg>> entry : set) {
|
|
|
|
|
Set<Entry<CkanGroup, RolesCkanGroupOrOrg>> subSet = entry.getValue().entrySet();
|
|
|
|
|
for (Entry<CkanGroup, RolesCkanGroupOrOrg> subEntry : subSet) {
|
|
|
|
|
toReturn.add(new OrganizationBean(subEntry.getKey().getTitle(), subEntry.getKey().getName(), false));
|
|
|
|
|
}
|
|
|
|
|
//Fixing Incident #12563
|
|
|
|
|
try{
|
|
|
|
|
DataCatalogue catalogue = getCatalogue(scope);
|
|
|
|
|
String apiKey = catalogue.getApiKeyFromUsername(username);
|
|
|
|
|
//Fixing Incident #12563
|
|
|
|
|
if(apiKey!=null && !apiKey.isEmpty()){
|
|
|
|
|
Map<String, Map<CkanGroup, RolesCkanGroupOrOrg>> mapRoleGroup = catalogue.getUserRoleByGroup(username, apiKey);
|
|
|
|
|
Set<Entry<String, Map<CkanGroup, RolesCkanGroupOrOrg>>> set = mapRoleGroup.entrySet();
|
|
|
|
|
for (Entry<String, Map<CkanGroup, RolesCkanGroupOrOrg>> entry : set) {
|
|
|
|
|
Set<Entry<CkanGroup, RolesCkanGroupOrOrg>> subSet = entry.getValue().entrySet();
|
|
|
|
|
for (Entry<CkanGroup, RolesCkanGroupOrOrg> subEntry : subSet) {
|
|
|
|
|
toReturn.add(new OrganizationBean(subEntry.getKey().getTitle(), subEntry.getKey().getName(), false));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
httpSession.setAttribute(keyPerScopeGroups, toReturn);
|
|
|
|
|
}else
|
|
|
|
|
logger.warn("The API_KEY for "+username+ " is null or empty in the catalogue: "+catalogue.getCatalogueUrl());
|
|
|
|
|
}catch(Exception e){
|
|
|
|
|
logger.error("Error on recovery the user groups for "+username, e);
|
|
|
|
|
}
|
|
|
|
|
httpSession.setAttribute(keyPerScopeGroups, toReturn);
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
logger.warn("Dev mode detected");
|
|
|
|
|