From 93b16ff7b68087574417939e8fde072ef87c4515 Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Wed, 20 Jul 2016 20:41:15 +0000 Subject: [PATCH] Now the list of organizations' titles is shown instead of their names. The list of profiles is evaluated dynamically if the user changes organizations in which he wants to publish git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@130607 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/ui/CreateDatasetForm.java | 372 ++++++++---------- .../server/CKANPublisherServicesImpl.java | 12 +- .../server/utils/Utils.java | 52 +-- .../shared/DatasetMetadataBean.java | 8 +- .../shared/OrganizationBean.java | 45 +++ 5 files changed, 246 insertions(+), 243 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/OrganizationBean.java diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.java index 6575b5f..1a1b6df 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.java @@ -21,6 +21,7 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetMetadata import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.LicensesBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetaDataProfileBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataFieldWrapper; +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean; import com.github.gwtbootstrap.client.ui.AlertBlock; import com.github.gwtbootstrap.client.ui.Button; @@ -40,7 +41,6 @@ import com.github.gwtbootstrap.client.ui.constants.AlertType; import com.github.gwtbootstrap.client.ui.constants.ButtonType; import com.github.gwtbootstrap.client.ui.resources.Bootstrap.Tabs; import com.google.gwt.core.client.GWT; -import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Style.Cursor; import com.google.gwt.dom.client.Style.Display; @@ -48,7 +48,6 @@ import com.google.gwt.event.dom.client.ChangeEvent; import com.google.gwt.event.dom.client.ChangeHandler; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; -import com.google.gwt.event.dom.client.DomEvent; import com.google.gwt.event.dom.client.KeyCodes; import com.google.gwt.event.dom.client.KeyDownEvent; import com.google.gwt.event.shared.HandlerManager; @@ -161,6 +160,7 @@ public class CreateDatasetForm extends Composite{ @UiField Popover popoverResources; @UiField ControlGroup metadataProfilesControlGroup; + // error message protected static final String ERROR_PRODUCT_CREATION = "There was an error while trying to publish your product, sorry.. Retry later"; // tab panel @@ -176,10 +176,10 @@ public class CreateDatasetForm extends Composite{ private LicensesBean licenseBean; // event bus - private final HandlerManager eventBus; + private HandlerManager eventBus; // added custom field entries - List customFieldEntriesList = new ArrayList(); + private List customFieldEntriesList = new ArrayList(); // dataset metadata bean private DatasetMetadataBean receivedBean; @@ -191,137 +191,24 @@ public class CreateDatasetForm extends Composite{ private boolean isWorkspaceRequest = false; // the list of MetaDataFieldSkeleton added - List listOfMetadataFields = new ArrayList(); + private List listOfMetadataFields = new ArrayList(); // resource table private ResourcesTable resourcesTable; // List of opened popup'ids - List popupOpenedIds = new ArrayList(); + private List popupOpenedIds = new ArrayList(); + + // map of organization name title + private Map nameTitleOrganizationMap = new HashMap(); /** * Invoked in the most general case * @param owner */ public CreateDatasetForm(String owner, HandlerManager eventBus) { - initWidget(uiBinder.createAndBindUi(this)); - this.owner = owner; - - // save event bus - this.eventBus = eventBus; - - // bind on events - bind(); - - // prepare info icons - prepareInfoIcons(); - - // set info block - setAlertBlock("Retrieving information, please wait...", AlertType.INFO, true); - - // disable continue/reset button - continueButton.setEnabled(false); - resetButton.setEnabled(false); - - // get back the licenses and the metadata information - ckanServices.getDatasetBean(null, owner, new AsyncCallback() { - - @Override - public void onSuccess(DatasetMetadataBean bean) { - - if(bean != null){ - - // save it - receivedBean = bean; - - // fill the form - versionTextbox.setText(String.valueOf(bean.getVersion())); - authorTextbox.setText(bean.getAuthorSurname() + " " + bean.getAuthorName()); - authorEmailTextbox.setText(bean.getAuthorEmail()); - maintainerTextbox.setText(bean.getAuthorSurname() + " " + bean.getAuthorName()); - maintainerEmailTextbox.setText(bean.getMaintainerEmail()); - - // set organizations - List organizations = bean.getOrganizationList(); - - for (String organization : organizations) { - organizationsListbox.addItem(organization); - } - - // force the selection of the first one, so that the list of profiles is downloaded - organizationsListbox.setSelectedIndex(0); - - // add change handler to dinamycally retrieve the list of profiles - organizationsListbox.addChangeHandler(new ChangeHandler() { - - @Override - public void onChange(ChangeEvent event) { - - organizationsListboxChangeHandlerBody(); - - } - }); - - // fire - DomEvent.fireNativeEvent(Document.get().createChangeEvent(), organizationsListbox); - - // try to retrieve the licenses - setAlertBlock("Retrieving licenses, please wait...", AlertType.INFO, true); - ckanServices.getLicenses(new AsyncCallback() { - - @Override - public void onSuccess(LicensesBean lBean) { - - if(lBean != null && !lBean.getLicenseTitles().isEmpty()){ - - licenseBean = lBean; - - // sort the list - List listOfNames = new ArrayList(); - Collections.copy(listOfNames, licenseBean.getLicenseTitles()); - Collections.sort(listOfNames); - - // fill the listbox - for(int i = 0; i < listOfNames.size(); i++){ - licenseListbox.addItem(listOfNames.get(i)); - } - - // set the url of the license, if any - showLicenseUrl(); - - // everything went ok - setAlertBlock("", AlertType.ERROR, false); - continueButton.setEnabled(true); - resetButton.setEnabled(true); - - }else{ - setAlertBlock("Error while retrieving licenses, try to refresh the page", AlertType.ERROR, true); - } - } - - @Override - public void onFailure(Throwable caught) { - - setAlertBlock("Error while retrieving licenses, try to refresh the page", AlertType.ERROR, true); - - } - }); - - }else{ - - setAlertBlock("Error while retrieving information, try to refresh the page", AlertType.ERROR, true); - } - - } - - @Override - public void onFailure(Throwable caught) { - - setAlertBlock("Error while retrieving information, try to refresh the page", AlertType.ERROR, true); - - } - }); + createDatasetFormBody(false, null, owner, eventBus); } @@ -330,7 +217,22 @@ public class CreateDatasetForm extends Composite{ * @param idFolderWorkspace * @param owner */ - public CreateDatasetForm(String idFolderWorkspace, String owner, final HandlerManager eventBus) { + public CreateDatasetForm(String idFolderWorkspace, String owner, HandlerManager eventBus) { + + createDatasetFormBody(true, idFolderWorkspace, owner, eventBus); + + } + + + /** + * The real constructor + * @param isWorkspaceRequest + * @param idFolderWorkspace + * @param owner + * @param eventBus + */ + private void createDatasetFormBody(boolean isWorkspaceRequest, String idFolderWorkspace, String owner, final HandlerManager eventBus){ + initWidget(uiBinder.createAndBindUi(this)); this.owner = owner; @@ -338,15 +240,15 @@ public class CreateDatasetForm extends Composite{ // save event bus this.eventBus = eventBus; - // prepare info icons - prepareInfoIcons(); - // workspace request - isWorkspaceRequest = true; + this.isWorkspaceRequest = isWorkspaceRequest; // bind on events bind(); + // prepare info icons + prepareInfoIcons(); + // set info block setAlertBlock("Retrieving information, please wait...", AlertType.INFO, true); @@ -357,10 +259,21 @@ public class CreateDatasetForm extends Composite{ // get back the licenses and the metadata information from the workspace ckanServices.getDatasetBean(idFolderWorkspace, owner, new AsyncCallback() { + @Override + public void onFailure(Throwable caught) { + + setAlertBlock("Error while retrieving information, try to refresh the page", AlertType.ERROR, true); + + } + @Override public void onSuccess(final DatasetMetadataBean bean) { - if(bean != null){ + if(bean == null){ + + setAlertBlock("Error while retrieving information, try to refresh the page", AlertType.ERROR, true); + } + else{ // save it receivedBean = bean; @@ -374,32 +287,6 @@ public class CreateDatasetForm extends Composite{ maintainerTextbox.setText(bean.getAuthorSurname() + " " + bean.getAuthorName()); maintainerEmailTextbox.setText(bean.getMaintainerEmail()); - // set organizations - List organizations = bean.getOrganizationList(); - - for (String organization : organizations) { - - organizationsListbox.addItem(organization); - - } - - // force the selection of the first one, so that the list of profiles is downloaded - organizationsListbox.setSelectedIndex(0); - - // add change handler to dinamycally retrieve the list of profiles - organizationsListbox.addChangeHandler(new ChangeHandler() { - - @Override - public void onChange(ChangeEvent event) { - - organizationsListboxChangeHandlerBody(); - - } - }); - - // fire - DomEvent.fireNativeEvent(Document.get().createChangeEvent(), organizationsListbox); - // retrieve custom fields Map customFieldsMap = bean.getCustomFields(); @@ -428,7 +315,6 @@ public class CreateDatasetForm extends Composite{ addResourcesCheckBox.getElement().getStyle().setDisplay(Display.INLINE_BLOCK); resourcesTable = new ResourcesTable(bean.getResources()); - // if there are not resources, for now just checked it ( and hide so that the step will be skipped) TODO if(bean.getResources() == null || bean.getResources().isEmpty()){ @@ -437,60 +323,106 @@ public class CreateDatasetForm extends Composite{ alertNoResources.setVisible(true); } - // try to retrieve the licenses - setAlertBlock("Retrieving licenses, please wait...", AlertType.INFO, true); - ckanServices.getLicenses(new AsyncCallback() { + // set organizations + List organizations = bean.getOrganizationList(); + + for (OrganizationBean organization : organizations) { + organizationsListbox.addItem(organization.getTitle()); + nameTitleOrganizationMap.put(organization.getTitle(), organization.getName()); + } + + // force the selection of the first one, and retrieve the list of profiles + organizationsListbox.setSelectedIndex(0); + + // add change handler to dinamycally retrieve the list of profiles + organizationsListbox.addChangeHandler(new ChangeHandler() { @Override - public void onSuccess(LicensesBean lBean) { + public void onChange(ChangeEvent event) { - if(lBean != null && !lBean.getLicenseTitles().isEmpty()){ - - licenseBean = lBean; - - // sort the list - List listOfNames = new ArrayList(); - Collections.copy(listOfNames, licenseBean.getLicenseTitles()); - Collections.sort(listOfNames); - - // fill the listbox - for(int i = 0; i < listOfNames.size(); i++){ - licenseListbox.addItem(listOfNames.get(i)); - } - - // set the url of the license, if any - showLicenseUrl(); - - // everything went ok - setAlertBlock("", AlertType.ERROR, false); - continueButton.setEnabled(true); - resetButton.setEnabled(true); - - }else{ - setAlertBlock("Error while retrieving licenses, try to refresh the page", AlertType.ERROR, true); - } - } - - @Override - public void onFailure(Throwable caught){ - - setAlertBlock("Error while retrieving licenses, try to refresh the page", AlertType.ERROR, true); + organizationsListboxChangeHandlerBody(); } }); - }else{ + // try to retrieve the profiles + setAlertBlock("Retrieving profiles, please wait...", AlertType.INFO, true); - setAlertBlock("Error while retrieving information, try to refresh the page", AlertType.ERROR, true); + // get the name of the organization from the title + String orgName = nameTitleOrganizationMap.get(organizationsListbox.getSelectedItemText()); + + // perform remote request of profiles for the selected organization + ckanServices.getProfiles(orgName, new AsyncCallback>() { + + @Override + public void onFailure(Throwable caught) { + + setAlertBlock("Error while retrieving profiles, try to refresh the page", AlertType.ERROR, true); + + } + + @Override + public void onSuccess(List result) { + + if(result == null){ + + setAlertBlock("Error while retrieving profiles, try to refresh the page", AlertType.ERROR, true); + + } + else{ + + receivedBean.setMetadataList(result); + prepareMetadataList(receivedBean); + organizationsListbox.setEnabled(true); + metadataProfilesFormatListbox.setEnabled(true); + + // try to retrieve the licenses + setAlertBlock("Retrieving licenses, please wait...", AlertType.INFO, true); + ckanServices.getLicenses(new AsyncCallback() { + + @Override + public void onFailure(Throwable caught){ + + setAlertBlock("Error while retrieving licenses, try to refresh the page", AlertType.ERROR, true); + + } + + @Override + public void onSuccess(LicensesBean lBean) { + + if(lBean != null && !lBean.getLicenseTitles().isEmpty()){ + + licenseBean = lBean; + + // sort the list + List listOfNames = new ArrayList(); + Collections.copy(listOfNames, licenseBean.getLicenseTitles()); + Collections.sort(listOfNames); + + // fill the listbox + for(int i = 0; i < listOfNames.size(); i++){ + licenseListbox.addItem(listOfNames.get(i)); + } + + // set the url of the license, if any + showLicenseUrl(); + + // everything went ok + setAlertBlock("", AlertType.ERROR, false); + continueButton.setEnabled(true); + resetButton.setEnabled(true); + + }else{ + + setAlertBlock("Error while retrieving licenses, try to refresh the page", AlertType.ERROR, true); + + } + } + }); + } + } + }); } - - } - - @Override - public void onFailure(Throwable caught) { - - setAlertBlock("Error while retrieving information, try to refresh the page", AlertType.ERROR, true); - } }); @@ -501,7 +433,6 @@ public class CreateDatasetForm extends Composite{ */ private void organizationsListboxChangeHandlerBody() { - // TODO // disable the list of organizations name so that the user doesn't change it again organizationsListbox.setEnabled(false); metadataProfilesFormatListbox.setEnabled(false); @@ -512,9 +443,18 @@ public class CreateDatasetForm extends Composite{ if(!metadataProfilesFormatListbox.getValue(i).equals("none")) metadataProfilesFormatListbox.removeItem(i); } + + // select "none" + metadataProfilesFormatListbox.setSelectedIndex(0); + + // get the name of the organization from the title + String orgName = nameTitleOrganizationMap.get(organizationsListbox.getSelectedItemText()); + + // try to retrieve the profiles + setAlertBlock("Retrieving profiles, please wait...", AlertType.INFO, true); // perform remote request of profiles for the selected organization - ckanServices.getProfiles(organizationsListbox.getSelectedItemText(), new AsyncCallback>() { + ckanServices.getProfiles(orgName, new AsyncCallback>() { @Override public void onSuccess(List result) { @@ -523,19 +463,19 @@ public class CreateDatasetForm extends Composite{ receivedBean.setMetadataList(result); prepareMetadataList(receivedBean); + + // everything went ok + setAlertBlock("", AlertType.ERROR, false); - } - - organizationsListbox.setEnabled(true); - metadataProfilesFormatListbox.setEnabled(true); + }else + setAlertBlock("Error while retrieving profiles, sorry", AlertType.ERROR, true); } @Override public void onFailure(Throwable caught) { - organizationsListbox.setEnabled(true); - metadataProfilesFormatListbox.setEnabled(true); + setAlertBlock("Error while retrieving profiles, sorry", AlertType.ERROR, true); } }); @@ -546,7 +486,7 @@ public class CreateDatasetForm extends Composite{ * Add the items to the listbox and put data into the metadataPanel * @param receivedBean */ - protected void prepareMetadataList(DatasetMetadataBean receivedBean) { + private void prepareMetadataList(DatasetMetadataBean receivedBean) { List beans = receivedBean.getMetadataList(); @@ -743,7 +683,17 @@ public class CreateDatasetForm extends Composite{ String authorEmail = authorEmailTextbox.getValue(); String maintainer = maintainerTextbox.getValue(); String maintainerEmail = maintainerEmailTextbox.getValue(); - String chosenOrganization = organizationsListbox.getSelectedItemText(); + String chosenOrganizationTitle = organizationsListbox.getSelectedItemText(); + + //we need to retrieve the organization's name from this title + List orgs = receivedBean.getOrganizationList(); + String chosenOrganization = null; + for (OrganizationBean organizationBean : orgs) { + if(chosenOrganizationTitle.equals(organizationBean.getTitle())){ + chosenOrganization = organizationBean.getName(); + break; + } + } // fill the bean receivedBean.setAuthorFullName(author); diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java index 2b3343b..8a126b5 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java @@ -21,6 +21,7 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.Utils; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetMetadataBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.LicensesBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetaDataProfileBean; +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBeanWrapper; import org.gcube.vomanagement.usermanagement.UserManager; import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager; @@ -152,14 +153,13 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C /** * Retrieve the list of organizations in which the user can publish (roles ADMIN) - * If he is a SYSADMIN, he can publish everywhere * @param username * @return the list of organizations */ - private List getUserOrganizationsListAdmin(String username, String scope) { + private List getUserOrganizationsListAdmin(String username, String scope) { logger.debug("Request for user " + username + " organizations list"); - List orgsName = new ArrayList(); + List orgsName = new ArrayList(); // get http session HttpSession httpSession = getThreadLocalRequest().getSession(); @@ -168,13 +168,13 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C String keyPerScope = Utils.concatenateSessionKeyScope(CKAN_ORGANIZATIONS_PUBLISH_KEY, scope); if(httpSession.getAttribute(keyPerScope) != null){ - orgsName = (List)httpSession.getAttribute(keyPerScope); + orgsName = (List)httpSession.getAttribute(keyPerScope); logger.info("List of organizations was into session "); } else{ orgsName = Utils.getUserOrganizationsListAdmin(scope, username, getASLSession().getGroupName(), this); httpSession.setAttribute(keyPerScope, orgsName); - logger.info("Organizations name for user " + username + " has been saved into session"); + logger.info("Organizations name for user " + username + " has been saved into session " + orgsName); } return orgsName; @@ -523,7 +523,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C String username = session.getUsername(); if(username.equals(TEST_USER)){ - logger.warn("SESSION EXPIRED! "); + logger.warn("SESSION EXPIRED!"); return deleted; }else{ try{ diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/Utils.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/Utils.java index 86a8976..8c86fdd 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/Utils.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/Utils.java @@ -26,6 +26,7 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.server.CKANPublisherSe import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetaDataProfileBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetaDataTypeWrapper; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataFieldWrapper; +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBeanWrapper; import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.RoleManager; @@ -38,6 +39,8 @@ import org.gcube.vomanagement.usermanagement.model.GCubeRole; import org.gcube.vomanagement.usermanagement.model.GatewayRolesNames; import org.slf4j.LoggerFactory; +import eu.trentorise.opendata.jackan.model.CkanOrganization; + /** * Util class with static methods * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) @@ -123,15 +126,15 @@ public class Utils { } /** - * Retrieve the highest ckan role the user has and also retrieve the list of organizations (scopes) in which the user has the ckan-admin role + * Retrieve the list of organizations in which the user has the ckan-admin role * @param currentScope the current scope * @param username the current username * @param groupName the current groupName * @param ckanPublisherServicesImpl */ - public static List getUserOrganizationsListAdmin(String currentScope, String username, String groupName, CKANPublisherServicesImpl ckanPublisherServicesImpl){ + public static List getUserOrganizationsListAdmin(String currentScope, String username, String groupName, CKANPublisherServicesImpl ckanPublisherServicesImpl){ - List toReturn = new ArrayList(); + List toReturn = new ArrayList(); try{ @@ -187,22 +190,20 @@ public class Utils { boolean res = ckanUtils.checkRole(username, gCubeGroupName, correspondentRoleToCheck); if(res){ - // ok, we have a admin role here - if(correspondentRoleToCheck.equals(RolesIntoOrganization.ADMIN)){ - toReturn.add(gCubeGroupName.toLowerCase()); - continue; // it is already the highest + // get the orgs of the user + List ckanOrgs = ckanUtils.getOrganizationsByUser(username); + for (CkanOrganization ckanOrganization : ckanOrgs) { + if(ckanOrganization.getName().equals(gCubeGroupName.toLowerCase())){ + toReturn.add(new OrganizationBean(ckanOrganization.getTitle(), ckanOrganization.getName())); + break; + } } } } } - // set the role - logger.debug("Setting role " + toReturn + " into session for user " + username); - }else if(groupManager.isVO(currentGroupId)){ - logger.debug("The list of organizations of the user " + username + " is " + groups); - for (GCubeGroup gCubeGroup : groups) { if(currentGroupId != gCubeGroup.getParentGroupId() || currentGroupId != gCubeGroup.getGroupId()) @@ -237,18 +238,18 @@ public class Utils { boolean res = ckanUtils.checkRole(username, gCubeGroupName, correspondentRoleToCheck); if(res){ - // ok, we have a admin role here - if(correspondentRoleToCheck.equals(RolesIntoOrganization.ADMIN)){ - toReturn.add(gCubeGroupName.toLowerCase()); - continue; // it is already the highest + // get the orgs of the user + List ckanOrgs = ckanUtils.getOrganizationsByUser(username); + for (CkanOrganization ckanOrganization : ckanOrgs) { + if(ckanOrganization.getName().equals(gCubeGroupName.toLowerCase())){ + toReturn.add(new OrganizationBean(ckanOrganization.getTitle(), ckanOrganization.getName())); + break; + } } } } } - // set the role - logger.debug("Setting role " + toReturn + " into session for user " + username ); - }else if(groupManager.isVRE(currentGroupId)){ // vre List roles = roleManager.listRolesByUserAndGroup(userManager.getUserId(username), groupManager.getGroupId(groupName)); @@ -274,8 +275,14 @@ public class Utils { boolean res = ckanUtils.checkRole(username, groupName, correspondentRoleToCheck); if(res){ - - toReturn.add(groupName.toLowerCase()); + // get the orgs of the user + List ckanOrgs = ckanUtils.getOrganizationsByUser(username); + for (CkanOrganization ckanOrganization : ckanOrgs) { + if(ckanOrganization.getName().equals(groupName.toLowerCase())){ + toReturn.add(new OrganizationBean(ckanOrganization.getTitle(), ckanOrganization.getName())); + break; + } + } } } } @@ -283,6 +290,7 @@ public class Utils { logger.error("Unable to retrieve the role information for this user. Returning member role", e); } + logger.info("Retrieved orgs in which the user has admin roles " + toReturn); return toReturn; } @@ -318,7 +326,7 @@ public class Utils { return null; } - + /** * Retrieve the list of metadata beans * @return diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/DatasetMetadataBean.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/DatasetMetadataBean.java index 06a942f..104aca9 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/DatasetMetadataBean.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/DatasetMetadataBean.java @@ -43,7 +43,7 @@ public class DatasetMetadataBean implements Serializable { private String maintainer; private String maintainerEmail; private String ownerIdentifier; // owner of the folder into the workspace (e.g., andrea.rossi) - private List organizationList; // list of organization in which the user is present and could create the dataset + private List organizationList; // list of organization in which the user is present and could create the dataset private String selectedOrganization; private List resources; // in case of workspace, this is the list of children private List metadataList; @@ -78,7 +78,7 @@ public class DatasetMetadataBean implements Serializable { String license, boolean visibility, String source, long version, String authorName, String authorSurname, String authorEmail, String maintainer, String maintainerEmail, String ownerIdentifier, - List organizationList, String selectedOrganization, + List organizationList, String selectedOrganization, List resources, List metadataList) { super(); @@ -231,11 +231,11 @@ public class DatasetMetadataBean implements Serializable { this.maintainerEmail = maintainerEmail; } - public List getOrganizationList() { + public List getOrganizationList() { return organizationList; } - public void setOrganizationList(List organizationList) { + public void setOrganizationList(List organizationList) { this.organizationList = organizationList; } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/OrganizationBean.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/OrganizationBean.java new file mode 100644 index 0000000..2f0214d --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/OrganizationBean.java @@ -0,0 +1,45 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.shared; + +import java.io.Serializable; + +/** + * A ckan organization like bean with organization name and title + * @author Costantino Perciante (costantino.perciante@isti.cnr.it) + */ +public class OrganizationBean implements Serializable{ + + private static final long serialVersionUID = -6566519399945530602L; + private String title; + private String name; + + public OrganizationBean(){ + super(); + } + + public OrganizationBean(String title, String name) { + super(); + this.title = title; + this.name = name; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "OrganizationBean [title=" + title + ", name=" + name + "]"; + } +}