Přidaná informační plocha. Ke členům komisí a středisek byla přidaná

vazba rodiče. Vyhodnocování příslušnosti ke středisku/komisi.
multitenant
Josef Rokos 11 years ago
parent 53d5d262b1
commit b1d27b085a

@ -3,6 +3,7 @@ package info.bukova.isspst.dao;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
public interface BaseDao<T> {
@ -14,5 +15,6 @@ public interface BaseDao<T> {
public Query getQuery(String query);
public List<T> execQuery(String query);
public String getEntityName();
public Session getSession();
}

@ -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<T> implements BaseDao<T> {
public void modify(T entity) {
sessionFactory.getCurrentSession().update(entity);
}
@Override
public Session getSession() {
return sessionFactory.getCurrentSession();
}
@SuppressWarnings("unchecked")
@Override

@ -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() {

@ -5,7 +5,7 @@ import javax.persistence.Table;
@Entity
@Table(name="MATERIAL")
public class Material extends RequestSubject {
public class Material extends RequirementSubject {

@ -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<Workgroup> parents;
@Transient
private boolean valid;
@ -60,4 +72,29 @@ public abstract class Member implements DataModel {
this.valid = valid;
}
public List<Workgroup> getParents() {
return parents;
}
public void setParents(List<Workgroup> parents) {
this.parents = parents;
}
public void addParent(Workgroup parent) {
if (parents == null) {
parents = new ArrayList<Workgroup>();
}
if (!parents.contains(parent)) {
parents.add(parent);
}
}
public void removeParent(Workgroup parent) {
if (parents == null) {
return;
}
parents.remove(parent);
}
}

@ -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;
}
}

@ -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;
}
}

@ -44,6 +44,7 @@ public class User extends Member implements UserDetails, DataModel {
public User() {
authorities = new ArrayList<Role>();
setParents(new ArrayList<Workgroup>());
}
@Override

@ -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<Member> removed;
public Workgroup() {
members = new ArrayList<JobMapping>();
removed = new ArrayList<Member>();
setParents(new ArrayList<Workgroup>());
centre = false;
}
@ -126,5 +131,9 @@ public class Workgroup extends Member implements OwnedDataModel {
public String toString() {
return getFullName();
}
public List<Member> getRemoved() {
return removed;
}
}

@ -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<Workgroup> {
public void addMember(Workgroup workgroup, Member member, Role role);
public void removeMember(Workgroup workgroup, JobMapping jobMapping);
public List<Workgroup> getWorkgroups();
public List<Workgroup> getCentres();
public boolean isMember(Workgroup workgroup, Member member);
public List<Workgroup> getUserCentres(User user);
public List<Workgroup> getUserWorkgroups(User user);
public List<Role> getUserWorkgroupRoles(Workgroup workgroup, User user);
}

@ -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<Workgroup> 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<Workgroup> 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<Workgroup> 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<Workgroup> 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<Workgroup> getUserCentres(User user) {
if (user.getParents() == null) {
return null;
}
List<Workgroup> centres = new ArrayList<Workgroup>();
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<Workgroup> getUserWorkgroups(User user) {
if (user.getParents() == null) {
return null;
}
List<Workgroup> wg = new ArrayList<Workgroup>();
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<Role> getUserWorkgroupRoles(Workgroup workgroup, User user) {
List<Role> roles = new ArrayList<Role>();
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);
}
}

@ -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<Workgroup, List<Role>> groupRoles;
@Init
public void init() {
user = User.class.cast(SecurityContextHolder.getContext().getAuthentication().getPrincipal());
groupRoles = new HashMap<Workgroup, List<Role>>();
List<Workgroup> wg = new ArrayList<Workgroup>();
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<Role> r = workgroupService.getUserWorkgroupRoles(w, user);
groupRoles.put(w, r);
}
}
public User getUser() {
return user;
}
public List<Workgroup> getCentres() {
return workgroupService.getUserCentres(user);
}
public List<Workgroup> getWorkgroups() {
return workgroupService.getUserWorkgroups(user);
}
public Map<Workgroup, List<Role>> getGroupRoles() {
return groupRoles;
}
}

@ -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

@ -1,6 +1,47 @@
<?page title="Informace" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="Informace" border="normal">
New Content Here!
<window border="normal" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('info.bukova.isspst.ui.dashboard.DashBoardVM')">
<caption zclass="form-caption" label="${labels.Info}" />
<vbox>
<hbox>
<label value="${labels.LogedInUser}"/> <image src="/img/user-small.png"/> <label value="@load(vm.user)"/>
</hbox>
<groupbox mold="3d">
<caption image="/img/commission-small.png" label="${labels.CentresForRequirements}"/>
<hbox children="@load(vm.centres)">
<template name="children">
<listbox model="@load(vm.groupRoles[each])">
<listhead>
<listheader label="@load(each.fullName)"/>
</listhead>
<template name="model" var="role">
<listitem>
<listcell label="@load(role.description)"/>
</listitem>
</template>
</listbox>
</template>
</hbox>
</groupbox>
<groupbox mold="3d">
<caption image="/img/commission-small.png" label="${labels.WorkgroupMembership}"/>
<hbox children="@load(vm.workgroups)">
<template name="children">
<listbox model="@load(vm.groupRoles[each])">
<listhead>
<listheader label="@load(each.fullName)"/>
</listhead>
<template name="model" var="role">
<listitem>
<listcell label="@load(role.description)"/>
</listitem>
</template>
</listbox>
</template>
</hbox>
</groupbox>
</vbox>
</window>
</zk>

@ -46,6 +46,7 @@
<u:include src="/app/header.zul" />
</div>
<div id="leftcolumn">
<u:button label="${labels.InfoReview}" href="/" width="100%"/>
<u:include src="/app/navigation.zul" />
</div>
<div id="maincolumn">

Loading…
Cancel
Save