1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package org.astrogrid.community.resolver ;
35
36 import org.apache.commons.logging.Log ;
37 import org.apache.commons.logging.LogFactory ;
38
39 import java.net.URL ;
40 import java.net.URISyntaxException ;
41
42 import org.astrogrid.store.Ivorn ;
43
44 import org.astrogrid.community.common.policy.data.AccountData ;
45 import org.astrogrid.community.common.ivorn.CommunityIvornParser ;
46
47 import org.astrogrid.registry.RegistryException;
48
49 import org.astrogrid.community.common.exception.CommunityPolicyException ;
50 import org.astrogrid.community.common.exception.CommunityServiceException ;
51 import org.astrogrid.community.common.exception.CommunityIdentifierException ;
52
53 import org.astrogrid.community.resolver.exception.CommunityResolverException ;
54
55 /***
56 * A utility to resolve an Ivorn identifier for a Community Account into an Ivorn for the Account home space..
57 *
58 */
59 public class CommunityAccountSpaceResolver
60 {
61 /***
62 * Our debug logger.
63 *
64 */
65 private static Log log = LogFactory.getLog(CommunityAccountSpaceResolver.class);
66
67 /***
68 * Public constructor, using the default Registry service.
69 *
70 */
71 public CommunityAccountSpaceResolver()
72 {
73
74
75 resolver = new CommunityAccountResolver() ;
76 }
77
78 /***
79 * Public constructor, for a specific Registry service.
80 * @param registry The endpoint address for our RegistryDelegate.
81 *
82 */
83 public CommunityAccountSpaceResolver(URL registry)
84 {
85
86
87 resolver = new CommunityAccountResolver(registry) ;
88 }
89
90 /***
91 * Our CommunityAccountResolver resolver.
92 *
93 */
94 private CommunityAccountResolver resolver ;
95
96 /***
97 * Resolve a Community Account identifier into the corresponding VoSpace identifier.
98 * @param ivorn The Community Account identifier.
99 * @return A new Ivorn for the corresponding VoSpace.
100 * @throws CommunityPolicyException If the Community cannot locate the Account.
101 * @throws CommunityServiceException If an error occurs in the Community service.
102 * @throws CommunityIdentifierException If the identifier is not valid.
103 * @throws CommunityResolverException If the Community is unable to resolve the identifier.
104 * @throws RegistryException If the Registry is unable to resolve the identifier.
105 *
106 */
107 public Ivorn resolve(Ivorn ivorn)
108 throws CommunityServiceException,
109 CommunityIdentifierException,
110 CommunityPolicyException,
111 CommunityResolverException,
112 RegistryException
113 {
114 log.debug("") ;
115 log.debug("----\"----") ;
116 log.debug("CommunityAccountSpaceResolver.resolve()") ;
117 log.debug(" Ivorn : " + ivorn) ;
118
119
120 if (null == ivorn)
121 {
122 throw new CommunityIdentifierException(
123 "Null identifier"
124 ) ;
125 }
126
127
128 return resolve(
129 new CommunityIvornParser(ivorn)
130 ) ;
131 }
132
133 /***
134 * Resolve a Community Account identifier into the corresponding VoSpace identifier.
135 * @param parser The Community Account identifier.
136 * @return A new Ivorn for the corresponding VoSpace.
137 * @throws CommunityPolicyException If the Community cannot locate the Account.
138 * @throws CommunityServiceException If an error occurs in the Community service.
139 * @throws CommunityIdentifierException If the identifier is not valid.
140 * @throws CommunityResolverException If the Community is unable to resolve the identifier.
141 * @throws RegistryException If the Registry is unable to resolve the identifier.
142 *
143 */
144 protected Ivorn resolve(CommunityIvornParser parser)
145 throws CommunityServiceException,
146 CommunityIdentifierException,
147 CommunityPolicyException,
148 CommunityResolverException,
149 RegistryException
150 {
151 log.debug("") ;
152 log.debug("----\"----") ;
153 log.debug("CommunityAccountSpaceResolver.resolve()") ;
154 log.debug(" Ivorn : " + ((null != parser) ? parser.getIvorn() : null)) ;
155
156
157 if (null == parser)
158 {
159 throw new CommunityIdentifierException(
160 "Null identifier"
161 ) ;
162 }
163
164
165 AccountData account = resolver.resolve(parser) ;
166 log.debug("CommunityAccountSpaceResolver.resolve()") ;
167 log.debug("Got Account") ;
168 log.debug("Account : " + account.getIdent()) ;
169 log.debug("Home : " + account.getHomeSpace()) ;
170
171
172 String home = account.getHomeSpace() ;
173
174
175 if (null != home)
176 {
177 log.debug("PASS : Got Account home.") ;
178 log.debug("Building new Ivorn based on Account home") ;
179 log.debug(" Home : " + home) ;
180 log.debug(" Path : " + parser.getRemainder()) ;
181
182
183 try {
184 return new Ivorn(
185 (home + parser.getRemainder())
186 ) ;
187 }
188 catch (URISyntaxException ouch)
189 {
190 throw new CommunityIdentifierException(
191 "Unable to parse Account home into an Ivorn",
192 ouch
193 ) ;
194 }
195 }
196
197
198 else {
199 throw new CommunityResolverException(
200 "Account does not have a home space defined",
201 parser.getIvorn()
202 ) ;
203 }
204 }
205 }