use of org.obiba.mica.user.UserProfileService 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);
}
}
}
use of org.obiba.mica.user.UserProfileService in project mica2 by obiba.
the class DataAccessController method getHistory.
@GetMapping("/data-access-history/{id:.+}")
public ModelAndView getHistory(@PathVariable String id) {
Subject subject = SecurityUtils.getSubject();
if (subject.isAuthenticated()) {
Map<String, Object> params = newParameters(id);
DataAccessRequest dar = (DataAccessRequest) params.get("dar");
addDataAccessConfiguration(params);
// merge change history from main form, feasibility and amendment forms
final List<FormStatusChangeEvent> events = Lists.newArrayList(dar.getStatusChangeHistory().stream().map(e -> new FormStatusChangeEvent(userProfileService, dar, e)).collect(Collectors.toList()));
getDataAccessFeasibilities(params).forEach(a -> {
a.getStatusChangeHistory().stream().map(e -> new FormStatusChangeEvent(userProfileService, a, e)).forEach(events::add);
});
getDataAccessAmendments(params).forEach(a -> {
a.getStatusChangeHistory().stream().map(e -> new FormStatusChangeEvent(userProfileService, a, e)).forEach(events::add);
});
// order change events
params.put("statusChangeEvents", events.stream().sorted(new Comparator<FormStatusChangeEvent>() {
@Override
public int compare(FormStatusChangeEvent event1, FormStatusChangeEvent event2) {
return event1.getDate().compareTo(event2.getDate());
}
}).collect(Collectors.toList()));
return new ModelAndView("data-access-history", params);
} else {
return new ModelAndView("redirect:../signin?redirect=" + micaConfigService.getContextPath() + "/data-access-history%2F" + id);
}
}
Aggregations