Exemple #1
0
 @GET
 @Path("/id")
 @Produces(MediaType.APPLICATION_JSON)
 public Response getUserInfo(@QueryParam("id") int id) {
   UserDAO userDAO = Factory.getInstance().getUserDAO();
   try {
     UserDTO user = new UserDTO(userDAO.getById(id));
     log.info("GetUser ID: success");
     return Response.ok().entity(user).build();
   } catch (Exception e) {
     log.info("GetUser ID: exception");
     return Response.ok().status(400).build();
   }
 }
Exemple #2
0
  @GET
  @Path("/mylogin")
  @Produces(MediaType.APPLICATION_JSON)
  public Response editUser(@CookieParam(value = "name") String uid) {

    UserDAO userDAO = Factory.getInstance().getUserDAO();
    SessionDAO sessionDAO = Factory.getInstance().getSessionDAO();

    UserEntity user = userDAO.getById(sessionDAO.haveKey(uid));
    UserDTO userDTO = new UserDTO(user);
    if (user == null) {

      return Response.ok().status(400).build();
    }
    System.out.println(user.getLogin());

    return Response.ok().entity(userDTO).build();
  }
  //    @PostConstruct
  public void init() {

    System.out.println("PostConstruct method call...");

    User ulan = new User();
    ulan.setName("Ulan");

    userDAO.save(ulan);

    User carl = new User("Carl");
    userDAO.save(carl);

    //        System.out.println(ulan);

    List<User> userList = userDAO.getUserList();

    System.out.println("UserList:");

    for (User u : userList) {
      System.out.println(u);
    }

    Loan loan1 = new Loan();
    loan1.setAmount(300);
    loan1.setTerm(15);

    Loan loan2 = new Loan();
    loan2.setAmount(200);
    loan2.setTerm(10);

    Loan loan3 = new Loan();
    loan3.setAmount(400);
    loan3.setTerm(20);

    User user1 = userList.get(0);

    user1.addLoan(loan1);
    user1.addLoan(loan2);

    User user2 = userList.get(1);

    user2.addLoan(loan3);

    userDAO.save(user1);
    userDAO.save(user2);

    List<Loan> loanList = loanDAO.getLoanList();
    System.out.println("Printing loanList:");
    for (Loan loan : loanList) {
      System.out.println(loan);
    }

    System.out.println("Printing whole DB:");
    userList = userDAO.getUserList();
    for (User u : userList) {
      System.out.println(u);
      for (Loan loan : u.getLoanList()) {
        System.out.println(loan);
      }
    }

    System.out.println("Printing list for User with ID 1");
    user1 = userDAO.getById(1);
    for (Loan loan : user1.getLoanList()) {
      System.out.println(loan);
    }

    System.out.println("Printing list for User with ID 2");
    user2 = userDAO.getById(2);
    for (Loan loan : user2.getLoanList()) {
      System.out.println(loan);
    }
  }