Search in sources :

Example 1 with UserSettingsPojo

use of won.owner.pojo.UserSettingsPojo in project webofneeds by researchstudio-sat.

the class RestUserController method getUserSettings.

@ResponseBody
@RequestMapping(value = "/settings", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
public // TODO: move transactionality annotation into the service layer
UserSettingsPojo getUserSettings(@RequestParam("uri") String uri) {
    String username = SecurityContextHolder.getContext().getAuthentication().getName();
    // cannot use user object from context since hw doesn't know about created in this session need,
    // therefore, we have to retrieve the user object from the user repository
    User user = userRepository.findByUsername(username);
    UserSettingsPojo userSettingsPojo = new UserSettingsPojo(user.getUsername(), user.getEmail());
    URI needUri = null;
    try {
        needUri = new URI(uri);
        userSettingsPojo.setNeedUri(uri);
        for (UserNeed userNeed : user.getUserNeeds()) {
            if (userNeed.getUri().equals(needUri)) {
                userSettingsPojo.setNotify(userNeed.isMatches(), userNeed.isRequests(), userNeed.isConversations());
                // userSettingsPojo.setEmail(user.getEmail());
                break;
            }
        }
    } catch (URISyntaxException e) {
        // TODO error response
        logger.warn(uri + " need uri problem", e);
    }
    return userSettingsPojo;
}
Also used : User(won.owner.model.User) UserNeed(won.owner.model.UserNeed) CheapInsecureRandomString(won.protocol.util.CheapInsecureRandomString) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) UserSettingsPojo(won.owner.pojo.UserSettingsPojo) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 User (won.owner.model.User)1 UserNeed (won.owner.model.UserNeed)1 UserSettingsPojo (won.owner.pojo.UserSettingsPojo)1 CheapInsecureRandomString (won.protocol.util.CheapInsecureRandomString)1