Integrated the roles defined in the UCD with the ActionDefinitions
This commit is contained in:
parent
25ff6fb152
commit
59a16651ce
|
@ -250,14 +250,7 @@ public class GeoPortalDataEntryApp implements EntryPoint {
|
||||||
myRights = gNADataEntryConfig.getUserRights();
|
myRights = gNADataEntryConfig.getUserRights();
|
||||||
initGUI();
|
initGUI();
|
||||||
GcubeUserRole userRole = myRights.getRoleRights().getUserRole();
|
GcubeUserRole userRole = myRights.getRoleRights().getUserRole();
|
||||||
String msg = "Logged in as ";
|
mainTabPanel.setRole(userRole);
|
||||||
if (userRole != null && userRole.getName() != null) {
|
|
||||||
msg += userRole.getName().substring(userRole.getName().indexOf("-") + 1,
|
|
||||||
userRole.getName().length());
|
|
||||||
} else
|
|
||||||
msg += "Member";
|
|
||||||
|
|
||||||
mainTabPanel.setRoleLabel(msg);
|
|
||||||
|
|
||||||
RoleRights roleRights = myRights.getRoleRights();
|
RoleRights roleRights = myRights.getRoleRights();
|
||||||
boolean canCreateNewItem = roleRights.getListPermessions().keySet()
|
boolean canCreateNewItem = roleRights.getListPermessions().keySet()
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.gcube.application.geoportalcommon.shared.SearchingFilter;
|
||||||
import org.gcube.application.geoportalcommon.shared.SearchingFilter.LOGICAL_OP;
|
import org.gcube.application.geoportalcommon.shared.SearchingFilter.LOGICAL_OP;
|
||||||
import org.gcube.application.geoportalcommon.shared.SearchingFilter.ORDER;
|
import org.gcube.application.geoportalcommon.shared.SearchingFilter.ORDER;
|
||||||
import org.gcube.application.geoportalcommon.shared.WhereClause;
|
import org.gcube.application.geoportalcommon.shared.WhereClause;
|
||||||
|
import org.gcube.application.geoportalcommon.shared.config.GcubeUserRole;
|
||||||
import org.gcube.application.geoportalcommon.shared.config.OPERATION_ON_ITEM;
|
import org.gcube.application.geoportalcommon.shared.config.OPERATION_ON_ITEM;
|
||||||
import org.gcube.application.geoportalcommon.shared.geoportal.ConfigurationDV;
|
import org.gcube.application.geoportalcommon.shared.geoportal.ConfigurationDV;
|
||||||
import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV;
|
import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV;
|
||||||
|
@ -180,6 +181,8 @@ public class GeonaMainTabPanel extends Composite {
|
||||||
|
|
||||||
private CacheSearchingFilterParametersFromConfig cacheSearchingFilterParameters;
|
private CacheSearchingFilterParametersFromConfig cacheSearchingFilterParameters;
|
||||||
|
|
||||||
|
private GcubeUserRole userRole;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new geona main tab panel.
|
* Instantiates a new geona main tab panel.
|
||||||
*
|
*
|
||||||
|
@ -440,9 +443,17 @@ public class GeonaMainTabPanel extends Composite {
|
||||||
/**
|
/**
|
||||||
* Sets the role label.
|
* Sets the role label.
|
||||||
*
|
*
|
||||||
* @param msg the new role label
|
* @param userRole the user role
|
||||||
|
* @param roleTitle the role title
|
||||||
*/
|
*/
|
||||||
public void setRoleLabel(String msg) {
|
public void setRole(GcubeUserRole userRole) {
|
||||||
|
this.userRole = userRole;
|
||||||
|
String msg = "Logged in as ";
|
||||||
|
if (userRole != null && userRole.getName() != null) {
|
||||||
|
msg += userRole.getName().substring(userRole.getName().indexOf("-") + 1,
|
||||||
|
userRole.getName().length());
|
||||||
|
} else
|
||||||
|
msg += "Member";
|
||||||
roleLabel.setText(msg);
|
roleLabel.setText(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -739,7 +750,7 @@ public class GeonaMainTabPanel extends Composite {
|
||||||
|
|
||||||
public <T> void showActionsOnSelected(List<T> selectItems) {
|
public <T> void showActionsOnSelected(List<T> selectItems) {
|
||||||
|
|
||||||
actionListPanel.showActionsOnSelected(selectItems);
|
actionListPanel.showActionsOnSelected(selectItems, userRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package org.gcube.portlets.user.geoportaldataentry.client.ui.action;
|
||||||
|
|
||||||
|
import org.gcube.application.geoportalcommon.shared.geoportal.config.ActionDefinitionDV;
|
||||||
|
|
||||||
|
import com.github.gwtbootstrap.client.ui.Button;
|
||||||
|
|
||||||
|
public class ActionDefButton {
|
||||||
|
|
||||||
|
private ActionDefinitionDV actionDefinitionDV;
|
||||||
|
private Button button;
|
||||||
|
|
||||||
|
public ActionDefButton(ActionDefinitionDV actionDefinitionDV, Button button) {
|
||||||
|
this.actionDefinitionDV = actionDefinitionDV;
|
||||||
|
this.button = button;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionDefinitionDV getActionDefinitionDV() {
|
||||||
|
return actionDefinitionDV;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Button getButton() {
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -5,7 +5,9 @@ import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.gcube.application.geoportalcommon.shared.config.GcubeUserRole;
|
||||||
import org.gcube.application.geoportalcommon.shared.geoportal.ResultDocumentDV;
|
import org.gcube.application.geoportalcommon.shared.geoportal.ResultDocumentDV;
|
||||||
import org.gcube.application.geoportalcommon.shared.geoportal.config.ActionDefinitionDV;
|
import org.gcube.application.geoportalcommon.shared.geoportal.config.ActionDefinitionDV;
|
||||||
import org.gcube.portlets.user.geoportaldataentry.client.events.WorkflowActionOnSelectedItemEvent;
|
import org.gcube.portlets.user.geoportaldataentry.client.events.WorkflowActionOnSelectedItemEvent;
|
||||||
|
@ -52,7 +54,7 @@ public class ActionListPanel extends Composite {
|
||||||
@UiField
|
@UiField
|
||||||
HTMLPanel actionListBasePanel;
|
HTMLPanel actionListBasePanel;
|
||||||
|
|
||||||
private Map<String, List<Button>> mapPhaseListButtons;
|
private Map<String, List<ActionDefButton>> mapPhaseListButtons;
|
||||||
|
|
||||||
private void initActions(List<ActionDefinitionDV> listActionDef) {
|
private void initActions(List<ActionDefinitionDV> listActionDef) {
|
||||||
|
|
||||||
|
@ -62,7 +64,7 @@ public class ActionListPanel extends Composite {
|
||||||
ButtonGroup buttonGroup = new ButtonGroup();
|
ButtonGroup buttonGroup = new ButtonGroup();
|
||||||
buttonGroup.getElement().addClassName("actions-button-group");
|
buttonGroup.getElement().addClassName("actions-button-group");
|
||||||
|
|
||||||
mapPhaseListButtons = new LinkedHashMap<String, List<Button>>();
|
mapPhaseListButtons = new LinkedHashMap<String, List<ActionDefButton>>();
|
||||||
|
|
||||||
for (ActionDefinitionDV actionDefinitionDV : listActionDef) {
|
for (ActionDefinitionDV actionDefinitionDV : listActionDef) {
|
||||||
Button butt = new Button();
|
Button butt = new Button();
|
||||||
|
@ -82,11 +84,11 @@ public class ActionListPanel extends Composite {
|
||||||
String[] displayOnPhases = actionDefinitionDV.getDisplayOnPhase();
|
String[] displayOnPhases = actionDefinitionDV.getDisplayOnPhase();
|
||||||
|
|
||||||
for (String displayOnPhase : displayOnPhases) {
|
for (String displayOnPhase : displayOnPhases) {
|
||||||
List<Button> mapPhase = mapPhaseListButtons.get(displayOnPhase);
|
List<ActionDefButton> mapPhase = mapPhaseListButtons.get(displayOnPhase);
|
||||||
if (mapPhase == null)
|
if (mapPhase == null)
|
||||||
mapPhase = new ArrayList<Button>();
|
mapPhase = new ArrayList<ActionDefButton>();
|
||||||
|
|
||||||
mapPhase.add(butt);
|
mapPhase.add(new ActionDefButton(actionDefinitionDV, butt));
|
||||||
mapPhaseListButtons.put(displayOnPhase, mapPhase);
|
mapPhaseListButtons.put(displayOnPhase, mapPhase);
|
||||||
}
|
}
|
||||||
buttonGroup.add(butt);
|
buttonGroup.add(butt);
|
||||||
|
@ -99,7 +101,7 @@ public class ActionListPanel extends Composite {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> void showActionsOnSelected(List<T> listSelected) {
|
public <T> void showActionsOnSelected(List<T> listSelected, GcubeUserRole userRole) {
|
||||||
setAllActionsVisible(false);
|
setAllActionsVisible(false);
|
||||||
|
|
||||||
if (listSelected.size() == 1) {
|
if (listSelected.size() == 1) {
|
||||||
|
@ -110,10 +112,23 @@ public class ActionListPanel extends Composite {
|
||||||
|
|
||||||
String itemPhase = ((ResultDocumentDV) item).getLifecycleInfo().getPhase();
|
String itemPhase = ((ResultDocumentDV) item).getLifecycleInfo().getPhase();
|
||||||
|
|
||||||
List<Button> listButtons = mapPhaseListButtons.get(itemPhase);
|
List<ActionDefButton> listButtons = mapPhaseListButtons.get(itemPhase);
|
||||||
for (Button button : listButtons) {
|
for (ActionDefButton actionDefButton : listButtons) {
|
||||||
button.setVisible(true);
|
|
||||||
actionListBasePanel.setVisible(true);
|
Set<String> roles = actionDefButton.getActionDefinitionDV().getRoles();
|
||||||
|
|
||||||
|
//No role/s defined means enable the action by default
|
||||||
|
if(roles.isEmpty()) {
|
||||||
|
actionDefButton.getButton().setVisible(true);
|
||||||
|
actionListBasePanel.setVisible(true);
|
||||||
|
}else {
|
||||||
|
//Checking if the userRole is matching the role defined in the ActionDefinition
|
||||||
|
boolean isRoleIntoActionDef= roles.stream().anyMatch(userRole.getName()::equalsIgnoreCase);
|
||||||
|
if(isRoleIntoActionDef) {
|
||||||
|
actionDefButton.getButton().setVisible(true);
|
||||||
|
actionListBasePanel.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,11 +137,11 @@ public class ActionListPanel extends Composite {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setAllActionsVisible(boolean bool) {
|
private void setAllActionsVisible(boolean bool) {
|
||||||
Iterator<List<Button>> collIterator = mapPhaseListButtons.values().iterator();
|
Iterator<List<ActionDefButton>> collIterator = mapPhaseListButtons.values().iterator();
|
||||||
while (collIterator.hasNext()) {
|
while (collIterator.hasNext()) {
|
||||||
List<Button> listButton = collIterator.next();
|
List<ActionDefButton> listButton = collIterator.next();
|
||||||
for (Button button : listButton) {
|
for (ActionDefButton actionDefButton : listButton) {
|
||||||
button.setVisible(bool);
|
actionDefButton.getButton().setVisible(bool);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.gcube.portlets.user.geoportaldataentry.client.ui.utils;
|
package org.gcube.portlets.user.geoportaldataentry.client.ui.utils;
|
||||||
|
|
||||||
|
import com.google.gwt.dom.client.Element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class HTMLUtil.
|
* The Class HTMLUtil.
|
||||||
*
|
*
|
||||||
|
@ -78,4 +80,66 @@ public class HTMLUtil {
|
||||||
return "</" + tag.name() + ">";
|
return "</" + tag.name() + ">";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Json to HTML.
|
||||||
|
*
|
||||||
|
* @param jsonTxt the json txt
|
||||||
|
* @param cssClassToTable the css class to table
|
||||||
|
* @return the element
|
||||||
|
*/
|
||||||
|
public static native Element jsonToHTML(String jsonTxt, String cssClassToTable)/*-{
|
||||||
|
try {
|
||||||
|
|
||||||
|
var jsonObj = JSON.parse(jsonTxt);
|
||||||
|
//console.log(jsonObj.length)
|
||||||
|
|
||||||
|
if (jsonObj.length == undefined)
|
||||||
|
jsonObj = [ jsonObj ]
|
||||||
|
//console.log(jsonObj.length)
|
||||||
|
|
||||||
|
// EXTRACT VALUE FOR HTML HEADER.
|
||||||
|
var col = [];
|
||||||
|
for (var i = 0; i < jsonObj.length; i++) {
|
||||||
|
for ( var key in jsonObj[i]) {
|
||||||
|
//console.log('key json' +key)
|
||||||
|
if (col.indexOf(key) === -1) {
|
||||||
|
col.push(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CREATE DYNAMIC TABLE.
|
||||||
|
var table = document.createElement("table");
|
||||||
|
var addDefaultCss = "json-to-html-table-column";
|
||||||
|
if (cssClassToTable) {
|
||||||
|
addDefaultCss = cssClassToTable;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
table.classList.add(addDefaultCss);
|
||||||
|
} catch (e) {
|
||||||
|
console.log('invalid css add', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ADD JSON DATA TO THE TABLE AS ROWS.
|
||||||
|
for (var i = 0; i < col.length; i++) {
|
||||||
|
|
||||||
|
tr = table.insertRow(-1);
|
||||||
|
var firstCell = tr.insertCell(-1);
|
||||||
|
//firstCell.style.cssText="font-weight: bold; text-align: center; vertical-align: middle;";
|
||||||
|
firstCell.innerHTML = col[i];
|
||||||
|
for (var j = 0; j < jsonObj.length; j++) {
|
||||||
|
var tabCell = tr.insertCell(-1);
|
||||||
|
var theValue = jsonObj[j][col[i]];
|
||||||
|
tabCell.innerHTML = theValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return table;
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.log('invalid json', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}-*/;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -745,7 +745,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
||||||
// DEV MODE
|
// DEV MODE
|
||||||
if (!SessionUtil.isIntoPortal()) {
|
if (!SessionUtil.isIntoPortal()) {
|
||||||
LOG.warn("OUT OF PORTAL - DEV MODE detected");
|
LOG.warn("OUT OF PORTAL - DEV MODE detected");
|
||||||
GcubeUserRole myRole = GcubeUserRole.DATA_MANAGER;
|
GcubeUserRole myRole = GcubeUserRole.DATA_EDITOR;
|
||||||
|
|
||||||
for (RoleRights roleRight : listUserRightsForRole) {
|
for (RoleRights roleRight : listUserRightsForRole) {
|
||||||
if (roleRight.getUserRole().equals(myRole)) {
|
if (roleRight.getUserRole().equals(myRole)) {
|
||||||
|
|
Loading…
Reference in New Issue