|
|
|
@ -8,15 +8,14 @@ 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;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class WorkgroupServiceImpl extends AbstractOwnedService<Workgroup> implements WorkgroupService {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -125,7 +124,7 @@ public class WorkgroupServiceImpl extends AbstractOwnedService<Workgroup> implem
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional
|
|
|
|
|
public List<Workgroup> getUserCentres(User user) {
|
|
|
|
|
if (user.equals(getLoggedInUser()) && sessionData.getUserCentres() != null) {
|
|
|
|
|
/*if (user.equals(getLoggedInUser()) && sessionData.getUserCentres() != null) {
|
|
|
|
|
return sessionData.getUserCentres();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -150,6 +149,67 @@ public class WorkgroupServiceImpl extends AbstractOwnedService<Workgroup> implem
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return centres;*/
|
|
|
|
|
return getUserCentres(user, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional
|
|
|
|
|
public List<Workgroup> getUserCentres(User user, boolean userOnly) {
|
|
|
|
|
if (!userOnly && user.equals(getLoggedInUser()) && sessionData.getUserCentres() != null) {
|
|
|
|
|
return sessionData.getUserCentres();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (userOnly && user.equals(getLoggedInUser()) && sessionData.getUserOnlyCentres() != null) {
|
|
|
|
|
return sessionData.getUserOnlyCentres();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Workgroup> parents;
|
|
|
|
|
|
|
|
|
|
if (userOnly) {
|
|
|
|
|
parents = filterUserOnly(user, getParents(user));
|
|
|
|
|
} else {
|
|
|
|
|
parents = getParents(user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (parents == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Workgroup> centres = new ArrayList<Workgroup>();
|
|
|
|
|
for (Workgroup w : parents) {
|
|
|
|
|
if (w.isCentre()) {
|
|
|
|
|
centres.add(w);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (Workgroup w : getUserWorkgroups(user)) {
|
|
|
|
|
loadParents(w);
|
|
|
|
|
for (Workgroup centre : w.getParents()) {
|
|
|
|
|
if (!centres.contains(centre)) {
|
|
|
|
|
centres.add(centre);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return centres;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<Workgroup> filterUserOnly(User user, List<Workgroup> wgList) {
|
|
|
|
|
List<Workgroup> centres = new ArrayList<Workgroup>();
|
|
|
|
|
|
|
|
|
|
for (Workgroup wg : wgList) {
|
|
|
|
|
List<Role> roles = getUserWorkgroupRoles(wg, user);
|
|
|
|
|
if (roles == null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (Role r : roles) {
|
|
|
|
|
if (r.getAuthority().equals(Constants.ROLE_USER)) {
|
|
|
|
|
centres.add(wg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return centres;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|