Specified the role the user has for each organization
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@131933 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
229e66c08c
commit
f27fda3d63
|
@ -4,9 +4,6 @@
|
|||
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
|
||||
<dependent-module archiveName="ckan-metadata-publisher-widget-1.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/ckan-metadata-publisher-widget/ckan-metadata-publisher-widget">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<property name="context-root" value="gcube-ckan-datacatalog"/>
|
||||
<property name="java-output-path" value="/gcube-ckan-datacatalog/target/gcube-ckan-datacatalog-1.0.0-SNAPSHOT/WEB-INF/classes"/>
|
||||
</wb-module>
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInOrgRole;
|
||||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint;
|
||||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanRole;
|
||||
|
||||
|
@ -40,7 +41,7 @@ public interface GcubeCkanDataCatalogService extends RemoteService {
|
|||
* Retrieve the list of organizations to whom the user belongs and their urls
|
||||
* @return
|
||||
*/
|
||||
Map<String, String> getCkanOrganizationsNamesAndUrlsForUser();
|
||||
List<BeanUserInOrgRole> getCkanOrganizationsNamesAndUrlsForUser();
|
||||
|
||||
/**
|
||||
* Logout from ckan
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
*/
|
||||
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInOrgRole;
|
||||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint;
|
||||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanRole;
|
||||
|
||||
|
@ -30,7 +31,7 @@ public interface GcubeCkanDataCatalogServiceAsync {
|
|||
void logoutURIFromCkan(AsyncCallback<String> callback);
|
||||
|
||||
void getCkanOrganizationsNamesAndUrlsForUser(
|
||||
AsyncCallback<Map<String, String>> callback);
|
||||
AsyncCallback<List<BeanUserInOrgRole>> callback);
|
||||
|
||||
void outsidePortal(AsyncCallback<Boolean> callback);
|
||||
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.view;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInOrgRole;
|
||||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint;
|
||||
|
||||
import com.github.gwtbootstrap.client.ui.Button;
|
||||
|
@ -14,6 +13,7 @@ import com.github.gwtbootstrap.client.ui.base.UnorderedList;
|
|||
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.HorizontalPanel;
|
||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||
|
||||
|
@ -23,7 +23,7 @@ import com.google.gwt.user.client.ui.VerticalPanel;
|
|||
*/
|
||||
public class CkanOrganizationsPanel extends VerticalPanel{
|
||||
|
||||
private Map<String, String> organizations;
|
||||
private List<BeanUserInOrgRole> organizations;
|
||||
private GCubeCkanDataCatalogPanel father;
|
||||
|
||||
public CkanOrganizationsPanel(
|
||||
|
@ -35,7 +35,7 @@ public class CkanOrganizationsPanel extends VerticalPanel{
|
|||
* Set the organizations to show. If a null list is passed, it is an error
|
||||
* @param result
|
||||
*/
|
||||
public void setOrganizations(Map<String, String> result) {
|
||||
public void setOrganizations(List<BeanUserInOrgRole> result) {
|
||||
|
||||
HorizontalPanel hPanel = new HorizontalPanel();
|
||||
hPanel.setStyleName("horizontal-panel-organizations");
|
||||
|
@ -63,27 +63,31 @@ public class CkanOrganizationsPanel extends VerticalPanel{
|
|||
}else{
|
||||
|
||||
UnorderedList list = new UnorderedList();
|
||||
Iterator<Entry<String, String>> iterator = organizations.entrySet().iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
final Map.Entry<String, String> entry = iterator
|
||||
.next();
|
||||
|
||||
for (final BeanUserInOrgRole org : organizations) {
|
||||
|
||||
Paragraph line = new Paragraph();
|
||||
Button b = new Button();
|
||||
b.setType(ButtonType.LINK);
|
||||
b.setText(entry.getKey());
|
||||
b.setText(org.getOrgName());
|
||||
b.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
|
||||
String request = getCkanRequest(entry.getValue(), null);
|
||||
String request = getCkanRequest(org.getOrgUrl(), null);
|
||||
father.instanceCkanFrame(request);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
ListItem item = new ListItem(b);
|
||||
line.add(b);
|
||||
Button role = new Button();
|
||||
role.setType(ButtonType.LINK);
|
||||
role.setText("as Catalogue-" + org.getRole().toString().toLowerCase());
|
||||
role.getElement().getStyle().setProperty("pointer-events", "none");
|
||||
line.add(role);
|
||||
ListItem item = new ListItem(line);
|
||||
list.add(item);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,10 +4,12 @@
|
|||
|
||||
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.view;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.GCubeCkanDataCatalog;
|
||||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.resource.CkanPortletResources;
|
||||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInOrgRole;
|
||||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint;
|
||||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanRole;
|
||||
import org.gcube.portlets.widgets.sessionchecker.client.CheckSession;
|
||||
|
@ -76,6 +78,24 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
|
|||
ckanAccessPoint = ckan;
|
||||
instanceCkanFrame(ckan.buildURI());
|
||||
GCubeCkanDataCatalogPanel.this.rootPanel.remove(loading);
|
||||
|
||||
// RETRIEVE USER'S ORGANIZATIONS
|
||||
GCubeCkanDataCatalog.service.getCkanOrganizationsNamesAndUrlsForUser(new AsyncCallback<List<BeanUserInOrgRole>>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(List<BeanUserInOrgRole> result) {
|
||||
|
||||
ckanOrganizationsPanel.setOrganizations(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
|
||||
// an error message will be displayed
|
||||
ckanOrganizationsPanel.setOrganizations(null);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
// now perform the other requests
|
||||
GCubeCkanDataCatalog.service.outsidePortal(new AsyncCallback<Boolean>() {
|
||||
|
@ -93,24 +113,6 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
|
|||
// polling for session expired check
|
||||
CheckSession.getInstance().startPolling();
|
||||
|
||||
// RETRIEVE USER'S ORGANIZATIONS
|
||||
GCubeCkanDataCatalog.service.getCkanOrganizationsNamesAndUrlsForUser(new AsyncCallback<Map<String, String>>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(Map<String, String> result) {
|
||||
|
||||
ckanOrganizationsPanel.setOrganizations(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
|
||||
// an error message will be displayed
|
||||
ckanOrganizationsPanel.setOrganizations(null);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
// MANAGE CKAN MANAGEMENT PANEL ACCORDING TO MY ROLE
|
||||
GCubeCkanDataCatalog.service.getMyRole(new AsyncCallback<CkanRole>() {
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ import java.io.InputStream;
|
|||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -27,6 +26,7 @@ import org.gcube.datacatalogue.ckanutillibrary.utils.SessionCatalogueAttributes;
|
|||
import org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods;
|
||||
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
|
||||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.GcubeCkanDataCatalogService;
|
||||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInOrgRole;
|
||||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint;
|
||||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanRole;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean;
|
||||
|
@ -411,14 +411,15 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getCkanOrganizationsNamesAndUrlsForUser() {
|
||||
public List<BeanUserInOrgRole> getCkanOrganizationsNamesAndUrlsForUser() {
|
||||
|
||||
Map<String, String> toReturn = new HashMap<>();
|
||||
List<BeanUserInOrgRole> toReturn = new ArrayList<BeanUserInOrgRole>();
|
||||
|
||||
if(!SessionUtil.isIntoPortal()){
|
||||
|
||||
logger.warn("You are not into the portal");
|
||||
toReturn.put("testVRE", "/organization/devvre");
|
||||
BeanUserInOrgRole org = new BeanUserInOrgRole("testVRE", "/organization/devvre", CkanRole.ADMIN);
|
||||
toReturn.add(org);
|
||||
|
||||
}else{
|
||||
|
||||
|
@ -434,13 +435,16 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
|
||||
// check if the aslsession already has such information
|
||||
if(httpSession.getAttribute(keyPerScope) != null){
|
||||
toReturn = (Map<String, String>) httpSession.getAttribute(keyPerScope);
|
||||
toReturn = (List<BeanUserInOrgRole>) httpSession.getAttribute(keyPerScope);
|
||||
logger.debug("List of organizations was into the session " + toReturn);
|
||||
}else{
|
||||
logger.debug("Organizations list wasn't into session, retrieving them");
|
||||
List<CkanOrganization> organizations = getCkanUtilsObj(scopePerCurrentUrl).getOrganizationsByUser(username);
|
||||
CKanUtils utils = getCkanUtilsObj(scopePerCurrentUrl);
|
||||
List<CkanOrganization> organizations = utils.getOrganizationsByUser(username);
|
||||
for (CkanOrganization ckanOrganization : organizations) {
|
||||
toReturn.put(ckanOrganization.getTitle(), "/organization/" + ckanOrganization.getName());
|
||||
String role = getCkanUtilsObj(scopePerCurrentUrl).getRoleOfUserInOrganization(username, ckanOrganization.getName(), utils.getApiKeyFromUsername(username));
|
||||
BeanUserInOrgRole org = new BeanUserInOrgRole(ckanOrganization.getTitle(), "/organization/" + ckanOrganization.getName(), CkanRole.valueOf(role.toUpperCase()));
|
||||
toReturn.add(org);
|
||||
}
|
||||
logger.debug("List of organizations to return for user " + username + " is " + toReturn);
|
||||
httpSession.setAttribute(keyPerScope, toReturn);
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* A bean that contains the tuple :
|
||||
* <Organization Name, Organization Url, User's role in it>
|
||||
* @author Costantino Perciante at ISTI-CNR
|
||||
* (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class BeanUserInOrgRole implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 9022496195659804838L;
|
||||
private String orgName;
|
||||
private String orgUrl;
|
||||
private CkanRole role;
|
||||
|
||||
public BeanUserInOrgRole() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param orgName
|
||||
* @param orgUrl
|
||||
* @param role
|
||||
*/
|
||||
public BeanUserInOrgRole(String orgName, String orgUrl, CkanRole role) {
|
||||
super();
|
||||
this.orgName = orgName;
|
||||
this.orgUrl = orgUrl;
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public String getOrgName() {
|
||||
return orgName;
|
||||
}
|
||||
|
||||
public void setOrgName(String orgName) {
|
||||
this.orgName = orgName;
|
||||
}
|
||||
|
||||
public String getOrgUrl() {
|
||||
return orgUrl;
|
||||
}
|
||||
|
||||
public void setOrgUrl(String orgUrl) {
|
||||
this.orgUrl = orgUrl;
|
||||
}
|
||||
|
||||
public CkanRole getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(CkanRole role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BeanUserInOrgRole [orgName=" + orgName + ", orgUrl=" + orgUrl
|
||||
+ ", role=" + role + "]";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue