From 43bd1566c899eb08c479d79f5904ef06a88f2c8f Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Mon, 5 Sep 2016 16:19:18 +0000 Subject: [PATCH] Several fixes due to changed ckan utils library git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@131119 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/ui/MetaDataFieldSkeleton.java | 25 +++++++++++++------ .../server/CKANPublisherServicesImpl.java | 17 ++++++++++--- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/MetaDataFieldSkeleton.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/MetaDataFieldSkeleton.java index 2f44ec2..229f9bf 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/MetaDataFieldSkeleton.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/MetaDataFieldSkeleton.java @@ -138,6 +138,10 @@ public class MetaDataFieldSkeleton extends Composite{ // set default value if(field.getDefaulValue() != null) ((ListBox)holder).setSelectedValue(field.getDefaulValue()); + + // check if multiple selection is allowed TODO + boolean isMultipleSelection = false; //field.isMultipleSelection(); + ((ListBox)holder).setMultipleSelect(isMultipleSelection); // add to the elementPanel elementPanel.add(holder); @@ -254,22 +258,30 @@ public class MetaDataFieldSkeleton extends Composite{ } /** - * Returns the current value of the field + * Returns the current value of the field (in case of multiselection Listbox returns + * the values separated by column) * @return */ public String getFieldCurrentValue(){ - String value; + String value = ""; // we validate only listbox and textbox if(holder.getClass().equals(ListBox.class)){ - value = ((ListBox)holder).getSelectedItemText(); - + + boolean first = true; + + for(int i = 0; i < ((ListBox)holder).getItemCount(); i++){ + if(((ListBox)holder).isItemSelected(i)){ + value += first ? ((ListBox)holder).getItemText(i) : ", " + ((ListBox)holder).getItemText(i); + first = false; + } + } + // if it was not mandatory but there was no choice, returning empty string if(!field.getMandatory()) if(value.equals("Select " + field.getFieldName())) return ""; - } else if(holder.getClass().equals(TextBox.class)) value = ((TextBox)holder).getText(); @@ -280,7 +292,7 @@ public class MetaDataFieldSkeleton extends Composite{ } /** - * Returns the current value of the field + * Returns the current name of the field * @return */ public String getFieldName(){ @@ -302,5 +314,4 @@ public class MetaDataFieldSkeleton extends Composite{ ((CheckBox)holder).setEnabled(false); } - } 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 81d3935..3e8d436 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 @@ -15,6 +15,7 @@ import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; import org.gcube.datacatalogue.ckanutillibrary.CKanUtils; import org.gcube.datacatalogue.ckanutillibrary.CkanUtilsFactory; import org.gcube.datacatalogue.ckanutillibrary.models.ResourceBean; +import org.gcube.datacatalogue.ckanutillibrary.utils.ApplicationProfileScopePerUrlReader; import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherService; import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.Utils; @@ -52,6 +53,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C private static final String CKAN_LICENSES_KEY = "ckanLicenses"; // licenses private static final String CKAN_ORGANIZATIONS_PUBLISH_KEY = "ckanOrganizationsPublish"; // here he can publish private static final String CKAN_PROFILES_KEY = "ckanProfiles"; // product profiles + private final static String CLIENT_PORTLET_URL = "currentClientUrlPortlet"; // set by the ckan portlet in session according + // the user's current url location /** * Retrieve an instance of the library for the scope @@ -216,9 +219,12 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C // get http session HttpSession httpSession = getThreadLocalRequest().getSession(); + String currentUrl = (String)httpSession.getAttribute(CLIENT_PORTLET_URL); + String scope = new ApplicationProfileScopePerUrlReader().getScopePerUrl(currentUrl); + // get key per scope - String keyPerScope = Utils.concatenateSessionKeyScope(CKAN_LICENSES_KEY, session.getScope()); + String keyPerScope = Utils.concatenateSessionKeyScope(CKAN_LICENSES_KEY, scope); LicensesBean licensesBean = null; if(httpSession.getAttribute(keyPerScope) != null){ @@ -226,7 +232,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C logger.debug("List of licenses was into session"); } else{ - List titlesLicenses = getCkanUtilsObj(session.getScope()).getLicenses(); + List titlesLicenses = getCkanUtilsObj(scope).getLicenses(); List titles = new ArrayList(); List urls = new ArrayList(); for (CkanLicense license : titlesLicenses) { @@ -252,7 +258,10 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C ASLSession aslSession = getASLSession(); String user = aslSession.getUsername(); - + + HttpSession httpSession = this.getThreadLocalRequest().getSession(); + String currentUrl = (String)httpSession.getAttribute(CLIENT_PORTLET_URL); + String scope = new ApplicationProfileScopePerUrlReader().getScopePerUrl(currentUrl); if(isWithinPortal()){ try{ @@ -280,7 +289,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C bean.setAuthorEmail(userOwner.getEmail()); bean.setMaintainer(userOwner.getFullname()); bean.setMaintainerEmail(userOwner.getEmail()); - bean.setOrganizationList(getUserOrganizationsListAdmin(owner, aslSession.getScope())); + bean.setOrganizationList(getUserOrganizationsListAdmin(owner, scope)); // if the request comes from the workspace if(folderId != null && !folderId.isEmpty()){