Search in sources :

Example 6 with NotAuthenticatedException

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;
}
Also used : NotAuthenticatedException(org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException) Dashboard(org.hisp.dhis.webapi.webdomain.user.Dashboard)

Example 7 with NotAuthenticatedException

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());
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) NotAuthenticatedException(org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException) ComplexNode(org.hisp.dhis.node.types.ComplexNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode)

Example 8 with NotAuthenticatedException

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);
}
Also used : User(org.hisp.dhis.user.User) NotAuthenticatedException(org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException) MessageConversation(org.hisp.dhis.message.MessageConversation) Interpretation(org.hisp.dhis.interpretation.Interpretation) Inbox(org.hisp.dhis.webapi.webdomain.user.Inbox) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with NotAuthenticatedException

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);
}
Also used : FilterTooShortException(org.hisp.dhis.webapi.controller.exception.FilterTooShortException) User(org.hisp.dhis.user.User) NotAuthenticatedException(org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException) Recipients(org.hisp.dhis.webapi.webdomain.user.Recipients) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with NotAuthenticatedException

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());
}
Also used : NotAuthenticatedException(org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException) CollectionNode(org.hisp.dhis.node.types.CollectionNode)

Aggregations

NotAuthenticatedException (org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException)16 User (org.hisp.dhis.user.User)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)3 CollectionNode (org.hisp.dhis.node.types.CollectionNode)3 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)3 FormOrganisationUnit (org.hisp.dhis.webapi.webdomain.FormOrganisationUnit)3 Dashboard (org.hisp.dhis.webapi.webdomain.user.Dashboard)3 List (java.util.List)2 Interpretation (org.hisp.dhis.interpretation.Interpretation)2 MessageConversation (org.hisp.dhis.message.MessageConversation)2 RootNode (org.hisp.dhis.node.types.RootNode)2 Forms (org.hisp.dhis.webapi.webdomain.Forms)2 UserAccount (org.hisp.dhis.webapi.webdomain.user.UserAccount)2 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 DashboardItem (org.hisp.dhis.dashboard.DashboardItem)1 DataElement (org.hisp.dhis.dataelement.DataElement)1 DataSet (org.hisp.dhis.dataset.DataSet)1