示例#1
0
 @Path("/user/getAll")
 @GET
 @ApiOperation(
     value = "Get all users",
     notes = "Get all users",
     responseClass = "List[com.commafeed.frontend.model.UserModel]")
 public Response getUsers() {
   Map<Long, UserModel> users = Maps.newHashMap();
   for (UserRole role : userRoleDAO.findAll()) {
     User user = role.getUser();
     Long key = user.getId();
     UserModel userModel = users.get(key);
     if (userModel == null) {
       userModel = new UserModel();
       userModel.setId(user.getId());
       userModel.setName(user.getName());
       userModel.setEmail(user.getEmail());
       userModel.setEnabled(!user.isDisabled());
       userModel.setCreated(user.getCreated());
       userModel.setLastLogin(user.getLastLogin());
       users.put(key, userModel);
     }
     if (role.getRole() == Role.ADMIN) {
       userModel.setAdmin(true);
     }
   }
   return Response.ok(users.values()).build();
 }
示例#2
0
 @Path("/user/get/{id}")
 @GET
 @ApiOperation(
     value = "Get user information",
     notes = "Get user information",
     responseClass = "com.commafeed.frontend.model.UserModel")
 public Response getUser(@ApiParam(value = "user id", required = true) @PathParam("id") Long id) {
   Preconditions.checkNotNull(id);
   User user = userDAO.findById(id);
   UserModel userModel = new UserModel();
   userModel.setId(user.getId());
   userModel.setName(user.getName());
   userModel.setEmail(user.getEmail());
   userModel.setEnabled(!user.isDisabled());
   for (UserRole role : userRoleDAO.findAll(user)) {
     if (role.getRole() == Role.ADMIN) {
       userModel.setAdmin(true);
     }
   }
   return Response.ok(userModel).build();
 }