From af1cf69958e715c0c485fa4dc6adda2dbdbea4f4 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Thu, 12 Jun 2014 21:18:28 +0200 Subject: [PATCH] =?UTF-8?q?Nov=C3=A1=20agenda=20na=20definici=20st=C5=99ed?= =?UTF-8?q?isek=20a=20pracovn=C3=ADch=20skupin.=20refs=20#97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/info/bukova/isspst/Constants.java | 15 +- .../info/bukova/isspst/dao/WorkgroupDao.java | 7 + .../isspst/dao/jpa/WorkgroupDaoJPA.java | 13 ++ .../info/bukova/isspst/data/JobMapping.java | 71 +++++++++ .../java/info/bukova/isspst/data/Member.java | 63 ++++++++ .../info/bukova/isspst/data/Permission.java | 22 ++- .../bukova/isspst/data/PermissionType.java | 9 ++ .../java/info/bukova/isspst/data/Role.java | 26 +++- .../java/info/bukova/isspst/data/User.java | 29 +++- .../info/bukova/isspst/data/Workgroup.java | 125 +++++++++++++++ .../isspst/services/users/RoleService.java | 4 + .../services/users/RoleServiceImpl.java | 14 ++ .../workgroups/WorkgroupException.java | 20 +++ .../services/workgroups/WorkgroupService.java | 17 ++ .../workgroups/WorkgroupServiceImpl.java | 57 +++++++ .../isspst/ui/workgroups/WorkgroupForm.java | 145 ++++++++++++++++++ .../isspst/ui/workgroups/WorkgroupList.java | 22 +++ src/main/resources/hibernate.cfg.xml | 3 + .../WEB-INF/locales/zk-label.properties | 3 + .../webapp/WEB-INF/spring/root-context.xml | 9 ++ .../webapp/admin/permissions/permForm.zul | 6 +- src/main/webapp/app/navigation.zul | 1 + src/main/webapp/img/commission-small.png | Bin 0 -> 1640 bytes src/main/webapp/img/commission.png | Bin 0 -> 3389 bytes src/main/webapp/img/user-small-red.png | Bin 0 -> 3897 bytes src/main/webapp/img/user-small.png | Bin 0 -> 4077 bytes src/main/webapp/img/user.png | Bin 0 -> 30694 bytes src/main/webapp/workgroups/index.zul | 10 ++ src/main/webapp/workgroups/workgroupForm.zul | 67 ++++++++ src/main/webapp/workgroups/workgroups.zul | 94 ++++++++++++ 30 files changed, 838 insertions(+), 14 deletions(-) create mode 100644 src/main/java/info/bukova/isspst/dao/WorkgroupDao.java create mode 100644 src/main/java/info/bukova/isspst/dao/jpa/WorkgroupDaoJPA.java create mode 100644 src/main/java/info/bukova/isspst/data/JobMapping.java create mode 100644 src/main/java/info/bukova/isspst/data/Member.java create mode 100644 src/main/java/info/bukova/isspst/data/PermissionType.java create mode 100644 src/main/java/info/bukova/isspst/data/Workgroup.java create mode 100644 src/main/java/info/bukova/isspst/services/workgroups/WorkgroupException.java create mode 100644 src/main/java/info/bukova/isspst/services/workgroups/WorkgroupService.java create mode 100644 src/main/java/info/bukova/isspst/services/workgroups/WorkgroupServiceImpl.java create mode 100644 src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupForm.java create mode 100644 src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupList.java create mode 100644 src/main/webapp/img/commission-small.png create mode 100644 src/main/webapp/img/commission.png create mode 100644 src/main/webapp/img/user-small-red.png create mode 100644 src/main/webapp/img/user-small.png create mode 100644 src/main/webapp/img/user.png create mode 100644 src/main/webapp/workgroups/index.zul create mode 100644 src/main/webapp/workgroups/workgroupForm.zul create mode 100644 src/main/webapp/workgroups/workgroups.zul diff --git a/src/main/java/info/bukova/isspst/Constants.java b/src/main/java/info/bukova/isspst/Constants.java index 0de11b44..065f05bf 100644 --- a/src/main/java/info/bukova/isspst/Constants.java +++ b/src/main/java/info/bukova/isspst/Constants.java @@ -10,6 +10,7 @@ import info.bukova.isspst.services.munits.MUnitService; import info.bukova.isspst.services.material.MaterialService; import info.bukova.isspst.services.users.RoleService; import info.bukova.isspst.services.users.UserService; +import info.bukova.isspst.services.workgroups.WorkgroupService; public class Constants { @@ -53,13 +54,15 @@ public class Constants { public final static String MOD_BUILDINGS = "BUILDINGS"; public final static String MOD_MUNITS = "MUNITS"; public final static String MOD_MATERIAL = "MATERIAL"; + public final static String MOD_WORKGROUPS = "WORKGROUPS"; public final static Module MODULES[] = { - new Module(MOD_USERS, "Uživatelé", UserService.class) - , new Module(MOD_PERMISSIONS, "Práva", RoleService.class) - , new Module(MOD_ADDRESSBOOK, "Dodavatelé", AdbService.class) - , new Module(MOD_BUILDINGS, "Budovy", BuildingService.class) - , new Module(MOD_MUNITS, "Měrné jednotky", MUnitService.class) - , new Module(MOD_MATERIAL, "Materiál", MaterialService.class) + new Module(MOD_USERS, "Uživatelé", UserService.class), + new Module(MOD_PERMISSIONS, "Práva", RoleService.class), + new Module(MOD_ADDRESSBOOK, "Dodavatelé", AdbService.class), + new Module(MOD_BUILDINGS, "Budovy", BuildingService.class), + new Module(MOD_MUNITS, "Měrné jednotky", MUnitService.class), + new Module(MOD_MATERIAL, "Materiál", MaterialService.class), + new Module(MOD_WORKGROUPS, "Pracovní skupiny", WorkgroupService.class) }; public final static String DYNAMIC_REPORT_NAME = "Tabulková sestava"; diff --git a/src/main/java/info/bukova/isspst/dao/WorkgroupDao.java b/src/main/java/info/bukova/isspst/dao/WorkgroupDao.java new file mode 100644 index 00000000..ecb69f9c --- /dev/null +++ b/src/main/java/info/bukova/isspst/dao/WorkgroupDao.java @@ -0,0 +1,7 @@ +package info.bukova.isspst.dao; + +import info.bukova.isspst.data.Workgroup; + +public interface WorkgroupDao extends BaseDao { + +} diff --git a/src/main/java/info/bukova/isspst/dao/jpa/WorkgroupDaoJPA.java b/src/main/java/info/bukova/isspst/dao/jpa/WorkgroupDaoJPA.java new file mode 100644 index 00000000..c2878147 --- /dev/null +++ b/src/main/java/info/bukova/isspst/dao/jpa/WorkgroupDaoJPA.java @@ -0,0 +1,13 @@ +package info.bukova.isspst.dao.jpa; + +import info.bukova.isspst.dao.WorkgroupDao; +import info.bukova.isspst.data.Workgroup; + +public class WorkgroupDaoJPA extends BaseDaoJPA implements WorkgroupDao { + + @Override + public String getEntityName() { + return Workgroup.class.getSimpleName(); + } + +} diff --git a/src/main/java/info/bukova/isspst/data/JobMapping.java b/src/main/java/info/bukova/isspst/data/JobMapping.java new file mode 100644 index 00000000..eebf4b1e --- /dev/null +++ b/src/main/java/info/bukova/isspst/data/JobMapping.java @@ -0,0 +1,71 @@ +package info.bukova.isspst.data; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "JOBMAPPING") +public class JobMapping { + + @Id + @Column(name = "ID") + @GeneratedValue + private int id; + @ManyToOne(fetch = FetchType.EAGER) + @JoinTable(name = "JOB_MEMBER", joinColumns = { @JoinColumn(name = "JOB_ID") }, inverseJoinColumns = { @JoinColumn(name = "MEMBER_ID") }) + private Member member; + @ManyToOne(fetch = FetchType.EAGER) + @JoinTable(name = "JOB_ROLE", joinColumns = { @JoinColumn(name = "JOB_ID") }, inverseJoinColumns = { @JoinColumn(name = "ROLE_ID") }) + private Role role; + + public JobMapping() { + + } + + public JobMapping(Member member, Role role) { + this.member = member; + this.role = role; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public Member getMember() { + return member; + } + + public void setMember(Member member) { + this.member = member; + } + + public Role getRole() { + return role; + } + + public void setRole(Role role) { + this.role = role; + } + + @Override + public boolean equals(Object o) { + if (o instanceof JobMapping + && ((JobMapping)o).getMember().equals(this.getMember()) + && ((JobMapping)o).getRole().equals(this.getRole())) { + return true; + } + return false; + } + +} diff --git a/src/main/java/info/bukova/isspst/data/Member.java b/src/main/java/info/bukova/isspst/data/Member.java new file mode 100644 index 00000000..bb812b58 --- /dev/null +++ b/src/main/java/info/bukova/isspst/data/Member.java @@ -0,0 +1,63 @@ +package info.bukova.isspst.data; + +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Transient; + +@Entity +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +public abstract class Member implements DataModel { + + @Id + @GeneratedValue(strategy = GenerationType.TABLE) + private int id; + @Column(name = "CREATED") + private Date created; + @Column(name = "MODIFIED") + private Date modified; + @Transient + private boolean valid; + + public abstract String getFullName(); + public abstract boolean isHasJob(); + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public Date getCreated() { + return created; + } + + public void setCreated(Date created) { + this.created = created; + } + + public Date getModified() { + return modified; + } + + public void setModified(Date modified) { + this.modified = modified; + } + + public boolean isValid() { + return valid; + } + + public void setValid(boolean valid) { + this.valid = valid; + } + +} diff --git a/src/main/java/info/bukova/isspst/data/Permission.java b/src/main/java/info/bukova/isspst/data/Permission.java index 64e510f8..d20cbeff 100644 --- a/src/main/java/info/bukova/isspst/data/Permission.java +++ b/src/main/java/info/bukova/isspst/data/Permission.java @@ -2,6 +2,8 @@ package info.bukova.isspst.data; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; import javax.persistence.Table; import org.springframework.security.core.GrantedAuthority; @@ -21,15 +23,33 @@ public class Permission extends BaseSimpleData implements GrantedAuthority { private String description; @Column(name="MODULE") private String module; + @Column(name = "TYPE") + @Enumerated(EnumType.ORDINAL) + private PermissionType type; public Permission(String authority, String description) { + this(); this.authority = authority; this.description = description; this.module = ""; } + public Permission(String authority, String description, String module) { + this(authority, description); + this.module = module; + } + + public Permission(String authority, String description, PermissionType type) { + this(authority, description, "", type); + } + + public Permission(String authority, String description, String module, PermissionType type) { + this(authority, description, module); + this.type = type; + } + public Permission() { - + type = PermissionType.GLOBAL; } @Override diff --git a/src/main/java/info/bukova/isspst/data/PermissionType.java b/src/main/java/info/bukova/isspst/data/PermissionType.java new file mode 100644 index 00000000..bc43b9ab --- /dev/null +++ b/src/main/java/info/bukova/isspst/data/PermissionType.java @@ -0,0 +1,9 @@ +package info.bukova.isspst.data; + +public enum PermissionType { + + GLOBAL, + WORKGROUP, + CENTRE + +} diff --git a/src/main/java/info/bukova/isspst/data/Role.java b/src/main/java/info/bukova/isspst/data/Role.java index ead151fb..338681bf 100644 --- a/src/main/java/info/bukova/isspst/data/Role.java +++ b/src/main/java/info/bukova/isspst/data/Role.java @@ -31,15 +31,21 @@ public class Role extends BaseSimpleData implements GrantedAuthority, DataModel @LazyCollection(LazyCollectionOption.FALSE) @JoinTable(name="ROLE_PERMISSION", joinColumns={@JoinColumn(name="ROLE_ID")}, inverseJoinColumns={@JoinColumn(name="PERMISSION_ID")}) private List permissions; + @Column(name = "WORKGROUP") + private boolean workgroup; + @Column(name = "CENTRE") + private boolean centre; public Role(String authority, String description) { + this(); this.authority = authority; - this.description = description; - this.permissions = new ArrayList(); + this.description = description; } public Role() { this.permissions = new ArrayList(); + centre = false; + workgroup = false; } @Override @@ -80,4 +86,20 @@ public class Role extends BaseSimpleData implements GrantedAuthority, DataModel } } + public boolean isWorkgroup() { + return workgroup; + } + + public void setWorkgroup(boolean workgroup) { + this.workgroup = workgroup; + } + + public boolean isCentre() { + return centre; + } + + public void setCentre(boolean centre) { + this.centre = centre; + } + } diff --git a/src/main/java/info/bukova/isspst/data/User.java b/src/main/java/info/bukova/isspst/data/User.java index 51adb0c0..9f8db047 100644 --- a/src/main/java/info/bukova/isspst/data/User.java +++ b/src/main/java/info/bukova/isspst/data/User.java @@ -15,7 +15,7 @@ import org.springframework.security.core.userdetails.UserDetails; @Entity @Table(name="USER") -public class User extends BaseSimpleData implements UserDetails, DataModel { +public class User extends Member implements UserDetails, DataModel { /** * @@ -129,10 +129,12 @@ public class User extends BaseSimpleData implements UserDetails, DataModel { public String getFullName() { String ret = ""; - if (firstName != null && !firstName.isEmpty()) { - ret = firstName + " "; + if (lastName != null && !lastName.isEmpty()) { + ret = lastName + " "; } - return ret + lastName == null ? "" : lastName; + ret = ret + (firstName == null ? "" : firstName); + + return ret; } public String getFirstName() { @@ -174,5 +176,24 @@ public class User extends BaseSimpleData implements UserDetails, DataModel { public void setNotify(boolean notify) { this.notify = notify; } + + @Override + public boolean equals(Object o) { + if ((o instanceof User) && (((User)o).getId() == this.getId())) { + return true; + } else { + return false; + } + } + + @Override + public String toString() { + return getFullName(); + } + + @Override + public boolean isHasJob() { + return true; + } } diff --git a/src/main/java/info/bukova/isspst/data/Workgroup.java b/src/main/java/info/bukova/isspst/data/Workgroup.java new file mode 100644 index 00000000..4d794647 --- /dev/null +++ b/src/main/java/info/bukova/isspst/data/Workgroup.java @@ -0,0 +1,125 @@ +package info.bukova.isspst.data; + +import java.util.ArrayList; +import java.util.List; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +import org.hibernate.annotations.LazyCollection; +import org.hibernate.annotations.LazyCollectionOption; + +@Entity +@Table(name = "WORKGROUP") +public class Workgroup extends Member implements OwnedDataModel { + + @Column(name = "CODE") + private String code; + @Column(name = "NAME") + private String name; + @ManyToMany(cascade = {CascadeType.ALL}) + @LazyCollection(LazyCollectionOption.FALSE) + @JoinTable(name="WORKGROUP_MEMBER", joinColumns={@JoinColumn(name="WORKGROUP_ID")}, inverseJoinColumns={@JoinColumn(name="JOBMAPPING_ID")}) + private List members; + @Column(name = "CENTRE") + private boolean centre; + //BaseData + @ManyToOne(fetch=FetchType.EAGER) + @JoinColumn(name="OWNED_BY_ID") + private User ownedBy; + @ManyToOne(fetch=FetchType.EAGER) + @JoinColumn(name="MODIFIED_BY_ID") + private User modifiedBy; + + + public Workgroup() { + members = new ArrayList(); + centre = false; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean isCentre() { + return centre; + } + + public void setCentre(boolean centre) { + this.centre = centre; + } + + @Override + public void setOwnedBy(User user) { + this.ownedBy = user; + } + + @Override + public User getOwnedBy() { + return ownedBy; + } + + @Override + public void setModifiedBy(User user) { + this.modifiedBy = user; + } + + @Override + public User getModifiedBy() { + return modifiedBy; + } + + @Override + public String getFullName() { + return name; + } + + @Override + public boolean isHasJob() { + return false; + } + + public List getMembers() { + return members; + } + + public void setMembers(List members) { + this.members = members; + } + + public void removeMember(JobMapping mapping) { + members.remove(mapping); + } + + public void removeMember(Member member, Role role) { + JobMapping mapping = new JobMapping(member, role); + members.remove(mapping); + } + + public boolean equals(Object o) { + if (o instanceof Workgroup && ((Workgroup)o).getId() == this.getId()) { + return true; + } + return false; + } + +} diff --git a/src/main/java/info/bukova/isspst/services/users/RoleService.java b/src/main/java/info/bukova/isspst/services/users/RoleService.java index e20ca4f2..e4c8f274 100644 --- a/src/main/java/info/bukova/isspst/services/users/RoleService.java +++ b/src/main/java/info/bukova/isspst/services/users/RoleService.java @@ -1,10 +1,14 @@ package info.bukova.isspst.services.users; +import java.util.List; + import info.bukova.isspst.data.Role; import info.bukova.isspst.services.Service; public interface RoleService extends Service { public Role getRoleByAuthority(String authority); + public List getWorkgroupRoles(); + public List getCentreRoles(); } diff --git a/src/main/java/info/bukova/isspst/services/users/RoleServiceImpl.java b/src/main/java/info/bukova/isspst/services/users/RoleServiceImpl.java index b538fe79..df31aa6d 100644 --- a/src/main/java/info/bukova/isspst/services/users/RoleServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/users/RoleServiceImpl.java @@ -1,5 +1,7 @@ package info.bukova.isspst.services.users; +import java.util.List; + import org.springframework.transaction.annotation.Transactional; import info.bukova.isspst.data.Role; @@ -13,4 +15,16 @@ public class RoleServiceImpl extends AbstractService implements RoleServic return this.selectSingle("from Role where authority = '" + authority + "'"); } + @Override + @Transactional + public List getWorkgroupRoles() { + return this.execQuery("from Role where workgroup = true"); + } + + @Override + @Transactional + public List getCentreRoles() { + return this.execQuery("from Role where centre = true"); + } + } diff --git a/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupException.java b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupException.java new file mode 100644 index 00000000..5aac8c29 --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupException.java @@ -0,0 +1,20 @@ +package info.bukova.isspst.services.workgroups; + +import info.bukova.isspst.services.IsspstException; + +public class WorkgroupException extends IsspstException { + + /** + * + */ + private static final long serialVersionUID = -1729975111741519801L; + + public final static String NO_WORGROUP = "WorkgroupNotAllowed"; + public final static String MSUT_HAS_CENTER = "RoleMustHasCentre"; + public final static String MUST_HAS_WORKGROUP = "WorkgroupMustHasCentre"; + + public WorkgroupException(String message) { + super(message); + } + +} diff --git a/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupService.java b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupService.java new file mode 100644 index 00000000..80411bb8 --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupService.java @@ -0,0 +1,17 @@ +package info.bukova.isspst.services.workgroups; + +import java.util.List; + +import info.bukova.isspst.data.Member; +import info.bukova.isspst.data.Role; +import info.bukova.isspst.data.Workgroup; +import info.bukova.isspst.services.Service; + +public interface WorkgroupService extends Service { + + public void addMember(Workgroup workgroup, Member member, Role role); + public List getWorkgroups(); + public List getCentres(); + public boolean isMember(Workgroup workgroup, Member member); + +} diff --git a/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupServiceImpl.java b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupServiceImpl.java new file mode 100644 index 00000000..2ed066cd --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupServiceImpl.java @@ -0,0 +1,57 @@ +package info.bukova.isspst.services.workgroups; + +import java.util.List; + +import org.springframework.transaction.annotation.Transactional; + +import info.bukova.isspst.Constants; +import info.bukova.isspst.data.JobMapping; +import info.bukova.isspst.data.Member; +import info.bukova.isspst.data.Role; +import info.bukova.isspst.data.Workgroup; +import info.bukova.isspst.services.AbstractOwnedService; + +public class WorkgroupServiceImpl extends AbstractOwnedService implements WorkgroupService { + + @Override + public void addMember(Workgroup workgroup, Member member, Role role) { + if (!member.isHasJob() && !role.getAuthority().equals(Constants.ROLE_USER)) { + throw new WorkgroupException(WorkgroupException.NO_WORGROUP); + } + if (workgroup.isCentre() && !role.isCentre()) { + throw new WorkgroupException(WorkgroupException.MSUT_HAS_CENTER); + } + if (!workgroup.isCentre() && !role.isWorkgroup()) { + throw new WorkgroupException(WorkgroupException.MUST_HAS_WORKGROUP); + } + + JobMapping mapping = new JobMapping(member, role); + if (!workgroup.getMembers().contains(mapping)) { + workgroup.getMembers().add(mapping); + } + } + + @Override + @Transactional + public List getWorkgroups() { + return this.execQuery("from Workgroup where centre = false"); + } + + @Override + @Transactional + public List getCentres() { + return this.execQuery("from Workgroup where centre = true"); + } + + @Override + public boolean isMember(Workgroup workgroup, Member member) { + for (JobMapping jm : workgroup.getMembers()) { + if (jm.getMember().equals(member)) { + return true; + } + } + + return false; + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupForm.java b/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupForm.java new file mode 100644 index 00000000..8f8179ee --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupForm.java @@ -0,0 +1,145 @@ +package info.bukova.isspst.ui.workgroups; + +import info.bukova.isspst.data.JobMapping; +import info.bukova.isspst.data.Member; +import info.bukova.isspst.data.Role; +import info.bukova.isspst.data.Workgroup; +import info.bukova.isspst.services.users.RoleService; +import info.bukova.isspst.services.users.UserService; +import info.bukova.isspst.services.workgroups.WorkgroupService; +import info.bukova.isspst.ui.FormViewModel; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.zkoss.bind.annotation.BindingParam; +import org.zkoss.bind.annotation.Command; +import org.zkoss.bind.annotation.Init; +import org.zkoss.bind.annotation.NotifyChange; +import org.zkoss.zk.ui.event.DropEvent; +import org.zkoss.zk.ui.select.annotation.WireVariable; +import org.zkoss.zul.Listitem; + +public class WorkgroupForm extends FormViewModel { + + @WireVariable + private UserService userService; + @WireVariable + private RoleService roleService; + @WireVariable + private WorkgroupService workgroupService; + private List users; + + @Init(superclass = true) + public void init() { + users = new ArrayList(); + users.addAll(userService.getAll()); + List wg = workgroupService.getWorkgroups(); + + for (Workgroup w : wg) { + if (!workgroupService.isMember(getDataBean(), w)) { + users.add(w); + } + } + } + + public List getUsers() { + return users; + } + + public List getWorkgroupRoles() { + if (getDataBean().isCentre()) { + return roleService.getCentreRoles(); + } else { + return roleService.getWorkgroupRoles(); + } + } + + @NotifyChange({"workgroupRoles", "centre"}) + public void setCentre(boolean centre) { + getDataBean().setCentre(centre); + } + + public boolean getCentre() { + return getDataBean().isCentre(); + } + + @Command + @NotifyChange({"users", "dataBean"}) + public void addMember(@BindingParam("event") DropEvent event) { + Set selected = ((Listitem)event.getDragged()).getListbox().getSelectedItems(); + + if (selected.isEmpty()) { + try { + Member u = ((Listitem)event.getDragged()).getValue(); + moveUser(u, event); + } catch(ClassCastException e) { + JobMapping u = ((Listitem)event.getDragged()).getValue(); + moveUser(u, event); + } + + + return; + } + + for (Listitem li : selected) { + try { + Member u = li.getValue(); + moveUser(u, event); + } catch (ClassCastException e) { + JobMapping u = li.getValue(); + moveUser(u, event); + } + } + } + + private void moveUser(JobMapping u, DropEvent event) { + String source = getSource(event); + String target = getTarget(event); + + if (source.equals(target)) { + return; + } + + getDataBean().removeMember(u); + + if (!target.equals("users")) { + moveUser(u.getMember(), event); + } else if (!u.getMember().isHasJob()) { + users.add(u.getMember()); + } + } + + private void moveUser(Member u, DropEvent event) { + String source = getSource(event); + String target = getTarget(event); + + if (source.equals(target)) { + return; + } + + workgroupService.addMember(getDataBean(), u, roleService.getRoleByAuthority(target)); + + if (!u.isHasJob()) { + users.remove(u); + } + } + + private String getSource(DropEvent event) { + return ((Listitem)event.getDragged()).getListbox().getId(); + } + + private String getTarget(DropEvent event) { + String target; + + if (event.getTarget() instanceof Listitem) { + target = ((Listitem)event.getTarget()).getListbox().getId(); + } else { + target = event.getTarget().getId(); + } + + return target; + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupList.java b/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupList.java new file mode 100644 index 00000000..30e21a54 --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/workgroups/WorkgroupList.java @@ -0,0 +1,22 @@ +package info.bukova.isspst.ui.workgroups; + +import org.zkoss.bind.annotation.Init; +import org.zkoss.zk.ui.select.annotation.WireVariable; + +import info.bukova.isspst.data.Workgroup; +import info.bukova.isspst.services.workgroups.WorkgroupService; +import info.bukova.isspst.ui.ListViewModel; + +public class WorkgroupList extends ListViewModel { + + @WireVariable + private WorkgroupService workgroupService; + + @Init + public void init() { + service = workgroupService; + dataClass = Workgroup.class; + formZul = "workgroupForm.zul"; + } + +} diff --git a/src/main/resources/hibernate.cfg.xml b/src/main/resources/hibernate.cfg.xml index 90d0f423..3c62d43a 100644 --- a/src/main/resources/hibernate.cfg.xml +++ b/src/main/resources/hibernate.cfg.xml @@ -13,6 +13,9 @@ + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index 199d4841..b292dce3 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -72,6 +72,9 @@ UsersGridColumnSureName=Příjmení AgendaMaterial=Materiál MaterialFormTitle=Materiál +AgendaWorkgroups=Pracovní skupiny +WorkgroupFormTitle=Pracvní skupina + ButtonStorno=Storno ButtonSave=Uložit diff --git a/src/main/webapp/WEB-INF/spring/root-context.xml b/src/main/webapp/WEB-INF/spring/root-context.xml index 89c44325..6ef6e9ad 100644 --- a/src/main/webapp/WEB-INF/spring/root-context.xml +++ b/src/main/webapp/WEB-INF/spring/root-context.xml @@ -124,6 +124,10 @@ + + + + @@ -180,5 +184,10 @@ + + + + + diff --git a/src/main/webapp/admin/permissions/permForm.zul b/src/main/webapp/admin/permissions/permForm.zul index 5538a9ea..7750943a 100644 --- a/src/main/webapp/admin/permissions/permForm.zul +++ b/src/main/webapp/admin/permissions/permForm.zul @@ -4,7 +4,11 @@ viewModel="@id('vm') @init('info.bukova.isspst.ui.users.PermissionForm')">