groups tab modified to be equal to the organization one (a list of groups' titles and roles)

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@134415 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-11-21 09:12:24 +00:00
parent d0a912b954
commit d7d3e2fc08
11 changed files with 185 additions and 175 deletions

View File

@ -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.2.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>

View File

@ -137,8 +137,9 @@ public class CkanEventHandlerManager {
@Override
public void onShowGroups(ShowUserGroupsEvent showUserDatasetsEvent) {
String request = getCkanRequest("/dashboard/groups", null);
panel.instanceCkanFrame(request);
//String request = getCkanRequest("/dashboard/groups", null);
//panel.instanceCkanFrame(request);
panel.showGroups();
}
});

View File

@ -2,8 +2,7 @@ package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client;
import java.util.List;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInGroupRole;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInOrgRole;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInOrgGroupRole;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanRole;
@ -46,14 +45,14 @@ public interface GcubeCkanDataCatalogService extends RemoteService {
*
* @return the ckan organizations names and urls for user
*/
List<BeanUserInOrgRole> getCkanOrganizationsNamesAndUrlsForUser();
List<BeanUserInOrgGroupRole> getCkanOrganizationsNamesAndUrlsForUser();
/**
* Retrieve the list of groups to whom the user belongs and their urls.
*
* @return the ckan groups names and urls for user
*/
List<BeanUserInGroupRole> getCkanGroupsNamesAndUrlsForUser();
List<BeanUserInOrgGroupRole> getCkanGroupsNamesAndUrlsForUser();
/**
* Logout from ckan.

View File

@ -5,8 +5,7 @@ package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client;
import java.util.List;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInGroupRole;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInOrgRole;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInOrgGroupRole;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanRole;
@ -64,15 +63,7 @@ public interface GcubeCkanDataCatalogServiceAsync {
* @return the ckan organizations names and urls for user
*/
void getCkanOrganizationsNamesAndUrlsForUser(
AsyncCallback<List<BeanUserInOrgRole>> callback);
/**
* Outside portal.
*
* @param callback the callback
*/
void outsidePortal(AsyncCallback<Boolean> callback);
AsyncCallback<List<BeanUserInOrgGroupRole>> callback);
/**
* Retrieve the list of groups to whom the user belongs and their urls.
@ -80,6 +71,13 @@ public interface GcubeCkanDataCatalogServiceAsync {
* @return the ckan groups names and urls for user
*/
void getCkanGroupsNamesAndUrlsForUser(
AsyncCallback<List<BeanUserInGroupRole>> callback);
AsyncCallback<List<BeanUserInOrgGroupRole>> callback);
/**
* Outside portal.
*
* @param callback the callback
*/
void outsidePortal(AsyncCallback<Boolean> callback);
}

View File

