View Javadoc
1   package org.andromda.timetracker.client;
2   
3   import java.util.Date;
4   import java.util.Properties;
5   import org.andromda.timetracker.domain.Role;
6   import org.andromda.timetracker.service.UserServiceDelegate;
7   import org.andromda.timetracker.service.UserServiceException;
8   import org.andromda.timetracker.vo.UserDetailsVO;
9   import org.andromda.timetracker.vo.UserRoleVO;
10  import org.andromda.timetracker.vo.UserVO;
11  
12  public class Client
13  {
14      private Properties prop;
15  
16      public void init()
17      {
18          prop = new Properties();
19          prop.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
20          prop.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
21          prop.put("java.naming.provider.url", "localhost");
22      }
23  
24      public void getAllUsersAsVO()
25      {
26          System.out.println("Getting all users...");
27  
28          UserVO[] users = null;
29  
30          UserServiceDelegate usd = new UserServiceDelegate(prop);
31          try
32          {
33              users = usd.getAllUsers();
34          }
35          catch (UserServiceException e)
36          {
37              // TODO Auto-generated catch block
38              e.printStackTrace();
39          }
40          finally
41          {
42              usd.close();
43          }
44  
45          if (users != null && users.length > 0)
46          {
47              for (UserVO userVO : users)
48              {
49                  System.out.println("user: " + userVO.toString() + " - " + userVO.getId());
50              }
51          }
52  
53          System.out.println("Got all users complete.");
54      }
55  
56  
57      public void addUser()
58      {
59          UserDetailsVO userDetailsVO = new UserDetailsVO();
60          userDetailsVO.setFirstName("vance");
61          userDetailsVO.setLastName("Karimi");
62          userDetailsVO.setUsername("vancek");
63          userDetailsVO.setPassword("monkey1");
64          userDetailsVO.setEmail("test@test.com");
65          userDetailsVO.setIsActive(true);
66          userDetailsVO.setCreationDate(new Date());
67  
68          UserRoleVO[] roles = new UserRoleVO[1];
69          roles[0] = new UserRoleVO();
70          roles[0].setRole(Role.ADMIN);
71  
72          userDetailsVO.setRoles(roles);
73  
74          UserServiceDelegate usd = null;
75          try
76          {
77              usd = new UserServiceDelegate(prop);
78              usd.registerUser(userDetailsVO);
79          }
80          finally
81          {
82              if (usd != null)
83              {
84                  usd.close();
85              }
86          }
87      }
88  }