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;
}
Aggregations