1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.scripting;
12
13 import org.astrogrid.community.User;
14 import org.astrogrid.community.beans.v1.Account;
15 import org.astrogrid.community.beans.v1.Credentials;
16 import org.astrogrid.community.beans.v1.Group;
17 import org.astrogrid.community.common.exception.CommunityIdentifierException;
18 import org.astrogrid.community.common.exception.CommunityServiceException;
19 import org.astrogrid.community.common.ivorn.CommunityAccountIvornFactory;
20 import org.astrogrid.store.Ivorn;
21
22 import java.net.URISyntaxException;
23
24 /*** Class to help construction of various kinds of object
25 * @author Noel Winstanley nw@jb.man.ac.uk 12-Mar-2004
26 *
27 *
28 */
29 public class ObjectBuilder {
30 /*** Construct a new ObjectHelper
31 *
32 */
33 public ObjectBuilder() {
34 super();
35 }
36 /*** helper method to create an account object
37 *
38 * @param username name of the user
39 * @param community community the user is registered with
40 * @return
41 */
42 public Account newAccount(String username,String community) {
43 Account acc = new Account();
44 acc.setName(username);
45 acc.setCommunity(community);
46 return acc;
47 }
48 /*** create a group object *
49 *
50 * @param groupName name of the group
51 * @param community community the group belongs to
52 * @return
53 */
54 public Group newGroup(String groupName,String community) {
55 Group g = new Group();
56 g.setName(groupName);
57 g.setCommunity(community);
58 return g;
59
60 }
61 /*** create a credentials object from an account and a group */
62 public Credentials newCredendtials(Account acc,Group grp) {
63 Credentials c = new Credentials();
64 c.setAccount(acc);
65 c.setGroup(grp);
66 c.setSecurityToken("token");
67 return c;
68 }
69
70 /*** create the anonymous user */
71 public User user() {
72 return new User();
73 }
74
75 /*** create a user
76 *
77 * @param userid username
78 * @param community community the user is registered with
79 * @param group group the user belongs to
80 * @param token not used
81 * @return
82 */
83 public User newUser(String userid,String community,String group,String token) {
84 return new User(userid,community,group,token);
85 }
86
87 /*** convert a user object into an ivorn that represents that user
88 *
89 * @param u a user object
90 * @return the equivalent user ivorn.
91 * @throws CommunityIdentifierException if the community is not known
92 */
93 public Ivorn newUserIvorn(User u) throws CommunityIdentifierException {
94 return newUserIvorn(u.getCommunity(),u.getAccount());
95 }
96 /*** create a user ivorn, from community and account name
97 *
98 * @param community the name of the community the account is registered with
99 * @param account the username
100 * @return
101 * @throws CommunityIdentifierException if the community is not known.
102 */
103 public Ivorn newUserIvorn(String community,String account) throws CommunityIdentifierException {
104 return CommunityAccountIvornFactory.createIvorn(community,account);
105 }
106 /*** create a user ivorn, from account name and locally-configured community
107 *
108 * @param account the username
109 * @return a user ivorn, where the comminity name is provided by local configuration
110 * @throws CommunityServiceException is the commnity service can't be accessed
111 * @throws CommunityIdentifierException
112 */
113 public Ivorn newLocalUserIvorn(String account) throws CommunityServiceException, CommunityIdentifierException {
114 return CommunityAccountIvornFactory.createLocal(account);
115 }
116
117 public Ivorn newIvorn(Ivorn root,String file) throws URISyntaxException {
118 String r = root.toString();
119 return new Ivorn(r + (r.endsWith("/") ? "" : "/") + file);
120 }
121
122 /*** construct an arbitrary ivorn object
123 * @throws URISyntaxException*/
124 public Ivorn newIvorn(String ivorn) throws URISyntaxException {
125 return new Ivorn(ivorn);
126 }
127 /*** construct an abritray ivorn object
128 *
129 * @param path the ivorn
130 * @param fragment a fragment - i.e. the bit after <tt>#</tt>
131 * @return an ivorn of form <tt>ivo://<i>path</i>#<i>fragment</i></tt>
132 */
133 public Ivorn newIvorn(String path,String fragment) {
134 return new Ivorn(path,fragment);
135 }
136 /*** construct an abritray ivorn object
137 *
138 * @param authority the authority of the ivorn
139 * @param key key into the authority
140 * @param fragment
141 * @return an ivorn of form <tt>ivo://<i>authority</i>/<i>key</i>#<i>fragment</i></tt>
142 */
143 public Ivorn newIvorn(String authority,String key,String fragment) {
144 return new Ivorn(authority,key,fragment);
145 }
146
147
148
149 }
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173