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
This commit is contained in:
Costantino Perciante 2016-09-05 16:19:18 +00:00
parent 74cb08dcd5
commit 43bd1566c8
2 changed files with 31 additions and 11 deletions

View File

@ -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);
}
}

View File

@ -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<CkanLicense> titlesLicenses = getCkanUtilsObj(session.getScope()).getLicenses();
List<CkanLicense> titlesLicenses = getCkanUtilsObj(scope).getLicenses();
List<String> titles = new ArrayList<String>();
List<String> urls = new ArrayList<String>();
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()){