diff --git a/pom.xml b/pom.xml index 91c454d4..4ee4cc5d 100644 --- a/pom.xml +++ b/pom.xml @@ -355,4 +355,13 @@ + + + + commons-codec + commons-codec + 1.8 + + + 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/filters/AddressFilter.java b/src/main/java/info/bukova/isspst/filters/AddressFilter.java index 468b59ea..3d876111 100644 --- a/src/main/java/info/bukova/isspst/filters/AddressFilter.java +++ b/src/main/java/info/bukova/isspst/filters/AddressFilter.java @@ -1,60 +1,60 @@ -package info.bukova.isspst.filters; - -import static info.bukova.isspst.StringUtils.not0ToStr; -import static info.bukova.isspst.StringUtils.nullStr; -import info.bukova.isspst.data.Address; - -import org.hamcrest.Description; -import org.hamcrest.Factory; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeMatcher; - -public class AddressFilter implements Filter
{ - - private Address condAddr; - - public AddressFilter(Address condAddr) { - this.condAddr = condAddr; - } - - private static class AddrMatcher extends TypeSafeMatcher
{ - - private Address condAddress; - - public AddrMatcher(Address cond) { - this.condAddress = cond; - } - - @Override - public void describeTo(Description desc) { - desc.appendText("address matches"); - } - - @Override - public boolean matchesSafely(Address item) { - return nullStr(item.getCompany()).toLowerCase().contains(nullStr(condAddress.getCompany()).toLowerCase()) - && nullStr(item.getCity()).toLowerCase().contains(nullStr(condAddress.getCity()).toLowerCase()) - && nullStr(item.getContactName()).toLowerCase().contains(nullStr(condAddress.getContactName()).toLowerCase()) - && nullStr(item.getStreet()).toLowerCase().contains(nullStr(condAddress.getStreet()).toLowerCase()) - && not0ToStr(item.getIc()).startsWith(not0ToStr(condAddress.getIc())) - && nullStr(item.getHouseNumber()).startsWith(nullStr(condAddress.getHouseNumber())); - } - - @Factory - public static Matcher
matchAddr(Address addr) { - return new AddrMatcher(addr); - } - } - - @Override - public AddrMatcher matcher() { - return new AddrMatcher(condAddr); - } - - @Override - public String queryString() { - // TODO query string - return ""; - } - -} +package info.bukova.isspst.filters; + +import static info.bukova.isspst.StringUtils.not0ToStr; +import static info.bukova.isspst.StringUtils.nullStr; +import info.bukova.isspst.data.Address; + +import org.hamcrest.Description; +import org.hamcrest.Factory; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; + +public class AddressFilter implements Filter
{ + + private Address condAddr; + + public AddressFilter(Address condAddr) { + this.condAddr = condAddr; + } + + private static class AddrMatcher extends TypeSafeMatcher
{ + + private Address condAddress; + + public AddrMatcher(Address cond) { + this.condAddress = cond; + } + + @Override + public void describeTo(Description desc) { + desc.appendText("address matches"); + } + + @Override + public boolean matchesSafely(Address item) { + return nullStr(item.getCompany()).toLowerCase().contains(nullStr(condAddress.getCompany()).toLowerCase()) + && nullStr(item.getCity()).toLowerCase().contains(nullStr(condAddress.getCity()).toLowerCase()) + && nullStr(item.getContactName()).toLowerCase().contains(nullStr(condAddress.getContactName()).toLowerCase()) + && nullStr(item.getStreet()).toLowerCase().contains(nullStr(condAddress.getStreet()).toLowerCase()) + && not0ToStr(item.getIc()).startsWith(not0ToStr(condAddress.getIc())) + && nullStr(item.getHouseNumber()).startsWith(nullStr(condAddress.getHouseNumber())); + } + + @Factory + public static Matcher
matchAddr(Address addr) { + return new AddrMatcher(addr); + } + } + + @Override + public AddrMatcher matcher() { + return new AddrMatcher(condAddr); + } + + @Override + public String queryString() { + // TODO query string + return ""; + } + +} diff --git a/src/main/java/info/bukova/isspst/filters/BuildingFilter.java b/src/main/java/info/bukova/isspst/filters/BuildingFilter.java index 787c6a22..8122546e 100644 --- a/src/main/java/info/bukova/isspst/filters/BuildingFilter.java +++ b/src/main/java/info/bukova/isspst/filters/BuildingFilter.java @@ -1,56 +1,56 @@ -package info.bukova.isspst.filters; - -import static info.bukova.isspst.StringUtils.nullStr; -import info.bukova.isspst.data.Building; - -import org.hamcrest.Description; -import org.hamcrest.Factory; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeMatcher; - -public class BuildingFilter implements Filter { - - private Building condBuilding; - - public BuildingFilter(Building condBuilding) { - this.condBuilding = condBuilding; - } - - private static class BuildingMatcher extends TypeSafeMatcher { - - private Building condBuilding; - - public BuildingMatcher(Building cond) { - this.condBuilding = cond; - } - - @Override - public void describeTo(Description desc) { - desc.appendText("buildings matches"); - } - - @Override - public boolean matchesSafely(Building item) { - return nullStr(item.getCode()).toLowerCase().contains(nullStr(condBuilding.getCode()).toLowerCase()) - && nullStr(item.getName()).toLowerCase().contains(nullStr(condBuilding.getName()).toLowerCase()) - && nullStr(item.getDescription()).toLowerCase().contains(nullStr(condBuilding.getDescription()).toLowerCase()); - } - - @Factory - public static Matcher matchBuilding(Building building) { - return new BuildingMatcher(building); - } - } - - @Override - public BuildingMatcher matcher() { - return new BuildingMatcher(condBuilding); - } - - @Override - public String queryString() { - // TODO query string - return ""; - } - -} +package info.bukova.isspst.filters; + +import static info.bukova.isspst.StringUtils.nullStr; +import info.bukova.isspst.data.Building; + +import org.hamcrest.Description; +import org.hamcrest.Factory; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; + +public class BuildingFilter implements Filter { + + private Building condBuilding; + + public BuildingFilter(Building condBuilding) { + this.condBuilding = condBuilding; + } + + private static class BuildingMatcher extends TypeSafeMatcher { + + private Building condBuilding; + + public BuildingMatcher(Building cond) { + this.condBuilding = cond; + } + + @Override + public void describeTo(Description desc) { + desc.appendText("buildings matches"); + } + + @Override + public boolean matchesSafely(Building item) { + return nullStr(item.getCode()).toLowerCase().contains(nullStr(condBuilding.getCode()).toLowerCase()) + && nullStr(item.getName()).toLowerCase().contains(nullStr(condBuilding.getName()).toLowerCase()) + && nullStr(item.getDescription()).toLowerCase().contains(nullStr(condBuilding.getDescription()).toLowerCase()); + } + + @Factory + public static Matcher matchBuilding(Building building) { + return new BuildingMatcher(building); + } + } + + @Override + public BuildingMatcher matcher() { + return new BuildingMatcher(condBuilding); + } + + @Override + public String queryString() { + // TODO query string + return ""; + } + +} diff --git a/src/main/java/info/bukova/isspst/filters/Filter.java b/src/main/java/info/bukova/isspst/filters/Filter.java index 9c206f58..39662386 100644 --- a/src/main/java/info/bukova/isspst/filters/Filter.java +++ b/src/main/java/info/bukova/isspst/filters/Filter.java @@ -1,10 +1,10 @@ -package info.bukova.isspst.filters; - -import org.hamcrest.TypeSafeMatcher; - -public interface Filter { - - public TypeSafeMatcher matcher(); - public String queryString(); - -} +package info.bukova.isspst.filters; + +import org.hamcrest.TypeSafeMatcher; + +public interface Filter { + + public TypeSafeMatcher matcher(); + public String queryString(); + +} diff --git a/src/main/java/info/bukova/isspst/filters/MUnitFilter.java b/src/main/java/info/bukova/isspst/filters/MUnitFilter.java index 55857dd2..4b467a2a 100644 --- a/src/main/java/info/bukova/isspst/filters/MUnitFilter.java +++ b/src/main/java/info/bukova/isspst/filters/MUnitFilter.java @@ -1,56 +1,56 @@ -package info.bukova.isspst.filters; - -import static info.bukova.isspst.StringUtils.nullStr; -import info.bukova.isspst.data.MUnit; - -import org.hamcrest.Description; -import org.hamcrest.Factory; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeMatcher; - -public class MUnitFilter implements Filter { - - private MUnit condMUnit; - - public MUnitFilter(MUnit condMUnit) { - this.condMUnit = condMUnit; - } - - private static class MUnitMatcher extends TypeSafeMatcher { - - private MUnit condMUnit; - - public MUnitMatcher(MUnit cond) { - this.condMUnit = cond; - } - - @Override - public void describeTo(Description desc) { - desc.appendText("munits matches"); - } - - @Override - public boolean matchesSafely(MUnit item) { - return nullStr(item.getCode()).toLowerCase().contains(nullStr(condMUnit.getCode()).toLowerCase()) - && nullStr(item.getName()).toLowerCase().contains(nullStr(condMUnit.getName()).toLowerCase()) - && nullStr(item.getDescription()).toLowerCase().contains(nullStr(condMUnit.getDescription()).toLowerCase()); - } - - @Factory - public static Matcher matchMUnit(MUnit munit) { - return new MUnitMatcher(munit); - } - } - - @Override - public MUnitMatcher matcher() { - return new MUnitMatcher(condMUnit); - } - - @Override - public String queryString() { - // TODO query string - return ""; - } - -} +package info.bukova.isspst.filters; + +import static info.bukova.isspst.StringUtils.nullStr; +import info.bukova.isspst.data.MUnit; + +import org.hamcrest.Description; +import org.hamcrest.Factory; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; + +public class MUnitFilter implements Filter { + + private MUnit condMUnit; + + public MUnitFilter(MUnit condMUnit) { + this.condMUnit = condMUnit; + } + + private static class MUnitMatcher extends TypeSafeMatcher { + + private MUnit condMUnit; + + public MUnitMatcher(MUnit cond) { + this.condMUnit = cond; + } + + @Override + public void describeTo(Description desc) { + desc.appendText("munits matches"); + } + + @Override + public boolean matchesSafely(MUnit item) { + return nullStr(item.getCode()).toLowerCase().contains(nullStr(condMUnit.getCode()).toLowerCase()) + && nullStr(item.getName()).toLowerCase().contains(nullStr(condMUnit.getName()).toLowerCase()) + && nullStr(item.getDescription()).toLowerCase().contains(nullStr(condMUnit.getDescription()).toLowerCase()); + } + + @Factory + public static Matcher matchMUnit(MUnit munit) { + return new MUnitMatcher(munit); + } + } + + @Override + public MUnitMatcher matcher() { + return new MUnitMatcher(condMUnit); + } + + @Override + public String queryString() { + // TODO query string + return ""; + } + +} diff --git a/src/main/java/info/bukova/isspst/filters/MaterialFilter.java b/src/main/java/info/bukova/isspst/filters/MaterialFilter.java index 971ef68c..d3b39d4e 100644 --- a/src/main/java/info/bukova/isspst/filters/MaterialFilter.java +++ b/src/main/java/info/bukova/isspst/filters/MaterialFilter.java @@ -1,56 +1,56 @@ -package info.bukova.isspst.filters; - -import static info.bukova.isspst.StringUtils.nullStr; -import info.bukova.isspst.data.Material; - -import org.hamcrest.Description; -import org.hamcrest.Factory; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeMatcher; - -public class MaterialFilter implements Filter { - - private Material condMaterial; - - public MaterialFilter(Material condMaterial) { - this.condMaterial = condMaterial; - } - - private static class MaterialMatcher extends TypeSafeMatcher { - - private Material condMaterial; - - public MaterialMatcher(Material cond) { - this.condMaterial = cond; - } - - @Override - public void describeTo(Description desc) { - desc.appendText("material matches"); - } - - @Override - public boolean matchesSafely(Material item) { - return nullStr(item.getCode()).toLowerCase().contains(nullStr(condMaterial.getCode()).toLowerCase()) - && nullStr(item.getName()).toLowerCase().contains(nullStr(condMaterial.getName()).toLowerCase()) - && nullStr(item.getDescription()).toLowerCase().contains(nullStr(condMaterial.getDescription()).toLowerCase()); - } - - @Factory - public static Matcher matchBuilding(Material material) { - return new MaterialMatcher(material); - } - } - - @Override - public MaterialMatcher matcher() { - return new MaterialMatcher(condMaterial); - } - - @Override - public String queryString() { - // TODO query string - return ""; - } - -} +package info.bukova.isspst.filters; + +import static info.bukova.isspst.StringUtils.nullStr; +import info.bukova.isspst.data.Material; + +import org.hamcrest.Description; +import org.hamcrest.Factory; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; + +public class MaterialFilter implements Filter { + + private Material condMaterial; + + public MaterialFilter(Material condMaterial) { + this.condMaterial = condMaterial; + } + + private static class MaterialMatcher extends TypeSafeMatcher { + + private Material condMaterial; + + public MaterialMatcher(Material cond) { + this.condMaterial = cond; + } + + @Override + public void describeTo(Description desc) { + desc.appendText("material matches"); + } + + @Override + public boolean matchesSafely(Material item) { + return nullStr(item.getCode()).toLowerCase().contains(nullStr(condMaterial.getCode()).toLowerCase()) + && nullStr(item.getName()).toLowerCase().contains(nullStr(condMaterial.getName()).toLowerCase()) + && nullStr(item.getDescription()).toLowerCase().contains(nullStr(condMaterial.getDescription()).toLowerCase()); + } + + @Factory + public static Matcher matchBuilding(Material material) { + return new MaterialMatcher(material); + } + } + + @Override + public MaterialMatcher matcher() { + return new MaterialMatcher(condMaterial); + } + + @Override + public String queryString() { + // TODO query string + return ""; + } + +} diff --git a/src/main/java/info/bukova/isspst/services/addressbook/AresOdpoved.java b/src/main/java/info/bukova/isspst/services/addressbook/AresOdpoved.java index 53027819..542c66c9 100644 --- a/src/main/java/info/bukova/isspst/services/addressbook/AresOdpoved.java +++ b/src/main/java/info/bukova/isspst/services/addressbook/AresOdpoved.java @@ -1,30 +1,30 @@ -package info.bukova.isspst.services.addressbook; - -import java.util.List; - -public class AresOdpoved { - - private long pocetZaznamu; - private String typVyhledani; - private List aresZaznam; - - public long getPocetZaznamu() { - return pocetZaznamu; - } - public void setPocetZaznamu(long pocetZaznamu) { - this.pocetZaznamu = pocetZaznamu; - } - public String getTypVyhledani() { - return typVyhledani; - } - public void setTypVyhledani(String typVyhledani) { - this.typVyhledani = typVyhledani; - } - public List getAresZaznam() { - return aresZaznam; - } - public void setAresZaznam(List aresZaznam) { - this.aresZaznam = aresZaznam; - } - -} +package info.bukova.isspst.services.addressbook; + +import java.util.List; + +public class AresOdpoved { + + private long pocetZaznamu; + private String typVyhledani; + private List aresZaznam; + + public long getPocetZaznamu() { + return pocetZaznamu; + } + public void setPocetZaznamu(long pocetZaznamu) { + this.pocetZaznamu = pocetZaznamu; + } + public String getTypVyhledani() { + return typVyhledani; + } + public void setTypVyhledani(String typVyhledani) { + this.typVyhledani = typVyhledani; + } + public List getAresZaznam() { + return aresZaznam; + } + public void setAresZaznam(List aresZaznam) { + this.aresZaznam = aresZaznam; + } + +} diff --git a/src/main/java/info/bukova/isspst/services/addressbook/AresZaznam.java b/src/main/java/info/bukova/isspst/services/addressbook/AresZaznam.java index 12e697b8..233a07e9 100644 --- a/src/main/java/info/bukova/isspst/services/addressbook/AresZaznam.java +++ b/src/main/java/info/bukova/isspst/services/addressbook/AresZaznam.java @@ -1,56 +1,56 @@ -package info.bukova.isspst.services.addressbook; - -public class AresZaznam { - - private String firma; - private long ico; - private String obec; - private String mestskaCast; - private String ulice; - private String cp; - private String psc; - - public String getFirma() { - return firma; - } - public void setFirma(String firma) { - this.firma = firma; - } - public long getIco() { - return ico; - } - public void setIco(long ico) { - this.ico = ico; - } - public String getObec() { - return obec; - } - public void setObec(String obec) { - this.obec = obec; - } - public String getMestskaCast() { - return mestskaCast; - } - public void setMestskaCast(String mestskaCast) { - this.mestskaCast = mestskaCast; - } - public String getUlice() { - return ulice; - } - public void setUlice(String ulice) { - this.ulice = ulice; - } - public String getCp() { - return cp; - } - public void setCp(String cp) { - this.cp = cp; - } - public String getPsc() { - return psc; - } - public void setPsc(String psc) { - this.psc = psc; - } - -} +package info.bukova.isspst.services.addressbook; + +public class AresZaznam { + + private String firma; + private long ico; + private String obec; + private String mestskaCast; + private String ulice; + private String cp; + private String psc; + + public String getFirma() { + return firma; + } + public void setFirma(String firma) { + this.firma = firma; + } + public long getIco() { + return ico; + } + public void setIco(long ico) { + this.ico = ico; + } + public String getObec() { + return obec; + } + public void setObec(String obec) { + this.obec = obec; + } + public String getMestskaCast() { + return mestskaCast; + } + public void setMestskaCast(String mestskaCast) { + this.mestskaCast = mestskaCast; + } + public String getUlice() { + return ulice; + } + public void setUlice(String ulice) { + this.ulice = ulice; + } + public String getCp() { + return cp; + } + public void setCp(String cp) { + this.cp = cp; + } + public String getPsc() { + return psc; + } + public void setPsc(String psc) { + this.psc = psc; + } + +} diff --git a/src/main/java/info/bukova/isspst/services/addressbook/ares.xsl b/src/main/java/info/bukova/isspst/services/addressbook/ares.xsl index c77d0d9a..c476b65a 100644 --- a/src/main/java/info/bukova/isspst/services/addressbook/ares.xsl +++ b/src/main/java/info/bukova/isspst/services/addressbook/ares.xsl @@ -1,28 +1,28 @@ - - - - - - - - - - - - - - - / - - - - - - - - - - + + + + + + + + + + + + + + + / + + + + + + + + + + diff --git a/src/main/java/info/bukova/isspst/services/addressbook/mappingAres.xml b/src/main/java/info/bukova/isspst/services/addressbook/mappingAres.xml index 0bd50b69..76cecc55 100644 --- a/src/main/java/info/bukova/isspst/services/addressbook/mappingAres.xml +++ b/src/main/java/info/bukova/isspst/services/addressbook/mappingAres.xml @@ -1,42 +1,42 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file 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 b3b5df06..170f86e9 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -87,6 +87,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')">