diff --git a/src/main/java/info/bukova/isspst/dao/BaseDao.java b/src/main/java/info/bukova/isspst/dao/BaseDao.java index f5d68adf..bdbc7a42 100644 --- a/src/main/java/info/bukova/isspst/dao/BaseDao.java +++ b/src/main/java/info/bukova/isspst/dao/BaseDao.java @@ -3,6 +3,7 @@ package info.bukova.isspst.dao; import java.util.List; import org.hibernate.Query; +import org.hibernate.Session; public interface BaseDao { @@ -14,5 +15,6 @@ public interface BaseDao { public Query getQuery(String query); public List execQuery(String query); public String getEntityName(); + public Session getSession(); } diff --git a/src/main/java/info/bukova/isspst/dao/jpa/BaseDaoJPA.java b/src/main/java/info/bukova/isspst/dao/jpa/BaseDaoJPA.java index 590ce4bb..7f9455d7 100644 --- a/src/main/java/info/bukova/isspst/dao/jpa/BaseDaoJPA.java +++ b/src/main/java/info/bukova/isspst/dao/jpa/BaseDaoJPA.java @@ -3,6 +3,7 @@ package info.bukova.isspst.dao.jpa; import java.util.List; import org.hibernate.Query; +import org.hibernate.Session; import org.hibernate.SessionFactory; import org.springframework.core.GenericTypeResolver; @@ -45,6 +46,11 @@ public abstract class BaseDaoJPA implements BaseDao { public void modify(T entity) { sessionFactory.getCurrentSession().update(entity); } + + @Override + public Session getSession() { + return sessionFactory.getCurrentSession(); + } @SuppressWarnings("unchecked") @Override diff --git a/src/main/java/info/bukova/isspst/data/JobMapping.java b/src/main/java/info/bukova/isspst/data/JobMapping.java index 7de91e9f..811002bd 100644 --- a/src/main/java/info/bukova/isspst/data/JobMapping.java +++ b/src/main/java/info/bukova/isspst/data/JobMapping.java @@ -6,7 +6,6 @@ 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; @@ -19,10 +18,10 @@ public class JobMapping { @GeneratedValue private int id; @ManyToOne(fetch = FetchType.EAGER) - @JoinTable(name = "JOB_MEMBER", joinColumns = { @JoinColumn(name = "JOB_ID") }, inverseJoinColumns = { @JoinColumn(name = "MEMBER_ID") }) + @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") }) + @JoinColumn(name = "ROLE_ID") private Role role; public JobMapping() { diff --git a/src/main/java/info/bukova/isspst/data/Material.java b/src/main/java/info/bukova/isspst/data/Material.java index 1096777d..0b57148a 100644 --- a/src/main/java/info/bukova/isspst/data/Material.java +++ b/src/main/java/info/bukova/isspst/data/Material.java @@ -5,7 +5,7 @@ import javax.persistence.Table; @Entity @Table(name="MATERIAL") -public class Material extends RequestSubject { +public class Material extends RequirementSubject { diff --git a/src/main/java/info/bukova/isspst/data/Member.java b/src/main/java/info/bukova/isspst/data/Member.java index b2538a7f..fcf28e6b 100644 --- a/src/main/java/info/bukova/isspst/data/Member.java +++ b/src/main/java/info/bukova/isspst/data/Member.java @@ -1,6 +1,8 @@ package info.bukova.isspst.data; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import javax.persistence.Column; import javax.persistence.Entity; @@ -9,8 +11,14 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; import javax.persistence.Transient; +import org.hibernate.annotations.LazyCollection; +import org.hibernate.annotations.LazyCollectionOption; + @Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public abstract class Member implements DataModel { @@ -22,6 +30,10 @@ public abstract class Member implements DataModel { private Date created; @Column(name = "MODIFIED") private Date modified; + @ManyToMany + @LazyCollection(LazyCollectionOption.FALSE) + @JoinTable(name="MEMBER_PARENT", joinColumns={@JoinColumn(name="MEMBER_ID")}, inverseJoinColumns={@JoinColumn(name="PARENT_ID")}) + private List parents; @Transient private boolean valid; @@ -60,4 +72,29 @@ public abstract class Member implements DataModel { this.valid = valid; } + public List getParents() { + return parents; + } + + public void setParents(List parents) { + this.parents = parents; + } + + public void addParent(Workgroup parent) { + if (parents == null) { + parents = new ArrayList(); + } + if (!parents.contains(parent)) { + parents.add(parent); + } + } + + public void removeParent(Workgroup parent) { + if (parents == null) { + return; + } + + parents.remove(parent); + } + } diff --git a/src/main/java/info/bukova/isspst/data/RequestSubject.java b/src/main/java/info/bukova/isspst/data/RequestSubject.java deleted file mode 100644 index b6e883b1..00000000 --- a/src/main/java/info/bukova/isspst/data/RequestSubject.java +++ /dev/null @@ -1,43 +0,0 @@ -package info.bukova.isspst.data; - -import javax.persistence.Column; -import javax.persistence.MappedSuperclass; - -import org.hibernate.validator.constraints.NotEmpty; - -@MappedSuperclass -public class RequestSubject extends BaseData { - - @Column(name = "CODE", unique = true) - private String code; - @Column(name = "NAME") - private String name; - @Column(name = "DESCRIPTION") - private String description; - - @NotEmpty(message = "{MaterialFormCodeConstr}") - 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 String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - -} diff --git a/src/main/java/info/bukova/isspst/data/RequirementSubject.java b/src/main/java/info/bukova/isspst/data/RequirementSubject.java new file mode 100644 index 00000000..6a2eca97 --- /dev/null +++ b/src/main/java/info/bukova/isspst/data/RequirementSubject.java @@ -0,0 +1,134 @@ +package info.bukova.isspst.data; + +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Transient; + +import org.hibernate.validator.constraints.NotEmpty; + +@Entity +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +public abstract class RequirementSubject implements OwnedDataModel { + + //OwnedDataModel + @Id + @Column(name =" ID") + @GeneratedValue(strategy = GenerationType.TABLE) + private int id; + @ManyToOne(fetch=FetchType.EAGER) + @JoinColumn(name="OWNED_BY_ID") + private User ownedBy; + @ManyToOne(fetch=FetchType.EAGER) + @JoinColumn(name="MODIFIED_BY_ID") + private User modifiedBy; + @Column(name = "CREATED") + private Date created; + @Column(name = "MODIFIED") + private Date modified; + @Transient + private boolean valid; + //RequirementSubject + @Column(name = "CODE", unique = true) + private String code; + @Column(name = "NAME") + private String name; + @Column(name = "DESCRIPTION") + private String description; + + + @NotEmpty(message = "{MaterialFormCodeConstr}") + 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 String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @Override + public int getId() { + return id; + } + + @Override + public void setId(int id) { + this.id = id; + } + + @Override + public User getOwnedBy() { + return ownedBy; + } + + @Override + public void setOwnedBy(User ownedBy) { + this.ownedBy = ownedBy; + } + + @Override + public User getModifiedBy() { + return modifiedBy; + } + + @Override + public void setModifiedBy(User modifiedBy) { + this.modifiedBy = modifiedBy; + } + + @Override + public Date getCreated() { + return created; + } + + @Override + public void setCreated(Date created) { + this.created = created; + } + + @Override + public Date getModified() { + return modified; + } + + @Override + public void setModified(Date modified) { + this.modified = modified; + } + + @Override + public boolean isValid() { + return valid; + } + + @Override + public void setValid(boolean valid) { + this.valid = valid; + } + +} diff --git a/src/main/java/info/bukova/isspst/data/User.java b/src/main/java/info/bukova/isspst/data/User.java index c7cf88fb..934c9bba 100644 --- a/src/main/java/info/bukova/isspst/data/User.java +++ b/src/main/java/info/bukova/isspst/data/User.java @@ -44,6 +44,7 @@ public class User extends Member implements UserDetails, DataModel { public User() { authorities = new ArrayList(); + setParents(new ArrayList()); } @Override diff --git a/src/main/java/info/bukova/isspst/data/Workgroup.java b/src/main/java/info/bukova/isspst/data/Workgroup.java index 7a2d7bef..92f73686 100644 --- a/src/main/java/info/bukova/isspst/data/Workgroup.java +++ b/src/main/java/info/bukova/isspst/data/Workgroup.java @@ -12,6 +12,7 @@ import javax.persistence.JoinTable; import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.Table; +import javax.persistence.Transient; import org.hibernate.annotations.LazyCollection; import org.hibernate.annotations.LazyCollectionOption; @@ -37,10 +38,14 @@ public class Workgroup extends Member implements OwnedDataModel { @ManyToOne(fetch=FetchType.EAGER) @JoinColumn(name="MODIFIED_BY_ID") private User modifiedBy; + @Transient + private List removed; public Workgroup() { members = new ArrayList(); + removed = new ArrayList(); + setParents(new ArrayList()); centre = false; } @@ -126,5 +131,9 @@ public class Workgroup extends Member implements OwnedDataModel { public String toString() { return getFullName(); } + + public List getRemoved() { + return removed; + } } diff --git a/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupService.java b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupService.java index 80411bb8..e1b8abd8 100644 --- a/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupService.java +++ b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupService.java @@ -2,16 +2,22 @@ package info.bukova.isspst.services.workgroups; import java.util.List; +import info.bukova.isspst.data.JobMapping; import info.bukova.isspst.data.Member; import info.bukova.isspst.data.Role; +import info.bukova.isspst.data.User; 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 void removeMember(Workgroup workgroup, JobMapping jobMapping); public List getWorkgroups(); public List getCentres(); public boolean isMember(Workgroup workgroup, Member member); + public List getUserCentres(User user); + public List getUserWorkgroups(User user); + public List getUserWorkgroupRoles(Workgroup workgroup, User user); } diff --git a/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupServiceImpl.java b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupServiceImpl.java index 401fad8b..d37932ea 100644 --- a/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupServiceImpl.java @@ -1,18 +1,21 @@ 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.User; import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.services.AbstractOwnedService; -public class WorkgroupServiceImpl extends AbstractOwnedService implements WorkgroupService { +import java.util.ArrayList; +import java.util.List; + +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.transaction.annotation.Transactional; +public class WorkgroupServiceImpl extends AbstractOwnedService implements WorkgroupService { + @Override public void addMember(Workgroup workgroup, Member member, Role role) { if (!member.isPerson() && !role.getAuthority().equals(Constants.ROLE_USER)) { @@ -36,6 +39,16 @@ public class WorkgroupServiceImpl extends AbstractOwnedService implem JobMapping mapping = new JobMapping(member, role); if (!workgroup.getMembers().contains(mapping)) { workgroup.getMembers().add(mapping); + member.addParent(workgroup); + } + } + + @Override + public void removeMember(Workgroup workgroup, JobMapping jobMapping) { + workgroup.removeMember(jobMapping); + if (!isMember(workgroup, jobMapping.getMember())) { + jobMapping.getMember().removeParent(workgroup); + workgroup.getRemoved().add(jobMapping.getMember()); } } @@ -80,21 +93,96 @@ public class WorkgroupServiceImpl extends AbstractOwnedService implem return true; } - -/* private boolean noIntersect(Workgroup w1, Workgroup w2) { - for (JobMapping jm1 : w1.getMembers()) { - for (JobMapping jm2 : w2.getMembers()) { - if (jm1.equals(jm2)) { - return false; + + @Override + public List getUserCentres(User user) { + if (user.getParents() == null) { + return null; + } + List centres = new ArrayList(); + for (Workgroup w : user.getParents()) { + if (w.isCentre()) { + centres.add(w); + } + } + + for (Workgroup w : getUserWorkgroups(user)) { + for (Workgroup centre : w.getParents()) { + if (!centres.contains(centre)) { + centres.add(centre); } } } + return centres; + } + + @Override + public List getUserWorkgroups(User user) { + if (user.getParents() == null) { + return null; + } + List wg = new ArrayList(); + for (Workgroup w: user.getParents()) { + if (!w.isCentre()) { + wg.add(w); + } + } - return true; + return wg; + } + + @Override + @Transactional + @PreAuthorize("hasPermission(this, 'PERM_ADD')") + public void add(Workgroup entity) { + super.add(entity); + updateMembers(entity); + } + + @Override + @Transactional + @PreAuthorize("hasPermission(this, 'PERM_EDIT')") + public void update(Workgroup entity) { + super.update(entity); + updateMembers(entity); } - private boolean checkIntersect() { - return true; - }*/ + private void updateMembers(Workgroup workgroup) { + for (JobMapping jm : workgroup.getMembers()) { + dao.getSession().merge(jm.getMember()); + } + + for (Member m : workgroup.getRemoved()) { + dao.getSession().merge(m); + } + } + + @Override + public List getUserWorkgroupRoles(Workgroup workgroup, User user) { + List roles = new ArrayList(); + + if (!isMember(workgroup, user)) { + return null; + } + + for (JobMapping jm : workgroup.getMembers()) { + if (jm.getMember().equals(user)) { + roles.add(jm.getRole()); + } + } + + return roles; + } + + @Override + @Transactional + @PreAuthorize("hasPermission(this, 'PERM_DELETE')") + public void delete(Workgroup entity) { + for (JobMapping m : entity.getMembers()) { + m.getMember().removeParent(entity); + dao.getSession().merge(m.getMember()); + } + super.delete(entity); + } } diff --git a/src/main/java/info/bukova/isspst/ui/dashboard/DashBoardVM.java b/src/main/java/info/bukova/isspst/ui/dashboard/DashBoardVM.java new file mode 100644 index 00000000..eb8e3d19 --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/dashboard/DashBoardVM.java @@ -0,0 +1,59 @@ +package info.bukova.isspst.ui.dashboard; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import info.bukova.isspst.data.Role; +import info.bukova.isspst.data.User; +import info.bukova.isspst.data.Workgroup; +import info.bukova.isspst.services.workgroups.WorkgroupService; + +import org.springframework.security.core.context.SecurityContextHolder; +import org.zkoss.bind.annotation.Init; +import org.zkoss.zk.ui.select.annotation.WireVariable; + +public class DashBoardVM { + + @WireVariable + private WorkgroupService workgroupService; + private User user; + private Map> groupRoles; + + @Init + public void init() { + user = User.class.cast(SecurityContextHolder.getContext().getAuthentication().getPrincipal()); + groupRoles = new HashMap>(); + + List wg = new ArrayList(); + if (workgroupService.getUserCentres(user) != null) { + wg.addAll(workgroupService.getUserCentres(user)); + } + if (workgroupService.getUserWorkgroups(user) != null) { + wg.addAll(workgroupService.getUserWorkgroups(user)); + } + + for (Workgroup w : wg) { + List r = workgroupService.getUserWorkgroupRoles(w, user); + groupRoles.put(w, r); + } + } + + public User getUser() { + return user; + } + + public List getCentres() { + return workgroupService.getUserCentres(user); + } + + public List getWorkgroups() { + return workgroupService.getUserWorkgroups(user); + } + + public Map> getGroupRoles() { + return groupRoles; + } + +} diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index c67f5645..2d0850ab 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -90,6 +90,12 @@ MaterialFormTitle=Materiál AgendaWorkgroups=Střediska / komise WorkgroupFormTitle=Pracvní skupina +CentresForRequirements=Střediska, pro která lze vkládat požadavky +WorkgroupMembership=Členství v komisích +LogedInUser=Přihlášený uživatel: +InfoReview=Přehled +Info=Informace + ButtonStorno=Storno ButtonSave=Uložit diff --git a/src/main/webapp/app/info.zul b/src/main/webapp/app/info.zul index 1aca925a..fadb7156 100644 --- a/src/main/webapp/app/info.zul +++ b/src/main/webapp/app/info.zul @@ -1,6 +1,47 @@ - -New Content Here! + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/app/template.zhtml b/src/main/webapp/app/template.zhtml index 1992abbd..7aa6bcc9 100644 --- a/src/main/webapp/app/template.zhtml +++ b/src/main/webapp/app/template.zhtml @@ -46,6 +46,7 @@
+