use of org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException in project dhis2-core by dhis2.
the class MeController method getDashboard.
@RequestMapping(value = "/dashboard")
@ResponseBody
public Dashboard getDashboard(HttpServletResponse response) throws Exception {
User currentUser = currentUserService.getCurrentUser();
if (currentUser == null) {
throw new NotAuthenticatedException();
}
Dashboard dashboard = new Dashboard();
dashboard.setUnreadMessageConversations(messageService.getUnreadMessageConversationCount());
dashboard.setUnreadInterpretations(interpretationService.getNewInterpretationCount());
return dashboard;
}
use of org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException in project dhis2-core by dhis2.
the class MeController method getCurrentUser.
@RequestMapping(value = "", method = RequestMethod.GET)
public void getCurrentUser(HttpServletResponse response) throws Exception {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
User currentUser = currentUserService.getCurrentUser();
if (currentUser == null) {
throw new NotAuthenticatedException();
}
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
CollectionNode collectionNode = fieldFilterService.filter(User.class, Collections.singletonList(currentUser), fields);
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
RootNode rootNode = NodeUtils.createRootNode(collectionNode.getChildren().get(0));
if (fieldsContains("settings", fields)) {
rootNode.addChild(new ComplexNode("settings")).addChildren(NodeUtils.createSimples(userSettingService.getUserSettingsWithFallbackByUserAsMap(currentUser, USER_SETTING_NAMES, true)));
}
if (fieldsContains("authorities", fields)) {
rootNode.addChild(new CollectionNode("authorities")).addChildren(NodeUtils.createSimples(currentUser.getUserCredentials().getAllAuthorities()));
}
nodeService.serialize(rootNode, "application/json", response.getOutputStream());
}
use of org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException in project dhis2-core by dhis2.
the class CurrentUserController method getInbox.
@RequestMapping(value = "/inbox", produces = { "application/json", "text/*" })
public void getInbox(HttpServletResponse response) throws Exception {
User user = currentUserService.getCurrentUser();
if (user == null) {
throw new NotAuthenticatedException();
}
Inbox inbox = new Inbox();
inbox.setMessageConversations(new ArrayList<>(messageService.getMessageConversations(0, MAX_OBJECTS)));
inbox.setInterpretations(new ArrayList<>(interpretationService.getInterpretations(0, MAX_OBJECTS)));
for (org.hisp.dhis.message.MessageConversation messageConversation : inbox.getMessageConversations()) {
messageConversation.setAccess(aclService.getAccess(messageConversation, user));
}
for (Interpretation interpretation : inbox.getInterpretations()) {
interpretation.setAccess(aclService.getAccess(interpretation, user));
}
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
renderService.toJson(response.getOutputStream(), inbox);
}
use of org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException in project dhis2-core by dhis2.
the class CurrentUserController method recipientsJson.
@RequestMapping(value = "/recipients", produces = { "application/json", "text/*" })
public void recipientsJson(HttpServletResponse response, @RequestParam(value = "filter") String filter) throws IOException, NotAuthenticatedException, FilterTooShortException {
User currentUser = currentUserService.getCurrentUser();
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.CACHE_1_HOUR);
if (currentUser == null) {
throw new NotAuthenticatedException();
}
if (3 > filter.length()) {
throw new FilterTooShortException();
}
Recipients recipients = new Recipients();
recipients.setOrganisationUnits(new HashSet<>(organisationUnitService.getOrganisationUnitsBetweenByName(filter, 0, MAX_OBJECTS)));
recipients.setUsers(new HashSet<>(userService.getAllUsersBetweenByName(filter, 0, MAX_OBJECTS)));
recipients.setUserGroups(new HashSet<>(userGroupService.getUserGroupsBetweenByName(filter, 0, MAX_OBJECTS)));
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
renderService.toJson(response.getOutputStream(), recipients);
}
use of org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException in project dhis2-core by dhis2.
the class MeController method updateCurrentUser.
@RequestMapping(value = "", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
public void updateCurrentUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
User currentUser = currentUserService.getCurrentUser();
if (currentUser == null) {
throw new NotAuthenticatedException();
}
User user = renderService.fromJson(request.getInputStream(), User.class);
merge(currentUser, user);
if (user.getUserCredentials() != null) {
updatePassword(currentUser, user.getUserCredentials().getPassword());
}
manager.update(currentUser);
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
CollectionNode collectionNode = fieldFilterService.filter(User.class, Collections.singletonList(currentUser), fields);
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
nodeService.serialize(NodeUtils.createRootNode(collectionNode.getChildren().get(0)), "application/json", response.getOutputStream());
}
Aggregations