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.v3.error.ErrorMessage;
24 import org.apache.juddi.v3.error.InvalidValueException;
25 import org.uddi.api_v3.BindingTemplate;
26 import org.uddi.api_v3.BusinessEntity;
27 import org.uddi.api_v3.BusinessService;
28 import org.uddi.api_v3.PublisherAssertion;
29 import org.uddi.api_v3.TModel;
30 import org.uddi.api_v3.TModelInstanceInfo;
31 import org.uddi.v3_service.DispositionReportFaultMessage;
32
33
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 public class Uddiuddiorgcategorizationvalidatedby implements ValueSetValidator{
69
70
71 public String getKey(){
72 return "uddi:uddi.org:categorization:validatedby";
73 }
74 @Override
75 public void validateValuesBindingTemplate(List<BindingTemplate> items, String xpath) throws DispositionReportFaultMessage {
76 if (items == null) {
77 return;
78 }
79
80 for (int i = 0; i < items.size(); i++) {
81 if (items.get(i).getCategoryBag() != null) {
82 AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getCategoryBag().getKeyedReference(), getKey(), "binding");
83 AbstractSimpleValidator.validateKeyNotPresentKeyRefGrp(items.get(i).getCategoryBag().getKeyedReferenceGroup(), getKey(), "binding");
84 }
85 if (items.get(i).getTModelInstanceDetails() != null) {
86 for (int k = 0; k < items.get(i).getTModelInstanceDetails().getTModelInstanceInfo().size(); k++) {
87 if (items.get(i).getTModelInstanceDetails().getTModelInstanceInfo().get(k) != null)
88 if (getKey().equalsIgnoreCase(items.get(i).getTModelInstanceDetails().getTModelInstanceInfo().get(k).getTModelKey())) {
89 throw new InvalidValueException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", "not allowed on binding templates"));
90 }
91 }
92 }
93 }
94 }
95
96 @Override
97 public void validateValuesBusinessEntity(List<BusinessEntity> items) throws DispositionReportFaultMessage {
98 if (items == null) {
99 return;
100 }
101 for (int i = 0; i < items.size(); i++) {
102 if (items.get(i).getCategoryBag() != null) {
103 AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getCategoryBag().getKeyedReference(), getKey(), "business");
104 AbstractSimpleValidator.validateKeyNotPresentKeyRefGrp(items.get(i).getCategoryBag().getKeyedReferenceGroup(), getKey(), "business");
105 }
106 if (items.get(i).getIdentifierBag() != null) {
107 AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getCategoryBag().getKeyedReference(), getKey(), "business");
108 }
109 if (items.get(i).getBusinessServices() != null) {
110 validateValuesBusinessService(items.get(i).getBusinessServices().getBusinessService(), "businessEntity(" + i + ").");
111 }
112 }
113 }
114
115 @Override
116 public void validateValuesBusinessService(List<BusinessService> items, String xpath) throws DispositionReportFaultMessage {
117 if (items == null) {
118 return;
119 }
120 for (int i = 0; i < items.size(); i++) {
121 if (items.get(i).getCategoryBag() != null) {
122 AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getCategoryBag().getKeyedReference(), getKey(), "service");
123 AbstractSimpleValidator.validateKeyNotPresentKeyRefGrp(items.get(i).getCategoryBag().getKeyedReferenceGroup(), getKey(), "service");
124 }
125 if (items.get(i).getBindingTemplates() != null) {
126 validateValuesBindingTemplate(items.get(i).getBindingTemplates().getBindingTemplate(), xpath + xpath + "businessService(" + i + ").identifierBag.");
127 }
128 }
129 }
130
131 @Override
132 public void validateValuesPublisherAssertion(List<PublisherAssertion> items) throws DispositionReportFaultMessage {
133 if (items == null) {
134 return;
135 }
136 for (int i = 0; i < items.size(); i++) {
137 AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getKeyedReference(), getKey(), "publisherAssertion");
138 }
139 }
140
141
142 @Override
143 public void validateTmodelInstanceDetails(List<TModelInstanceInfo> tModelInstanceInfo, String xpath) throws DispositionReportFaultMessage {
144 if (tModelInstanceInfo == null) {
145 return;
146 }
147 for (int k = 0; k < tModelInstanceInfo.size(); k++) {
148 if (getKey().equalsIgnoreCase(tModelInstanceInfo.get(k).getTModelKey())) {
149 throw new InvalidValueException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", "not allowed on tModel instance info"));
150 }
151 }
152 }
153
154 @Override
155 public void validateValuesTModel(List<TModel> items) throws DispositionReportFaultMessage {
156 if (items == null) {
157 return;
158 }
159 EntityManager em = PersistenceManager.getEntityManager();
160 EntityTransaction tx = em.getTransaction();
161 try {
162 for (int i = 0; i < items.size(); i++) {
163 if (items.get(i).getCategoryBag() != null) {
164 for (int k = 0; k < items.get(i).getCategoryBag().getKeyedReference().size(); k++) {
165 if (getKey().equalsIgnoreCase(items.get(i).getCategoryBag().getKeyedReference().get(k).getTModelKey())) {
166
167 org.apache.juddi.model.BindingTemplate find = em.find(org.apache.juddi.model.BindingTemplate.class, items.get(i).getCategoryBag().getKeyedReference().get(k).getKeyValue());
168 if (find == null) {
169 throw new InvalidValueException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", "Referenced key " + items.get(i).getCategoryBag().getKeyedReference().get(k).getKeyValue() + " does not exist"));
170 }
171 }
172 }
173 }
174 if (items.get(i).getIdentifierBag() != null) {
175 AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getIdentifierBag().getKeyedReference(), getKey(), "tmodel identbag");
176 }
177 }
178 } catch (DispositionReportFaultMessage d) {
179 throw d;
180 } finally {
181 if (tx.isActive()) {
182 tx.rollback();
183 }
184 em.close();
185 }
186 }
187
188 @Override
189 public List<String> getValidValues() {
190 return Collections.EMPTY_LIST;
191 }
192
193 }