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 * The owningBusiness tModel represents a category system that may be used to35 * locate the businessEntity associated with the publisher of a tModel.36 *37 * It is often desirable to be able to discover the business entity that38 * represents the publisher of a given tModel. When choosing among similar Web39 * service definitions, for example, it is useful to be able to determine that40 * one of them is published by a known organization. For most UDDI entities this41 * can be deduced by inspecting the containment hierarchy of the entity to its42 * root businessEntity. For tModels, the UDDI owningBusiness category system43 * fills this need by allowing tModels to point to the businessEntity of their44 * publisher.45 *46 * The value set of this value set is the set of businessKeys. The content of47 * keyValue in keyedReferences that refers to this tModel must be a businessKey.48 * The keyValue is used to specify that the businessEntity whose businessKey is49 * the keyValue in a keyedReference "owns" the tagged tModel. The entity tagged50 * must be a tModel, the referred-to businessEntity must exist, and it must have51 * been published by the same publisher.52 *53 * @author Alex O'Ree54 */55publicclassUddiuddiorgcategorizationowningbusinessimplementsValueSetValidator {
5657public String getMyKey() {
58return"uddi:uddi.org:categorization:owningbusiness";
59 }
6061 @Override
62publicvoid validateValuesBindingTemplate(List<BindingTemplate> items, String xpath) throws DispositionReportFaultMessage {
63if (items == null) {
64return;
65 }
6667for (int i = 0; i < items.size(); i++) {
68if (items.get(i).getCategoryBag() != null) {
69 AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getCategoryBag().getKeyedReference(), getMyKey(), "binding");
70 AbstractSimpleValidator.validateKeyNotPresentKeyRefGrp(items.get(i).getCategoryBag().getKeyedReferenceGroup(), getMyKey(), "binding");
71 }
72if (items.get(i).getTModelInstanceDetails() != null) {
73for (int k = 0; k < items.get(i).getTModelInstanceDetails().getTModelInstanceInfo().size(); k++) {
74if (items.get(i).getTModelInstanceDetails().getTModelInstanceInfo().get(k) != null) {
75if (getMyKey().equalsIgnoreCase(items.get(i).getTModelInstanceDetails().getTModelInstanceInfo().get(k).getTModelKey())) {
76thrownewInvalidValueException(newErrorMessage("errors.valuesetvalidation.invalidcontent", "not allowed on binding templates"));
77 }
78 }
79 }
80 }
81 }
82 }
8384 @Override
85publicvoid validateValuesBusinessEntity(List<BusinessEntity> items) throws DispositionReportFaultMessage {
86if (items == null) {
87return;
88 }
89for (int i = 0; i < items.size(); i++) {
90if (items.get(i).getCategoryBag() != null) {
91 AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getCategoryBag().getKeyedReference(), getMyKey(), "business");
92 AbstractSimpleValidator.validateKeyNotPresentKeyRefGrp(items.get(i).getCategoryBag().getKeyedReferenceGroup(), getMyKey(), "business");
93 }
94if (items.get(i).getIdentifierBag() != null) {
95 AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getCategoryBag().getKeyedReference(), getMyKey(), "business");
96 }
97if (items.get(i).getBusinessServices() != null) {
98 validateValuesBusinessService(items.get(i).getBusinessServices().getBusinessService(), "businessEntity(" + i + ").");
99 }
100 }
101 }
102103 @Override
104publicvoid validateValuesBusinessService(List<BusinessService> items, String xpath) throws DispositionReportFaultMessage {
105if (items == null) {
106return;
107 }
108for (int i = 0; i < items.size(); i++) {
109if (items.get(i).getCategoryBag() != null) {
110 AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getCategoryBag().getKeyedReference(), getMyKey(), "service");
111 AbstractSimpleValidator.validateKeyNotPresentKeyRefGrp(items.get(i).getCategoryBag().getKeyedReferenceGroup(), getMyKey(), "service");
112 }
113if (items.get(i).getBindingTemplates() != null) {
114 validateValuesBindingTemplate(items.get(i).getBindingTemplates().getBindingTemplate(), xpath + xpath + "businessService(" + i + ").identifierBag.");
115 }
116 }
117 }
118119 @Override
120publicvoid validateValuesPublisherAssertion(List<PublisherAssertion> items) throws DispositionReportFaultMessage {
121if (items == null) {
122return;
123 }
124for (int i = 0; i < items.size(); i++) {
125 AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getKeyedReference(), getMyKey(), "publisherAssertion");
126 }
127 }
128129 @Override
130publicvoid validateTmodelInstanceDetails(List<TModelInstanceInfo> tModelInstanceInfo, String xpath) throws DispositionReportFaultMessage {
131if (tModelInstanceInfo == null) {
132return;
133 }
134for (int k = 0; k < tModelInstanceInfo.size(); k++) {
135if (getMyKey().equalsIgnoreCase(tModelInstanceInfo.get(k).getTModelKey())) {
136thrownewInvalidValueException(newErrorMessage("errors.valuesetvalidation.invalidcontent", "not allowed on tModel instance info"));
137 }
138 }
139 }
140141 @Override
142publicvoid validateValuesTModel(List<TModel> items) throws DispositionReportFaultMessage {
143if (items == null) {
144return;
145 }
146 EntityManager em = PersistenceManager.getEntityManager();
147 EntityTransaction tx = em.getTransaction();
148try {
149for (int i = 0; i < items.size(); i++) {
150if (items.get(i).getCategoryBag() != null) {
151for (int k = 0; k < items.get(i).getCategoryBag().getKeyedReference().size(); k++) {
152if (getMyKey().equalsIgnoreCase(items.get(i).getCategoryBag().getKeyedReference().get(k).getTModelKey())) {
153//The content of keyValue in keyedReferences that refers to this tModel must be a businessKey. 154//the referred-to businessEntity must exist, and it must have been published by the same publisher.155 org.apache.juddi.model.BusinessEntity find = em.find(org.apache.juddi.model.BusinessEntity.class, items.get(i).getCategoryBag().getKeyedReference().get(k).getKeyValue());
156157if (find == null) {
158thrownewInvalidValueException(newErrorMessage("errors.valuesetvalidation.invalidcontent", "Referenced key " + items.get(i).getCategoryBag().getKeyedReference().get(k).getKeyValue() + " does not exist"));
159 } else {
160if (items.get(i).getTModelKey() != null) {
161 org.apache.juddi.model.Tmodel tm = em.find(org.apache.juddi.model.Tmodel.class, items.get(i).getTModelKey());
162if (tm == null) {
163//this is a project tModel, let access control rules take care of ownership info 164 } elseif (find.getAuthorizedName().equalsIgnoreCase(tm.getAuthorizedName())) {
165thrownewInvalidValueException(newErrorMessage("errors.valuesetvalidation.invalidcontent", "Referenced key " + items.get(i).getCategoryBag().getKeyedReference().get(k).getKeyValue() + " exists but is not owned by you."));
166 }
167 } else {
168//this is a project tModel, let access control rules take care of ownership info169 }
170 }
171 }
172 }
173 }
174if (items.get(i).getIdentifierBag() != null) {
175 AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getIdentifierBag().getKeyedReference(), getMyKey(), "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 }
192 }