1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.juddi.validation.vsv;
17
18 import java.util.Collections;
19 import java.util.List;
20 import javax.persistence.EntityManager;
21 import javax.persistence.EntityTransaction;
22 import org.apache.juddi.config.PersistenceManager;
23 import org.apache.juddi.model.Tmodel;
24 import org.apache.juddi.v3.error.ErrorMessage;
25 import org.apache.juddi.v3.error.InvalidValueException;
26 import org.uddi.api_v3.BindingTemplate;
27 import org.uddi.api_v3.BusinessEntity;
28 import org.uddi.api_v3.BusinessService;
29 import org.uddi.api_v3.KeyedReference;
30 import org.uddi.api_v3.PublisherAssertion;
31 import org.uddi.api_v3.TModel;
32 import org.uddi.api_v3.TModelInstanceInfo;
33 import org.uddi.v3_service.DispositionReportFaultMessage;
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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 public class Uddiuddiorgidentifierisreplacedby implements ValueSetValidator {
173
174 public String getMyKey(){
175 return "uddi:uddi.org:identifier:isreplacedby";
176 }
177
178 @Override
179 public void validateValuesBindingTemplate(List<BindingTemplate> items, String xpath) throws DispositionReportFaultMessage {
180 if (items == null) {
181 return;
182 }
183
184 for (int i = 0; i < items.size(); i++) {
185 if (items.get(i).getCategoryBag() != null) {
186 AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getCategoryBag().getKeyedReference(), getMyKey(), "binding");
187 AbstractSimpleValidator.validateKeyNotPresentKeyRefGrp(items.get(i).getCategoryBag().getKeyedReferenceGroup(), getMyKey(), "binding");
188 }
189 if (items.get(i).getTModelInstanceDetails() != null) {
190 for (int k = 0; k < items.get(i).getTModelInstanceDetails().getTModelInstanceInfo().size(); k++) {
191 if (items.get(i).getTModelInstanceDetails().getTModelInstanceInfo().get(k) != null) {
192 if (getMyKey().equalsIgnoreCase(items.get(i).getTModelInstanceDetails().getTModelInstanceInfo().get(k).getTModelKey())) {
193 throw new InvalidValueException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", "not allowed on binding templates"));
194 }
195 }
196 }
197 }
198 }
199 }
200
201 @Override
202 public void validateValuesBusinessEntity(List<BusinessEntity> items) throws DispositionReportFaultMessage {
203 if (items == null) {
204 return;
205 }
206
207 EntityManager em = PersistenceManager.getEntityManager();
208 EntityTransaction tx = em.getTransaction();
209 try {
210 tx.begin();
211 for (int i = 0; i < items.size(); i++) {
212 if (items.get(i).getCategoryBag() != null) {
213 for (int k = 0; k < items.get(i).getCategoryBag().getKeyedReference().size(); k++) {
214 if (getMyKey().equalsIgnoreCase(items.get(i).getCategoryBag().getKeyedReference().get(k).getTModelKey())) {
215
216 if (items.get(i).getCategoryBag().getKeyedReference().get(k).getTModelKey().equalsIgnoreCase(items.get(i).getBusinessKey())) {
217 throw new InvalidValueException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", "Referenced key " + items.get(i).getCategoryBag().getKeyedReference().get(k).getKeyValue() + " can't reference itself"));
218 }
219
220 try {
221 org.apache.juddi.model.BusinessEntity find = em.find(org.apache.juddi.model.BusinessEntity.class, items.get(i).getCategoryBag().getKeyedReference().get(k).getKeyValue());
222 if (find == null) {
223
224 if (!ContainsBusinessKey(items, items.get(i).getCategoryBag().getKeyedReference().get(k).getKeyValue())) {
225 throw new InvalidValueException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", "Referenced key " + items.get(i).getCategoryBag().getKeyedReference().get(k).getKeyValue() + " does not exist"));
226 }
227 }
228 } catch (ClassCastException c) {
229
230 throw new InvalidValueException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", "Referenced key " + items.get(i).getCategoryBag().getKeyedReference().get(k).getKeyValue() + " must be a business"));
231
232 }
233 }
234 }
235 }
236 if (items.get(i).getIdentifierBag() != null) {
237 for (int k = 0; k < items.get(i).getIdentifierBag().getKeyedReference().size(); k++) {
238 if (getMyKey().equalsIgnoreCase(items.get(i).getIdentifierBag().getKeyedReference().get(k).getTModelKey())) {
239
240 if (items.get(i).getIdentifierBag().getKeyedReference().get(k).getTModelKey().equalsIgnoreCase(items.get(i).getBusinessKey())) {
241 throw new InvalidValueException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", "Referenced key " + items.get(i).getIdentifierBag().getKeyedReference().get(k).getKeyValue() + " can't reference itself"));
242 }
243
244 try {
245 org.apache.juddi.model.BusinessEntity find = em.find(org.apache.juddi.model.BusinessEntity.class, items.get(i).getIdentifierBag().getKeyedReference().get(k).getKeyValue());
246 if (find == null) {
247
248 if (!ContainsBusinessKey(items, items.get(i).getIdentifierBag().getKeyedReference().get(k).getKeyValue())) {
249 throw new InvalidValueException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", "Referenced key " + items.get(i).getIdentifierBag().getKeyedReference().get(k).getKeyValue() + " does not exist"));
250 }
251 }
252 } catch (ClassCastException c) {
253
254 throw new InvalidValueException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", "Referenced key " + items.get(i).getIdentifierBag().getKeyedReference().get(k).getKeyValue() + " must be a business"));
255
256 }
257 }
258 }
259 }
260 }
261 tx.commit();
262 } catch (DispositionReportFaultMessage d) {
263 throw d;
264 } finally {
265 if (tx.isActive()) {
266 tx.rollback();
267 }
268 em.close();
269 }
270 }
271
272 @Override
273 public void validateValuesBusinessService(List<BusinessService> items, String xpath) throws DispositionReportFaultMessage {
274 if (items == null) {
275 return;
276 }
277 for (int i = 0; i < items.size(); i++) {
278 if (items.get(i).getCategoryBag() != null) {
279 AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getCategoryBag().getKeyedReference(), getMyKey(), "service");
280 AbstractSimpleValidator.validateKeyNotPresentKeyRefGrp(items.get(i).getCategoryBag().getKeyedReferenceGroup(), getMyKey(), "service");
281 }
282 if (items.get(i).getBindingTemplates() != null) {
283 validateValuesBindingTemplate(items.get(i).getBindingTemplates().getBindingTemplate(), xpath + xpath + "businessService(" + i + ").identifierBag.");
284 }
285 }
286 }
287
288 @Override
289 public void validateValuesPublisherAssertion(List<PublisherAssertion> items) throws DispositionReportFaultMessage {
290 if (items == null) {
291 return;
292 }
293 for (int i = 0; i < items.size(); i++) {
294 AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getKeyedReference(), getMyKey(), "publisherAssertion");
295 }
296 }
297
298
299 @Override
300 public void validateTmodelInstanceDetails(List<TModelInstanceInfo> tModelInstanceInfo, String xpath) throws DispositionReportFaultMessage {
301 if (tModelInstanceInfo == null) {
302 return;
303 }
304 for (int k = 0; k < tModelInstanceInfo.size(); k++) {
305 if (getMyKey().equalsIgnoreCase(tModelInstanceInfo.get(k).getTModelKey())) {
306 throw new InvalidValueException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", "not allowed on tModel instance info"));
307 }
308 }
309 }
310
311 @Override
312 public void validateValuesTModel(List<TModel> items) throws DispositionReportFaultMessage {
313 if (items == null) {
314 return;
315 }
316
317 EntityManager em = PersistenceManager.getEntityManager();
318 EntityTransaction tx = em.getTransaction();
319
320 try {
321 tx.begin();
322 for (int i = 0; i < items.size(); i++) {
323 if (items.get(i).getCategoryBag() != null) {
324 for (int k = 0; k < items.get(i).getCategoryBag().getKeyedReference().size(); k++) {
325 if (getMyKey().equalsIgnoreCase(items.get(i).getCategoryBag().getKeyedReference().get(k).getTModelKey())) {
326
327 if (items.get(i).getCategoryBag().getKeyedReference().get(k).getTModelKey().equalsIgnoreCase(items.get(i).getTModelKey())) {
328 throw new InvalidValueException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", "Referenced key " + items.get(i).getCategoryBag().getKeyedReference().get(k).getKeyValue() + " can't reference itself"));
329 }
330
331 Tmodel find = null;
332 try {
333 find = em.find(org.apache.juddi.model.Tmodel.class, items.get(i).getCategoryBag().getKeyedReference().get(k).getKeyValue());
334
335 } catch (ClassCastException c) {
336
337 throw new InvalidValueException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", "Referenced key " + items.get(i).getCategoryBag().getKeyedReference().get(k).getKeyValue() + " must be a tModel"));
338
339 }
340 if (find == null) {
341
342 if (!ContainsKey(items, items.get(i).getIdentifierBag().getKeyedReference().get(k).getKeyValue())) {
343 throw new InvalidValueException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", "Referenced key " + items.get(i).getCategoryBag().getKeyedReference().get(k).getKeyValue() + " does not exist"));
344 }
345 }
346 }
347 }
348 }
349 if (items.get(i).getIdentifierBag() != null) {
350 for (int k = 0; k < items.get(i).getIdentifierBag().getKeyedReference().size(); k++) {
351 if (getMyKey().equalsIgnoreCase(items.get(i).getIdentifierBag().getKeyedReference().get(k).getTModelKey())) {
352
353 if (items.get(i).getIdentifierBag().getKeyedReference().get(k).getTModelKey().equalsIgnoreCase(items.get(i).getTModelKey())) {
354 throw new InvalidValueException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", "Referenced key " + items.get(i).getIdentifierBag().getKeyedReference().get(k).getKeyValue() + " can't reference itself"));
355 }
356 Tmodel find = null;
357 try {
358 find = em.find(org.apache.juddi.model.Tmodel.class, items.get(i).getIdentifierBag().getKeyedReference().get(k).getKeyValue());
359
360 } catch (ClassCastException c) {
361
362 throw new InvalidValueException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", "Referenced key " + items.get(i).getIdentifierBag().getKeyedReference().get(k).getKeyValue() + " must be a tModel"));
363
364 }
365 if (find == null) {
366
367 if (!ContainsKey(items, items.get(i).getIdentifierBag().getKeyedReference().get(k).getKeyValue())) {
368 throw new InvalidValueException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", "Referenced key " + items.get(i).getIdentifierBag().getKeyedReference().get(k).getKeyValue() + " does not exist"));
369 }
370 }
371 }
372 }
373 }
374 }
375 tx.commit();
376 } catch (DispositionReportFaultMessage d) {
377 throw d;
378 } finally {
379 if (tx.isActive()) {
380 tx.rollback();
381 }
382 em.close();
383 }
384 }
385
386 @Override
387 public List<String> getValidValues() {
388 return Collections.EMPTY_LIST;
389 }
390
391 private boolean ContainsKey(List<TModel> items, String keyValue) {
392 for (int i = 0; i < items.size(); i++) {
393 if (items.get(i).getTModelKey().equalsIgnoreCase(keyValue)) {
394 return true;
395 }
396 }
397 return false;
398 }
399
400 private boolean ContainsBusinessKey(List<BusinessEntity> items, String keyValue) {
401 for (int i = 0; i < items.size(); i++) {
402 if (items.get(i).getBusinessKey().equalsIgnoreCase(keyValue)) {
403 return true;
404 }
405 }
406 return false;
407 }
408
409 }