1/*2 * Copyright 2014 The Apache Software Foundation.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package org.apache.juddi.validation.vsv;
1718import java.util.Collections;
19import java.util.List;
20import javax.persistence.EntityManager;
21import javax.persistence.EntityTransaction;
22import org.apache.juddi.config.PersistenceManager;
23import org.apache.juddi.model.Tmodel;
24import org.apache.juddi.v3.error.ErrorMessage;
25import org.apache.juddi.v3.error.InvalidValueException;
26import org.uddi.api_v3.BindingTemplate;
27import org.uddi.api_v3.BusinessEntity;
28import org.uddi.api_v3.BusinessService;
29import org.uddi.api_v3.KeyedReference;
30import org.uddi.api_v3.PublisherAssertion;
31import org.uddi.api_v3.TModel;
32import org.uddi.api_v3.TModelInstanceInfo;
33import org.uddi.v3_service.DispositionReportFaultMessage;
3435/**36 * UDDI provides a mechanism that may be used by publishers to categorize UDDI37 * entities according to any number of category systems. See Appendix F Using38 * Categorization for more information. This section defines a tModel used to39 * associate a tModel, frequently a category system, with some other tModel,40 * frequently the value set of some other category system, for the purpose of41 * extension or redefinition of purpose.42 *43 * Most value sets are used with some purpose in mind. To avoid ambiguity in44 * publisher and inquirer intent it is not uncommon for this purpose to be45 * explicitly associated with the value set in its tModel. The IS0 316646 * geographic category system, for example, has the purpose service offering47 * area.48 *49 * Similarly, the UDDI API is comprised of a fixed set of programming interfaces50 * and structures. UDDI registries can extend the UDDI API through schema51 * derivation, to offer additional functionality.52 *53 * The Derived From category system exists to allow tModels to refer to the54 * tModels that they extend in some way. Value set values can be re-used by55 * referring a derived value set tModel to the values in some other value set56 * tModel. The reason for reuse can be for assigning another purpose to the set57 * of values, for extending the set of values, for associating one set of values58 * with another, or for some other kind of derivation. * Specification tModels59 * that extend some other specification tModel can similarly use this category60 * system to refer to the tModels they extend, providing end users with61 * knowledge about the full scope of the API.62 * <br><br>63 * Valid Values - The keyValue attribute in a keyedReference element that64 * references this tModel within a categoryBag MUST be some other tModelKey in65 * the UDDI registry. For value set derivations the tModel that is referred to66 * contain the root values for the derived value set. A tModel for a derived67 * value set is not automatically checked if the referred to value set is68 * checked. The derived value set must itself go through the registry's process69 * for making the derived value set checked.70 *71 * @author Alex O'Ree72 */73publicclassUddiuddiorgcategorizationderivedfromimplementsValueSetValidator {
7475public String getMyKey() {
76return"uddi:uddi.org:categorization:derivedfrom";
77 }
7879 @Override
80publicvoid validateValuesBindingTemplate(List<BindingTemplate> items, String xpath) throws DispositionReportFaultMessage {
81if (items == null) {
82return;
83 }
8485for (int i = 0; i < items.size(); i++) {
86if (items.get(i).getCategoryBag() != null) {
87 AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getCategoryBag().getKeyedReference(), getMyKey(), "binding");
88 AbstractSimpleValidator.validateKeyNotPresentKeyRefGrp(items.get(i).getCategoryBag().getKeyedReferenceGroup(), getMyKey(), "binding");
89 }
90if (items.get(i).getTModelInstanceDetails() != null) {
91for (int k = 0; k < items.get(i).getTModelInstanceDetails().getTModelInstanceInfo().size(); k++) {
92if (items.get(i).getTModelInstanceDetails().getTModelInstanceInfo().get(k) != null) {
93if (getMyKey().equalsIgnoreCase(items.get(i).getTModelInstanceDetails().getTModelInstanceInfo().get(k).getTModelKey())) {
94thrownewInvalidValueException(newErrorMessage("errors.valuesetvalidation.invalidcontent", "not allowed on binding templates"));
95 }
96 }
97 }
98 }
99 }
100 }
101102 @Override
103publicvoid validateValuesBusinessEntity(List<BusinessEntity> items) throws DispositionReportFaultMessage {
104if (items == null) {
105return;
106 }
107for (int i = 0; i < items.size(); i++) {
108if (items.get(i).getCategoryBag() != null) {
109 AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getCategoryBag().getKeyedReference(), getMyKey(), "business");
110 AbstractSimpleValidator.validateKeyNotPresentKeyRefGrp(items.get(i).getCategoryBag().getKeyedReferenceGroup(), getMyKey(), "business");
111 }
112if (items.get(i).getIdentifierBag() != null) {
113 AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getCategoryBag().getKeyedReference(), getMyKey(), "business");
114 }
115if (items.get(i).getBusinessServices() != null) {
116 validateValuesBusinessService(items.get(i).getBusinessServices().getBusinessService(), "businessEntity(" + i + ").");
117 }
118 }
119 }
120121 @Override
122publicvoid validateValuesBusinessService(List<BusinessService> items, String xpath) throws DispositionReportFaultMessage {
123if (items == null) {
124return;
125 }
126for (int i = 0; i < items.size(); i++) {
127if (items.get(i).getCategoryBag() != null) {
128 AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getCategoryBag().getKeyedReference(), getMyKey(), "service");
129 AbstractSimpleValidator.validateKeyNotPresentKeyRefGrp(items.get(i).getCategoryBag().getKeyedReferenceGroup(), getMyKey(), "service");
130 }
131if (items.get(i).getBindingTemplates() != null) {
132 validateValuesBindingTemplate(items.get(i).getBindingTemplates().getBindingTemplate(), xpath + xpath + "businessService(" + i + ").identifierBag.");
133 }
134 }
135 }
136137 @Override
138publicvoid validateValuesPublisherAssertion(List<PublisherAssertion> items) throws DispositionReportFaultMessage {
139if (items == null) {
140return;
141 }
142for (int i = 0; i < items.size(); i++) {
143 AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getKeyedReference(), getMyKey(), "publisherAssertion");
144 }
145 }
146147privatevoid validatedValuesKeyRef(List<KeyedReference> items, String xpath) throws DispositionReportFaultMessage {
148if (items == null) {
149return;
150 }
151 StringBuilder err = new StringBuilder();
152for (int i = 0; i < items.size(); i++) {
153 List<String> validValues = getValidValues();
154if (validValues != null) {
155//ok we have some work to do156boolean valid = false;
157for (int k = 0; k < validValues.size(); k++) {
158if (validValues.get(k).equals(items.get(i).getKeyValue())) {
159 valid = true;
160 }
161 }
162if (!valid) {
163 err.append(xpath + "keyedReference(" + i + ") ");
164 }
165 }
166 }
167if (err.length() > 0) {
168thrownewInvalidValueException(newErrorMessage("errors.valuesetvalidation.invalidcontent", err.toString()));
169 }
170 }
171172 @Override
173publicvoid validateTmodelInstanceDetails(List<TModelInstanceInfo> tModelInstanceInfo, String xpath) throws DispositionReportFaultMessage {
174if (tModelInstanceInfo == null) {
175return;
176 }
177for (int k = 0; k < tModelInstanceInfo.size(); k++) {
178if (getMyKey().equalsIgnoreCase(tModelInstanceInfo.get(k).getTModelKey())) {
179thrownewInvalidValueException(newErrorMessage("errors.valuesetvalidation.invalidcontent", "not allowed on tModel instance info"));
180 }
181 }
182 }
183184 @Override
185publicvoid validateValuesTModel(List<TModel> items) throws DispositionReportFaultMessage {
186if (items == null) {
187return;
188 }
189 EntityManager em = PersistenceManager.getEntityManager();
190 EntityTransaction tx = em.getTransaction();
191try {
192for (int i = 0; i < items.size(); i++) {
193if (items.get(i).getCategoryBag() != null) {
194for (int k = 0; k < items.get(i).getCategoryBag().getKeyedReference().size(); k++) {
195if (getMyKey().equalsIgnoreCase(items.get(i).getCategoryBag().getKeyedReference().get(k).getTModelKey())) {
196//TODO look up value197Tmodel find = em.find(org.apache.juddi.model.Tmodel.class, items.get(i).getCategoryBag().getKeyedReference().get(k).getKeyValue());
198if (find == null) {
199thrownewInvalidValueException(newErrorMessage("errors.valuesetvalidation.invalidcontent", "Referenced key " + items.get(i).getCategoryBag().getKeyedReference().get(k).getKeyValue() + " does not exist"));
200 }
201 }
202 }
203 }
204if (items.get(i).getIdentifierBag() != null) {
205 AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getIdentifierBag().getKeyedReference(), getMyKey(), "tmodel identbag");
206 }
207 }
208 } catch (DispositionReportFaultMessage d) {
209throw d;
210 } finally {
211if (tx.isActive()) {
212 tx.rollback();
213 }
214 em.close();
215 }
216 }
217218 @Override
219public List<String> getValidValues() {
220return Collections.EMPTY_LIST;
221 }
222223 }