diff --git a/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/AccountView.java b/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/AccountView.java index 79e4d84..a3ab284 100644 --- a/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/AccountView.java +++ b/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/AccountView.java @@ -6,6 +6,7 @@ import de.muehlencord.shared.account.business.account.entity.AccountEntity; import de.muehlencord.shared.account.business.account.entity.AccountException; import de.muehlencord.shared.account.business.account.entity.AccountStatus; import de.muehlencord.shared.account.business.account.entity.ApplicationRoleEntity; +import de.muehlencord.shared.account.business.application.entity.ApplicationEntity; import de.muehlencord.shared.jeeutil.FacesUtil; import java.io.Serializable; import java.util.ArrayList; @@ -56,9 +57,9 @@ public class AccountView implements Serializable { return accountList; } - public List getAllApplicationRoles() { + public List getAllApplicationRoles(ApplicationEntity application) { if (applicationRoles == null) { - applicationRoles = appliationRoleService.getAllRoles(); + applicationRoles = appliationRoleService.getAllRoles(application); } return applicationRoles; } diff --git a/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/GroupView.java b/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/RoleView.java similarity index 78% rename from account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/GroupView.java rename to account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/RoleView.java index be3c456..993c025 100644 --- a/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/GroupView.java +++ b/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/RoleView.java @@ -19,14 +19,15 @@ import de.muehlencord.shared.account.business.account.boundary.ApplicationRoleCo import de.muehlencord.shared.account.business.account.entity.AccountException; import de.muehlencord.shared.account.business.account.entity.ApplicationPermissionEntity; import de.muehlencord.shared.account.business.account.entity.ApplicationRoleEntity; +import de.muehlencord.shared.account.business.application.entity.ApplicationEntity; import de.muehlencord.shared.jeeutil.FacesUtil; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import javax.ejb.EJB; import javax.enterprise.context.SessionScoped; -import javax.inject.Named; -import javax.validation.constraints.Size; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.ManagedProperty; import org.primefaces.event.SelectEvent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,23 +36,19 @@ import org.slf4j.LoggerFactory; * * @author Joern Muehlencord */ +@ManagedBean(name = "roleView") @SessionScoped -@Named -public class GroupView implements Serializable { +public class RoleView implements Serializable { private static final long serialVersionUID = 1669321020398119007L; - private static final Logger LOGGER = LoggerFactory.getLogger(GroupView.class); + private static final Logger LOGGER = LoggerFactory.getLogger(RoleView.class); + + @ManagedProperty(value = "#{applicationView}") + private ApplicationView applicationView; @EJB ApplicationRoleControl applicationRoleControl; - @Size(max = 80) - private String newRoleName; - @Size(max = 200) - private String newRoleDescription; - // flag to determine whether a role is selected or not - private boolean isPermissionSelected = false; - private List allRoles = null; private List currentRolePermissions = null; private List missingApplicationsPermissions = null; @@ -62,31 +59,30 @@ public class GroupView implements Serializable { public List getAllRoles() { if (allRoles == null) { - allRoles = applicationRoleControl.getAllRoles(); + allRoles = applicationRoleControl.getAllRoles(applicationView.getCurrentApplication()); } return allRoles; } - public void newRole() { - if ((newRoleName == null) || (newRoleName.trim().length() == 0)) { - FacesUtil.addGlobalErrorMessage("Error", "Permission name must not be null"); - } else if ((newRoleDescription == null) || (newRoleDescription.trim().length() == 0)) { - FacesUtil.addGlobalErrorMessage("Error", "Permission name must not be null"); - } else { - applicationRoleControl.createOrUpdate(newRoleName, newRoleDescription); - allRoles = null; // force reload - newRoleName = null; - newRoleDescription = null; - } + public void startNewRole() { + this.currentRole = new ApplicationRoleEntity(applicationView.getCurrentApplication()); } - public void editRole() { - if (currentRole == null) { - FacesUtil.addGlobalErrorMessage("Error", "Please select a permission to edit"); - } else { + public void cancelEditRole() { + this.currentRole = null; + } + + public void saveEditRole() { + if ((currentRole == null) || (currentRole.getRoleName() == null) || (currentRole.getRoleName().trim().length() == 0)) { + FacesUtil.addGlobalErrorMessage("Error", "Permission name must not be null"); + } else if (currentRole.getId() == null) { + applicationRoleControl.create(currentRole); allRoles = null; // force reload - newRoleName = currentRole.getRoleName(); - newRoleDescription = currentRole.getRoleDescription(); + FacesUtil.addGlobalInfoMessage("Info", "Role " + currentRole.getRoleName() + " created"); + } else { + applicationRoleControl.create(currentRole); + allRoles = null; // force reload + FacesUtil.addGlobalInfoMessage("Info", "Role " + currentRole.getRoleName() + " updated"); } } @@ -110,6 +106,10 @@ public class GroupView implements Serializable { } } + public boolean getPermissionSelected() { + return currentPermission != null; + } + public void onRoleSelect(SelectEvent event) { currentRolePermissions = null; currentRolePermissions = getRolePermissions(); @@ -191,16 +191,20 @@ public class GroupView implements Serializable { } } - - public void selectPermission() { - this.isPermissionSelected = true; - } - - public void deselectPermission() { - this.isPermissionSelected = false; - } + +// public void selectPermission() { +// this.isPermissionSelected = true; +// } +// +// public void deselectPermission() { +// this.isPermissionSelected = false; +// } /* *** getter / setter *** */ + public void setApplicationView(ApplicationView applicationView) { + this.applicationView = applicationView; + } + public ApplicationRoleEntity getCurrentRole() { return currentRole; } @@ -217,22 +221,6 @@ public class GroupView implements Serializable { this.currentPermission = currentPermission; } - public String getNewRoleName() { - return newRoleName; - } - - public void setNewRoleName(String newRoleName) { - this.newRoleName = newRoleName; - } - - public String getNewRoleDescription() { - return newRoleDescription; - } - - public void setNewRoleDescription(String newRoleDescription) { - this.newRoleDescription = newRoleDescription; - } - public ApplicationPermissionEntity getNewPermission() { return newPermission; } @@ -241,12 +229,4 @@ public class GroupView implements Serializable { this.newPermission = newPermission; } - public boolean isIsPermissionSelected() { - return isPermissionSelected; - } - - public void setIsPermissionSelected(boolean isPermissionSelected) { - this.isPermissionSelected = isPermissionSelected; - } - } diff --git a/account-ui/src/main/resources/de/muehlencord/shared/account/web/presentation/messages.properties b/account-ui/src/main/resources/de/muehlencord/shared/account/web/presentation/messages.properties index ae11f3c..0531262 100644 --- a/account-ui/src/main/resources/de/muehlencord/shared/account/web/presentation/messages.properties +++ b/account-ui/src/main/resources/de/muehlencord/shared/account/web/presentation/messages.properties @@ -129,3 +129,4 @@ label_phoneNumber=Phone Number label_template_waitlist_cancelled=Waitlist cancelled mail template msgs_menu_status=Status menu_status=Status +button_add=Add diff --git a/account-ui/src/main/resources/de/muehlencord/shared/account/web/presentation/messages_de.properties b/account-ui/src/main/resources/de/muehlencord/shared/account/web/presentation/messages_de.properties index ac1af1a..b3cdd01 100644 --- a/account-ui/src/main/resources/de/muehlencord/shared/account/web/presentation/messages_de.properties +++ b/account-ui/src/main/resources/de/muehlencord/shared/account/web/presentation/messages_de.properties @@ -130,3 +130,4 @@ label_phoneNumber=Telefonnummer label_template_waitlist_cancelled=Vorlage Warteliste Abbruch msgs_menu_status=Status menu_status=Status +button_add=Hinzuf\u00fcgen diff --git a/account-ui/src/main/resources/de/muehlencord/shared/account/web/presentation/messages_en.properties b/account-ui/src/main/resources/de/muehlencord/shared/account/web/presentation/messages_en.properties index 382fcb1..ceaabd1 100644 --- a/account-ui/src/main/resources/de/muehlencord/shared/account/web/presentation/messages_en.properties +++ b/account-ui/src/main/resources/de/muehlencord/shared/account/web/presentation/messages_en.properties @@ -130,3 +130,4 @@ label_phoneNumber=Phone Number label_template_waitlist_cancelled=Waitlist cancelled mail template msgs_menu_status=Status menu_status=Status +button_add=Add diff --git a/account-ui/src/main/webapp/login.xhtml b/account-ui/src/main/webapp/login.xhtml index 3cfb3fe..5c4b639 100644 --- a/account-ui/src/main/webapp/login.xhtml +++ b/account-ui/src/main/webapp/login.xhtml @@ -86,9 +86,6 @@ -

 

- diff --git a/account-ui/src/main/webapp/web/account.xhtml b/account-ui/src/main/webapp/web/account.xhtml index c2c42f1..5c6967b 100644 --- a/account-ui/src/main/webapp/web/account.xhtml +++ b/account-ui/src/main/webapp/web/account.xhtml @@ -14,7 +14,7 @@ - List all accounts + for #{applicationView.currentApplication.applicationName} diff --git a/account-ui/src/main/webapp/web/roles.xhtml b/account-ui/src/main/webapp/web/roles.xhtml index 904570c..4d70e32 100644 --- a/account-ui/src/main/webapp/web/roles.xhtml +++ b/account-ui/src/main/webapp/web/roles.xhtml @@ -9,60 +9,51 @@ xmlns:composite="http://xmlns.jcp.org/jsf/composite/composite"> - Group Overview + Roles Overview - List all groups + for #{applicationView.currentApplication.applicationName} - - -
-
-
- - -
-
-
-
- - -
-
-
- -
-
- -
-
- - - -
-
-
- - - - - + + + - + + + + +
+
+ +
+
+ +
+
+ + + +
+
+
- - - + + + + + @@ -71,17 +62,17 @@ - - + +
- +
- +
@@ -91,6 +82,47 @@
-
+ + + + + + + +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ +
+ + +
+
+ + +
+
+
+
+
diff --git a/account/src/main/java/de/muehlencord/shared/account/business/account/boundary/ApplicationRoleControl.java b/account/src/main/java/de/muehlencord/shared/account/business/account/boundary/ApplicationRoleControl.java index 58a119d..9e29993 100644 --- a/account/src/main/java/de/muehlencord/shared/account/business/account/boundary/ApplicationRoleControl.java +++ b/account/src/main/java/de/muehlencord/shared/account/business/account/boundary/ApplicationRoleControl.java @@ -8,6 +8,7 @@ package de.muehlencord.shared.account.business.account.boundary; import de.muehlencord.shared.account.business.account.entity.AccountException; import de.muehlencord.shared.account.business.account.entity.ApplicationPermissionEntity; import de.muehlencord.shared.account.business.account.entity.ApplicationRoleEntity; +import de.muehlencord.shared.account.business.application.entity.ApplicationEntity; import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -37,8 +38,9 @@ public class ApplicationRoleControl implements Serializable { @PersistenceContext EntityManager em; - public List getAllRoles() { + public List getAllRoles(ApplicationEntity application) { Query query = em.createNamedQuery("ApplicationRoleEntity.findAll"); + query.setParameter ("application", application); List roles = query.getResultList(); if (roles == null) { @@ -49,25 +51,35 @@ public class ApplicationRoleControl implements Serializable { } @Transactional - public void createOrUpdate(String name, String description) { + public void createOrUpdate(ApplicationEntity application, String name, String description) { ApplicationRoleEntity role = findByName(name); if (role == null) { - role = new ApplicationRoleEntity(name, description); + role = new ApplicationRoleEntity(application, name, description); em.persist(role); } else { role.setRoleDescription(description); em.merge(role); } } - - public void delete(ApplicationRoleEntity permission) throws AccountException { - ApplicationRoleEntity existingPermission = attach(permission); - em.remove(existingPermission); + + @Transactional + public void create(ApplicationRoleEntity role) { + em.persist(role); + } + + @Transactional + public void update (ApplicationRoleEntity role) { + em.merge(role); } - public ApplicationRoleEntity attach(ApplicationRoleEntity permission) throws AccountException { + public void delete(ApplicationRoleEntity role) throws AccountException { + ApplicationRoleEntity existingRole = attach(role); + em.remove(existingRole); + } + + public ApplicationRoleEntity attach(ApplicationRoleEntity role) throws AccountException { try { - return em.merge(permission); + return em.merge(role); } catch (OptimisticLockException ex) { throw new AccountException("Entity updated / deleted, please reload", true); } diff --git a/account/src/main/java/de/muehlencord/shared/account/business/account/entity/ApplicationRoleEntity.java b/account/src/main/java/de/muehlencord/shared/account/business/account/entity/ApplicationRoleEntity.java index d49f149..f03477d 100644 --- a/account/src/main/java/de/muehlencord/shared/account/business/account/entity/ApplicationRoleEntity.java +++ b/account/src/main/java/de/muehlencord/shared/account/business/account/entity/ApplicationRoleEntity.java @@ -31,9 +31,9 @@ import org.hibernate.annotations.Type; @Table(name = "application_role") @XmlRootElement @NamedQueries({ - @NamedQuery(name = "ApplicationRoleEntity.findAll", query = "SELECT a FROM ApplicationRoleEntity a ORDER BY a.roleName") - , @NamedQuery(name = "ApplicationRoleEntity.findByRoleName", query = "SELECT a FROM ApplicationRoleEntity a WHERE a.roleName = :roleName") - , @NamedQuery(name = "ApplicationRoleEntity.findByRoleDescription", query = "SELECT a FROM ApplicationRoleEntity a WHERE a.roleDescription = :roleDescription")}) + @NamedQuery(name = "ApplicationRoleEntity.findAll", query = "SELECT a FROM ApplicationRoleEntity a WHERE a.application = :application ORDER BY a.roleName"), + @NamedQuery(name = "ApplicationRoleEntity.findByRoleName", query = "SELECT a FROM ApplicationRoleEntity a WHERE a.application = :application AND a.roleName = :roleName"), + @NamedQuery(name = "ApplicationRoleEntity.findByRoleDescription", query = "SELECT a FROM ApplicationRoleEntity a WHERE a.application = :application AND a.roleDescription = :roleDescription")}) public class ApplicationRoleEntity implements Serializable { @@ -66,23 +66,28 @@ public class ApplicationRoleEntity implements Serializable { private List applicationPermissionList; @JoinColumn(name = "application", referencedColumnName = "id") @ManyToOne(optional = false) - private ApplicationEntity application; + private ApplicationEntity application; public ApplicationRoleEntity() { } - - public ApplicationRoleEntity(UUID id) { - this.id = id; - } - - public ApplicationRoleEntity(String roleName, String roleDescription) { + + public ApplicationRoleEntity(ApplicationEntity application) { this.id = null; + this.application = application; + this.roleName = null; + this.roleDescription = null; + } + + public ApplicationRoleEntity(ApplicationEntity application, String roleName, String roleDescription) { + this.id = null; + this.application = application; this.roleName = roleName; this.roleDescription = roleDescription; } - public ApplicationRoleEntity(UUID id, String roleName, String roleDescription) { + public ApplicationRoleEntity(UUID id, ApplicationEntity application, String roleName, String roleDescription) { this.id = id; + this.application = application; this.roleName = roleName; this.roleDescription = roleDescription; } @@ -128,14 +133,14 @@ public class ApplicationRoleEntity implements Serializable { public void setApplicationPermissionList(List applicationPermissionList) { this.applicationPermissionList = applicationPermissionList; } - + public ApplicationEntity getApplication() { return application; } public void setApplication(ApplicationEntity application) { this.application = application; - } + } @Override public int hashCode() {