use of org.obiba.mica.network.service.NetworkSetService in project mica2 by obiba.
the class SessionInterceptor method populateUserEntries.
public static void populateUserEntries(ModelAndView modelAndView, UserProfileService userProfileService, VariableSetService variableSetService, StudySetService studySetService, NetworkSetService networkSetService, SubjectAclService subjectAclService) {
Subject subject = SecurityUtils.getSubject();
if (subject.isAuthenticated()) {
String username = subject.getPrincipal().toString();
try {
Map<String, Object> params = userProfileService.getProfileMap(username, true);
List<String> roles = Lists.newArrayList(Roles.MICA_ADMIN, Roles.MICA_REVIEWER, Roles.MICA_EDITOR, Roles.MICA_DAO, Roles.MICA_USER);
boolean[] result = subject.hasRoles(roles);
for (int i = result.length - 1; i >= 0; i--) {
if (!result[i])
roles.remove(i);
}
params.put("roles", roles);
params.put("hasPermissionOnAnyDraftDocument", subjectAclService.findBySubject(subject.getPrincipal().toString(), SubjectAcl.Type.USER).stream().anyMatch(acl -> Arrays.stream(ALL_DRAFT_RESOURCES).anyMatch(res -> res.equals(acl.getResource()))));
params.put("variablesCart", new Cart(variableSetService.getCartCurrentUser()));
params.put("variablesLists", variableSetService.getAllCurrentUser().stream().filter(DocumentSet::hasName).collect(Collectors.toList()));
params.put("studiesCart", new Cart(studySetService.getCartCurrentUser()));
params.put("networksCart", new Cart(networkSetService.getCartCurrentUser()));
modelAndView.getModel().put("user", params);
} catch (Exception e) {
log.warn("Cannot retrieve profile of user {}", username, e);
}
}
}
Aggregations