#25433 Added spinner during resource creation, implemented

This commit is contained in:
Francesco Mangiacrapa 2023-07-25 15:24:37 +02:00
parent 316912b060
commit 0cdad77490
6 changed files with 220 additions and 189 deletions

View File

@ -4,6 +4,12 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v2.1.3-SNAPSHOT] - 2023-07-25
**Enhancement**
- [#25433] Added spinner during resource creation
## [v2.1.2] - 2023-03-10 ## [v2.1.2] - 2023-03-10
**Bug fixes** **Bug fixes**

View File

@ -7,13 +7,13 @@
<parent> <parent>
<artifactId>maven-parent</artifactId> <artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId> <groupId>org.gcube.tools</groupId>
<version>1.1.0</version> <version>1.2.0</version>
<relativePath /> <relativePath />
</parent> </parent>
<groupId>org.gcube.portlets.widgets</groupId> <groupId>org.gcube.portlets.widgets</groupId>
<artifactId>ckan-metadata-publisher-widget</artifactId> <artifactId>ckan-metadata-publisher-widget</artifactId>
<version>2.1.2</version> <version>2.1.3-SNAPSHOT</version>
<name>gCube Ckan metadata publisher widget</name> <name>gCube Ckan metadata publisher widget</name>
<description> <description>

View File

@ -1,13 +1,20 @@
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.icons; package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.icons;
import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ClientBundle; import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.ImageResource; import com.google.gwt.resources.client.ImageResource;
public interface Images extends ClientBundle { public interface Images extends ClientBundle {
/** The Constant ICONS. */
public static final Images ICONS = GWT.create(Images.class);
@Source("file.png") @Source("file.png")
ImageResource fileIcon(); ImageResource fileIcon();
@Source("folder.png") @Source("folder.png")
ImageResource folderIcon(); ImageResource folderIcon();
@Source("loading.gif")
ImageResource loading();
} }

View File

@ -3,6 +3,7 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.resources;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherService; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherService;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherServiceAsync; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherServiceAsync;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.AddResourceEvent; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.AddResourceEvent;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils.LoaderIcon;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
import com.github.gwtbootstrap.client.ui.AlertBlock; import com.github.gwtbootstrap.client.ui.AlertBlock;
@ -23,6 +24,7 @@ import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window; import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.Widget;
/** /**
@ -57,6 +59,7 @@ public class AddResourceToDataset extends Composite{
@UiField Button goToDatasetButton; @UiField Button goToDatasetButton;
@UiField ControlGroup urlControlGroup; @UiField ControlGroup urlControlGroup;
@UiField ControlGroup nameControlGroup; @UiField ControlGroup nameControlGroup;
@UiField FlowPanel infoPanel;
public AddResourceToDataset(HandlerManager eventBus, String datasetId, String datasetTitle, String datasetOrg, String owner, final String datasetUrl) { public AddResourceToDataset(HandlerManager eventBus, String datasetId, String datasetTitle, String datasetOrg, String owner, final String datasetUrl) {
initWidget(uiBinder.createAndBindUi(this)); initWidget(uiBinder.createAndBindUi(this));
@ -130,11 +133,15 @@ public class AddResourceToDataset extends Composite{
// disable add button // disable add button
addResourceButton.setEnabled(false); addResourceButton.setEnabled(false);
LoaderIcon loader = new LoaderIcon("Adding resource, please wait...");
infoPanel.add(loader);
// try to create // try to create
ckanServices.addResourceToDataset(resource, datasetId, new AsyncCallback<ResourceElementBean>() { ckanServices.addResourceToDataset(resource, datasetId, new AsyncCallback<ResourceElementBean>() {
@Override @Override
public void onSuccess(ResourceElementBean result) { public void onSuccess(ResourceElementBean result) {
infoPanel.clear();
if(result != null){ if(result != null){
showAlert("Resource created correctly", AlertType.SUCCESS); showAlert("Resource created correctly", AlertType.SUCCESS);
@ -153,7 +160,7 @@ public class AddResourceToDataset extends Composite{
@Override @Override
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
infoPanel.clear();
showAlert("Unable to add this resource, sorry. Error is: " + caught.getMessage(), AlertType.ERROR); showAlert("Unable to add this resource, sorry. Error is: " + caught.getMessage(), AlertType.ERROR);
} }

View File

@ -59,8 +59,10 @@
</b:Legend> </b:Legend>
<b:Alert type="INFO" close="false">The URL of the resource you are <b:Alert type="INFO" close="false">The URL of the resource you are
publishing (only HTTPS URLs are allowed). If your resource is a file that you own on your publishing (only HTTPS URLs are allowed). If your resource is a
desktop, please upload that file to your workspace and generate a file that you own on your
desktop, please upload that file to your
workspace and generate a
public URL for that file.</b:Alert> public URL for that file.</b:Alert>
<b:ControlGroup ui:field="urlControlGroup"> <b:ControlGroup ui:field="urlControlGroup">
@ -108,6 +110,9 @@
<b:Button title="Add resource" ui:field="addResourceButton" <b:Button title="Add resource" ui:field="addResourceButton"
type="PRIMARY">Add</b:Button> type="PRIMARY">Add</b:Button>
<g:FlowPanel ui:field="infoPanel">
</g:FlowPanel>
</b:Fieldset> </b:Fieldset>
</b:Form> </b:Form>

View File

@ -50,10 +50,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.liferay.portal.service.UserLocalServiceUtil; import com.liferay.portal.service.UserLocalServiceUtil;
/** /**
* Server side of the data publisher. * Server side of the data publisher.
*
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/ */
public class CKANPublisherServicesImpl extends RemoteServiceServlet implements CKanPublisherService { public class CKANPublisherServicesImpl extends RemoteServiceServlet implements CKanPublisherService {
@ -61,7 +60,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
private static final long serialVersionUID = 7252248774050361697L; private static final long serialVersionUID = 7252248774050361697L;
// Logger // Logger
//private static final org.slf4j.Logger logger = LoggerFactory.getLogger(CKANPublisherServicesImpl.class); // private static final org.slf4j.Logger logger =
// LoggerFactory.getLogger(CKANPublisherServicesImpl.class);
private static final Logger logger = LoggerFactory.getLogger(CKANPublisherServicesImpl.class); private static final Logger logger = LoggerFactory.getLogger(CKANPublisherServicesImpl.class);
private static final String ITEM_URL_FIELD = "Item URL"; private static final String ITEM_URL_FIELD = "Item URL";
private static final String SYS_TYPE = "system:type"; private static final String SYS_TYPE = "system:type";
@ -70,7 +70,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
// map <orgName, scope> // map <orgName, scope>
private ConcurrentHashMap<String, String> mapOrganizationScope = new ConcurrentHashMap<String, String>(); private ConcurrentHashMap<String, String> mapOrganizationScope = new ConcurrentHashMap<String, String>();
/** /**
* Dev mode set contexts. * Dev mode set contexts.
*/ */
@ -94,17 +93,20 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
DataCatalogue instance = null; DataCatalogue instance = null;
String scopeInWhichDiscover = null; String scopeInWhichDiscover = null;
try { 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); logger.debug("Discovering ckan instance into scope " + scopeInWhichDiscover);
instance = DataCatalogueFactory.getFactory().getUtilsPerScope(scopeInWhichDiscover); instance = DataCatalogueFactory.getFactory().getUtilsPerScope(scopeInWhichDiscover);
} catch (Exception e) { } catch (Exception e) {
logger.warn("Unable to retrieve ckan utils in scope " + scopeInWhichDiscover + ". Error is " + e.getLocalizedMessage()); logger.warn("Unable to retrieve ckan utils in scope " + scopeInWhichDiscover + ". Error is "
+ e.getLocalizedMessage());
} }
return instance; return instance;
} }
/** /**
* Retrieve the list of organizations in which the user can publish (roles ADMIN/EDITOR). * Retrieve the list of organizations in which the user can publish (roles
* ADMIN/EDITOR).
* *
* @param username the username * @param username the username
* @param scope the scope * @param scope the scope
@ -112,22 +114,24 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
* @throws UserManagementSystemException the user management system exception * @throws UserManagementSystemException the user management system exception
* @throws GroupRetrievalFault the group retrieval fault * @throws GroupRetrievalFault the group retrieval fault
*/ */
private List<OrganizationBean> getUserOrganizationsListAdmin(String username, String scope) throws UserManagementSystemException, GroupRetrievalFault { private List<OrganizationBean> getUserOrganizationsListAdmin(String username, String scope)
throws UserManagementSystemException, GroupRetrievalFault {
logger.debug("Request for user " + username + " organizations list"); logger.debug("Request for user " + username + " organizations list");
List<OrganizationBean> orgsName = new ArrayList<OrganizationBean>(); List<OrganizationBean> orgsName = new ArrayList<OrganizationBean>();
HttpSession httpSession = getThreadLocalRequest().getSession(); HttpSession httpSession = getThreadLocalRequest().getSession();
String keyPerScope = CatalogueUtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_ORGANIZATIONS_PUBLISH_KEY, scope); String keyPerScope = CatalogueUtilMethods
.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_ORGANIZATIONS_PUBLISH_KEY, scope);
if (httpSession.getAttribute(keyPerScope) != null) { if (httpSession.getAttribute(keyPerScope) != null) {
orgsName = (List<OrganizationBean>) httpSession.getAttribute(keyPerScope); orgsName = (List<OrganizationBean>) httpSession.getAttribute(keyPerScope);
logger.info("List of organizations was into session " + orgsName); logger.info("List of organizations was into session " + orgsName);
} } else {
else{
String gatewayURL = GenericUtils.getGatewayClientHostname(getThreadLocalRequest()); String gatewayURL = GenericUtils.getGatewayClientHostname(getThreadLocalRequest());
logger.info("The Gateway URL is: " + gatewayURL); logger.info("The Gateway URL is: " + gatewayURL);
CatalogueRoleManager.getHighestRole(scope, username, GenericUtils.getGroupFromScope(scope).getGroupName(), this, orgsName, gatewayURL); CatalogueRoleManager.getHighestRole(scope, username, GenericUtils.getGroupFromScope(scope).getGroupName(),
this, orgsName, gatewayURL);
httpSession.setAttribute(keyPerScope, orgsName); httpSession.setAttribute(keyPerScope, orgsName);
logger.info("Organizations name for user " + username + " has been saved into session " + orgsName); logger.info("Organizations name for user " + username + " has been saved into session " + orgsName);
} }
@ -144,8 +148,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
try { try {
UserLocalServiceUtil.getService(); UserLocalServiceUtil.getService();
return true; return true;
} } catch (com.liferay.portal.kernel.bean.BeanLocatorException ex) {
catch (com.liferay.portal.kernel.bean.BeanLocatorException ex) {
logger.trace("Development Mode ON"); logger.trace("Development Mode ON");
return false; return false;
} }
@ -155,12 +158,12 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
* Gets the workspace from storage hub. * Gets the workspace from storage hub.
* *
* @return the workspace from storage hub * @return the workspace from storage hub
* @throws Exception * @throws Exception the exception
* the exception
*/ */
protected Workspace getWorkspaceFromStorageHub() throws Exception { protected Workspace getWorkspaceFromStorageHub() throws Exception {
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest()); GCubeUser user = PortalContext.getConfiguration().getCurrentUser(this.getThreadLocalRequest());
StorageHubWrapper storageHubWrapper = WorkspaceUtils.getStorageHubWrapper(this.getThreadLocalRequest(), null, user); StorageHubWrapper storageHubWrapper = WorkspaceUtils.getStorageHubWrapper(this.getThreadLocalRequest(), null,
user);
return storageHubWrapper.getWorkspace(); return storageHubWrapper.getWorkspace();
} }
@ -190,7 +193,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
HttpSession httpSession = getThreadLocalRequest().getSession(); HttpSession httpSession = getThreadLocalRequest().getSession();
String scope = GenericUtils.getScopeFromClientUrl(getThreadLocalRequest()); String scope = GenericUtils.getScopeFromClientUrl(getThreadLocalRequest());
logger.info("Request for CKAN licenses for scope " + scope); logger.info("Request for CKAN licenses for scope " + scope);
String keyPerScope = CatalogueUtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_LICENSES_KEY, scope); String keyPerScope = CatalogueUtilMethods
.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_LICENSES_KEY, scope);
// if(!isWithinPortal()){ // if(!isWithinPortal()){
// logger.info("DEV MODE returning funny licenses..."); // logger.info("DEV MODE returning funny licenses...");
@ -203,8 +207,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
if (httpSession.getAttribute(keyPerScope) != null) { if (httpSession.getAttribute(keyPerScope) != null) {
licensesBean = (List<LicenseBean>) httpSession.getAttribute(keyPerScope); licensesBean = (List<LicenseBean>) httpSession.getAttribute(keyPerScope);
logger.info("List of licenses was into session"); logger.info("List of licenses was into session");
} } else {
else{
List<CkanLicense> licenses = getCatalogue(scope).getLicenses(); List<CkanLicense> licenses = getCatalogue(scope).getLicenses();
licensesBean = new ArrayList<LicenseBean>(); licensesBean = new ArrayList<LicenseBean>();
for (CkanLicense license : licenses) { for (CkanLicense license : licenses) {
@ -215,7 +218,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
Collections.sort(licensesBean, new Comparator<LicenseBean>() { Collections.sort(licensesBean, new Comparator<LicenseBean>() {
public int compare(LicenseBean l1, LicenseBean l2) { public int compare(LicenseBean l1, LicenseBean l2) {
return l1.getTitle().compareTo(l2.getTitle()); return l1.getTitle().compareTo(l2.getTitle());
}}); }
});
httpSession.setAttribute(keyPerScope, licensesBean); httpSession.setAttribute(keyPerScope, licensesBean);
logger.info("List of licenses has been saved into session"); logger.info("List of licenses has been saved into session");
@ -224,7 +228,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
return licensesBean; return licensesBean;
} }
/** /**
* Gets the dataset bean. * Gets the dataset bean.
* *
@ -246,8 +249,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
String scope = GenericUtils.getScopeFromClientUrl(getThreadLocalRequest()); String scope = GenericUtils.getScopeFromClientUrl(getThreadLocalRequest());
logger.debug("Scope recovered from session is " + scope); logger.debug("Scope recovered from session is " + scope);
logger.debug("Request dataset metadata bean for folder with id " + folderId logger.debug(
+ " whose owner is " + userName); "Request dataset metadata bean for folder with id " + folderId + " whose owner is " + userName);
UserManager liferUserManager = new LiferayUserManager(); UserManager liferUserManager = new LiferayUserManager();
GCubeUser userOwner = liferUserManager.getUserByUsername(userName); GCubeUser userOwner = liferUserManager.getUserByUsername(userName);
@ -406,33 +409,22 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
} }
} }
String datasetId = utils.createCkanDatasetMultipleCustomFields(userName, String datasetId = utils.createCkanDatasetMultipleCustomFields(userName, title, null, organizationNameOrId,
title, author, authorMail, maintainer, maintainerMail, version, description, licenseId, listOfTags,
null, customFields, resources, setPublic, true, true);
organizationNameOrId,
author,
authorMail,
maintainer,
maintainerMail,
version,
description,
licenseId,
listOfTags,
customFields,
resources,
setPublic,
true,
true);
if (datasetId != null) { if (datasetId != null) {
logger.info("Dataset created!"); logger.info("Dataset created!");
toCreate.setId(datasetId); toCreate.setId(datasetId);
//#23491 Building the go to the item to "Catalogue Portlet URL" (instead of URI Resolver URL) // #23491 Building the go to the item to "Catalogue Portlet URL" (instead of URI
// Resolver URL)
String catalogueURL = utils.getPortletUrl(); String catalogueURL = utils.getPortletUrl();
// logger.debug("Returning catalogueURL: "+catalogueURL);
// logger.debug("Returning datasetId: "+datasetId);
toCreate.setSource(String.format("%s?path=/dataset/%s", catalogueURL, datasetId)); toCreate.setSource(String.format("%s?path=/dataset/%s", catalogueURL, datasetId));
logger.debug("Returning getSource(): " + toCreate.getSource());
logger.debug("Returning dataset: " + toCreate); logger.debug("Returning dataset: " + toCreate);
// #24744 Returning lazy object // #24744 Returning lazy object
@ -476,22 +468,19 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
logger.info("called addResourceToDataset"); logger.info("called addResourceToDataset");
devModeSetContexts(); devModeSetContexts();
String username = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername(); String username = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername();
logger.debug("Incoming request for creating new resource for dataset with id " + datasetId + " and organization name of the dataset is " + resource.getOrganizationNameDatasetParent()); logger.debug("Incoming request for creating new resource for dataset with id " + datasetId
+ " and organization name of the dataset is " + resource.getOrganizationNameDatasetParent());
logger.debug("Owner is " + username + " and resource is " + resource); logger.debug("Owner is " + username + " and resource is " + resource);
ResourceBean resourceBean = new ResourceBean( ResourceBean resourceBean = new ResourceBean(resource.getUrl(), resource.getName(), resource.getDescription(),
resource.getUrl(), null, username, datasetId, null);
resource.getName(),
resource.getDescription(),
null,
username,
datasetId,
null);
// get the scope in which we should discover the ckan instance given the organization name in which the dataset was created // get the scope in which we should discover the ckan instance given the
// organization name in which the dataset was created
String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent()); String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent());
DataCatalogue catalogue = getCatalogue(scope); DataCatalogue catalogue = getCatalogue(scope);
String resourceId = catalogue.addResourceToDataset(resourceBean, resource.getOrganizationNameDatasetParent(), username); String resourceId = catalogue.addResourceToDataset(resourceBean, resource.getOrganizationNameDatasetParent(),
username);
if (resourceId != null) { if (resourceId != null) {
logger.info("Resource " + resource.getName() + " is now available"); logger.info("Resource " + resource.getName() + " is now available");
@ -517,7 +506,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
boolean deleted = false; boolean deleted = false;
devModeSetContexts(); devModeSetContexts();
try { try {
// get the scope in which we should discover the ckan instance given the organization name in which the dataset was created // get the scope in which we should discover the ckan instance given the
// organization name in which the dataset was created
String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent()); String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent());
DataCatalogue catalogue = getCatalogue(scope); DataCatalogue catalogue = getCatalogue(scope);
String username = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername(); String username = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername();
@ -573,7 +563,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
try { try {
String scopeFromOrgName = getScopeFromOrgName(orgName); String scopeFromOrgName = getScopeFromOrgName(orgName);
String idFromTitle = CatalogueUtilMethods.fromProductTitleToName(title); String idFromTitle = CatalogueUtilMethods.fromProductTitleToName(title);
logger.debug("Evaluating if dataset with id " + title + " in context " + scopeFromOrgName + " already exists"); logger.debug(
"Evaluating if dataset with id " + title + " in context " + scopeFromOrgName + " already exists");
return getCatalogue(scopeFromOrgName).existProductWithNameOrId(idFromTitle); return getCatalogue(scopeFromOrgName).existProductWithNameOrId(idFromTitle);
} catch (Exception e) { } catch (Exception e) {
logger.error("Unable to check if such a dataset id already exists", e); logger.error("Unable to check if such a dataset id already exists", e);
@ -582,12 +573,14 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
} }
/** /**
* The method tries to retrieve the scope related to the organization using the map first, * The method tries to retrieve the scope related to the organization using the
* if no match is found, it retrieves such information by using liferay * map first, if no match is found, it retrieves such information by using
* liferay
*/ */
private String getScopeFromOrgName(String orgName) { private String getScopeFromOrgName(String orgName) {
logger.info("Request for scope related to orgName " + orgName + " [map that will be used is " + mapOrganizationScope.toString() + "]"); logger.info("Request for scope related to orgName " + orgName + " [map that will be used is "
+ mapOrganizationScope.toString() + "]");
if (orgName == null || orgName.isEmpty()) if (orgName == null || orgName.isEmpty())
throw new IllegalArgumentException("orgName cannot be empty or null!"); throw new IllegalArgumentException("orgName cannot be empty or null!");
@ -601,7 +594,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
String evaluatedScope = GenericUtils.retrieveScopeFromOrganizationName(orgName); String evaluatedScope = GenericUtils.retrieveScopeFromOrganizationName(orgName);
// see #20801 // see #20801
if (evaluatedScope == null || evaluatedScope.isEmpty()) { if (evaluatedScope == null || evaluatedScope.isEmpty()) {
logger.warn("Scope detected for OrganizationName: "+orgName+" is null or empty, skipping filling 'mapOrganizationScope' and returning null"); logger.warn("Scope detected for OrganizationName: " + orgName
+ " is null or empty, skipping filling 'mapOrganizationScope' and returning null");
return toReturn; return toReturn;
} }
mapOrganizationScope.put(orgName, evaluatedScope); mapOrganizationScope.put(orgName, evaluatedScope);
@ -640,10 +634,12 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
// get http session // get http session
HttpSession httpSession = getThreadLocalRequest().getSession(); HttpSession httpSession = getThreadLocalRequest().getSession();
String scope = orgName != null ? getScopeFromOrgName(orgName) : GenericUtils.getScopeFromClientUrl(getThreadLocalRequest()); String scope = orgName != null ? getScopeFromOrgName(orgName)
: GenericUtils.getScopeFromClientUrl(getThreadLocalRequest());
// check if they are in session // check if they are in session
String keyPerScopeGroups = CatalogueUtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_GROUPS_MEMBER, scope); String keyPerScopeGroups = CatalogueUtilMethods
.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_GROUPS_MEMBER, scope);
if (httpSession.getAttribute(keyPerScopeGroups) != null) { if (httpSession.getAttribute(keyPerScopeGroups) != null) {
toReturn = (List<OrganizationBean>) httpSession.getAttribute(keyPerScopeGroups); toReturn = (List<OrganizationBean>) httpSession.getAttribute(keyPerScopeGroups);
@ -655,17 +651,20 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
DataCatalogue catalogue = getCatalogue(scope); DataCatalogue catalogue = getCatalogue(scope);
// Fixing Incident #12563 // Fixing Incident #12563
if (username != null && !username.isEmpty()) { if (username != null && !username.isEmpty()) {
Map<String, Map<CkanGroup, RolesCkanGroupOrOrg>> mapRoleGroup = catalogue.getUserRoleByGroup(username); Map<String, Map<CkanGroup, RolesCkanGroupOrOrg>> mapRoleGroup = catalogue
.getUserRoleByGroup(username);
Set<Entry<String, Map<CkanGroup, RolesCkanGroupOrOrg>>> set = mapRoleGroup.entrySet(); Set<Entry<String, Map<CkanGroup, RolesCkanGroupOrOrg>>> set = mapRoleGroup.entrySet();
for (Entry<String, Map<CkanGroup, RolesCkanGroupOrOrg>> entry : set) { for (Entry<String, Map<CkanGroup, RolesCkanGroupOrOrg>> entry : set) {
Set<Entry<CkanGroup, RolesCkanGroupOrOrg>> subSet = entry.getValue().entrySet(); Set<Entry<CkanGroup, RolesCkanGroupOrOrg>> subSet = entry.getValue().entrySet();
for (Entry<CkanGroup, RolesCkanGroupOrOrg> subEntry : subSet) { for (Entry<CkanGroup, RolesCkanGroupOrOrg> subEntry : subSet) {
toReturn.add(new OrganizationBean(subEntry.getKey().getTitle(), subEntry.getKey().getName(), false)); toReturn.add(new OrganizationBean(subEntry.getKey().getTitle(),
subEntry.getKey().getName(), false));
} }
} }
httpSession.setAttribute(keyPerScopeGroups, toReturn); httpSession.setAttribute(keyPerScopeGroups, toReturn);
} else } else
logger.warn("The API_KEY for "+username+ " is null or empty in the catalogue: "+catalogue.getCatalogueUrl()); logger.warn("The API_KEY for " + username + " is null or empty in the catalogue: "
+ catalogue.getCatalogueUrl());
} catch (Exception e) { } catch (Exception e) {
logger.error("Error on recovery the user groups for " + username, e); logger.error("Error on recovery the user groups for " + username, e);
} }
@ -677,7 +676,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
return toReturn; return toReturn;
} }
/** /**
* Checks if is publisher user. * Checks if is publisher user.
* *
@ -704,11 +702,15 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
String scopePerCurrentUrl = GenericUtils.getScopeFromClientUrl(getThreadLocalRequest()); String scopePerCurrentUrl = GenericUtils.getScopeFromClientUrl(getThreadLocalRequest());
// get key per scope // get key per scope
String keyPerScopeRole = CatalogueUtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_HIGHEST_ROLE, scopePerCurrentUrl); String keyPerScopeRole = CatalogueUtilMethods
String keyPerScopeOrganizations = CatalogueUtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_ORGANIZATIONS_PUBLISH_KEY, scopePerCurrentUrl); .concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_HIGHEST_ROLE, scopePerCurrentUrl);
String keyPerScopeGroups = CatalogueUtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_GROUPS_MEMBER, scopePerCurrentUrl); String keyPerScopeOrganizations = CatalogueUtilMethods.concatenateSessionKeyScope(
SessionCatalogueAttributes.CKAN_ORGANIZATIONS_PUBLISH_KEY, scopePerCurrentUrl);
String keyPerScopeGroups = CatalogueUtilMethods
.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_GROUPS_MEMBER, scopePerCurrentUrl);
// check if this information was already into session(true means the user has at least in one org // check if this information was already into session(true means the user has at
// least in one org
// the role editor), false that he is just a member so he cannot publish // the role editor), false that he is just a member so he cannot publish
RolesCkanGroupOrOrg role = (RolesCkanGroupOrOrg) httpSession.getAttribute(keyPerScopeRole); RolesCkanGroupOrOrg role = (RolesCkanGroupOrOrg) httpSession.getAttribute(keyPerScopeRole);
@ -720,16 +722,20 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
try { try {
GroupManager gm = new LiferayGroupManager(); GroupManager gm = new LiferayGroupManager();
String groupName = gm.getGroup(gm.getGroupIdFromInfrastructureScope(scopePerCurrentUrl)).getGroupName(); String groupName = gm.getGroup(gm.getGroupIdFromInfrastructureScope(scopePerCurrentUrl))
.getGroupName();
// we build up also a list that keeps track of the scopes (orgs) in which the user has role ADMIN/EDITOR // we build up also a list that keeps track of the scopes (orgs) in which the
// user has role ADMIN/EDITOR
List<OrganizationBean> orgsInWhichAtLeastEditorRole = new ArrayList<OrganizationBean>(); List<OrganizationBean> orgsInWhichAtLeastEditorRole = new ArrayList<OrganizationBean>();
String gatewayURL = GenericUtils.getGatewayClientHostname(getThreadLocalRequest()); String gatewayURL = GenericUtils.getGatewayClientHostname(getThreadLocalRequest());
logger.info("The Gateway URL is: " + gatewayURL); logger.info("The Gateway URL is: " + gatewayURL);
role = CatalogueRoleManager.getHighestRole(scopePerCurrentUrl, username, groupName, this, orgsInWhichAtLeastEditorRole, gatewayURL); role = CatalogueRoleManager.getHighestRole(scopePerCurrentUrl, username, groupName, this,
orgsInWhichAtLeastEditorRole, gatewayURL);
// if he is an admin/editor preload: // if he is an admin/editor preload:
// 1) organizations in which he can publish (the widget will find these info in session) // 1) organizations in which he can publish (the widget will find these info in
// session)
if (!role.equals(RolesCkanGroupOrOrg.MEMBER)) { if (!role.equals(RolesCkanGroupOrOrg.MEMBER)) {
httpSession.setAttribute(keyPerScopeOrganizations, orgsInWhichAtLeastEditorRole); httpSession.setAttribute(keyPerScopeOrganizations, orgsInWhichAtLeastEditorRole);
String orgName = scopePerCurrentUrl.split("/")[scopePerCurrentUrl.split("/").length - 1]; String orgName = scopePerCurrentUrl.split("/")[scopePerCurrentUrl.split("/").length - 1];