This project has retired. For details please refer to its Attic page.
Uddiuddiorgcategorizationowningbusiness xref
View Javadoc
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 at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * 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 and
14   * limitations under the License.
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   * The owningBusiness tModel represents a category system that may be used to
35   * locate the businessEntity associated with the publisher of a tModel.
36   *
37   * It is often desirable to be able to discover the business entity that
38   * represents the publisher of a given tModel. When choosing among similar Web
39   * service definitions, for example, it is useful to be able to determine that
40   * one of them is published by a known organization. For most UDDI entities this
41   * can be deduced by inspecting the containment hierarchy of the entity to its
42   * root businessEntity. For tModels, the UDDI owningBusiness category system
43   * fills this need by allowing tModels to point to the businessEntity of their
44   * publisher.
45   *
46   * The value set of this value set is the set of businessKeys. The content of
47   * keyValue in keyedReferences that refers to this tModel must be a businessKey.
48   * The keyValue is used to specify that the businessEntity whose businessKey is
49   * the keyValue in a keyedReference "owns" the tagged tModel. The entity tagged
50   * must be a tModel, the referred-to businessEntity must exist, and it must have
51   * been published by the same publisher.
52   *
53   * @author Alex O'Ree
54   */
55  public class Uddiuddiorgcategorizationowningbusiness implements ValueSetValidator {
56  
57          public String getMyKey() {
58                  return "uddi:uddi.org:categorization:owningbusiness";
59          }
60  
61          @Override
62          public void validateValuesBindingTemplate(List<BindingTemplate> items, String xpath) throws DispositionReportFaultMessage {
63                  if (items == null) {
64                          return;
65                  }
66  
67                  for (int i = 0; i < items.size(); i++) {
68                          if (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                          }
72                          if (items.get(i).getTModelInstanceDetails() != null) {
73                                  for (int k = 0; k < items.get(i).getTModelInstanceDetails().getTModelInstanceInfo().size(); k++) {
74                                          if (items.get(i).getTModelInstanceDetails().getTModelInstanceInfo().get(k) != null) {
75                                                  if (getMyKey().equalsIgnoreCase(items.get(i).getTModelInstanceDetails().getTModelInstanceInfo().get(k).getTModelKey())) {
76                                                          throw new InvalidValueException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", "not allowed on binding templates"));
77                                                  }
78                                          }
79                                  }
80                          }
81                  }
82          }
83  
84          @Override
85          public void validateValuesBusinessEntity(List<BusinessEntity> items) throws DispositionReportFaultMessage {
86                  if (items == null) {
87                          return;
88                  }
89                  for (int i = 0; i < items.size(); i++) {
90                          if (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                          }
94                          if (items.get(i).getIdentifierBag() != null) {
95                                  AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getCategoryBag().getKeyedReference(), getMyKey(), "business");
96                          }
97                          if (items.get(i).getBusinessServices() != null) {
98                                  validateValuesBusinessService(items.get(i).getBusinessServices().getBusinessService(), "businessEntity(" + i + ").");
99                          }
100                 }
101         }
102 
103         @Override
104         public void validateValuesBusinessService(List<BusinessService> items, String xpath) throws DispositionReportFaultMessage {
105                 if (items == null) {
106                         return;
107                 }
108                 for (int i = 0; i < items.size(); i++) {
109                         if (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                         }
113                         if (items.get(i).getBindingTemplates() != null) {
114                                 validateValuesBindingTemplate(items.get(i).getBindingTemplates().getBindingTemplate(), xpath + xpath + "businessService(" + i + ").identifierBag.");
115                         }
116                 }
117         }
118 
119         @Override
120         public void validateValuesPublisherAssertion(List<PublisherAssertion> items) throws DispositionReportFaultMessage {
121                 if (items == null) {
122                         return;
123                 }
124                 for (int i = 0; i < items.size(); i++) {
125                         AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getKeyedReference(), getMyKey(), "publisherAssertion");
126                 }
127         }
128 
129         @Override
130         public void validateTmodelInstanceDetails(List<TModelInstanceInfo> tModelInstanceInfo, String xpath) throws DispositionReportFaultMessage {
131                 if (tModelInstanceInfo == null) {
132                         return;
133                 }
134                 for (int k = 0; k < tModelInstanceInfo.size(); k++) {
135                         if (getMyKey().equalsIgnoreCase(tModelInstanceInfo.get(k).getTModelKey())) {
136                                 throw new InvalidValueException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", "not allowed on tModel instance info"));
137                         }
138                 }
139         }
140 
141         @Override
142         public void validateValuesTModel(List<TModel> items) throws DispositionReportFaultMessage {
143                 if (items == null) {
144                         return;
145                 }
146                 EntityManager em = PersistenceManager.getEntityManager();
147                 EntityTransaction tx = em.getTransaction();
148                 try {
149                         for (int i = 0; i < items.size(); i++) {
150                                 if (items.get(i).getCategoryBag() != null) {
151                                         for (int k = 0; k < items.get(i).getCategoryBag().getKeyedReference().size(); k++) {
152                                                 if (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());
156 
157                                                         if (find == null) {
158                                                                 throw new InvalidValueException(new ErrorMessage("errors.valuesetvalidation.invalidcontent", "Referenced key " + items.get(i).getCategoryBag().getKeyedReference().get(k).getKeyValue() + " does not exist"));
159                                                         } else {
160                                                                 if (items.get(i).getTModelKey() != null) {
161                                                                         org.apache.juddi.model.Tmodel tm = em.find(org.apache.juddi.model.Tmodel.class, items.get(i).getTModelKey());
162                                                                         if (tm == null) {
163                                                                                 //this is a project tModel, let access control rules take care of ownership info        
164                                                                         } else if (find.getAuthorizedName().equalsIgnoreCase(tm.getAuthorizedName())) {
165                                                                                 throw new InvalidValueException(new ErrorMessage("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 info
169                                                                 }
170                                                         }
171                                                 }
172                                         }
173                                 }
174                                 if (items.get(i).getIdentifierBag() != null) {
175                                         AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getIdentifierBag().getKeyedReference(), getMyKey(), "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 }