Ejemplo n.º 1
0
  @RequestMapping(method = RequestMethod.GET)
  @ResponseBody
  public Map<String, Object> listMessages(
      @RequestParam(value = "since", defaultValue = "") String since) {
    final Map<String, Object> response = new HashMap<String, Object>();
    final List<MessageDto> messageList = new ArrayList<MessageDto>();
    final List<Message> list = messageDao.listBySubject(null, null, since);
    final RestStatusDto statusDto = new RestStatusDto();

    if (list != null) {
      final String newSince = MessageDao.getCursor(list);

      for (Message m : list) {
        final MessageDto dto = new MessageDto();
        DtoMarshaller.copyToDto(m, dto);
        messageList.add(dto);
      }

      statusDto.setSince(newSince);
      statusDto.setNum(list.size());
    }
    response.put("meta", statusDto);
    response.put("messages", messageList);
    return response;
  }
Ejemplo n.º 2
0
  // delete user by id
  @RequestMapping(method = RequestMethod.DELETE, value = "/{id}")
  @ResponseBody
  public Map<String, RestStatusDto> deleteUserById(@PathVariable("id") Long id) {
    final Map<String, RestStatusDto> response = new HashMap<String, RestStatusDto>();
    User u = userDao.getByKey(id);
    RestStatusDto statusDto = null;
    statusDto = new RestStatusDto();
    statusDto.setStatus("failed");

    // check if user exists in the datastore
    if (u != null) {
      // delete user group
      userDao.delete(u);
      statusDto.setStatus("ok");
    }
    response.put("meta", statusDto);
    return response;
  }
Ejemplo n.º 3
0
  // update existing user
  @RequestMapping(method = RequestMethod.PUT, value = "/{id}")
  @ResponseBody
  public Map<String, Object> saveExistingUser(@RequestBody UserPayload payLoad) {
    final UserDto userDto = payLoad.getUser();
    final Map<String, Object> response = new HashMap<String, Object>();
    UserDto dto = null;

    RestStatusDto statusDto = new RestStatusDto();
    statusDto.setStatus("failed");

    // if the POST data contains a valid userDto, continue.
    // Otherwise, server will respond with 400 Bad Request
    if (userDto != null) {
      Long keyId = userDto.getKeyId();
      User u;

      // if the userDto has a key, try to get the user.
      if (keyId != null) {
        u = userDao.getByKey(keyId);
        // if we find the user, update it's properties
        if (u != null) {
          // copy the properties, except the createdDateTime property,
          // because it is set in the Dao.
          BeanUtils.copyProperties(userDto, u, new String[] {"createdDateTime", "config"});

          if (u.getPermissionList().equals(String.valueOf(AppRole.SUPER_ADMIN.getLevel()))) {
            u.setPermissionList(String.valueOf(AppRole.USER.getLevel()));
          }

          u = userDao.save(u);
          dto = new UserDto();
          BeanUtils.copyProperties(u, dto, new String[] {"config"});
          if (u.getKey() != null) {
            dto.setKeyId(u.getKey().getId());
          }
          statusDto.setStatus("ok");
        }
      }
    }
    response.put("meta", statusDto);
    response.put("user", dto);
    return response;
  }