#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,18 +50,18 @@ 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 {
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.
*/ */
@ -80,7 +79,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
GenericUtils.getCurrentContext(getThreadLocalRequest(), true); GenericUtils.getCurrentContext(getThreadLocalRequest(), true);
GenericUtils.getCurrentToken(getThreadLocalRequest(), true); GenericUtils.getCurrentToken(getThreadLocalRequest(), true);
} }
} }
/** /**
@ -89,45 +88,50 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
* @param scope if it is null it is evaluated from the session * @param scope if it is null it is evaluated from the session
* @return the catalogue * @return the catalogue
*/ */
public DataCatalogue getCatalogue(String scope){ public DataCatalogue getCatalogue(String scope) {
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
* @return the list of organizations * @return the list of organizations
* @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,23 +148,22 @@ 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;
} }
} }
/** /**
* 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,8 +193,9 @@ 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...");
// List<LicenseBean> licenses = new ArrayList<LicenseBean>(); // List<LicenseBean> licenses = new ArrayList<LicenseBean>();
@ -200,11 +204,10 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
// } // }
List<LicenseBean> licensesBean = null; List<LicenseBean> licensesBean = null;
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) {
@ -212,10 +215,11 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
} }
// sort the list // sort the list
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");
@ -223,7 +227,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
return licensesBean; return licensesBean;
} }
/** /**
* Gets the dataset bean. * Gets the dataset bean.
@ -233,21 +236,21 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
* @throws Exception the exception * @throws Exception the exception
*/ */
@Override @Override
public DatasetBean getDatasetBean(String folderId) throws Exception{ public DatasetBean getDatasetBean(String folderId) throws Exception {
DatasetBean bean = null; DatasetBean bean = null;
String userName = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername(); String userName = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername();
logger.info("DatasetBean request for " + folderId + " and " + userName); logger.info("DatasetBean request for " + folderId + " and " + userName);
if(isWithinPortal()){ if (isWithinPortal()) {
try{ try {
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);
@ -268,21 +271,21 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
bean.setTagsVocabulary(discoverTagsVocabulary(scope)); bean.setTagsVocabulary(discoverTagsVocabulary(scope));
// if the request comes from the workspace // if the request comes from the workspace
if(folderId != null && !folderId.isEmpty()){ if (folderId != null && !folderId.isEmpty()) {
Workspace workspace = getWorkspaceFromStorageHub(); Workspace workspace = getWorkspaceFromStorageHub();
WorkspaceUtils.toWorkspaceResource(folderId, userName, bean, workspace); WorkspaceUtils.toWorkspaceResource(folderId, userName, bean, workspace);
} }
}catch(Exception e){ } catch (Exception e) {
logger.error("Error while retrieving bean information", e); logger.error("Error while retrieving bean information", e);
throw new Exception("Error while retrieving basic information " + e.getMessage()); throw new Exception("Error while retrieving basic information " + e.getMessage());
} }
}else{ } else {
logger.info("DEV MODE DETECTED"); logger.info("DEV MODE DETECTED");
GenericUtils.getCurrentToken(getThreadLocalRequest(), true); GenericUtils.getCurrentToken(getThreadLocalRequest(), true);
try{ try {
bean = new DatasetBean(); bean = new DatasetBean();
bean.setId(folderId); bean.setId(folderId);
bean.setDescription("This is a fantastic description"); bean.setDescription("This is a fantastic description");
@ -295,19 +298,19 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
bean.setMaintainer("Francesco Mangiacrapa"); bean.setMaintainer("Francesco Mangiacrapa");
bean.setMaintainerEmail("francesco.mangiacrapa@isti.cnr.it"); bean.setMaintainerEmail("francesco.mangiacrapa@isti.cnr.it");
//UPDATED By Francesco // UPDATED By Francesco
String scope = GenericUtils.getCurrentContext(this.getThreadLocalRequest(), false); String scope = GenericUtils.getCurrentContext(this.getThreadLocalRequest(), false);
String vreName = scope.substring(scope.lastIndexOf("/")+1,scope.length()); String vreName = scope.substring(scope.lastIndexOf("/") + 1, scope.length());
logger.debug("In dev mode using the scope: "+scope+" and VRE name: "+vreName); logger.debug("In dev mode using the scope: " + scope + " and VRE name: " + vreName);
bean.setOrganizationList(Arrays.asList(new OrganizationBean(vreName, vreName.toLowerCase(), true))); bean.setOrganizationList(Arrays.asList(new OrganizationBean(vreName, vreName.toLowerCase(), true)));
bean.setOwnerIdentifier(userName); bean.setOwnerIdentifier(userName);
if(folderId != null && !folderId.isEmpty()){ if (folderId != null && !folderId.isEmpty()) {
Workspace workspace = getWorkspaceFromStorageHub(); Workspace workspace = getWorkspaceFromStorageHub();
WorkspaceUtils.toWorkspaceResource(folderId, userName, bean, workspace); WorkspaceUtils.toWorkspaceResource(folderId, userName, bean, workspace);
} }
}catch(Exception e){ } catch (Exception e) {
logger.error("Error while building bean into dev mode", e); logger.error("Error while building bean into dev mode", e);
throw new Exception("Error while retrieving basic information " + e.getMessage()); throw new Exception("Error while retrieving basic information " + e.getMessage());
} }
@ -323,15 +326,15 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
* @param context the context * @param context the context
* @return a list of tags vocabulary * @return a list of tags vocabulary
*/ */
private List<String> discoverTagsVocabulary(String context){ private List<String> discoverTagsVocabulary(String context) {
logger.debug("Looking for vocabulary of tags in this context " + 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); List<String> vocabulary = (List<String>) getThreadLocalRequest().getSession().getAttribute(keyPerVocabulary);
if(vocabulary == null){ if (vocabulary == null) {
vocabulary = DiscoverTagsList.discoverTagsList(context); vocabulary = DiscoverTagsList.discoverTagsList(context);
if(vocabulary != null) if (vocabulary != null)
getThreadLocalRequest().getSession().setAttribute(keyPerVocabulary, vocabulary); getThreadLocalRequest().getSession().setAttribute(keyPerVocabulary, vocabulary);
} }
@ -348,7 +351,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
* @throws Exception the exception * @throws Exception the exception
*/ */
@Override @Override
public List<String> getTagsForOrganization(String orgName) throws Exception{ public List<String> getTagsForOrganization(String orgName) throws Exception {
return discoverTagsVocabulary(getScopeFromOrgName(orgName)); return discoverTagsVocabulary(getScopeFromOrgName(orgName));
} }
@ -360,9 +363,9 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
* @throws Exception the exception * @throws Exception the exception
*/ */
@Override @Override
public DatasetBean createCKanDataset(DatasetBean toCreate) throws Exception{ public DatasetBean createCKanDataset(DatasetBean toCreate) throws Exception {
try{ try {
devModeSetContexts(); devModeSetContexts();
logger.info("Request for creating a dataset with these information " + toCreate); logger.info("Request for creating a dataset with these information " + toCreate);
String userName = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername(); String userName = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername();
@ -380,7 +383,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
Map<String, List<String>> customFields = toCreate.getCustomFields(); Map<String, List<String>> customFields = toCreate.getCustomFields();
// add Type for custom fields // add Type for custom fields
if(toCreate.getChosenType() != null) if (toCreate.getChosenType() != null)
customFields.put(SYS_TYPE, Arrays.asList(toCreate.getChosenType())); customFields.put(SYS_TYPE, Arrays.asList(toCreate.getChosenType()));
boolean setPublic = toCreate.getVisibility(); boolean setPublic = toCreate.getVisibility();
@ -388,9 +391,9 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
// get the list of resources and convert to ResourceBean // get the list of resources and convert to ResourceBean
List<ResourceBean> resources = null; List<ResourceBean> resources = null;
ResourceElementBean resourcesToAdd = toCreate.getResourceRoot(); ResourceElementBean resourcesToAdd = toCreate.getResourceRoot();
//converting to resources to be added // converting to resources to be added
if(resourcesToAdd != null){ if (resourcesToAdd != null) {
Workspace workspace = getWorkspaceFromStorageHub(); Workspace workspace = getWorkspaceFromStorageHub();
resources = WorkspaceUtils.toResources(toCreate, workspace, userName); resources = WorkspaceUtils.toResources(toCreate, workspace, userName);
} }
@ -398,63 +401,52 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
logger.debug("The user wants to publish in organization with name " + organizationNameOrId); logger.debug("The user wants to publish in organization with name " + organizationNameOrId);
String scope = getScopeFromOrgName(organizationNameOrId); String scope = getScopeFromOrgName(organizationNameOrId);
DataCatalogue utils = getCatalogue(scope); DataCatalogue utils = getCatalogue(scope);
if (!isWithinPortal()) { if (!isWithinPortal()) {
logger.debug("Should be added:"); logger.debug("Should be added:");
for (String key : customFields.keySet()) { for (String key : customFields.keySet()) {
logger.debug("Custom field with key: "+key+", value: "+customFields.get(key)); logger.debug("Custom field with key: " + key + ", value: " + customFields.get(key));
} }
} }
String datasetId = utils.createCkanDatasetMultipleCustomFields(userName,
title,
null,
organizationNameOrId,
author,
authorMail,
maintainer,
maintainerMail,
version,
description,
licenseId,
listOfTags,
customFields,
resources,
setPublic,
true,
true);
String datasetId = utils.createCkanDatasetMultipleCustomFields(userName, title, null, organizationNameOrId,
if(datasetId != null){ author, authorMail, maintainer, maintainerMail, version, description, licenseId, listOfTags,
customFields, resources, setPublic, true, true);
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
String catalogueURL = utils.getPortletUrl(); // Resolver URL)
toCreate.setSource(String.format("%s?path=/dataset/%s", catalogueURL,datasetId)); String catalogueURL = utils.getPortletUrl();
logger.debug("Returning dataset: "+toCreate); // logger.debug("Returning catalogueURL: "+catalogueURL);
// logger.debug("Returning datasetId: "+datasetId);
//#24744 Returning lazy object toCreate.setSource(String.format("%s?path=/dataset/%s", catalogueURL, datasetId));
logger.debug("Returning getSource(): " + toCreate.getSource());
logger.debug("Returning dataset: " + toCreate);
// #24744 Returning lazy object
toCreate.setGroups(null); toCreate.setGroups(null);
toCreate.setCustomFields(null); toCreate.setCustomFields(null);
toCreate.setGroupsForceCreation(null); toCreate.setGroupsForceCreation(null);
toCreate.setMetadataList(null); toCreate.setMetadataList(null);
toCreate.setOrganizationList(null); toCreate.setOrganizationList(null);
logger.info("Returning lazy dataset: "+toCreate); logger.info("Returning lazy dataset: " + toCreate);
//createdDatasetBean.getSource(); // createdDatasetBean.getSource();
//createdDatasetBean.getTitle(); // createdDatasetBean.getTitle();
// resourceForm = new AddResourceToDataset(eventBus, createdDatasetBean.getId(), // resourceForm = new AddResourceToDataset(eventBus, createdDatasetBean.getId(),
// createdDatasetBean.getTitle(), // createdDatasetBean.getTitle(),
// createdDatasetBean.getSelectedOrganization(), owner, datasetUrl); // createdDatasetBean.getSelectedOrganization(), owner, datasetUrl);
return toCreate; return toCreate;
}else{ } else {
logger.error("Failed to create the dataset"); logger.error("Failed to create the dataset");
} }
}catch(Exception e){ } catch (Exception e) {
logger.error("Error while creating item ", e); logger.error("Error while creating item ", e);
throw new Exception(e.getMessage()); throw new Exception(e.getMessage());
} }
@ -462,38 +454,35 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
return null; return null;
} }
/** /**
* Adds the resource to dataset. * Adds the resource to dataset.
* *
* @param resource the resource * @param resource the resource
* @param datasetId the dataset id * @param datasetId the dataset id
* @return the resource element bean * @return the resource element bean
* @throws Exception the exception * @throws Exception the exception
*/ */
@Override @Override
public ResourceElementBean addResourceToDataset(ResourceElementBean resource, String datasetId) throws Exception{ public ResourceElementBean addResourceToDataset(ResourceElementBean resource, String datasetId) throws Exception {
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");
// set its id and turn it to the client // set its id and turn it to the client
resource.setOriginalIdInWorkspace(resourceId); resource.setOriginalIdInWorkspace(resourceId);
@ -512,26 +501,27 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
* @throws Exception the exception * @throws Exception the exception
*/ */
@Override @Override
public boolean deleteResourceFromDataset(ResourceElementBean resource) throws Exception{ public boolean deleteResourceFromDataset(ResourceElementBean resource) throws Exception {
logger.debug("Request for deleting resource " + resource); logger.debug("Request for deleting resource " + resource);
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();
deleted = catalogue.deleteResourceFromDataset(resource.getOriginalIdInWorkspace(),username); deleted = catalogue.deleteResourceFromDataset(resource.getOriginalIdInWorkspace(), username);
if(deleted){ if (deleted) {
logger.info("Resource described by " + resource + " deleted"); logger.info("Resource described by " + resource + " deleted");
}else } else
logger.error("Resource described by " + resource + " NOT deleted"); logger.error("Resource described by " + resource + " NOT deleted");
}catch(Exception e){ } catch (Exception e) {
logger.error("Error while trying to delete resource described by " + resource, e); logger.error("Error while trying to delete resource described by " + resource, e);
throw new Exception("Error while trying to delete resource." + e.getMessage()); throw new Exception("Error while trying to delete resource." + e.getMessage());
} }
return deleted; return deleted;
} }
/** /**
@ -542,15 +532,15 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
* @throws Exception the exception * @throws Exception the exception
*/ */
@Override @Override
public List<MetaDataProfileBean> getProfiles(String orgName) throws Exception{ public List<MetaDataProfileBean> getProfiles(String orgName) throws Exception {
logger.debug("Requested profiles for products into orgName " + orgName); logger.debug("Requested profiles for products into orgName " + orgName);
List<MetaDataProfileBean> toReturn = new ArrayList<MetaDataProfileBean>(); List<MetaDataProfileBean> toReturn = new ArrayList<MetaDataProfileBean>();
try{ try {
String evaluatedScope = getScopeFromOrgName(orgName); String evaluatedScope = getScopeFromOrgName(orgName);
logger.debug("Evaluated scope is " + evaluatedScope); logger.debug("Evaluated scope is " + evaluatedScope);
toReturn = MetadataDiscovery.getMetadataProfilesList(evaluatedScope, getThreadLocalRequest()); toReturn = MetadataDiscovery.getMetadataProfilesList(evaluatedScope, getThreadLocalRequest());
}catch(Exception e){ } catch (Exception e) {
logger.error("Failed to retrieve profiles for scope coming from organization name " + orgName, e); logger.error("Failed to retrieve profiles for scope coming from organization name " + orgName, e);
throw e; throw e;
} }
@ -561,57 +551,61 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
/** /**
* Dataset id already exists. * Dataset id already exists.
* *
* @param title the title * @param title the title
* @param orgName the org name * @param orgName the org name
* @return true, if successful * @return true, if successful
* @throws Exception the exception * @throws Exception the exception
*/ */
@Override @Override
public boolean datasetIdAlreadyExists(String title, String orgName) throws Exception{ public boolean datasetIdAlreadyExists(String title, String orgName) throws Exception {
if(title == null || title.isEmpty()) if (title == null || title.isEmpty())
return true; // it's an error somehow return true; // it's an error somehow
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);
throw new Exception("Unable to check if such a dataset id already exists " + e.getMessage()); throw new Exception("Unable to check if such a dataset id already exists " + e.getMessage());
} }
} }
/** /**
* 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 "
if(orgName == null || orgName.isEmpty()) + mapOrganizationScope.toString() + "]");
if (orgName == null || orgName.isEmpty())
throw new IllegalArgumentException("orgName cannot be empty or null!"); throw new IllegalArgumentException("orgName cannot be empty or null!");
String toReturn = null; String toReturn = null;
if(isWithinPortal()){ if (isWithinPortal()) {
if(mapOrganizationScope.containsKey(orgName)) { if (mapOrganizationScope.containsKey(orgName)) {
toReturn = mapOrganizationScope.get(orgName); toReturn = mapOrganizationScope.get(orgName);
}else{ } else {
try{ try {
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);
toReturn = evaluatedScope; toReturn = evaluatedScope;
}catch(Exception e){ } catch (Exception e) {
logger.error("Failed to retrieve scope from OrgName for organization " + orgName, e); logger.error("Failed to retrieve scope from OrgName for organization " + orgName, e);
} }
} }
}else{ } else {
//UPDATED By FRANCESCO // UPDATED By FRANCESCO
toReturn = GenericUtils.getCurrentContext(this.getThreadLocalRequest(), false); toReturn = GenericUtils.getCurrentContext(this.getThreadLocalRequest(), false);
mapOrganizationScope.put(orgName, toReturn); mapOrganizationScope.put(orgName, toReturn);
} }
@ -630,54 +624,58 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
List<OrganizationBean> toReturn = new ArrayList<OrganizationBean>(); List<OrganizationBean> toReturn = new ArrayList<OrganizationBean>();
if(isWithinPortal()){ if (isWithinPortal()) {
GCubeUser user = GenericUtils.getCurrentUser(getThreadLocalRequest()); GCubeUser user = GenericUtils.getCurrentUser(getThreadLocalRequest());
String username = null; String username = null;
if(user!=null) if (user != null)
username = user.getUsername(); username = user.getUsername();
logger.debug("Request for user " + username + " groups. Organization name is " + orgName); logger.debug("Request for user " + username + " groups. Organization name is " + orgName);
// 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);
logger.info("Found user's groups in session " + toReturn); logger.info("Found user's groups in session " + toReturn);
}else{ } else {
//Fixing Incident #12563 // Fixing Incident #12563
try{ try {
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: "
}catch(Exception e){ + catalogue.getCatalogueUrl());
logger.error("Error on recovery the user groups for "+username, e); } catch (Exception e) {
logger.error("Error on recovery the user groups for " + username, e);
} }
} }
}else{ } else {
logger.warn("Dev mode detected"); logger.warn("Dev mode detected");
toReturn = Arrays.asList(); toReturn = Arrays.asList();
} }
return toReturn; return toReturn;
} }
/** /**
* Checks if is publisher user. * Checks if is publisher user.
* *
@ -686,17 +684,17 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
* @throws Exception the exception * @throws Exception the exception
*/ */
@Override @Override
public boolean isPublisherUser(boolean isWorkspaceRequest) throws Exception{ public boolean isPublisherUser(boolean isWorkspaceRequest) throws Exception {
String username = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername(); String username = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername();
logger.info("Checking if the user " + username + " can publish or not on the catalogue"); logger.info("Checking if the user " + username + " can publish or not on the catalogue");
if(!isWithinPortal()){ if (!isWithinPortal()) {
logger.warn("OUT FROM PORTAL DETECTED RETURNING TRUE"); logger.warn("OUT FROM PORTAL DETECTED RETURNING TRUE");
return true; return true;
} }
try{ try {
HttpSession httpSession = this.getThreadLocalRequest().getSession(); HttpSession httpSession = this.getThreadLocalRequest().getSession();
@ -704,38 +702,46 @@ 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);
// if the attribute was already set.. // if the attribute was already set..
if(role != null) if (role != null)
return !role.equals(RolesCkanGroupOrOrg.MEMBER); return !role.equals(RolesCkanGroupOrOrg.MEMBER);
else{ else {
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
if(!role.equals(RolesCkanGroupOrOrg.MEMBER)){ // session)
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];
httpSession.setAttribute(keyPerScopeGroups, getUserGroups(orgName)); httpSession.setAttribute(keyPerScopeGroups, getUserGroups(orgName));
} }
}catch(Exception e){ } catch (Exception e) {
logger.error("Unable to retrieve the role information for this user. Returning FALSE", e); logger.error("Unable to retrieve the role information for this user. Returning FALSE", e);
return false; return false;
} }
@ -747,7 +753,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
logger.info("Does the user have the right to publish on the catalogue? " + role); logger.info("Does the user have the right to publish on the catalogue? " + role);
return !role.equals(RolesCkanGroupOrOrg.MEMBER); return !role.equals(RolesCkanGroupOrOrg.MEMBER);
}catch(Exception e){ } catch (Exception e) {
logger.error("Failed to check the user's role", e); logger.error("Failed to check the user's role", e);
throw new Exception("Failed to check if you are an Administrator or Editor " + e.getMessage()); throw new Exception("Failed to check if you are an Administrator or Editor " + e.getMessage());
} }
@ -762,10 +768,10 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
*/ */
@Override @Override
public boolean isGeoJSONValid(String geoJson) throws Exception { public boolean isGeoJSONValid(String geoJson) throws Exception {
try{ try {
new ObjectMapper().readValue(geoJson, GeoJsonObject.class); new ObjectMapper().readValue(geoJson, GeoJsonObject.class);
return true; return true;
}catch(Exception e){ } catch (Exception e) {
throw new Exception("GeoJSON field with value '" + geoJson + "' seems not valid!"); throw new Exception("GeoJSON field with value '" + geoJson + "' seems not valid!");
} }
} }