#25433 Added spinner during resource creation, implemented
This commit is contained in:
parent
316912b060
commit
0cdad77490
|
@ -4,6 +4,12 @@
|
|||
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).
|
||||
|
||||
## [v2.1.3-SNAPSHOT] - 2023-07-25
|
||||
|
||||
**Enhancement**
|
||||
|
||||
- [#25433] Added spinner during resource creation
|
||||
|
||||
## [v2.1.2] - 2023-03-10
|
||||
|
||||
**Bug fixes**
|
||||
|
|
4
pom.xml
4
pom.xml
|
@ -7,13 +7,13 @@
|
|||
<parent>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
<version>1.1.0</version>
|
||||
<version>1.2.0</version>
|
||||
<relativePath />
|
||||
</parent>
|
||||
|
||||
<groupId>org.gcube.portlets.widgets</groupId>
|
||||
<artifactId>ckan-metadata-publisher-widget</artifactId>
|
||||
<version>2.1.2</version>
|
||||
<version>2.1.3-SNAPSHOT</version>
|
||||
<name>gCube Ckan metadata publisher widget</name>
|
||||
|
||||
<description>
|
||||
|
|
|
@ -1,13 +1,20 @@
|
|||
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.ImageResource;
|
||||
|
||||
public interface Images extends ClientBundle {
|
||||
|
||||
/** The Constant ICONS. */
|
||||
public static final Images ICONS = GWT.create(Images.class);
|
||||
|
||||
@Source("file.png")
|
||||
ImageResource fileIcon();
|
||||
|
||||
@Source("folder.png")
|
||||
ImageResource folderIcon();
|
||||
|
||||
@Source("loading.gif")
|
||||
ImageResource loading();
|
||||
}
|
||||
|
|
|
@ -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.CKanPublisherServiceAsync;
|
||||
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 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.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
/**
|
||||
|
@ -57,6 +59,7 @@ public class AddResourceToDataset extends Composite{
|
|||
@UiField Button goToDatasetButton;
|
||||
@UiField ControlGroup urlControlGroup;
|
||||
@UiField ControlGroup nameControlGroup;
|
||||
@UiField FlowPanel infoPanel;
|
||||
|
||||
public AddResourceToDataset(HandlerManager eventBus, String datasetId, String datasetTitle, String datasetOrg, String owner, final String datasetUrl) {
|
||||
initWidget(uiBinder.createAndBindUi(this));
|
||||
|
@ -130,11 +133,15 @@ public class AddResourceToDataset extends Composite{
|
|||
// disable add button
|
||||
addResourceButton.setEnabled(false);
|
||||
|
||||
LoaderIcon loader = new LoaderIcon("Adding resource, please wait...");
|
||||
infoPanel.add(loader);
|
||||
|
||||
// try to create
|
||||
ckanServices.addResourceToDataset(resource, datasetId, new AsyncCallback<ResourceElementBean>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(ResourceElementBean result) {
|
||||
infoPanel.clear();
|
||||
|
||||
if(result != null){
|
||||
showAlert("Resource created correctly", AlertType.SUCCESS);
|
||||
|
@ -153,7 +160,7 @@ public class AddResourceToDataset extends Composite{
|
|||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
|
||||
infoPanel.clear();
|
||||
showAlert("Unable to add this resource, sorry. Error is: " + caught.getMessage(), AlertType.ERROR);
|
||||
|
||||
}
|
||||
|
|
|
@ -59,8 +59,10 @@
|
|||
</b:Legend>
|
||||
|
||||
<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
|
||||
desktop, please upload that file to your workspace and generate a
|
||||
publishing (only HTTPS URLs are allowed). If your resource is 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>
|
||||
|
||||
<b:ControlGroup ui:field="urlControlGroup">
|
||||
|
@ -108,6 +110,9 @@
|
|||
<b:Button title="Add resource" ui:field="addResourceButton"
|
||||
type="PRIMARY">Add</b:Button>
|
||||
|
||||
<g:FlowPanel ui:field="infoPanel">
|
||||
</g:FlowPanel>
|
||||
|
||||
</b:Fieldset>
|
||||
</b:Form>
|
||||
|
||||
|
|
|
@ -50,18 +50,18 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Server side of the data publisher.
|
||||
*
|
||||
* @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;
|
||||
|
||||
// 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 String ITEM_URL_FIELD = "Item URL";
|
||||
private static final String SYS_TYPE = "system:type";
|
||||
|
@ -70,7 +70,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
// map <orgName, scope>
|
||||
private ConcurrentHashMap<String, String> mapOrganizationScope = new ConcurrentHashMap<String, String>();
|
||||
|
||||
|
||||
/**
|
||||
* Dev mode set contexts.
|
||||
*/
|
||||
|
@ -89,45 +88,50 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
* @param scope if it is null it is evaluated from the session
|
||||
* @return the catalogue
|
||||
*/
|
||||
public DataCatalogue getCatalogue(String scope){
|
||||
public DataCatalogue getCatalogue(String scope) {
|
||||
|
||||
DataCatalogue instance = null;
|
||||
String scopeInWhichDiscover = null;
|
||||
try{
|
||||
scopeInWhichDiscover = scope != null && !scope.isEmpty() ? scope : GenericUtils.getCurrentContext(getThreadLocalRequest(), false);
|
||||
try {
|
||||
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){
|
||||
logger.warn("Unable to retrieve ckan utils in scope " + scopeInWhichDiscover + ". Error is " + e.getLocalizedMessage());
|
||||
} catch (Exception e) {
|
||||
logger.warn("Unable to retrieve ckan utils in scope " + scopeInWhichDiscover + ". Error is "
|
||||
+ e.getLocalizedMessage());
|
||||
}
|
||||
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 scope the scope
|
||||
* @param scope the scope
|
||||
* @return the list of organizations
|
||||
* @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");
|
||||
List<OrganizationBean> orgsName = new ArrayList<OrganizationBean>();
|
||||
|
||||
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){
|
||||
orgsName = (List<OrganizationBean>)httpSession.getAttribute(keyPerScope);
|
||||
if (httpSession.getAttribute(keyPerScope) != null) {
|
||||
orgsName = (List<OrganizationBean>) httpSession.getAttribute(keyPerScope);
|
||||
logger.info("List of organizations was into session " + orgsName);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
String gatewayURL = GenericUtils.getGatewayClientHostname(getThreadLocalRequest());
|
||||
logger.info("The Gateway URL is: "+gatewayURL);
|
||||
CatalogueRoleManager.getHighestRole(scope, username, GenericUtils.getGroupFromScope(scope).getGroupName(), this, orgsName, gatewayURL);
|
||||
logger.info("The Gateway URL is: " + gatewayURL);
|
||||
CatalogueRoleManager.getHighestRole(scope, username, GenericUtils.getGroupFromScope(scope).getGroupName(),
|
||||
this, orgsName, gatewayURL);
|
||||
httpSession.setAttribute(keyPerScope, 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 {
|
||||
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;
|
||||
}
|
||||
|
@ -155,12 +158,12 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
* Gets the workspace from storage hub.
|
||||
*
|
||||
* @return the workspace from storage hub
|
||||
* @throws Exception
|
||||
* the exception
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
protected Workspace getWorkspaceFromStorageHub() throws Exception {
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -190,7 +193,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
HttpSession httpSession = getThreadLocalRequest().getSession();
|
||||
String scope = GenericUtils.getScopeFromClientUrl(getThreadLocalRequest());
|
||||
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()){
|
||||
// logger.info("DEV MODE returning funny licenses...");
|
||||
|
@ -200,11 +204,10 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
// }
|
||||
|
||||
List<LicenseBean> licensesBean = null;
|
||||
if(httpSession.getAttribute(keyPerScope) != null){
|
||||
licensesBean = (List<LicenseBean>)httpSession.getAttribute(keyPerScope);
|
||||
if (httpSession.getAttribute(keyPerScope) != null) {
|
||||
licensesBean = (List<LicenseBean>) httpSession.getAttribute(keyPerScope);
|
||||
logger.info("List of licenses was into session");
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
List<CkanLicense> licenses = getCatalogue(scope).getLicenses();
|
||||
licensesBean = new ArrayList<LicenseBean>();
|
||||
for (CkanLicense license : licenses) {
|
||||
|
@ -212,10 +215,11 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
}
|
||||
|
||||
// sort the list
|
||||
Collections.sort(licensesBean, new Comparator<LicenseBean>(){
|
||||
public int compare(LicenseBean l1, LicenseBean l2){
|
||||
Collections.sort(licensesBean, new Comparator<LicenseBean>() {
|
||||
public int compare(LicenseBean l1, LicenseBean l2) {
|
||||
return l1.getTitle().compareTo(l2.getTitle());
|
||||
}});
|
||||
}
|
||||
});
|
||||
|
||||
httpSession.setAttribute(keyPerScope, licensesBean);
|
||||
logger.info("List of licenses has been saved into session");
|
||||
|
@ -224,7 +228,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
return licensesBean;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the dataset bean.
|
||||
*
|
||||
|
@ -233,21 +236,21 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
* @throws Exception the exception
|
||||
*/
|
||||
@Override
|
||||
public DatasetBean getDatasetBean(String folderId) throws Exception{
|
||||
public DatasetBean getDatasetBean(String folderId) throws Exception {
|
||||
|
||||
DatasetBean bean = null;
|
||||
String userName = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername();
|
||||
|
||||
logger.info("DatasetBean request for " + folderId + " and " + userName);
|
||||
|
||||
if(isWithinPortal()){
|
||||
try{
|
||||
if (isWithinPortal()) {
|
||||
try {
|
||||
|
||||
String scope = GenericUtils.getScopeFromClientUrl(getThreadLocalRequest());
|
||||
|
||||
logger.debug("Scope recovered from session is " + scope);
|
||||
logger.debug("Request dataset metadata bean for folder with id " + folderId
|
||||
+ " whose owner is " + userName);
|
||||
logger.debug(
|
||||
"Request dataset metadata bean for folder with id " + folderId + " whose owner is " + userName);
|
||||
|
||||
UserManager liferUserManager = new LiferayUserManager();
|
||||
GCubeUser userOwner = liferUserManager.getUserByUsername(userName);
|
||||
|
@ -268,21 +271,21 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
bean.setTagsVocabulary(discoverTagsVocabulary(scope));
|
||||
|
||||
// if the request comes from the workspace
|
||||
if(folderId != null && !folderId.isEmpty()){
|
||||
if (folderId != null && !folderId.isEmpty()) {
|
||||
Workspace workspace = getWorkspaceFromStorageHub();
|
||||
WorkspaceUtils.toWorkspaceResource(folderId, userName, bean, workspace);
|
||||
}
|
||||
|
||||
}catch(Exception e){
|
||||
} catch (Exception e) {
|
||||
logger.error("Error while retrieving bean information", e);
|
||||
throw new Exception("Error while retrieving basic information " + e.getMessage());
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
|
||||
logger.info("DEV MODE DETECTED");
|
||||
GenericUtils.getCurrentToken(getThreadLocalRequest(), true);
|
||||
|
||||
try{
|
||||
try {
|
||||
bean = new DatasetBean();
|
||||
bean.setId(folderId);
|
||||
bean.setDescription("This is a fantastic description");
|
||||
|
@ -295,19 +298,19 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
bean.setMaintainer("Francesco Mangiacrapa");
|
||||
bean.setMaintainerEmail("francesco.mangiacrapa@isti.cnr.it");
|
||||
|
||||
//UPDATED By Francesco
|
||||
// UPDATED By Francesco
|
||||
String scope = GenericUtils.getCurrentContext(this.getThreadLocalRequest(), false);
|
||||
String vreName = scope.substring(scope.lastIndexOf("/")+1,scope.length());
|
||||
logger.debug("In dev mode using the scope: "+scope+" and VRE name: "+vreName);
|
||||
String vreName = scope.substring(scope.lastIndexOf("/") + 1, scope.length());
|
||||
logger.debug("In dev mode using the scope: " + scope + " and VRE name: " + vreName);
|
||||
bean.setOrganizationList(Arrays.asList(new OrganizationBean(vreName, vreName.toLowerCase(), true)));
|
||||
|
||||
bean.setOwnerIdentifier(userName);
|
||||
|
||||
if(folderId != null && !folderId.isEmpty()){
|
||||
if (folderId != null && !folderId.isEmpty()) {
|
||||
Workspace workspace = getWorkspaceFromStorageHub();
|
||||
WorkspaceUtils.toWorkspaceResource(folderId, userName, bean, workspace);
|
||||
}
|
||||
}catch(Exception e){
|
||||
} catch (Exception e) {
|
||||
logger.error("Error while building bean into dev mode", e);
|
||||
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
|
||||
* @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);
|
||||
String keyPerVocabulary = CatalogueUtilMethods.concatenateSessionKeyScope(TAGS_VOCABULARY_KEY, context);
|
||||
|
||||
List<String> vocabulary = (List<String>) getThreadLocalRequest().getSession().getAttribute(keyPerVocabulary);
|
||||
if(vocabulary == null){
|
||||
if (vocabulary == null) {
|
||||
vocabulary = DiscoverTagsList.discoverTagsList(context);
|
||||
if(vocabulary != null)
|
||||
if (vocabulary != null)
|
||||
getThreadLocalRequest().getSession().setAttribute(keyPerVocabulary, vocabulary);
|
||||
}
|
||||
|
||||
|
@ -348,7 +351,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
* @throws Exception the exception
|
||||
*/
|
||||
@Override
|
||||
public List<String> getTagsForOrganization(String orgName) throws Exception{
|
||||
public List<String> getTagsForOrganization(String orgName) throws Exception {
|
||||
return discoverTagsVocabulary(getScopeFromOrgName(orgName));
|
||||
}
|
||||
|
||||
|
@ -360,9 +363,9 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
* @throws Exception the exception
|
||||
*/
|
||||
@Override
|
||||
public DatasetBean createCKanDataset(DatasetBean toCreate) throws Exception{
|
||||
public DatasetBean createCKanDataset(DatasetBean toCreate) throws Exception {
|
||||
|
||||
try{
|
||||
try {
|
||||
devModeSetContexts();
|
||||
logger.info("Request for creating a dataset with these information " + toCreate);
|
||||
String userName = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername();
|
||||
|
@ -380,7 +383,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
Map<String, List<String>> customFields = toCreate.getCustomFields();
|
||||
|
||||
// add Type for custom fields
|
||||
if(toCreate.getChosenType() != null)
|
||||
if (toCreate.getChosenType() != null)
|
||||
customFields.put(SYS_TYPE, Arrays.asList(toCreate.getChosenType()));
|
||||
|
||||
boolean setPublic = toCreate.getVisibility();
|
||||
|
@ -389,8 +392,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
List<ResourceBean> resources = null;
|
||||
ResourceElementBean resourcesToAdd = toCreate.getResourceRoot();
|
||||
|
||||
//converting to resources to be added
|
||||
if(resourcesToAdd != null){
|
||||
// converting to resources to be added
|
||||
if (resourcesToAdd != null) {
|
||||
Workspace workspace = getWorkspaceFromStorageHub();
|
||||
resources = WorkspaceUtils.toResources(toCreate, workspace, userName);
|
||||
}
|
||||
|
@ -402,59 +405,48 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
if (!isWithinPortal()) {
|
||||
logger.debug("Should be added:");
|
||||
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,
|
||||
author, authorMail, maintainer, maintainerMail, version, description, licenseId, listOfTags,
|
||||
customFields, resources, setPublic, true, true);
|
||||
|
||||
|
||||
if(datasetId != null){
|
||||
if (datasetId != null) {
|
||||
|
||||
logger.info("Dataset created!");
|
||||
toCreate.setId(datasetId);
|
||||
|
||||
//#23491 Building the go to the item to "Catalogue Portlet URL" (instead of URI Resolver URL)
|
||||
String catalogueURL = utils.getPortletUrl();
|
||||
toCreate.setSource(String.format("%s?path=/dataset/%s", catalogueURL,datasetId));
|
||||
logger.debug("Returning dataset: "+toCreate);
|
||||
// #23491 Building the go to the item to "Catalogue Portlet URL" (instead of URI
|
||||
// Resolver URL)
|
||||
String catalogueURL = utils.getPortletUrl();
|
||||
// logger.debug("Returning catalogueURL: "+catalogueURL);
|
||||
// logger.debug("Returning datasetId: "+datasetId);
|
||||
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
|
||||
// #24744 Returning lazy object
|
||||
toCreate.setGroups(null);
|
||||
toCreate.setCustomFields(null);
|
||||
toCreate.setGroupsForceCreation(null);
|
||||
toCreate.setMetadataList(null);
|
||||
toCreate.setOrganizationList(null);
|
||||
|
||||
logger.info("Returning lazy dataset: "+toCreate);
|
||||
logger.info("Returning lazy dataset: " + toCreate);
|
||||
|
||||
//createdDatasetBean.getSource();
|
||||
//createdDatasetBean.getTitle();
|
||||
// createdDatasetBean.getSource();
|
||||
// createdDatasetBean.getTitle();
|
||||
// resourceForm = new AddResourceToDataset(eventBus, createdDatasetBean.getId(),
|
||||
// createdDatasetBean.getTitle(),
|
||||
// createdDatasetBean.getSelectedOrganization(), owner, datasetUrl);
|
||||
return toCreate;
|
||||
}else{
|
||||
} else {
|
||||
logger.error("Failed to create the dataset");
|
||||
}
|
||||
|
||||
}catch(Exception e){
|
||||
} catch (Exception e) {
|
||||
logger.error("Error while creating item ", e);
|
||||
throw new Exception(e.getMessage());
|
||||
}
|
||||
|
@ -466,34 +458,31 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
/**
|
||||
* Adds the resource to dataset.
|
||||
*
|
||||
* @param resource the resource
|
||||
* @param resource the resource
|
||||
* @param datasetId the dataset id
|
||||
* @return the resource element bean
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Override
|
||||
public ResourceElementBean addResourceToDataset(ResourceElementBean resource, String datasetId) throws Exception{
|
||||
public ResourceElementBean addResourceToDataset(ResourceElementBean resource, String datasetId) throws Exception {
|
||||
logger.info("called addResourceToDataset");
|
||||
devModeSetContexts();
|
||||
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);
|
||||
|
||||
ResourceBean resourceBean = new ResourceBean(
|
||||
resource.getUrl(),
|
||||
resource.getName(),
|
||||
resource.getDescription(),
|
||||
null,
|
||||
username,
|
||||
datasetId,
|
||||
null);
|
||||
ResourceBean resourceBean = new ResourceBean(resource.getUrl(), 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());
|
||||
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");
|
||||
// set its id and turn it to the client
|
||||
resource.setOriginalIdInWorkspace(resourceId);
|
||||
|
@ -512,21 +501,22 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
* @throws Exception the exception
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteResourceFromDataset(ResourceElementBean resource) throws Exception{
|
||||
public boolean deleteResourceFromDataset(ResourceElementBean resource) throws Exception {
|
||||
logger.debug("Request for deleting resource " + resource);
|
||||
boolean deleted = false;
|
||||
devModeSetContexts();
|
||||
try{
|
||||
// get the scope in which we should discover the ckan instance given the organization name in which the dataset was created
|
||||
try {
|
||||
// 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());
|
||||
DataCatalogue catalogue = getCatalogue(scope);
|
||||
String username = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername();
|
||||
deleted = catalogue.deleteResourceFromDataset(resource.getOriginalIdInWorkspace(),username);
|
||||
if(deleted){
|
||||
deleted = catalogue.deleteResourceFromDataset(resource.getOriginalIdInWorkspace(), username);
|
||||
if (deleted) {
|
||||
logger.info("Resource described by " + resource + " deleted");
|
||||
}else
|
||||
} else
|
||||
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);
|
||||
throw new Exception("Error while trying to delete resource." + e.getMessage());
|
||||
}
|
||||
|
@ -542,15 +532,15 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
* @throws Exception the exception
|
||||
*/
|
||||
@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);
|
||||
List<MetaDataProfileBean> toReturn = new ArrayList<MetaDataProfileBean>();
|
||||
try{
|
||||
try {
|
||||
String evaluatedScope = getScopeFromOrgName(orgName);
|
||||
logger.debug("Evaluated scope is " + evaluatedScope);
|
||||
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);
|
||||
throw e;
|
||||
}
|
||||
|
@ -561,57 +551,61 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
/**
|
||||
* Dataset id already exists.
|
||||
*
|
||||
* @param title the title
|
||||
* @param title the title
|
||||
* @param orgName the org name
|
||||
* @return true, if successful
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Override
|
||||
public boolean datasetIdAlreadyExists(String title, String orgName) throws Exception{
|
||||
if(title == null || title.isEmpty())
|
||||
public boolean datasetIdAlreadyExists(String title, String orgName) throws Exception {
|
||||
if (title == null || title.isEmpty())
|
||||
return true; // it's an error somehow
|
||||
try{
|
||||
try {
|
||||
String scopeFromOrgName = getScopeFromOrgName(orgName);
|
||||
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);
|
||||
}catch(Exception e){
|
||||
} catch (Exception 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());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The method tries to retrieve the scope related to the organization using the map first,
|
||||
* if no match is found, it retrieves such information by using liferay
|
||||
* The method tries to retrieve the scope related to the organization using the
|
||||
* 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() + "]");
|
||||
if(orgName == null || orgName.isEmpty())
|
||||
logger.info("Request for scope related to orgName " + orgName + " [map that will be used is "
|
||||
+ mapOrganizationScope.toString() + "]");
|
||||
if (orgName == null || orgName.isEmpty())
|
||||
throw new IllegalArgumentException("orgName cannot be empty or null!");
|
||||
|
||||
String toReturn = null;
|
||||
|
||||
if(isWithinPortal()){
|
||||
if(mapOrganizationScope.containsKey(orgName)) {
|
||||
if (isWithinPortal()) {
|
||||
if (mapOrganizationScope.containsKey(orgName)) {
|
||||
toReturn = mapOrganizationScope.get(orgName);
|
||||
}else{
|
||||
try{
|
||||
} else {
|
||||
try {
|
||||
String evaluatedScope = GenericUtils.retrieveScopeFromOrganizationName(orgName);
|
||||
//see #20801
|
||||
if(evaluatedScope==null || evaluatedScope.isEmpty()) {
|
||||
logger.warn("Scope detected for OrganizationName: "+orgName+" is null or empty, skipping filling 'mapOrganizationScope' and returning null");
|
||||
// see #20801
|
||||
if (evaluatedScope == null || evaluatedScope.isEmpty()) {
|
||||
logger.warn("Scope detected for OrganizationName: " + orgName
|
||||
+ " is null or empty, skipping filling 'mapOrganizationScope' and returning null");
|
||||
return toReturn;
|
||||
}
|
||||
mapOrganizationScope.put(orgName, evaluatedScope);
|
||||
toReturn = evaluatedScope;
|
||||
}catch(Exception e){
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to retrieve scope from OrgName for organization " + orgName, e);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
//UPDATED By FRANCESCO
|
||||
} else {
|
||||
// UPDATED By FRANCESCO
|
||||
toReturn = GenericUtils.getCurrentContext(this.getThreadLocalRequest(), false);
|
||||
mapOrganizationScope.put(orgName, toReturn);
|
||||
}
|
||||
|
@ -630,54 +624,58 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
|
||||
List<OrganizationBean> toReturn = new ArrayList<OrganizationBean>();
|
||||
|
||||
if(isWithinPortal()){
|
||||
if (isWithinPortal()) {
|
||||
GCubeUser user = GenericUtils.getCurrentUser(getThreadLocalRequest());
|
||||
String username = null;
|
||||
if(user!=null)
|
||||
if (user != null)
|
||||
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
|
||||
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
|
||||
String keyPerScopeGroups = CatalogueUtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_GROUPS_MEMBER, scope);
|
||||
String keyPerScopeGroups = CatalogueUtilMethods
|
||||
.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_GROUPS_MEMBER, scope);
|
||||
|
||||
if(httpSession.getAttribute(keyPerScopeGroups) != null){
|
||||
toReturn = (List<OrganizationBean>)httpSession.getAttribute(keyPerScopeGroups);
|
||||
if (httpSession.getAttribute(keyPerScopeGroups) != null) {
|
||||
toReturn = (List<OrganizationBean>) httpSession.getAttribute(keyPerScopeGroups);
|
||||
logger.info("Found user's groups in session " + toReturn);
|
||||
}else{
|
||||
} else {
|
||||
|
||||
//Fixing Incident #12563
|
||||
try{
|
||||
// Fixing Incident #12563
|
||||
try {
|
||||
DataCatalogue catalogue = getCatalogue(scope);
|
||||
//Fixing Incident #12563
|
||||
if(username!=null && !username.isEmpty()){
|
||||
Map<String, Map<CkanGroup, RolesCkanGroupOrOrg>> mapRoleGroup = catalogue.getUserRoleByGroup(username);
|
||||
// Fixing Incident #12563
|
||||
if (username != null && !username.isEmpty()) {
|
||||
Map<String, Map<CkanGroup, RolesCkanGroupOrOrg>> mapRoleGroup = catalogue
|
||||
.getUserRoleByGroup(username);
|
||||
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));
|
||||
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);
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
logger.warn("Dev mode detected");
|
||||
toReturn = Arrays.asList();
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if is publisher user.
|
||||
*
|
||||
|
@ -686,17 +684,17 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
* @throws Exception the exception
|
||||
*/
|
||||
@Override
|
||||
public boolean isPublisherUser(boolean isWorkspaceRequest) throws Exception{
|
||||
public boolean isPublisherUser(boolean isWorkspaceRequest) throws Exception {
|
||||
|
||||
String username = GenericUtils.getCurrentUser(getThreadLocalRequest()).getUsername();
|
||||
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");
|
||||
return true;
|
||||
}
|
||||
|
||||
try{
|
||||
try {
|
||||
|
||||
HttpSession httpSession = this.getThreadLocalRequest().getSession();
|
||||
|
||||
|
@ -704,38 +702,46 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
String scopePerCurrentUrl = GenericUtils.getScopeFromClientUrl(getThreadLocalRequest());
|
||||
|
||||
// get key per scope
|
||||
String keyPerScopeRole = CatalogueUtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_HIGHEST_ROLE, scopePerCurrentUrl);
|
||||
String keyPerScopeOrganizations = CatalogueUtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_ORGANIZATIONS_PUBLISH_KEY, scopePerCurrentUrl);
|
||||
String keyPerScopeGroups = CatalogueUtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_GROUPS_MEMBER, scopePerCurrentUrl);
|
||||
String keyPerScopeRole = CatalogueUtilMethods
|
||||
.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_HIGHEST_ROLE, 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
|
||||
RolesCkanGroupOrOrg role = (RolesCkanGroupOrOrg) httpSession.getAttribute(keyPerScopeRole);
|
||||
|
||||
// if the attribute was already set..
|
||||
if(role != null)
|
||||
if (role != null)
|
||||
return !role.equals(RolesCkanGroupOrOrg.MEMBER);
|
||||
else{
|
||||
else {
|
||||
|
||||
try{
|
||||
try {
|
||||
|
||||
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>();
|
||||
String gatewayURL = GenericUtils.getGatewayClientHostname(getThreadLocalRequest());
|
||||
logger.info("The Gateway URL is: "+gatewayURL);
|
||||
role = CatalogueRoleManager.getHighestRole(scopePerCurrentUrl, username, groupName, this, orgsInWhichAtLeastEditorRole, gatewayURL);
|
||||
logger.info("The Gateway URL is: " + gatewayURL);
|
||||
role = CatalogueRoleManager.getHighestRole(scopePerCurrentUrl, username, groupName, this,
|
||||
orgsInWhichAtLeastEditorRole, gatewayURL);
|
||||
|
||||
// if he is an admin/editor preload:
|
||||
// 1) organizations in which he can publish (the widget will find these info in session)
|
||||
if(!role.equals(RolesCkanGroupOrOrg.MEMBER)){
|
||||
// 1) organizations in which he can publish (the widget will find these info in
|
||||
// session)
|
||||
if (!role.equals(RolesCkanGroupOrOrg.MEMBER)) {
|
||||
httpSession.setAttribute(keyPerScopeOrganizations, orgsInWhichAtLeastEditorRole);
|
||||
String orgName = scopePerCurrentUrl.split("/")[scopePerCurrentUrl.split("/").length - 1];
|
||||
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);
|
||||
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);
|
||||
return !role.equals(RolesCkanGroupOrOrg.MEMBER);
|
||||
|
||||
}catch(Exception e){
|
||||
} catch (Exception 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());
|
||||
}
|
||||
|
@ -762,10 +768,10 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
*/
|
||||
@Override
|
||||
public boolean isGeoJSONValid(String geoJson) throws Exception {
|
||||
try{
|
||||
try {
|
||||
new ObjectMapper().readValue(geoJson, GeoJsonObject.class);
|
||||
return true;
|
||||
}catch(Exception e){
|
||||
} catch (Exception e) {
|
||||
throw new Exception("GeoJSON field with value '" + geoJson + "' seems not valid!");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue