Commit 47396495 by Tuukka Kivilahti

some backend and create

1 parent c7a7529e
...@@ -10,6 +10,8 @@ import fi.insomnia.bortal.model.Role; ...@@ -10,6 +10,8 @@ import fi.insomnia.bortal.model.Role;
import java.util.List; import java.util.List;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* *
...@@ -21,9 +23,24 @@ public class RoleBean implements RoleBeanLocal { ...@@ -21,9 +23,24 @@ public class RoleBean implements RoleBeanLocal {
@EJB @EJB
private RoleFacade roleFacade; private RoleFacade roleFacade;
private static final Logger logger = LoggerFactory.getLogger(RoleBean.class);
public List<Role> listRoles() { public List<Role> listRoles() {
return roleFacade.findAll(); return roleFacade.findAll();
} }
public void mergeChanges(Role role) {
roleFacade.merge(role);
}
public Role create(Role role) {
roleFacade.create(role);
return role;
}
// Add business logic below. (Right-click in editor and choose // Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method") // "Insert Code > Add Business Method")
......
...@@ -19,5 +19,7 @@ public interface RoleBeanLocal { ...@@ -19,5 +19,7 @@ public interface RoleBeanLocal {
public List<Role> listRoles(); public List<Role> listRoles();
public void mergeChanges(Role role); public void mergeChanges(Role role);
public Role create(Role role);
} }
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:tools="http://java.sun.com/jsf/composite/tools"
xmlns:role="http://java.sun.com/jsf/composite/tools/role">
<composite:interface>
</composite:interface>
<composite:implementation>
<h:form>
<tools:canWrite target="roleManagement">
<f:facet name="errorMessage">
<h:outputText value="#{i18n['nasty.user']}" />
</f:facet>
<ui:include src="form.xhtml" />
<h:commandButton value="#{i18n['create']}" action="#{roleView.create}" />
</tools:canWrite>
</h:form>
</composite:implementation>
</html>
...@@ -54,7 +54,20 @@ public class RoleView { ...@@ -54,7 +54,20 @@ public class RoleView {
roleBean.mergeChanges(role); roleBean.mergeChanges(role);
return "roleSave"; return "roleSaved";
}
public String create() {
if (!sessionhandler.canWrite("roleManagement")) {
// Give message to administration what happened here.
throw new PermissionDeniedException(securitybean, getSessionhandler().getUser(), "User " + getSessionhandler().getUser() + " does not have permission to create role!");
}
role = roleBean.create(role);
return "roleCreated";
} }
public String edit() { public String edit() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!