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
This commit is contained in:
parent
ce61a87679
commit
93b16ff7b6
|
@ -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<CustomFieldEntry> customFieldEntriesList = new ArrayList<CustomFieldEntry>();
|
||||
private List<CustomFieldEntry> customFieldEntriesList = new ArrayList<CustomFieldEntry>();
|
||||
|
||||
// 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<MetaDataFieldSkeleton> listOfMetadataFields = new ArrayList<MetaDataFieldSkeleton>();
|
||||
private List<MetaDataFieldSkeleton> listOfMetadataFields = new ArrayList<MetaDataFieldSkeleton>();
|
||||
|
||||
// resource table
|
||||
private ResourcesTable resourcesTable;
|
||||
|
||||
// List of opened popup'ids
|
||||
List<String> popupOpenedIds = new ArrayList<String>();
|
||||
private List<String> popupOpenedIds = new ArrayList<String>();
|
||||
|
||||
// map of organization name title
|
||||
private Map<String, String> nameTitleOrganizationMap = new HashMap<String, String>();
|
||||
|
||||
/**
|
||||
* 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<DatasetMetadataBean>() {
|
||||
|
||||
@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<String> 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<LicensesBean>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(LicensesBean lBean) {
|
||||
|
||||
if(lBean != null && !lBean.getLicenseTitles().isEmpty()){
|
||||
|
||||
licenseBean = lBean;
|
||||
|
||||
// sort the list
|
||||
List<String> listOfNames = new ArrayList<String>();
|
||||
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<DatasetMetadataBean>() {
|
||||
|
||||
@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<String> 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<String, String> 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<LicensesBean>() {
|
||||
// set organizations
|
||||
List<OrganizationBean> 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<String> listOfNames = new ArrayList<String>();
|
||||
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<List<MetaDataProfileBean>>() {
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
|
||||
setAlertBlock("Error while retrieving profiles, try to refresh the page", AlertType.ERROR, true);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(List<MetaDataProfileBean> 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<LicensesBean>() {
|
||||
|
||||
@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<String> listOfNames = new ArrayList<String>();
|
||||
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<List<MetaDataProfileBean>>() {
|
||||
ckanServices.getProfiles(orgName, new AsyncCallback<List<MetaDataProfileBean>>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(List<MetaDataProfileBean> 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<MetaDataProfileBean> 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<OrganizationBean> 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);
|
||||
|
|
|
@ -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<String> getUserOrganizationsListAdmin(String username, String scope) {
|
||||
private List<OrganizationBean> getUserOrganizationsListAdmin(String username, String scope) {
|
||||
|
||||
logger.debug("Request for user " + username + " organizations list");
|
||||
List<String> orgsName = new ArrayList<String>();
|
||||
List<OrganizationBean> orgsName = new ArrayList<OrganizationBean>();
|
||||
|
||||
// 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<String>)httpSession.getAttribute(keyPerScope);
|
||||
orgsName = (List<OrganizationBean>)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{
|
||||
|
|
|
@ -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<String> getUserOrganizationsListAdmin(String currentScope, String username, String groupName, CKANPublisherServicesImpl ckanPublisherServicesImpl){
|
||||
public static List<OrganizationBean> getUserOrganizationsListAdmin(String currentScope, String username, String groupName, CKANPublisherServicesImpl ckanPublisherServicesImpl){
|
||||
|
||||
List<String> toReturn = new ArrayList<String>();
|
||||
List<OrganizationBean> toReturn = new ArrayList<OrganizationBean>();
|
||||
|
||||
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<CkanOrganization> 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<CkanOrganization> 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<GCubeRole> 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<CkanOrganization> 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
|
||||
|
|
|
@ -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<String> organizationList; // list of organization in which the user is present and could create the dataset
|
||||
private List<OrganizationBean> organizationList; // list of organization in which the user is present and could create the dataset
|
||||
private String selectedOrganization;
|
||||
private List<ResourceBeanWrapper> resources; // in case of workspace, this is the list of children
|
||||
private List<MetaDataProfileBean> 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<String> organizationList, String selectedOrganization,
|
||||
List<OrganizationBean> organizationList, String selectedOrganization,
|
||||
List<ResourceBeanWrapper> resources,
|
||||
List<MetaDataProfileBean> metadataList) {
|
||||
super();
|
||||
|
@ -231,11 +231,11 @@ public class DatasetMetadataBean implements Serializable {
|
|||
this.maintainerEmail = maintainerEmail;
|
||||
}
|
||||
|
||||
public List<String> getOrganizationList() {
|
||||
public List<OrganizationBean> getOrganizationList() {
|
||||
return organizationList;
|
||||
}
|
||||
|
||||
public void setOrganizationList(List<String> organizationList) {
|
||||
public void setOrganizationList(List<OrganizationBean> organizationList) {
|
||||
this.organizationList = organizationList;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 + "]";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue