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.v3.error.ErrorMessage;
24import org.apache.juddi.v3.error.InvalidValueException;
25import org.uddi.api_v3.BindingTemplate;
26import org.uddi.api_v3.BusinessEntity;
27import org.uddi.api_v3.BusinessService;
28import org.uddi.api_v3.PublisherAssertion;
29import org.uddi.api_v3.TModel;
30import org.uddi.api_v3.TModelInstanceInfo;
31import org.uddi.v3_service.DispositionReportFaultMessage;
3233/**34 * This tModel represents a category system that is used to point a tModel35 * representing a checked value set to the bindingTemplate for a value set36 * caching or value set validation Web service.37 *38 * One of the concepts that tModels can represent is a checked value set. A39 * checked value set is one whose use is monitored by a validation algorithm.40 * There are two types of validation algorithms: simple checking of referenced41 * values against a pre-defined set of allowable values, and any other kind of42 * validation. UDDI provides the Value Set API set (see Section 5.6 Value Set43 * API Set) to acquire the set of allowable values or execute an external44 * validation algorithm.45 *46 * A validation algorithm for a checked value set can be acquired by nodes47 * privately, or can be obtained through normal UDDI discovery. The validatedBy48 * category system facilitates discovery of the value set caching or value set49 * validation Web service for a checked value set tModel by pointing to the50 * bindingTemplate for the Web service. *51 * For the Web service to be useful, it must recognize any and all checked value52 * sets that it is expected to be associated with. The recommended way for doing53 * so is to place the tModels for the checked value sets it supports in the54 * tModelInstanceDetails of the bindingTemplate for the Web service. Registry55 * policy may require that providers of the Web service recognize value sets56 * supported using this technique.57 * 58* Valid Values59 *60 * The keyValues in keyedReferences that refer to this tModel must be61 * bindingKeys. Such a keyValue SHOULD reference a bindingTemplate that62 * specifies a Web service that implements a value set caching or value set63 * validation API and which SHOULD reference the value set tModel so categorized64 * with this category system. No other contextual checks are performed.65 *66 * @author Alex O'Ree67 */68publicclassUddiuddiorgcategorizationvalidatedbyimplementsValueSetValidator{
697071public String getKey(){
72return"uddi:uddi.org:categorization:validatedby";
73 }
74 @Override
75publicvoid validateValuesBindingTemplate(List<BindingTemplate> items, String xpath) throws DispositionReportFaultMessage {
76if (items == null) {
77return;
78 }
7980for (int i = 0; i < items.size(); i++) {
81if (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 }
85if (items.get(i).getTModelInstanceDetails() != null) {
86for (int k = 0; k < items.get(i).getTModelInstanceDetails().getTModelInstanceInfo().size(); k++) {
87if (items.get(i).getTModelInstanceDetails().getTModelInstanceInfo().get(k) != null)
88if (getKey().equalsIgnoreCase(items.get(i).getTModelInstanceDetails().getTModelInstanceInfo().get(k).getTModelKey())) {
89thrownewInvalidValueException(newErrorMessage("errors.valuesetvalidation.invalidcontent", "not allowed on binding templates"));
90 }
91 }
92 }
93 }
94 }
9596 @Override
97publicvoid validateValuesBusinessEntity(List<BusinessEntity> items) throws DispositionReportFaultMessage {
98if (items == null) {
99return;
100 }
101for (int i = 0; i < items.size(); i++) {
102if (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 }
106if (items.get(i).getIdentifierBag() != null) {
107 AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getCategoryBag().getKeyedReference(), getKey(), "business");
108 }
109if (items.get(i).getBusinessServices() != null) {
110 validateValuesBusinessService(items.get(i).getBusinessServices().getBusinessService(), "businessEntity(" + i + ").");
111 }
112 }
113 }
114115 @Override
116publicvoid validateValuesBusinessService(List<BusinessService> items, String xpath) throws DispositionReportFaultMessage {
117if (items == null) {
118return;
119 }
120for (int i = 0; i < items.size(); i++) {
121if (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 }
125if (items.get(i).getBindingTemplates() != null) {
126 validateValuesBindingTemplate(items.get(i).getBindingTemplates().getBindingTemplate(), xpath + xpath + "businessService(" + i + ").identifierBag.");
127 }
128 }
129 }
130131 @Override
132publicvoid validateValuesPublisherAssertion(List<PublisherAssertion> items) throws DispositionReportFaultMessage {
133if (items == null) {
134return;
135 }
136for (int i = 0; i < items.size(); i++) {
137 AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getKeyedReference(), getKey(), "publisherAssertion");
138 }
139 }
140141142 @Override
143publicvoid validateTmodelInstanceDetails(List<TModelInstanceInfo> tModelInstanceInfo, String xpath) throws DispositionReportFaultMessage {
144if (tModelInstanceInfo == null) {
145return;
146 }
147for (int k = 0; k < tModelInstanceInfo.size(); k++) {
148if (getKey().equalsIgnoreCase(tModelInstanceInfo.get(k).getTModelKey())) {
149thrownewInvalidValueException(newErrorMessage("errors.valuesetvalidation.invalidcontent", "not allowed on tModel instance info"));
150 }
151 }
152 }
153154 @Override
155publicvoid validateValuesTModel(List<TModel> items) throws DispositionReportFaultMessage {
156if (items == null) {
157return;
158 }
159 EntityManager em = PersistenceManager.getEntityManager();
160 EntityTransaction tx = em.getTransaction();
161try {
162for (int i = 0; i < items.size(); i++) {
163if (items.get(i).getCategoryBag() != null) {
164for (int k = 0; k < items.get(i).getCategoryBag().getKeyedReference().size(); k++) {
165if (getKey().equalsIgnoreCase(items.get(i).getCategoryBag().getKeyedReference().get(k).getTModelKey())) {
166167 org.apache.juddi.model.BindingTemplate find = em.find(org.apache.juddi.model.BindingTemplate.class, items.get(i).getCategoryBag().getKeyedReference().get(k).getKeyValue());
168if (find == null) {
169thrownewInvalidValueException(newErrorMessage("errors.valuesetvalidation.invalidcontent", "Referenced key " + items.get(i).getCategoryBag().getKeyedReference().get(k).getKeyValue() + " does not exist"));
170 }
171 }
172 }
173 }
174if (items.get(i).getIdentifierBag() != null) {
175 AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getIdentifierBag().getKeyedReference(), getKey(), "tmodel identbag");
176 }
177 }
178 } catch (DispositionReportFaultMessage d) {
179throw d;
180 } finally {
181if (tx.isActive()) {
182 tx.rollback();
183 }
184 em.close();
185 }
186 }
187188 @Override
189public List<String> getValidValues() {
190return Collections.EMPTY_LIST;
191 }
192193 }