@ -3,7 +3,7 @@ package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.view;
import java.util.List;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.resource.CkanPortletResources;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInGroupRole;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInOrgGroupRole;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint;
import com.github.gwtbootstrap.client.ui.Button;
@ -25,7 +25,7 @@ import com.google.gwt.user.client.ui.VerticalPanel;
*/
public class CkanGroupsPanel extends VerticalPanel{
private List<BeanUserInGroupRole> groups;
private List<BeanUserInOrgGroupRole> groups;
private GCubeCkanDataCatalogPanel father;
private Image loading = new Image(CkanPortletResources.ICONS.loading());
@ -42,7 +42,7 @@ public class CkanGroupsPanel extends VerticalPanel{
* Set the groups to show. If a null list is passed, it is an error
* @param result
*/
public void setGroups(List<BeanUserInGroupRole> result) {
public void setGroups(List<BeanUserInOrgGroupRole> result) {
this.groups = result;
@ -72,18 +72,18 @@ public class CkanGroupsPanel extends VerticalPanel{
UnorderedList list = new UnorderedList();
for (final BeanUserInGroupRole org : groups) {
for (final BeanUserInOrgGroupRole org : groups) {
Paragraph line = new Paragraph();
Button b = new Button();
b.setType(ButtonType.LINK);
b.setText(org.getGroupName());
b.setText(org.getName());
b.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
String request = getCkanRequest(org.getOrgUrl(), null);
String request = getCkanRequest(org.getUrl(), null);
father.instanceCkanFrame(request);
}

View File

@ -3,7 +3,7 @@ package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.view;
import java.util.List;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.resource.CkanPortletResources;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInOrgRole;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInOrgGroupRole;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint;
import com.github.gwtbootstrap.client.ui.Button;
@ -25,7 +25,7 @@ import com.google.gwt.user.client.ui.VerticalPanel;
*/
public class CkanOrganizationsPanel extends VerticalPanel{
private List<BeanUserInOrgRole> organizations;
private List<BeanUserInOrgGroupRole> organizations;
private GCubeCkanDataCatalogPanel father;
private Image loading = new Image(CkanPortletResources.ICONS.loading());
@ -42,7 +42,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(List<BeanUserInOrgRole> result) {
public void setOrganizations(List<BeanUserInOrgGroupRole> result) {
this.organizations = result;
@ -72,18 +72,18 @@ public class CkanOrganizationsPanel extends VerticalPanel{
UnorderedList list = new UnorderedList();
for (final BeanUserInOrgRole org : organizations) {
for (final BeanUserInOrgGroupRole org : organizations) {
Paragraph line = new Paragraph();
Button b = new Button();
b.setType(ButtonType.LINK);
b.setText(org.getOrgName());
b.setText(org.getName());
b.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
String request = getCkanRequest(org.getOrgUrl(), null);
String request = getCkanRequest(org.getUrl(), null);
father.instanceCkanFrame(request);
}

View File

@ -10,7 +10,7 @@ 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.BeanUserInOrgGroupRole;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanRole;
import org.gcube.portlets.widgets.sessionchecker.client.CheckSession;
@ -39,6 +39,7 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
private ScrollPanel centerScrollable = new ScrollPanel();
private CkanFramePanel ckanFramePanel;
private CkanOrganizationsPanel ckanOrganizationsPanel;
private CkanGroupsPanel ckanGroupsPanel;
private Image loading = new Image(CkanPortletResources.ICONS.loading());
private RootPanel rootPanel;
private HandlerManager eventBus;
@ -61,6 +62,7 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
ckanFramePanel = new CkanFramePanel(eventBus);
managementPanel = new CkanMetadataManagementPanel(eventBus);
ckanOrganizationsPanel = new CkanOrganizationsPanel(this);
ckanGroupsPanel = new CkanGroupsPanel(this);
initPanel();
setTopPanelVisible(true);
@ -133,11 +135,11 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
break;
}
// RETRIEVE USER'S ORGANIZATIONS
GCubeCkanDataCatalog.service.getCkanOrganizationsNamesAndUrlsForUser(new AsyncCallback<List<BeanUserInOrgRole>>() {
// retrieve organizations
GCubeCkanDataCatalog.service.getCkanOrganizationsNamesAndUrlsForUser(new AsyncCallback<List<BeanUserInOrgGroupRole>>() {
@Override
public void onSuccess(List<BeanUserInOrgRole> result) {
public void onSuccess(List<BeanUserInOrgGroupRole> result) {
ckanOrganizationsPanel.setOrganizations(result);
}
@ -151,6 +153,24 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
}
});
// retrieve groups
GCubeCkanDataCatalog.service.getCkanGroupsNamesAndUrlsForUser(new AsyncCallback<List<BeanUserInOrgGroupRole>>() {
@Override
public void onSuccess(List<BeanUserInOrgGroupRole> result) {
ckanGroupsPanel.setGroups(result);
}
@Override
public void onFailure(Throwable caught) {
ckanGroupsPanel.setGroups(null);
}
});
}
});
}
@ -236,6 +256,7 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
ckanFramePanel.setVisible(true);
ckanOrganizationsPanel.setVisible(false);
ckanGroupsPanel.setVisible(false);
return ckanFramePanel.instanceFrame(ckanUrlConnector);
}
@ -250,6 +271,7 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
containerIntoScrollPanel.setWidth("100%");
containerIntoScrollPanel.add(ckanFramePanel);
containerIntoScrollPanel.add(ckanOrganizationsPanel);
containerIntoScrollPanel.add(ckanGroupsPanel);
centerScrollable.add(containerIntoScrollPanel);
ckanOrganizationsPanel.setVisible(false);
addToMiddle(centerScrollable);
@ -388,6 +410,17 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
public void showOrganizations() {
ckanOrganizationsPanel.setVisible(true);
ckanGroupsPanel.setVisible(false);
ckanFramePanel.setVisible(false);
}
/**
* Show the groups panel.
*/
public void showGroups() {
ckanGroupsPanel.setVisible(true);
ckanOrganizationsPanel.setVisible(false);
ckanFramePanel.setVisible(false);
}
}

View File

@ -19,8 +19,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.BeanUserInGroupRole;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInOrgRole;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInOrgGroupRole;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanRole;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.GroupBean;
@ -449,14 +448,14 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
}
@Override
public List<BeanUserInOrgRole> getCkanOrganizationsNamesAndUrlsForUser() {
public List<BeanUserInOrgGroupRole> getCkanOrganizationsNamesAndUrlsForUser() {
List<BeanUserInOrgRole> toReturn = new ArrayList<BeanUserInOrgRole>();
List<BeanUserInOrgGroupRole> toReturn = new ArrayList<BeanUserInOrgGroupRole>();
if(!SessionUtil.isIntoPortal()){
logger.warn("You are not into the portal");
BeanUserInOrgRole org = new BeanUserInOrgRole("testVRE", "/organization/devvre", CkanRole.ADMIN);
BeanUserInOrgGroupRole org = new BeanUserInOrgGroupRole("testVRE", "/organization/devvre", CkanRole.ADMIN);
toReturn.add(org);
}else{
@ -473,7 +472,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
// check if the aslsession already has such information
if(httpSession.getAttribute(keyPerScope) != null){
toReturn = (List<BeanUserInOrgRole>) httpSession.getAttribute(keyPerScope);
toReturn = (List<BeanUserInOrgGroupRole>) httpSession.getAttribute(keyPerScope);
logger.debug("List of organizations was into the session " + toReturn);
}else{
logger.debug("Organizations list wasn't into session, retrieving them");
@ -482,7 +481,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
String apiKey = catalogue.getApiKeyFromUsername(username);
for (CkanOrganization ckanOrganization : organizations) {
String role = catalogue.getRoleOfUserInOrganization(username, ckanOrganization.getName(), apiKey);
BeanUserInOrgRole org = new BeanUserInOrgRole(ckanOrganization.getTitle(), "/organization/" + ckanOrganization.getName(), CkanRole.valueOf(role.toUpperCase()));
BeanUserInOrgGroupRole org = new BeanUserInOrgGroupRole(ckanOrganization.getTitle(), "/organization/" + ckanOrganization.getName(), CkanRole.valueOf(role.toUpperCase()));
toReturn.add(org);
}
logger.debug("List of organizations to return for user " + username + " is " + toReturn);
@ -493,6 +492,53 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
return toReturn;
}
@Override
public List<BeanUserInOrgGroupRole> getCkanGroupsNamesAndUrlsForUser() {
List<BeanUserInOrgGroupRole> toReturn = new ArrayList<BeanUserInOrgGroupRole>();
if(!SessionUtil.isIntoPortal()){
logger.warn("You are not into the portal");
BeanUserInOrgGroupRole org = new BeanUserInOrgGroupRole("testGroup", "/group/testgroup", CkanRole.MEMBER);
toReturn.add(org);
}else{
HttpSession httpSession = this.getThreadLocalRequest().getSession();
ASLSession session = getASLSession(httpSession);
String username = session.getUsername();
// retrieve scope per current portlet url
String scopePerCurrentUrl = (String)this.getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_GROUPS_USER_KEY, scopePerCurrentUrl);
if(!username.equals(TEST_USER)){
// check if the aslsession already has such information
if(httpSession.getAttribute(keyPerScope) != null){
toReturn = (List<BeanUserInOrgGroupRole>) httpSession.getAttribute(keyPerScope);
logger.debug("List of groups was into the session " + toReturn);
}else{
logger.debug("Groups list wasn't into session, retrieving them");
DataCatalogue catalogue = getCatalogue(scopePerCurrentUrl);
List<CkanGroup> groups = catalogue.getGroupsByUser(username);
String apiKey = catalogue.getApiKeyFromUsername(username);
for (CkanGroup ckanGroup : groups) {
String role = catalogue.getRoleOfUserInGroup(username, ckanGroup.getName(), apiKey);
BeanUserInOrgGroupRole org = new BeanUserInOrgGroupRole(ckanGroup.getTitle(), "/group/" + ckanGroup.getName(), CkanRole.valueOf(role.toUpperCase()));
toReturn.add(org);
}
logger.debug("List of organizations to return for user " + username + " is " + toReturn);
httpSession.setAttribute(keyPerScope, toReturn);
}
}
}
return toReturn;
}
@Override
public boolean outsidePortal() {
@ -511,10 +557,4 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
}
}
@Override
public List<BeanUserInGroupRole> getCkanGroupsNamesAndUrlsForUser() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -1,62 +0,0 @@
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared;
import java.io.Serializable;
/**
* A bean that contains the tuple :
* <Group Name, Organization Url, User's role in it>
* @author Costantino Perciante at ISTI-CNR
* (costantino.perciante@isti.cnr.it)
*/
public class BeanUserInGroupRole implements Serializable {
private static final long serialVersionUID = 9022496195659804838L;
private String groupName;
private String orgUrl;
private CkanRole role;
public BeanUserInGroupRole() {
super();
}
/**
* @param groupName
* @param orgUrl
* @param role
*/
public BeanUserInGroupRole(String groupName, String orgUrl, CkanRole role) {
super();
this.groupName = groupName;
this.orgUrl = orgUrl;
this.role = role;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
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 "BeanUserInGroupRole [groupName=" + groupName + ", orgUrl="
+ orgUrl + ", role=" + role + "]";
}
}

View File

@ -0,0 +1,67 @@
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared;
import java.io.Serializable;
/**
* A bean that contains the tuple:
* <ul>
* <li>Organization/Group Name
* <li>Organization/Group Url
* <li>User's role in it
* </ul>
* @author Costantino Perciante at ISTI-CNR
* (costantino.perciante@isti.cnr.it)
*/
public class BeanUserInOrgGroupRole implements Serializable {
private static final long serialVersionUID = 9022496195659804838L;
private String name;
private String url;
private CkanRole role;
public BeanUserInOrgGroupRole() {
super();
}
/**
* @param orgName
* @param orgUrl
* @param role
*/
public BeanUserInOrgGroupRole(String name, String url, CkanRole role) {
super();
this.name = name;
this.url = url;
this.role = role;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public CkanRole getRole() {
return role;
}
public void setRole(CkanRole role) {
this.role = role;
}
@Override
public String toString() {
return "BeanUserInOrgGroupRole [name=" + name + ", url=" + url
+ ", role=" + role + "]";
}
}

View File

@ -1,63 +0,0 @@
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 + "]";
}
}