Optimalizace načítání dat z databáze. Joinované kolekce lze označit jako

lazy. Do servisní vrstvy se pak implementuje transakční metoda s anotací
LazyLoader, která donačte kolekci.
multitenant
Josef Rokos 10 years ago
parent 5b69b04264
commit a32451167d

@ -171,6 +171,7 @@ public class AppInitListener implements ServletContextListener {
boolean adminExists = false;
for (User u : userService.getAll()) {
userService.loadAuthorities(u);
if (userService.hasRole(u, Constants.ROLE_ADMIN)) {
adminExists = true;
break;

@ -0,0 +1,59 @@
package info.bukova.isspst;
import info.bukova.isspst.data.Role;
import info.bukova.isspst.data.User;
import info.bukova.isspst.data.Workgroup;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
public class SessionData implements Serializable {
/**
*
*/
private static final long serialVersionUID = -764426911263559758L;
private List<Workgroup> userCentres;
private List<Workgroup> userWorkgroups;
private User currentUser;
private Map<Integer, List<Role>> workgroupRoles;
public SessionData() {
}
public List<Workgroup> getUserCentres() {
return userCentres;
}
public void setUserCentres(List<Workgroup> userCentres) {
this.userCentres = userCentres;
}
public List<Workgroup> getUserWorkgroups() {
return userWorkgroups;
}
public void setUserWorkgroups(List<Workgroup> userWorkgroups) {
this.userWorkgroups = userWorkgroups;
}
public User getCurrentUser() {
return currentUser;
}
public void setCurrentUser(User currentUser) {
this.currentUser = currentUser;
}
public Map<Integer, List<Role>> getWorkgroupRoles() {
return workgroupRoles;
}
public void setWorkgroupRoles(Map<Integer, List<Role>> workgroupRoles) {
this.workgroupRoles = workgroupRoles;
}
}

@ -31,7 +31,7 @@ public abstract class Member implements DataModel {
@Column(name = "MODIFIED")
private Date modified;
@ManyToMany
@LazyCollection(LazyCollectionOption.FALSE)
@LazyCollection(LazyCollectionOption.TRUE)
@JoinTable(name="MEMBER_PARENT", joinColumns={@JoinColumn(name="MEMBER_ID")}, inverseJoinColumns={@JoinColumn(name="PARENT_ID")})
private List<Workgroup> parents;
@Transient

@ -38,7 +38,7 @@ public class User extends Member implements UserDetails, DataModel {
private String email;
@Column(name="NOTIFY")
private boolean notify;
@ManyToMany(fetch=FetchType.EAGER)
@ManyToMany(fetch=FetchType.LAZY)
@JoinTable(name="USER_ROLE", joinColumns={@JoinColumn(name="USER_ID")}, inverseJoinColumns={@JoinColumn(name="ROLE_ID")})
private List<Role> authorities;

@ -1,5 +1,6 @@
package info.bukova.isspst.data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@ -19,14 +20,19 @@ import org.hibernate.annotations.LazyCollectionOption;
@Entity
@Table(name = "WORKGROUP")
public class Workgroup extends Member implements OwnedDataModel {
public class Workgroup extends Member implements OwnedDataModel, Serializable {
/**
*
*/
private static final long serialVersionUID = -5039169434782289101L;
@Column(name = "CODE")
private String code;
@Column(name = "NAME")
private String name;
@ManyToMany(cascade = {CascadeType.ALL})
@LazyCollection(LazyCollectionOption.FALSE)
@LazyCollection(LazyCollectionOption.TRUE)
@JoinTable(name="WORKGROUP_MEMBER", joinColumns={@JoinColumn(name="WORKGROUP_ID")}, inverseJoinColumns={@JoinColumn(name="JOBMAPPING_ID")})
private List<JobMapping> members;
@Column(name = "CENTRE")

@ -0,0 +1,59 @@
package info.bukova.isspst.security;
import info.bukova.isspst.SessionData;
import info.bukova.isspst.data.Role;
import info.bukova.isspst.data.User;
import info.bukova.isspst.data.Workgroup;
import info.bukova.isspst.services.users.UserService;
import info.bukova.isspst.services.workgroups.WorkgroupService;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
public class LoginSuccessHandler implements AuthenticationSuccessHandler {
@Autowired
private SessionData sessionData;
@Autowired
private WorkgroupService workgroupService;
@Autowired
private UserService userService;
private static final Logger logger = LoggerFactory.getLogger(LoginSuccessHandler.class);
@Override
public void onAuthenticationSuccess(HttpServletRequest request,
HttpServletResponse response, Authentication auth) throws IOException,
ServletException {
User u = (User) userService.loadUserByUsername(((User)auth.getPrincipal()).getUsername());
logger.info("User " + u.getUsername() + " logged in");
sessionData.setUserCentres(workgroupService.getUserCentres((User) auth.getPrincipal()));
sessionData.setUserWorkgroups(workgroupService.getUserWorkgroups((User) auth.getPrincipal()));
workgroupService.loadParents(u);
sessionData.setCurrentUser(u);
Map<Integer, List<Role>> wgRoles = new HashMap<Integer, List<Role>>();
for (Workgroup w : u.getParents()) {
wgRoles.put(w.getId(), workgroupService.getUserWorkgroupRoles(w, u));
}
sessionData.setWorkgroupRoles(wgRoles);
response.sendRedirect("app/");
}
}

@ -36,6 +36,10 @@ public class AbstractOwnedService<T extends OwnedDataModel> extends AbstractServ
@Transactional
protected User getLoggedInUser() {
if (sessionData.getCurrentUser() != null) {
return sessionData.getCurrentUser();
}
try {
String query = "from User where USERNAME = '" + ((UserDetails)SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername() + "'";
Query q = dao.getQuery(query);

@ -3,6 +3,7 @@ package info.bukova.isspst.services;
import static ch.lambdaj.Lambda.filter;
import info.bukova.isspst.Constants;
import info.bukova.isspst.Module;
import info.bukova.isspst.SessionData;
import info.bukova.isspst.dao.BaseDao;
import info.bukova.isspst.data.DataModel;
import info.bukova.isspst.data.NumberSeries;
@ -10,6 +11,9 @@ import info.bukova.isspst.filters.Filter;
import info.bukova.isspst.reporting.Report;
import info.bukova.isspst.services.numberseries.NumberSeriesService;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@ -20,6 +24,7 @@ import javax.validation.Validator;
import org.hibernate.NonUniqueResultException;
import org.hibernate.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
@ -27,6 +32,8 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
protected BaseDao<T> dao;
private Validator validator;
@Autowired
protected SessionData sessionData;
private NumberSeriesService numberSeriesService;
@ -183,4 +190,36 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
return currentNumber;
}
@Override
@Transactional
public void loadLazyData(T entity) {
loadLazyData("", entity);
}
@Override
@Transactional
public void loadLazyData(String group, T entity) {
Method[] methods = this.getClass().getMethods();
for (Method m : methods) {
Annotation[] annotations = m.getAnnotations();
for (Annotation a : annotations) {
if (a instanceof LazyLoader) {
String[] values = ((LazyLoader) a).value();
if (group.isEmpty() || values.length == 0 || Arrays.asList(values).contains(group)) {
try {
m.invoke(this, entity);
} catch (IllegalArgumentException e) {
throw new LazyLoadException(e.getCause());
} catch (IllegalAccessException e) {
throw new LazyLoadException(e.getCause());
} catch (InvocationTargetException e) {
throw new LazyLoadException(e.getCause());
}
}
}
}
}
}
}

@ -0,0 +1,12 @@
package info.bukova.isspst.services;
public class LazyLoadException extends RuntimeException {
private static final long serialVersionUID = -2251676786418660140L;
public LazyLoadException(Throwable cause) {
super(cause);
}
}

@ -0,0 +1,12 @@
package info.bukova.isspst.services;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface LazyLoader {
String[] value() default "";
}

@ -13,6 +13,8 @@ public interface Service<T> {
public void update(T entity);
public void delete(T entity);
public void validate(T entity) throws ValidationException;
public void loadLazyData(T entity);
public void loadLazyData(String group, T entity);
public List<T> getAll();
public List<T> execQuery(String query);
public T selectSingle(String query);

@ -9,11 +9,13 @@ import info.bukova.isspst.data.User;
import info.bukova.isspst.data.Workflow;
import info.bukova.isspst.data.Workgroup;
import info.bukova.isspst.services.AbstractOwnedService;
import info.bukova.isspst.services.LazyLoader;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.hibernate.LazyInitializationException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
@ -69,27 +71,58 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
@Override
@Transactional
@LazyLoader({"grid", "form"})
public void loadAuthItems(T entity) {
T e = dao.getById(entity.getId());
e.getAuthorization().size();
entity.setAuthorization(e.getAuthorization());
try {
if (entity.getAuthorization() == null) {
throw new LazyInitializationException("");
}
entity.getAuthorization().size();
} catch (LazyInitializationException ex) {
T e = dao.getById(entity.getId());
e.getAuthorization().size();
entity.setAuthorization(e.getAuthorization());
}
}
@Override
@Transactional
@LazyLoader("grid")
public void loadType(T data) {
T e = dao.getById(data.getId());
e.getType().getType();
data.setType(e.getType());
try {
if (data.getType() == null) {
throw new LazyInitializationException("");
}
data.getType().getType();
} catch (LazyInitializationException ex) {
T e = dao.getById(data.getId());
if (e.getType() == null) {
return;
}
e.getType().getType();
data.setType(e.getType());
}
}
@Override
@Transactional
@LazyLoader({"grid", "form"})
public void loadWorkflow(T data) {
T e = dao.getById(data.getId());
e.getWorkflow().size();
data.setWorkflow(e.getWorkflow());
try {
if (data.getWorkflow() == null) {
throw new LazyInitializationException("");
}
data.getWorkflow().size();
} catch (LazyInitializationException ex) {
T e = dao.getById(data.getId());
e.getWorkflow().size();
e.getOwnedBy().getFullName();
data.setWorkflow(e.getWorkflow());
data.setOwnedBy(e.getOwnedBy());
}
}
@Override

@ -4,11 +4,13 @@ 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.LazyLoader;
import info.bukova.isspst.services.workgroups.WorkgroupService;
import java.util.Date;
import java.util.List;
import org.hibernate.LazyInitializationException;
import org.hibernate.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PostFilter;
@ -66,7 +68,7 @@ public class TripRequirementServiceImpl extends RequirementBaseServiceImpl<TripR
@PostFilter("hasPermission(filterObject, 'PERM_SHOW_CENTRE_REQ')")
public List<TripRequirement> getCentreReq() {
List<Workgroup> wgList = workgroupService.getUserCentres(getLoggedInUser());
Query q = dao.getQuery("select tr from TripRequirement tr join tr.centre c where tr.state != :state and c in (:wgList)");
Query q = dao.getQuery("select tr from TripRequirement tr join fetch tr.ownedBy join tr.centre c where tr.state != :state and c in (:wgList) order by tr.numser");
q.setParameterList("wgList", wgList);
q.setParameter("state", RequirementState.APPROVED);
return q.list();
@ -79,25 +81,36 @@ public class TripRequirementServiceImpl extends RequirementBaseServiceImpl<TripR
@PostFilter("hasPermission(filterObject, 'PERM_SHOW_WORKGROUP_REQ')")
public List<TripRequirement> getWorkgroupReq() {
List<Workgroup> wgList = workgroupService.getUserWorkgroups(getLoggedInUser());
Query q = dao.getQuery("select tr from TripRequirement tr join tr.workgroup w where tr.state != :state and w in (:wgList)");
Query q = dao.getQuery("select tr from TripRequirement tr join fetch tr.ownedBy join tr.workgroup w where tr.state != :state and w in (:wgList) order by tr.numser");
q.setParameterList("wgList", wgList);
q.setParameter("state", RequirementState.APPROVED);
return q.list();
}
@SuppressWarnings("unchecked")
@Override
@Transactional
@PreAuthorize("hasPermission(this, 'PERM_SHOW_ALL_REQ')")
public List<TripRequirement> getFromAll() {
return super.getAll();
Query q = dao.getQuery("from TripRequirement as tr join fetch tr.ownedBy order by tr.numser");
return q.list();
}
@Override
@Transactional
@LazyLoader("form")
public void loadPassangers(TripRequirement entity) {
TripRequirement e = dao.getById(entity.getId());
e.getPassengers().size();
entity.setPassengers(e.getPassengers());
try {
if (entity.getPassengers() == null) {
throw new LazyInitializationException("");
}
entity.getPassengers().size();
} catch (LazyInitializationException ex) {
TripRequirement e = dao.getById(entity.getId());
e.getPassengers().size();
entity.setPassengers(e.getPassengers());
}
}
}

@ -18,5 +18,6 @@ public interface UserService extends UserDetailsService, Service<User> {
public String encodePassword(User user, String plain);
public void grantAdmin();
public void removeAccess();
public void loadAuthorities(User user);
}

@ -4,6 +4,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.hibernate.LazyInitializationException;
import org.hibernate.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@ -18,6 +19,7 @@ import info.bukova.isspst.Constants;
import info.bukova.isspst.data.Role;
import info.bukova.isspst.data.User;
import info.bukova.isspst.services.AbstractService;
import info.bukova.isspst.services.LazyLoader;
public class UserServiceImpl extends AbstractService<User> implements UserService {
@ -34,7 +36,7 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
public UserDetails loadUserByUsername(String username)
throws UsernameNotFoundException {
Query q = dao.getQuery("from User user where user.username = :username");
Query q = dao.getQuery("from User user join fetch user.authorities where user.username = :username");
q.setString("username", username);
User u = (User) q.uniqueResult();
@ -73,6 +75,10 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
@Override
@Transactional
public User getCurrent() {
if (sessionData.getCurrentUser() != null) {
return sessionData.getCurrentUser();
}
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth != null && auth.getPrincipal() != null) {
@ -128,5 +134,22 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
return u;
}
@Override
@Transactional
@LazyLoader({"grid", "form"})
public void loadAuthorities(User user) {
try {
if (user.getAuthorities() == null) {
throw new LazyInitializationException("");
}
user.getAuthorities().size();
} catch (LazyInitializationException ex) {
User u = dao.getById(user.getId());
u.getAuthorities().size();
user.setAuthorities(u.getAuthorities());
}
}
}

@ -20,5 +20,7 @@ public interface WorkgroupService extends Service<Workgroup> {
public List<Workgroup> getUserWorkgroups(User user);
public List<Role> getUserWorkgroupRoles(Workgroup workgroup, User user);
public List<Member> getMembers(Workgroup workgroup);
public void loadMembers(Workgroup workgroup);
public void loadParents(Member member);
}

@ -7,10 +7,12 @@ import info.bukova.isspst.data.Role;
import info.bukova.isspst.data.User;
import info.bukova.isspst.data.Workgroup;
import info.bukova.isspst.services.AbstractOwnedService;
import info.bukova.isspst.services.LazyLoader;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.LazyInitializationException;
import org.hibernate.Query;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
@ -66,7 +68,13 @@ public class WorkgroupServiceImpl extends AbstractOwnedService<Workgroup> implem
}
@Override
@Transactional
public boolean isMember(Workgroup workgroup, Member member) {
if (member.equals(getLoggedInUser()) && sessionData.getCurrentUser() != null) {
return member.getParents().contains(workgroup);
}
loadMembers(workgroup);
for (JobMapping jm : workgroup.getMembers()) {
if (jm.getMember().equals(member)) {
return true;
@ -98,6 +106,10 @@ public class WorkgroupServiceImpl extends AbstractOwnedService<Workgroup> implem
@Override
@Transactional
public List<Workgroup> getUserCentres(User user) {
if (user.equals(getLoggedInUser()) && sessionData.getUserCentres() != null) {
return sessionData.getUserCentres();
}
List<Workgroup> parents = getParents(user);
if (parents == null) {
@ -112,6 +124,7 @@ public class WorkgroupServiceImpl extends AbstractOwnedService<Workgroup> implem
}
for (Workgroup w : getUserWorkgroups(user)) {
loadParents(w);
for (Workgroup centre : w.getParents()) {
if (!centres.contains(centre)) {
centres.add(centre);
@ -124,6 +137,10 @@ public class WorkgroupServiceImpl extends AbstractOwnedService<Workgroup> implem
@Override
@Transactional
public List<Workgroup> getUserWorkgroups(User user) {
if (user.equals(getLoggedInUser()) && sessionData.getUserWorkgroups() != null) {
return sessionData.getUserWorkgroups();
}
List<Workgroup> parents = getParents(user);
if (parents == null) {
@ -141,15 +158,9 @@ public class WorkgroupServiceImpl extends AbstractOwnedService<Workgroup> implem
}
private List<Workgroup> getParents(User user) {
List<Workgroup> parents;
loadParents(user);
if (user.getParents() == null) {
parents = loadUser(user).getParents();
} else {
parents = user.getParents();
}
return parents;
return user.getParents();
}
private User loadUser(User user) {
@ -186,6 +197,10 @@ public class WorkgroupServiceImpl extends AbstractOwnedService<Workgroup> implem
@Override
@Transactional
public List<Role> getUserWorkgroupRoles(Workgroup workgroup, User user) {
if (user.equals(getLoggedInUser()) && sessionData.getWorkgroupRoles() != null) {
return sessionData.getWorkgroupRoles().get(workgroup.getId());
}
List<Role> roles = new ArrayList<Role>();
User u;
@ -199,6 +214,8 @@ public class WorkgroupServiceImpl extends AbstractOwnedService<Workgroup> implem
return null;
}
loadMembers(workgroup);
for (JobMapping jm : workgroup.getMembers()) {
if (jm.getMember().equals(u)) {
roles.add(jm.getRole());
@ -212,7 +229,9 @@ public class WorkgroupServiceImpl extends AbstractOwnedService<Workgroup> implem
@Transactional
@PreAuthorize("hasPermission(this, 'PERM_DELETE')")
public void delete(Workgroup entity) {
loadMembers(entity);
for (JobMapping m : entity.getMembers()) {
loadParents(m.getMember());
m.getMember().removeParent(entity);
dao.getSession().merge(m.getMember());
}
@ -221,6 +240,7 @@ public class WorkgroupServiceImpl extends AbstractOwnedService<Workgroup> implem
@Override
public List<Member> getMembers(Workgroup workgroup) {
loadMembers(workgroup);
List<JobMapping> jmList = workgroup.getMembers();
List<Member> members = new ArrayList<Member>();
@ -231,4 +251,42 @@ public class WorkgroupServiceImpl extends AbstractOwnedService<Workgroup> implem
return members;
}
@Override
@Transactional
@LazyLoader({"grid", "form"})
public void loadMembers(Workgroup workgroup) {
try {
if (workgroup.getMembers() == null) {
throw new LazyInitializationException("");
}
workgroup.getMembers().size();
} catch (LazyInitializationException e) {
Workgroup w = dao.getById(workgroup.getId());
w.getMembers().size();
workgroup.setMembers(w.getMembers());
}
}
@Override
@Transactional
@LazyLoader("form")
public void loadParents(Member member) {
try {
if (member.getParents() == null) {
throw new LazyInitializationException("");
}
member.getParents().size();
} catch (LazyInitializationException e) {
if (member.isPerson()) {
User u = loadUser((User) member);
u.getParents().size();
member.setParents(u.getParents());
} else {
Workgroup w = dao.getById(member.getId());
w.getParents().size();
member.setParents(w.getParents());
}
}
}
}

@ -61,7 +61,7 @@ public class ListViewModel<T extends DataModel> {
}
protected void loadLazyData(T data) {
service.loadLazyData("grid", data);
}
public void setDataFilter(Filter<T> dataFilter) {
@ -164,7 +164,7 @@ public class ListViewModel<T extends DataModel> {
}
protected void loadLazyDataForEdit(T data) {
service.loadLazyData("form", data);
}
@Command

@ -1,17 +1,16 @@
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.users.UserService;
import info.bukova.isspst.services.workgroups.WorkgroupService;
import org.springframework.security.core.context.SecurityContextHolder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.zkoss.bind.annotation.Init;
import org.zkoss.zk.ui.select.annotation.WireVariable;
@ -26,11 +25,7 @@ public class DashBoardVM {
@Init
public void init() {
user = User.class.cast(SecurityContextHolder.getContext().getAuthentication().getPrincipal());
if (user.getParents() == null) { // try reload from DB
user = userService.getCurrent();
}
user = userService.getCurrent();
groupRoles = new HashMap<Workgroup, List<Role>>();

@ -16,13 +16,6 @@ public class RequirementSubpage<T extends RequirementBase> extends ListViewModel
return (RequirementBaseService<T>) service;
}
@Override
protected void loadLazyData(T data) {
this.getReqService().loadAuthItems(data);
this.getReqService().loadWorkflow(data);
this.getReqService().loadType(data);
}
@Command
@NotifyChange({"dataBean", "canApprove"})
public void approve() {

@ -60,9 +60,4 @@ public class TripRequirementListAll extends RequirementSubpage<TripRequirement>
this.reload();
}
@Override
protected void loadLazyDataForEdit(TripRequirement data) {
tripRequirementService.loadPassangers(data);
}
}

@ -57,9 +57,4 @@ public class TripRequirementListCentre extends RequirementSubpage<TripRequiremen
this.reload();
}
@Override
protected void loadLazyDataForEdit(TripRequirement data) {
tripRequirementService.loadPassangers(data);
}
}

@ -63,9 +63,4 @@ public class TripRequirementListWorkgroup extends RequirementSubpage<TripRequire
this.reload();
}
@Override
protected void loadLazyDataForEdit(TripRequirement data) {
tripRequirementService.loadPassangers(data);
}
}

@ -76,6 +76,7 @@ public class WorkgroupForm extends FormViewModel<Workgroup> {
if (!r.getAuthority().equals(Constants.ROLE_USER)) {
List<User> users = userService.getUsersWithRole(r);
for (User u : users) {
workgroupService.loadParents(u);
workgroupService.addMember(getDataBean(), u, r);
}
}
@ -124,6 +125,8 @@ public class WorkgroupForm extends FormViewModel<Workgroup> {
return;
}
workgroupService.loadMembers(getDataBean());
workgroupService.loadParents(u.getMember());
workgroupService.removeMember(getDataBean(), u);
if (!target.equals("users")) {
@ -139,6 +142,13 @@ public class WorkgroupForm extends FormViewModel<Workgroup> {
return;
}
workgroupService.loadMembers(getDataBean());
workgroupService.loadParents(u);
if (!u.isPerson()) {
workgroupService.loadMembers((Workgroup) u);
}
workgroupService.addMember(getDataBean(), u, roleService.getRoleByAuthority(target));
if (!u.isPerson()) {

@ -35,6 +35,7 @@ public class WorkgroupList extends ListViewModel<Workgroup> {
formZul = "workgroupForm.zul";
dataFilter = new WorkgroupFilter(getFilterTemplate());
treeFactory = new WorkgroupTreeFactory();
treeFactory.setWorkgroupService(workgroupService);
boolConverter = new BoolConverter();
}

@ -7,6 +7,7 @@ import info.bukova.isspst.Constants;
import info.bukova.isspst.data.JobMapping;
import info.bukova.isspst.data.Member;
import info.bukova.isspst.data.Workgroup;
import info.bukova.isspst.services.workgroups.WorkgroupService;
import org.zkoss.zul.DefaultTreeModel;
import org.zkoss.zul.TreeModel;
@ -14,6 +15,8 @@ import org.zkoss.zul.TreeNode;
public class WorkgroupTreeFactory {
private WorkgroupService workgroupService;
public TreeModel<TreeNode<Member>> createTreeModel(Workgroup workgroup) {
WorkgroupTreeNode root = new WorkgroupTreeNode(null, generateChildren(workgroup));
@ -24,6 +27,8 @@ public class WorkgroupTreeFactory {
Collection<WorkgroupTreeNode> children = new LinkedList<WorkgroupTreeNode>();
Workgroup workgroup = Workgroup.class.cast(member);
workgroupService.loadMembers(workgroup);
for (JobMapping jm : workgroup.getMembers()) {
if (jm.getRole().getAuthority().equals(Constants.ROLE_USER) && jm.getMember().isPerson()) {
children.add(new WorkgroupTreeNode(jm.getMember()));
@ -35,4 +40,8 @@ public class WorkgroupTreeFactory {
return children;
}
public void setWorkgroupService(WorkgroupService workgroupService) {
this.workgroupService = workgroupService;
}
}

@ -49,6 +49,7 @@
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<!-- <prop key="hibernate.enable_lazy_load_no_trans">true</prop> -->
</props>
</property>
</bean>
@ -81,7 +82,8 @@
<security:intercept-url pattern="/admin/addressbook/**" access="hasRole('PERM_READ_ADDRESSBOOK')"/>
<security:intercept-url pattern="/munits/**" access="hasRole('PERM_READ_MUNITS')"/>
<security:form-login login-page="/login.zhtml"
authentication-failure-handler-ref="loginFail"/>
authentication-failure-handler-ref="loginFail"
authentication-success-handler-ref="loginSuccess"/>
<security:http-basic/>
<security:logout invalidate-session="true"/>
</security:http>
@ -101,6 +103,8 @@
<bean id="loginFail" class="info.bukova.isspst.security.LoginFailHandler"/>
<bean id="loginSuccess" class="info.bukova.isspst.security.LoginSuccessHandler"/>
<!-- Reporting -->
<bean id="reportDefinition" class="info.bukova.isspst.reporting.ReportDefinition" scope="session">
<aop:scoped-proxy/>
@ -110,6 +114,11 @@
<bean id="genFactory" class="info.bukova.isspst.reporting.GeneratorFactory"/>
<!-- Session data -->
<bean id="sessionData" class="info.bukova.isspst.SessionData" scope="session">
<aop:scoped-proxy/>
</bean>
<!-- DAO -->
<bean id="userDao" class="info.bukova.isspst.dao.jpa.UserDaoJPA">
<property name="sessionFactory" ref="sessionFactory"/>

Loading…
Cancel
Save