Search in sources :

Example 1 with StudySetService

use of org.obiba.mica.study.service.StudySetService 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);
        }
    }
}
Also used : Arrays(java.util.Arrays) SubjectAclService(org.obiba.mica.security.service.SubjectAclService) Logger(org.slf4j.Logger) VariableSetService(org.obiba.mica.dataset.service.VariableSetService) Roles(org.obiba.mica.security.Roles) LoggerFactory(org.slf4j.LoggerFactory) HttpServletResponse(javax.servlet.http.HttpServletResponse) UserProfileService(org.obiba.mica.user.UserProfileService) Collectors(java.util.stream.Collectors) HandlerInterceptorAdapter(org.springframework.web.servlet.handler.HandlerInterceptorAdapter) NetworkSetService(org.obiba.mica.network.service.NetworkSetService) SubjectAcl(org.obiba.mica.security.domain.SubjectAcl) Inject(javax.inject.Inject) ModelAndView(org.springframework.web.servlet.ModelAndView) DocumentSet(org.obiba.mica.core.domain.DocumentSet) Component(org.springframework.stereotype.Component) HttpServletRequest(javax.servlet.http.HttpServletRequest) List(java.util.List) Lists(com.google.common.collect.Lists) Subject(org.apache.shiro.subject.Subject) Map(java.util.Map) Cart(org.obiba.mica.web.controller.domain.Cart) SecurityUtils(org.apache.shiro.SecurityUtils) StudySetService(org.obiba.mica.study.service.StudySetService) DocumentSet(org.obiba.mica.core.domain.DocumentSet) Subject(org.apache.shiro.subject.Subject) Cart(org.obiba.mica.web.controller.domain.Cart)

Aggregations

Lists (com.google.common.collect.Lists)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 SecurityUtils (org.apache.shiro.SecurityUtils)1 Subject (org.apache.shiro.subject.Subject)1 DocumentSet (org.obiba.mica.core.domain.DocumentSet)1 VariableSetService (org.obiba.mica.dataset.service.VariableSetService)1 NetworkSetService (org.obiba.mica.network.service.NetworkSetService)1 Roles (org.obiba.mica.security.Roles)1 SubjectAcl (org.obiba.mica.security.domain.SubjectAcl)1 SubjectAclService (org.obiba.mica.security.service.SubjectAclService)1 StudySetService (org.obiba.mica.study.service.StudySetService)1 UserProfileService (org.obiba.mica.user.UserProfileService)1 Cart (org.obiba.mica.web.controller.domain.Cart)1 Logger (org.slf4j.Logger)1