From eade2dd793e3367e2c1a993876a3391668d35eee Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Mon, 14 Jul 2014 12:20:11 +0200 Subject: [PATCH] =?UTF-8?q?P=C5=99idan=C3=A1=20agenda=20pro=20schvalov?= =?UTF-8?q?=C3=A1n=C3=AD=20slu=C5=BEebn=C3=ADch=20cest.=20Interface=20pro?= =?UTF-8?q?=20servisn=C3=AD=20t=C5=99=C3=ADdy=20po=C5=BEadavk=C5=AF=20(zat?= =?UTF-8?q?=C3=ADm=20pr=C3=A1zdn=C3=BD).=20refs=20#108=20refs=20#100?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/info/bukova/isspst/Constants.java | 6 +- .../bukova/isspst/dao/TripRequirementDao.java | 7 + .../isspst/dao/jpa/TripRequirementDaoJPA.java | 9 + .../info/bukova/isspst/data/Permission.java | 8 + .../info/bukova/isspst/data/Requirement.java | 6 +- .../bukova/isspst/data/RequirementBase.java | 21 +- .../bukova/isspst/data/TripRequirement.java | 48 ++ .../isspst/filters/TripRequirementFilter.java | 71 ++ .../security/IsspstPermissionEvaluator.java | 90 ++- .../requirement/RequirementBaseService.java | 5 + .../requirement/RequirementServiceImpl.java | 2 +- .../requirement/RequirementTypeService.java | 2 + .../RequirementTypeServiceImpl.java | 8 + .../requirement/TripRequirementService.java | 14 + .../TripRequirementServiceImpl.java | 92 +++ .../services/users/RoleServiceImpl.java | 15 +- .../services/workgroups/WorkgroupService.java | 1 + .../workgroups/WorkgroupServiceImpl.java | 58 +- .../info/bukova/isspst/ui/ListViewModel.java | 6 +- .../info/bukova/isspst/ui/NavigationVM.java | 4 + .../ui/requirement/TripRequirementForm.java | 33 + .../ui/requirement/TripRequirementList.java | 79 +++ .../requirement/TripRequirementListAll.java | 59 ++ .../TripRequirementListCentre.java | 53 ++ .../TripRequirementListWorkgroup.java | 59 ++ src/main/resources/hibernate.cfg.xml | 1 + .../WEB-INF/locales/zk-label.properties | 11 + .../webapp/WEB-INF/spring/root-context.xml | 18 +- src/main/webapp/app/navigation.zul | 7 + src/main/webapp/requirements/toolbar.zul | 8 + src/main/webapp/trips/requirement/index.zul | 10 + .../webapp/trips/requirement/requirements.zul | 610 ++++++++++++++++++ .../trips/requirement/requirementsForm.zul | 90 +++ 33 files changed, 1485 insertions(+), 26 deletions(-) create mode 100644 src/main/java/info/bukova/isspst/dao/TripRequirementDao.java create mode 100644 src/main/java/info/bukova/isspst/dao/jpa/TripRequirementDaoJPA.java create mode 100644 src/main/java/info/bukova/isspst/data/TripRequirement.java create mode 100644 src/main/java/info/bukova/isspst/filters/TripRequirementFilter.java create mode 100644 src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java create mode 100644 src/main/java/info/bukova/isspst/services/requirement/TripRequirementService.java create mode 100644 src/main/java/info/bukova/isspst/services/requirement/TripRequirementServiceImpl.java create mode 100644 src/main/java/info/bukova/isspst/ui/requirement/TripRequirementForm.java create mode 100644 src/main/java/info/bukova/isspst/ui/requirement/TripRequirementList.java create mode 100644 src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListAll.java create mode 100644 src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListCentre.java create mode 100644 src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListWorkgroup.java create mode 100644 src/main/webapp/requirements/toolbar.zul create mode 100644 src/main/webapp/trips/requirement/index.zul create mode 100644 src/main/webapp/trips/requirement/requirements.zul create mode 100644 src/main/webapp/trips/requirement/requirementsForm.zul diff --git a/src/main/java/info/bukova/isspst/Constants.java b/src/main/java/info/bukova/isspst/Constants.java index cb2695e3..2b27db4b 100644 --- a/src/main/java/info/bukova/isspst/Constants.java +++ b/src/main/java/info/bukova/isspst/Constants.java @@ -8,10 +8,10 @@ import info.bukova.isspst.reporting.Report; import info.bukova.isspst.reporting.ReportMapping; import info.bukova.isspst.services.addressbook.AdbService; import info.bukova.isspst.services.buildings.BuildingService; +import info.bukova.isspst.services.munits.MUnitService; import info.bukova.isspst.services.reqsubjects.MaterialService; import info.bukova.isspst.services.reqsubjects.ServiceItemService; -import info.bukova.isspst.services.munits.MUnitService; -import info.bukova.isspst.services.requirement.RequirementService; +import info.bukova.isspst.services.requirement.RequirementBaseService; import info.bukova.isspst.services.requirement.RequirementTypeService; import info.bukova.isspst.services.users.RoleService; import info.bukova.isspst.services.users.UserService; @@ -72,7 +72,7 @@ public class Constants { new Module(MOD_MATERIAL, "Materiál", MaterialService.class), new Module(MOD_SERVICES, "Služby", ServiceItemService.class), new Module(MOD_WORKGROUPS, "Pracovní skupiny", WorkgroupService.class), - new Module(MOD_REQUIREMENTS, "Požadavky", RequirementService.class), + new Module(MOD_REQUIREMENTS, "Požadavky", RequirementBaseService.class), new Module(MOD_WORKFLOW, "Procesy schválení", RequirementTypeService.class) }; diff --git a/src/main/java/info/bukova/isspst/dao/TripRequirementDao.java b/src/main/java/info/bukova/isspst/dao/TripRequirementDao.java new file mode 100644 index 00000000..eda9b438 --- /dev/null +++ b/src/main/java/info/bukova/isspst/dao/TripRequirementDao.java @@ -0,0 +1,7 @@ +package info.bukova.isspst.dao; + +import info.bukova.isspst.data.TripRequirement; + +public interface TripRequirementDao extends BaseDao { + +} diff --git a/src/main/java/info/bukova/isspst/dao/jpa/TripRequirementDaoJPA.java b/src/main/java/info/bukova/isspst/dao/jpa/TripRequirementDaoJPA.java new file mode 100644 index 00000000..7751022e --- /dev/null +++ b/src/main/java/info/bukova/isspst/dao/jpa/TripRequirementDaoJPA.java @@ -0,0 +1,9 @@ +package info.bukova.isspst.dao.jpa; + +import info.bukova.isspst.dao.TripRequirementDao; +import info.bukova.isspst.data.TripRequirement; + +public class TripRequirementDaoJPA extends BaseDaoJPA implements + TripRequirementDao { + +} diff --git a/src/main/java/info/bukova/isspst/data/Permission.java b/src/main/java/info/bukova/isspst/data/Permission.java index d20cbeff..5ab15ab4 100644 --- a/src/main/java/info/bukova/isspst/data/Permission.java +++ b/src/main/java/info/bukova/isspst/data/Permission.java @@ -86,4 +86,12 @@ public class Permission extends BaseSimpleData implements GrantedAuthority { } } + public PermissionType getType() { + return type; + } + + public void setType(PermissionType type) { + this.type = type; + } + } diff --git a/src/main/java/info/bukova/isspst/data/Requirement.java b/src/main/java/info/bukova/isspst/data/Requirement.java index 17889b5c..eb97623a 100644 --- a/src/main/java/info/bukova/isspst/data/Requirement.java +++ b/src/main/java/info/bukova/isspst/data/Requirement.java @@ -12,6 +12,9 @@ import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; +import org.hibernate.annotations.LazyCollection; +import org.hibernate.annotations.LazyCollectionOption; + @Entity @Table(name = "REQUIREMENT") public class Requirement extends BaseData implements DataModel @@ -32,8 +35,9 @@ public class Requirement extends BaseData implements DataModel @Column(name = "DESCRIPTION") private String description; - @OneToMany(fetch = FetchType.EAGER, cascade=CascadeType.ALL) + @OneToMany(cascade=CascadeType.ALL) @JoinColumn(name = "REQUIREMENT_ID") + @LazyCollection(LazyCollectionOption.FALSE) private List items; public List getItems() diff --git a/src/main/java/info/bukova/isspst/data/RequirementBase.java b/src/main/java/info/bukova/isspst/data/RequirementBase.java index 6ad8595e..363f3f72 100644 --- a/src/main/java/info/bukova/isspst/data/RequirementBase.java +++ b/src/main/java/info/bukova/isspst/data/RequirementBase.java @@ -30,10 +30,13 @@ public class RequirementBase extends BaseData { @Column(name = "DESCRIPTION") private String description; @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "CENTRE_ID") + private Workgroup centre; + @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "WORKGROUP_ID") private Workgroup workgroup; @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @LazyCollection(LazyCollectionOption.FALSE) + @LazyCollection(LazyCollectionOption.TRUE) private List authorization; @Column(name = "STATE") @Enumerated(EnumType.ORDINAL) @@ -91,4 +94,20 @@ public class RequirementBase extends BaseData { this.state = state; } + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Workgroup getCentre() { + return centre; + } + + public void setCentre(Workgroup centre) { + this.centre = centre; + } + } diff --git a/src/main/java/info/bukova/isspst/data/TripRequirement.java b/src/main/java/info/bukova/isspst/data/TripRequirement.java new file mode 100644 index 00000000..2e41145b --- /dev/null +++ b/src/main/java/info/bukova/isspst/data/TripRequirement.java @@ -0,0 +1,48 @@ +package info.bukova.isspst.data; + +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +@Entity +@Table(name = "TRIPREQUIREMENT") +public class TripRequirement extends RequirementBase { + + @Column(name = "TRIP_FROM") + private String from; + @Column(name = "TRIP_TO") + private String to; + @Column(name = "TRIP_DATE") + private Date tripDate; + + public TripRequirement() { + this.setOwnedBy(new User()); + } + + public String getFrom() { + return from; + } + + public void setFrom(String from) { + this.from = from; + } + + public String getTo() { + return to; + } + + public void setTo(String to) { + this.to = to; + } + + public Date getTripDate() { + return tripDate; + } + + public void setTripDate(Date tripDate) { + this.tripDate = tripDate; + } + +} diff --git a/src/main/java/info/bukova/isspst/filters/TripRequirementFilter.java b/src/main/java/info/bukova/isspst/filters/TripRequirementFilter.java new file mode 100644 index 00000000..55c906e0 --- /dev/null +++ b/src/main/java/info/bukova/isspst/filters/TripRequirementFilter.java @@ -0,0 +1,71 @@ +package info.bukova.isspst.filters; + +import info.bukova.isspst.DateTimeUtils; +import info.bukova.isspst.StringUtils; +import info.bukova.isspst.data.TripRequirement; + +import org.hamcrest.Description; +import org.hamcrest.Factory; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; + +public class TripRequirementFilter implements Filter +{ + + private TripRequirement condition; + + public TripRequirementFilter(TripRequirement cond) + { + this.condition = cond; + } + + private static class TripRequirementMatcher extends TypeSafeMatcher + { + + private TripRequirement condition; + + public TripRequirementMatcher(TripRequirement cond) + { + this.condition = cond; + } + + @Override + public void describeTo(Description desc) + { + desc.appendText("requirement matches"); + } + + @Override + public boolean matchesSafely(TripRequirement item) + { + boolean foundNumser = StringUtils.isEqualForFilter(item.getNumser(), condition.getNumser()); + boolean foundReqDate = DateTimeUtils.isEqualByDateForFilter(item.getReqDate(), condition.getReqDate()); + boolean foundDescription = StringUtils.isEqualForFilter(item.getDescription(), condition.getDescription()); + boolean foundFrom = StringUtils.isEqualForFilter(item.getFrom(), condition.getFrom()); + boolean foundTo = StringUtils.isEqualForFilter(item.getTo(), condition.getTo()); + boolean foundWorkgroup = (condition.getWorkgroup() == null ||(item.getWorkgroup() != null && item.getWorkgroup().equals(condition.getWorkgroup()))); + boolean foundCentre = (condition.getCentre() == null || (item.getCentre() != null && item.getCentre().equals(condition.getCentre()))); + boolean foundOwner = StringUtils.isEqualForFilter(item.getOwnedBy().getLastName(), condition.getOwnedBy().getLastName()); + return foundNumser && foundReqDate && foundDescription && foundFrom && foundTo && foundWorkgroup && foundCentre && foundOwner; + } + + @Factory + public static Matcher matchTripRequirement(TripRequirement building) + { + return new TripRequirementMatcher(building); + } + } + + @Override + public TripRequirementMatcher matcher() + { + return new TripRequirementMatcher(condition); + } + + @Override + public String queryString() + { + return ""; + } + +} diff --git a/src/main/java/info/bukova/isspst/security/IsspstPermissionEvaluator.java b/src/main/java/info/bukova/isspst/security/IsspstPermissionEvaluator.java index 7c1ab9c0..8dc534ff 100644 --- a/src/main/java/info/bukova/isspst/security/IsspstPermissionEvaluator.java +++ b/src/main/java/info/bukova/isspst/security/IsspstPermissionEvaluator.java @@ -2,31 +2,115 @@ package info.bukova.isspst.security; import info.bukova.isspst.Constants; import info.bukova.isspst.Module; +import info.bukova.isspst.data.DataModel; +import info.bukova.isspst.data.Permission; +import info.bukova.isspst.data.PermissionType; +import info.bukova.isspst.data.RequirementBase; import info.bukova.isspst.data.Role; +import info.bukova.isspst.data.User; +import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.services.Service; +import info.bukova.isspst.services.workgroups.WorkgroupService; import java.io.Serializable; import java.util.List; import org.springframework.security.access.PermissionEvaluator; import org.springframework.security.core.Authentication; +import org.springframework.transaction.annotation.Transactional; +@Transactional public class IsspstPermissionEvaluator implements PermissionEvaluator { - + + private WorkgroupService wgService; + + public void setWorkgroupService(WorkgroupService wgService) { + this.wgService = wgService; + } + @SuppressWarnings("unchecked") @Override public boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission) { - List perms = (List) authentication.getAuthorities(); String perm = ""; if (permission instanceof String) { perm = (String) permission; } - if (targetDomainObject instanceof Service) + Permission appPermission = null; + for (Permission p : Constants.SPECIAL_PERMISSIONS) { + if (p.getAuthority().equals(perm)) { + appPermission = p; + } + } + + if ((targetDomainObject instanceof Service) && (appPermission == null || appPermission.getType() == PermissionType.GLOBAL)) { + List perms = (List) authentication.getAuthorities(); return evaluateGlobal((Service) targetDomainObject, perm, perms); + } else { + return evaluateSpecial(authentication, targetDomainObject, appPermission); + } + + } + + private boolean evaluateSpecial(Authentication auth, Object domainObject, Permission permission) { + List userWorkgroups; + + if (!(auth.getPrincipal() instanceof User)) { + return false; + } + + User user = (User)auth.getPrincipal(); + + if (domainObject instanceof DataModel) { + return filterDomainObject(user, (DataModel)domainObject, permission); + } + + if (permission.getType() == PermissionType.CENTRE) { + userWorkgroups = wgService.getUserCentres((User)auth.getPrincipal()); + } else { + userWorkgroups = wgService.getUserWorkgroups((User)auth.getPrincipal()); + } + + for (Workgroup wg : userWorkgroups) { + List wgRoles = wgService.getUserWorkgroupRoles(wg, user); + for (Role r : wgRoles) { + for (Permission p : r.getPermissions()) { + if (p.getAuthority().equals(permission.getAuthority())) { + return true; + } + } + } + } + + return false; + } + + private boolean filterDomainObject(User user, DataModel domainObject, Permission permission) { + if (!(domainObject instanceof RequirementBase)) { + return false; + } + + RequirementBase req = (RequirementBase) domainObject; + Workgroup reqWg; + + if (permission.getType() == PermissionType.CENTRE) { + reqWg = req.getCentre(); + } else { + reqWg = req.getWorkgroup(); + } + + if (wgService.isMember(reqWg, user)) { + List roles = wgService.getUserWorkgroupRoles(reqWg, user); + for (Role r : roles) { + for (Permission p : r.getPermissions()) { + if (p.getAuthority().equals(permission.getAuthority())) { + return true; + } + } + } } return false; diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java new file mode 100644 index 00000000..b6a8723b --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java @@ -0,0 +1,5 @@ +package info.bukova.isspst.services.requirement; + +public interface RequirementBaseService { + +} diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java index d0e9c52a..ba5fad99 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java @@ -8,7 +8,7 @@ import java.util.Date; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; -public class RequirementServiceImpl extends AbstractOwnedService implements RequirementService +public class RequirementServiceImpl extends AbstractOwnedService implements RequirementService, RequirementBaseService { @Override protected Requirement createEntity() diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementTypeService.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementTypeService.java index 60fd752e..cfbf4104 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementTypeService.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementTypeService.java @@ -4,5 +4,7 @@ import info.bukova.isspst.data.RequirementType; import info.bukova.isspst.services.Service; public interface RequirementTypeService extends Service { + + public RequirementType getTypeById(String id); } diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementTypeServiceImpl.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementTypeServiceImpl.java index ee7d9ada..c48d6501 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementTypeServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementTypeServiceImpl.java @@ -1,8 +1,16 @@ package info.bukova.isspst.services.requirement; +import org.springframework.transaction.annotation.Transactional; + import info.bukova.isspst.data.RequirementType; import info.bukova.isspst.services.AbstractOwnedService; public class RequirementTypeServiceImpl extends AbstractOwnedService implements RequirementTypeService { + @Override + @Transactional + public RequirementType getTypeById(String id) { + return selectSingle("from RequirementType where type = '" + id + "'"); + } + } diff --git a/src/main/java/info/bukova/isspst/services/requirement/TripRequirementService.java b/src/main/java/info/bukova/isspst/services/requirement/TripRequirementService.java new file mode 100644 index 00000000..3285cc7b --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/requirement/TripRequirementService.java @@ -0,0 +1,14 @@ +package info.bukova.isspst.services.requirement; + +import java.util.List; + +import info.bukova.isspst.data.TripRequirement; +import info.bukova.isspst.services.Service; + +public interface TripRequirementService extends Service { + + public List getCentreReq(); + public List getWorkgroupReq(); + public List getFromAll(); + +} diff --git a/src/main/java/info/bukova/isspst/services/requirement/TripRequirementServiceImpl.java b/src/main/java/info/bukova/isspst/services/requirement/TripRequirementServiceImpl.java new file mode 100644 index 00000000..46b84443 --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/requirement/TripRequirementServiceImpl.java @@ -0,0 +1,92 @@ +package info.bukova.isspst.services.requirement; + +import info.bukova.isspst.Constants; +import info.bukova.isspst.data.RequirementState; +import info.bukova.isspst.data.TripRequirement; +import info.bukova.isspst.data.Workgroup; +import info.bukova.isspst.services.AbstractOwnedService; +import info.bukova.isspst.services.workgroups.WorkgroupService; + +import java.util.Date; +import java.util.List; + +import org.hibernate.Query; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PostFilter; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.transaction.annotation.Transactional; + +public class TripRequirementServiceImpl extends AbstractOwnedService + implements TripRequirementService, RequirementBaseService { + + @Autowired + private RequirementTypeService reqTypeService; + @Autowired + private WorkgroupService workgroupService; + + @Override + protected TripRequirement createEntity() { + TripRequirement tr = new TripRequirement(); + tr.setReqDate(new Date()); + tr.setType(reqTypeService.getTypeById(Constants.REQTYPE_BUSINESSTRIP)); + tr.setState(RequirementState.NEW); + return tr; + } + + @Override + @Transactional + @PreAuthorize("hasPermission(this, 'PERM_ADD')") + public void add(TripRequirement entity) { + Workgroup reqWorkgroup = null; + for (Workgroup w : workgroupService.getUserWorkgroups(getLoggedInUser())) { + if (workgroupService.getMembers(entity.getCentre()).contains(w)) { + reqWorkgroup = w; + } + } + entity.setWorkgroup(reqWorkgroup); + entity.setNumser(getNumberSerie()); + super.add(entity); + } + + @SuppressWarnings("unchecked") + @Override + @Transactional + @PreAuthorize("hasPermission(this, 'PERM_READ')") + public List getAll() { + Query q = dao.getQuery("from TripRequirement where ownedBy = :owner"); + q.setParameter("owner", getLoggedInUser()); + return q.list(); + } + + @SuppressWarnings("unchecked") + @Override + @Transactional + @PreAuthorize("hasPermission(this, 'PERM_SHOW_CENTRE_REQ')") + @PostFilter("hasPermission(filterObject, 'PERM_SHOW_CENTRE_REQ')") + public List getCentreReq() { + List wgList = workgroupService.getUserCentres(getLoggedInUser()); + Query q = dao.getQuery("select tr from TripRequirement tr join tr.centre c where c in (:wgList)"); + q.setParameterList("wgList", wgList); + return q.list(); + } + + @SuppressWarnings("unchecked") + @Override + @Transactional + @PreAuthorize("hasPermission(this, 'PERM_SHOW_WORKGROUP_REQ')") + @PostFilter("hasPermission(filterObject, 'PERM_SHOW_WORKGROUP_REQ')") + public List getWorkgroupReq() { + List wgList = workgroupService.getUserWorkgroups(getLoggedInUser()); + Query q = dao.getQuery("select tr from TripRequirement tr join tr.workgroup w where w in (:wgList)"); + q.setParameterList("wgList", wgList); + return q.list(); + } + + @Override + @Transactional + @PreAuthorize("hasPermission(this, 'PERM_SHOW_ALL_REQ')") + public List getFromAll() { + return super.getAll(); + } + +} 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 684ff97d..944f93fe 100644 --- a/src/main/java/info/bukova/isspst/services/users/RoleServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/users/RoleServiceImpl.java @@ -1,21 +1,17 @@ package info.bukova.isspst.services.users; +import info.bukova.isspst.data.Permission; +import info.bukova.isspst.data.Role; +import info.bukova.isspst.services.AbstractService; + import java.util.HashSet; import java.util.List; import java.util.Set; import org.hibernate.Query; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; -import info.bukova.isspst.data.Permission; -import info.bukova.isspst.data.Role; -import info.bukova.isspst.services.AbstractService; - public class RoleServiceImpl extends AbstractService implements RoleService { - - @Autowired - private PermissionService permService; @Override @Transactional @@ -55,7 +51,8 @@ public class RoleServiceImpl extends AbstractService implements RoleServic @Override @Transactional public List getRolesWithPermission(String authority, boolean centre) { - Permission p = permService.selectSingle("from Permission where authority = '" + authority + "'"); + Query q = dao.getQuery("from Permission where authority = '" + authority + "'"); + Permission p = (Permission) q.uniqueResult(); return getRolesWithPermission(p, centre); } 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 e1b8abd8..229b25dc 100644 --- a/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupService.java +++ b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupService.java @@ -19,5 +19,6 @@ public interface WorkgroupService extends Service { public List getUserCentres(User user); public List getUserWorkgroups(User user); public List getUserWorkgroupRoles(Workgroup workgroup, User user); + public List getMembers(Workgroup workgroup); } 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 d37932ea..abdafbde 100644 --- a/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupServiceImpl.java @@ -11,6 +11,7 @@ import info.bukova.isspst.services.AbstractOwnedService; import java.util.ArrayList; import java.util.List; +import org.hibernate.Query; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; @@ -95,12 +96,16 @@ public class WorkgroupServiceImpl extends AbstractOwnedService implem } @Override + @Transactional public List getUserCentres(User user) { - if (user.getParents() == null) { + List parents = getParents(user); + + if (parents == null) { return null; } + List centres = new ArrayList(); - for (Workgroup w : user.getParents()) { + for (Workgroup w : parents) { if (w.isCentre()) { centres.add(w); } @@ -117,12 +122,16 @@ public class WorkgroupServiceImpl extends AbstractOwnedService implem } @Override + @Transactional public List getUserWorkgroups(User user) { - if (user.getParents() == null) { + List parents = getParents(user); + + if (parents == null) { return null; } + List wg = new ArrayList(); - for (Workgroup w: user.getParents()) { + for (Workgroup w: parents) { if (!w.isCentre()) { wg.add(w); } @@ -130,6 +139,23 @@ public class WorkgroupServiceImpl extends AbstractOwnedService implem return wg; } + + private List getParents(User user) { + List parents; + + if (user.getParents() == null) { + parents = loadUser(user).getParents(); + } else { + parents = user.getParents(); + } + + return parents; + } + + private User loadUser(User user) { + Query q = dao.getQuery("from User where username = '" + user.getUsername() + "'"); + return (User) q.uniqueResult(); + } @Override @Transactional @@ -158,15 +184,23 @@ public class WorkgroupServiceImpl extends AbstractOwnedService implem } @Override + @Transactional public List getUserWorkgroupRoles(Workgroup workgroup, User user) { List roles = new ArrayList(); + User u; + + if (user.getId() == 0) { + u = loadUser(user); + } else { + u = user; + } - if (!isMember(workgroup, user)) { + if (!isMember(workgroup, u)) { return null; } for (JobMapping jm : workgroup.getMembers()) { - if (jm.getMember().equals(user)) { + if (jm.getMember().equals(u)) { roles.add(jm.getRole()); } } @@ -185,4 +219,16 @@ public class WorkgroupServiceImpl extends AbstractOwnedService implem super.delete(entity); } + @Override + public List getMembers(Workgroup workgroup) { + List jmList = workgroup.getMembers(); + List members = new ArrayList(); + + for (JobMapping jm : jmList) { + members.add(jm.getMember()); + } + + return members; + } + } diff --git a/src/main/java/info/bukova/isspst/ui/ListViewModel.java b/src/main/java/info/bukova/isspst/ui/ListViewModel.java index e8a8777a..f6e673f6 100644 --- a/src/main/java/info/bukova/isspst/ui/ListViewModel.java +++ b/src/main/java/info/bukova/isspst/ui/ListViewModel.java @@ -308,9 +308,13 @@ public class ListViewModel { } private void loadFromDbSync() { - dataList.addAll(service.getAll()); + dataList.addAll(getListFromService()); fullList = dataList; } + + protected List getListFromService() { + return service.getAll(); + } protected void showForm() { Map arg = new HashMap(); diff --git a/src/main/java/info/bukova/isspst/ui/NavigationVM.java b/src/main/java/info/bukova/isspst/ui/NavigationVM.java index 72d9a205..ccd34470 100644 --- a/src/main/java/info/bukova/isspst/ui/NavigationVM.java +++ b/src/main/java/info/bukova/isspst/ui/NavigationVM.java @@ -46,6 +46,10 @@ public class NavigationVM { return moduleUrl.contains("orders"); } + public boolean isTrips() { + return moduleUrl.contains("trips"); + } + public boolean isSettings() { return moduleUrl.contains("settings"); } diff --git a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementForm.java b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementForm.java new file mode 100644 index 00000000..60086ca3 --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementForm.java @@ -0,0 +1,33 @@ +package info.bukova.isspst.ui.requirement; + +import java.util.List; + +import org.zkoss.bind.annotation.Init; +import org.zkoss.zk.ui.select.annotation.WireVariable; + +import info.bukova.isspst.data.TripRequirement; +import info.bukova.isspst.data.Workgroup; +import info.bukova.isspst.services.users.UserService; +import info.bukova.isspst.services.workgroups.WorkgroupService; +import info.bukova.isspst.ui.FormViewModel; + +public class TripRequirementForm extends FormViewModel { + + @WireVariable + private UserService userService; + + @WireVariable + private WorkgroupService workgroupService; + + private List centres; + + @Init(superclass = true) + public void init() { + centres = workgroupService.getUserCentres(userService.getCurrent()); + } + + public List getCentres() { + return centres; + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementList.java b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementList.java new file mode 100644 index 00000000..3b87ca18 --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementList.java @@ -0,0 +1,79 @@ +package info.bukova.isspst.ui.requirement; + +import info.bukova.isspst.data.TripRequirement; +import info.bukova.isspst.data.Workgroup; +import info.bukova.isspst.filters.TripRequirementFilter; +import info.bukova.isspst.services.requirement.TripRequirementService; +import info.bukova.isspst.services.users.UserService; +import info.bukova.isspst.services.workgroups.WorkgroupService; +import info.bukova.isspst.ui.ListViewModel; + +import java.util.List; + +import org.zkoss.bind.annotation.GlobalCommand; +import org.zkoss.bind.annotation.Init; +import org.zkoss.bind.annotation.NotifyChange; +import org.zkoss.zk.ui.select.annotation.WireVariable; + +public class TripRequirementList extends ListViewModel { + + @WireVariable + private TripRequirementService tripRequirementService; + @WireVariable + private WorkgroupService workgroupService; + @WireVariable + private UserService userService; + private List myCentres; + private boolean showCentre; + private boolean showWorkgroup; + private boolean showAll; + + @Init + public void init() { + service = tripRequirementService; + dataClass = TripRequirement.class; + formZul = "requirementsForm.zul"; + + showCentre = true; + showWorkgroup = true; + showAll = true; + + dataFilter = new TripRequirementFilter(getFilterTemplate()); + myCentres = workgroupService.getUserCentres(userService.getCurrent()); + } + + @GlobalCommand + @NotifyChange("showCentre") + public void disableCentre() { + showCentre = false; + } + + @GlobalCommand + @NotifyChange("showWorkgroup") + public void disableWorkgroup() { + showWorkgroup = false; + } + + @GlobalCommand + @NotifyChange("showAll") + public void disableAll() { + showAll = false; + } + + public boolean isShowCentre() { + return showCentre; + } + + public boolean isShowWorkgroup() { + return showWorkgroup; + } + + public boolean isShowAll() { + return showAll; + } + + public List getMyCentres() { + return myCentres; + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListAll.java b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListAll.java new file mode 100644 index 00000000..13209f19 --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListAll.java @@ -0,0 +1,59 @@ +package info.bukova.isspst.ui.requirement; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.security.access.AccessDeniedException; +import org.zkoss.bind.BindUtils; +import org.zkoss.bind.annotation.Init; +import org.zkoss.zk.ui.select.annotation.WireVariable; + +import info.bukova.isspst.data.TripRequirement; +import info.bukova.isspst.data.Workgroup; +import info.bukova.isspst.filters.TripRequirementFilter; +import info.bukova.isspst.services.requirement.TripRequirementService; +import info.bukova.isspst.services.users.UserService; +import info.bukova.isspst.services.workgroups.WorkgroupService; +import info.bukova.isspst.ui.ListViewModel; + +public class TripRequirementListAll extends ListViewModel { + + @WireVariable + private TripRequirementService tripRequirementService; + @WireVariable + private WorkgroupService workgroupService; + @WireVariable + private UserService userService; + private List allCentres; + private List allWorkgroups; + + @Init + public void init() { + service = tripRequirementService; + dataClass = TripRequirement.class; + formZul = "requirementsForm.zul"; + dataFilter = new TripRequirementFilter(getFilterTemplate()); + + allCentres = workgroupService.getCentres(); + allWorkgroups = workgroupService.getWorkgroups(); + } + + @Override + protected List getListFromService() { + try { + return tripRequirementService.getFromAll(); + } catch (AccessDeniedException e) { + BindUtils.postGlobalCommand(null, null, "disableAll", null); + return new ArrayList(); + } + } + + public List getAllCentres() { + return allCentres; + } + + public List getAllWorkgroups() { + return allWorkgroups; + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListCentre.java b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListCentre.java new file mode 100644 index 00000000..6eac2a19 --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListCentre.java @@ -0,0 +1,53 @@ +package info.bukova.isspst.ui.requirement; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.security.access.AccessDeniedException; +import org.zkoss.bind.BindUtils; +import org.zkoss.bind.annotation.Init; +import org.zkoss.zk.ui.select.annotation.WireVariable; + +import info.bukova.isspst.data.TripRequirement; +import info.bukova.isspst.data.Workgroup; +import info.bukova.isspst.filters.TripRequirementFilter; +import info.bukova.isspst.services.requirement.TripRequirementService; +import info.bukova.isspst.services.users.UserService; +import info.bukova.isspst.services.workgroups.WorkgroupService; +import info.bukova.isspst.ui.ListViewModel; + +public class TripRequirementListCentre extends ListViewModel { + + @WireVariable + private TripRequirementService tripRequirementService; + @WireVariable + private WorkgroupService workgroupService; + @WireVariable + private UserService userService; + private List myCentres; + + @Init + public void init() { + service = tripRequirementService; + dataClass = TripRequirement.class; + formZul = "requirementsForm.zul"; + dataFilter = new TripRequirementFilter(getFilterTemplate()); + + myCentres = workgroupService.getUserCentres(userService.getCurrent()); + } + + @Override + protected List getListFromService() { + try { + return tripRequirementService.getCentreReq(); + } catch (AccessDeniedException e) { + BindUtils.postGlobalCommand(null, null, "disableCentre", null); + return new ArrayList(); + } + } + + public List getMyCentres() { + return myCentres; + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListWorkgroup.java b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListWorkgroup.java new file mode 100644 index 00000000..78167bcd --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementListWorkgroup.java @@ -0,0 +1,59 @@ +package info.bukova.isspst.ui.requirement; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.security.access.AccessDeniedException; +import org.zkoss.bind.BindUtils; +import org.zkoss.bind.annotation.Init; +import org.zkoss.zk.ui.select.annotation.WireVariable; + +import info.bukova.isspst.data.TripRequirement; +import info.bukova.isspst.data.Workgroup; +import info.bukova.isspst.filters.TripRequirementFilter; +import info.bukova.isspst.services.requirement.TripRequirementService; +import info.bukova.isspst.services.users.UserService; +import info.bukova.isspst.services.workgroups.WorkgroupService; +import info.bukova.isspst.ui.ListViewModel; + +public class TripRequirementListWorkgroup extends ListViewModel { + + @WireVariable + private TripRequirementService tripRequirementService; + @WireVariable + private WorkgroupService workgroupService; + @WireVariable + private UserService userService; + private List myCentres; + private List myWorkgroups; + + @Init + public void init() { + service = tripRequirementService; + dataClass = TripRequirement.class; + formZul = "requirementsForm.zul"; + dataFilter = new TripRequirementFilter(getFilterTemplate()); + + myCentres = workgroupService.getUserCentres(userService.getCurrent()); + myWorkgroups = workgroupService.getUserWorkgroups(userService.getCurrent()); + } + + @Override + protected List getListFromService() { + try { + return tripRequirementService.getWorkgroupReq(); + } catch (AccessDeniedException e) { + BindUtils.postGlobalCommand(null, null, "disableWorkgroup", null); + return new ArrayList(); + } + } + + public List getMyCentres() { + return myCentres; + } + + public List getMyWorkgroups() { + return myWorkgroups; + } + +} diff --git a/src/main/resources/hibernate.cfg.xml b/src/main/resources/hibernate.cfg.xml index aa541823..32f448a8 100644 --- a/src/main/resources/hibernate.cfg.xml +++ b/src/main/resources/hibernate.cfg.xml @@ -20,6 +20,7 @@ + diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index fcbac827..b11f2f29 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -16,11 +16,22 @@ RequirementsFormReqDate=Datum požadavku RequirementsFormCenter=Středisko RequirementsFormDescription=Popis RequirementsFormDeliveryDate=Datum dodání +RequirementsFormFrom=Z +RequirementsFormTo=Do +RequirementsFormPurpose=Účel cesty RequirementsGridNumberSerie=Číslo RequirementsGridReqDate=Datum požadavku RequirementsGridCenter=Středisko RequirementsGridDescription=Popis RequirementsGridDeliveryDate=Datum dodání +RequirementsGridFrom=Z +RequirementsGridTo=Do +RequirementsGridWorkgroup=Komise +RequirementsGridOwnedBy=Vytvořil +RequirementsGridMy=Moje +RequirementsGridMyCentres=Má střediska +RequirementsGridMyWorkgroups=Mé komise +RequirementsGridAll=Vše RequirementItemCode=Kód RequirementItemName=Text diff --git a/src/main/webapp/WEB-INF/spring/root-context.xml b/src/main/webapp/WEB-INF/spring/root-context.xml index 57c97f6d..c6187b0a 100644 --- a/src/main/webapp/WEB-INF/spring/root-context.xml +++ b/src/main/webapp/WEB-INF/spring/root-context.xml @@ -70,7 +70,9 @@ - + + + @@ -161,6 +163,10 @@ + + + + @@ -223,6 +229,10 @@ + + + + @@ -266,4 +276,10 @@ + + + + + + diff --git a/src/main/webapp/app/navigation.zul b/src/main/webapp/app/navigation.zul index bc4856e7..8ff62c45 100644 --- a/src/main/webapp/app/navigation.zul +++ b/src/main/webapp/app/navigation.zul @@ -8,6 +8,7 @@ + @@ -26,6 +27,12 @@ + + + + + + diff --git a/src/main/webapp/requirements/toolbar.zul b/src/main/webapp/requirements/toolbar.zul new file mode 100644 index 00000000..8da490e0 --- /dev/null +++ b/src/main/webapp/requirements/toolbar.zul @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/trips/requirement/index.zul b/src/main/webapp/trips/requirement/index.zul new file mode 100644 index 00000000..86024360 --- /dev/null +++ b/src/main/webapp/trips/requirement/index.zul @@ -0,0 +1,10 @@ + + + + + String gridZul = "requirements.zul"; + + + + + \ No newline at end of file diff --git a/src/main/webapp/trips/requirement/requirements.zul b/src/main/webapp/trips/requirement/requirements.zul new file mode 100644 index 00000000..b0c5b903 --- /dev/null +++ b/src/main/webapp/trips/requirement/requirements.zul @@ -0,0 +1,610 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+ + + +
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+
+ +
+
+ + + + + + + + + + + + + + + +
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+ + + +
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+
+ +
+
+ + + + + + + + + + + + + + + +
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+ + + +
+ +
+
+
+ +
+ + + +
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+
+ +
+
+ + + + + + + + + + + + + + + +
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+ + + +
+ +
+
+
+ +
+ + + +
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+
+ +
+
+
+
+ + + +
+
\ No newline at end of file diff --git a/src/main/webapp/trips/requirement/requirementsForm.zul b/src/main/webapp/trips/requirement/requirementsForm.zul new file mode 100644 index 00000000..ab4984c4 --- /dev/null +++ b/src/main/webapp/trips/requirement/requirementsForm.zul @@ -0,0 +1,90 @@ + + + + + + + + + + + + + ${labels.RequirementsFormNumberSerie} : + + + + + + ${labels.RequirementsFormReqDate} : + + + + + + ${labels.RequirementsFormCenter} : + + + + + + + + ${labels.RequirementsFormFrom} : + + + + + + ${labels.RequirementsFormTo} : + + + + + + ${labels.RequirementsFormPurpose} : + + + + + + + + + + + \ No newline at end of file