Commit 9a4f2c3a by Juho Juopperi

Merge branch 'master' of dev.intra.insomnia.fi:/data/bortal

2 parents 414a825e f4a76ba2
......@@ -2,12 +2,14 @@
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fi.insomnia.bortal.beans;
import fi.insomnia.bortal.facade.RoleFacade;
import fi.insomnia.bortal.model.Role;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import org.slf4j.Logger;
......@@ -22,7 +24,6 @@ public class RoleBean implements RoleBeanLocal {
@EJB
private RoleFacade roleFacade;
private static final Logger logger = LoggerFactory.getLogger(RoleBean.class);
public List<Role> listRoles() {
......@@ -41,8 +42,43 @@ public class RoleBean implements RoleBeanLocal {
return role;
}
public List<Role> getPossibleParents(Role role) {
List<Role> roleList = listRoles();
List<Role> children = getAllChilds(role, new HashSet<Role>());
for (Role unit : children) {
if (roleList.contains(role)) {
roleList.remove(role);
}
}
return roleList;
}
private static List<Role> getAllChilds(Role role, Set<Role> checkedRoles) {
List<Role> returnList = new ArrayList<Role>();
if (checkedRoles.contains(role)) {
return returnList;
}
for (Role unit : role.getChildren()) {
List<Role> someList = getAllChilds(unit, checkedRoles);
returnList.addAll(someList);
}
checkedRoles.add(role);
return returnList;
}
// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method")
}
......@@ -21,5 +21,7 @@ public interface RoleBeanLocal {
public void mergeChanges(Role role);
public Role create(Role role);
public List<Role> getPossibleParents(Role role);
}
......@@ -14,6 +14,10 @@
<ui:composition>
<h:panelGrid>
<h:outputText value="#{i18n['role.name']}" /><h:inputText value="#{roleView.role.name}" />
<h:selectManyListbox value="#{roleView.role.parents}">
<f:selectItems value="#{roleView.possibleParents}" />
</h:selectManyListbox>
</h:panelGrid>
</ui:composition>
</html>
......
......@@ -9,6 +9,7 @@ import fi.insomnia.bortal.beans.SecurityBeanLocal;
import fi.insomnia.bortal.exceptions.PermissionDeniedException;
import fi.insomnia.bortal.handler.SessionHandler;
import fi.insomnia.bortal.model.Role;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
......@@ -107,4 +108,11 @@ public class RoleView {
public void setSessionhandler(SessionHandler sessionhandler) {
this.sessionhandler = sessionhandler;
}
/**
* @return the possibleParents
*/
public List<Role> getPossibleParents() {
return roleBean.getPossibleParents(role);
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!