blob: 2a91ead70565565524cd123268c1bf0f9c922f56 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>Uddiuddiorgcategorizationderivedfrom.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">jUDDI Core - OpenJPA</a> &gt; <a href="index.source.html" class="el_package">org.apache.juddi.validation.vsv</a> &gt; <span class="el_source">Uddiuddiorgcategorizationderivedfrom.java</span></div><h1>Uddiuddiorgcategorizationderivedfrom.java</h1><pre class="source lang-java linenums">/*
* Copyright 2014 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.juddi.validation.vsv;
import java.util.Collections;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import org.apache.juddi.config.PersistenceManager;
import org.apache.juddi.model.Tmodel;
import org.apache.juddi.v3.error.ErrorMessage;
import org.apache.juddi.v3.error.InvalidValueException;
import org.uddi.api_v3.BindingTemplate;
import org.uddi.api_v3.BusinessEntity;
import org.uddi.api_v3.BusinessService;
import org.uddi.api_v3.KeyedReference;
import org.uddi.api_v3.PublisherAssertion;
import org.uddi.api_v3.TModel;
import org.uddi.api_v3.TModelInstanceInfo;
import org.uddi.v3_service.DispositionReportFaultMessage;
/**
* UDDI provides a mechanism that may be used by publishers to categorize UDDI
* entities according to any number of category systems. See Appendix F Using
* Categorization for more information. This section defines a tModel used to
* associate a tModel, frequently a category system, with some other tModel,
* frequently the value set of some other category system, for the purpose of
* extension or redefinition of purpose.
*
* Most value sets are used with some purpose in mind. To avoid ambiguity in
* publisher and inquirer intent it is not uncommon for this purpose to be
* explicitly associated with the value set in its tModel. The IS0 3166
* geographic category system, for example, has the purpose service offering
* area.
*
* Similarly, the UDDI API is comprised of a fixed set of programming interfaces
* and structures. UDDI registries can extend the UDDI API through schema
* derivation, to offer additional functionality.
*
* The Derived From category system exists to allow tModels to refer to the
* tModels that they extend in some way. Value set values can be re-used by
* referring a derived value set tModel to the values in some other value set
* tModel. The reason for reuse can be for assigning another purpose to the set
* of values, for extending the set of values, for associating one set of values
* with another, or for some other kind of derivation. * Specification tModels
* that extend some other specification tModel can similarly use this category
* system to refer to the tModels they extend, providing end users with
* knowledge about the full scope of the API.
* &lt;br&gt;&lt;br&gt;
* Valid Values - The keyValue attribute in a keyedReference element that
* references this tModel within a categoryBag MUST be some other tModelKey in
* the UDDI registry. For value set derivations the tModel that is referred to
* contain the root values for the derived value set. A tModel for a derived
* value set is not automatically checked if the referred to value set is
* checked. The derived value set must itself go through the registry's process
* for making the derived value set checked.
*
* @author Alex O'Ree
*/
<span class="fc" id="L73">public class Uddiuddiorgcategorizationderivedfrom implements ValueSetValidator {</span>
public String getMyKey() {
<span class="fc" id="L76"> return &quot;uddi:uddi.org:categorization:derivedfrom&quot;;</span>
}
@Override
public void validateValuesBindingTemplate(List&lt;BindingTemplate&gt; items, String xpath) throws DispositionReportFaultMessage {
<span class="pc bpc" id="L81" title="1 of 2 branches missed."> if (items == null) {</span>
<span class="nc" id="L82"> return;</span>
}
<span class="pc bpc" id="L85" title="1 of 2 branches missed."> for (int i = 0; i &lt; items.size(); i++) {</span>
<span class="nc bnc" id="L86" title="All 2 branches missed."> if (items.get(i).getCategoryBag() != null) {</span>
<span class="nc" id="L87"> AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getCategoryBag().getKeyedReference(), getMyKey(), &quot;binding&quot;);</span>
<span class="nc" id="L88"> AbstractSimpleValidator.validateKeyNotPresentKeyRefGrp(items.get(i).getCategoryBag().getKeyedReferenceGroup(), getMyKey(), &quot;binding&quot;);</span>
}
<span class="nc bnc" id="L90" title="All 2 branches missed."> if (items.get(i).getTModelInstanceDetails() != null) {</span>
<span class="nc bnc" id="L91" title="All 2 branches missed."> for (int k = 0; k &lt; items.get(i).getTModelInstanceDetails().getTModelInstanceInfo().size(); k++) {</span>
<span class="nc bnc" id="L92" title="All 2 branches missed."> if (items.get(i).getTModelInstanceDetails().getTModelInstanceInfo().get(k) != null) {</span>
<span class="nc bnc" id="L93" title="All 2 branches missed."> if (getMyKey().equalsIgnoreCase(items.get(i).getTModelInstanceDetails().getTModelInstanceInfo().get(k).getTModelKey())) {</span>
<span class="nc" id="L94"> throw new InvalidValueException(new ErrorMessage(&quot;errors.valuesetvalidation.invalidcontent&quot;, &quot;not allowed on binding templates&quot;));</span>
}
}
}
}
}
<span class="fc" id="L100"> }</span>
@Override
public void validateValuesBusinessEntity(List&lt;BusinessEntity&gt; items) throws DispositionReportFaultMessage {
<span class="pc bpc" id="L104" title="1 of 2 branches missed."> if (items == null) {</span>
<span class="nc" id="L105"> return;</span>
}
<span class="pc bpc" id="L107" title="1 of 2 branches missed."> for (int i = 0; i &lt; items.size(); i++) {</span>
<span class="nc bnc" id="L108" title="All 2 branches missed."> if (items.get(i).getCategoryBag() != null) {</span>
<span class="nc" id="L109"> AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getCategoryBag().getKeyedReference(), getMyKey(), &quot;business&quot;);</span>
<span class="nc" id="L110"> AbstractSimpleValidator.validateKeyNotPresentKeyRefGrp(items.get(i).getCategoryBag().getKeyedReferenceGroup(), getMyKey(), &quot;business&quot;);</span>
}
<span class="nc bnc" id="L112" title="All 2 branches missed."> if (items.get(i).getIdentifierBag() != null) {</span>
<span class="nc" id="L113"> AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getCategoryBag().getKeyedReference(), getMyKey(), &quot;business&quot;);</span>
}
<span class="nc bnc" id="L115" title="All 2 branches missed."> if (items.get(i).getBusinessServices() != null) {</span>
<span class="nc" id="L116"> validateValuesBusinessService(items.get(i).getBusinessServices().getBusinessService(), &quot;businessEntity(&quot; + i + &quot;).&quot;);</span>
}
}
<span class="fc" id="L119"> }</span>
@Override
public void validateValuesBusinessService(List&lt;BusinessService&gt; items, String xpath) throws DispositionReportFaultMessage {
<span class="pc bpc" id="L123" title="1 of 2 branches missed."> if (items == null) {</span>
<span class="nc" id="L124"> return;</span>
}
<span class="pc bpc" id="L126" title="1 of 2 branches missed."> for (int i = 0; i &lt; items.size(); i++) {</span>
<span class="nc bnc" id="L127" title="All 2 branches missed."> if (items.get(i).getCategoryBag() != null) {</span>
<span class="nc" id="L128"> AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getCategoryBag().getKeyedReference(), getMyKey(), &quot;service&quot;);</span>
<span class="nc" id="L129"> AbstractSimpleValidator.validateKeyNotPresentKeyRefGrp(items.get(i).getCategoryBag().getKeyedReferenceGroup(), getMyKey(), &quot;service&quot;);</span>
}
<span class="nc bnc" id="L131" title="All 2 branches missed."> if (items.get(i).getBindingTemplates() != null) {</span>
<span class="nc" id="L132"> validateValuesBindingTemplate(items.get(i).getBindingTemplates().getBindingTemplate(), xpath + xpath + &quot;businessService(&quot; + i + &quot;).identifierBag.&quot;);</span>
}
}
<span class="fc" id="L135"> }</span>
@Override
public void validateValuesPublisherAssertion(List&lt;PublisherAssertion&gt; items) throws DispositionReportFaultMessage {
<span class="pc bpc" id="L139" title="1 of 2 branches missed."> if (items == null) {</span>
<span class="nc" id="L140"> return;</span>
}
<span class="pc bpc" id="L142" title="1 of 2 branches missed."> for (int i = 0; i &lt; items.size(); i++) {</span>
<span class="nc" id="L143"> AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getKeyedReference(), getMyKey(), &quot;publisherAssertion&quot;);</span>
}
<span class="fc" id="L145"> }</span>
private void validatedValuesKeyRef(List&lt;KeyedReference&gt; items, String xpath) throws DispositionReportFaultMessage {
<span class="nc bnc" id="L148" title="All 2 branches missed."> if (items == null) {</span>
<span class="nc" id="L149"> return;</span>
}
<span class="nc" id="L151"> StringBuilder err = new StringBuilder();</span>
<span class="nc bnc" id="L152" title="All 2 branches missed."> for (int i = 0; i &lt; items.size(); i++) {</span>
<span class="nc" id="L153"> List&lt;String&gt; validValues = getValidValues();</span>
<span class="nc bnc" id="L154" title="All 2 branches missed."> if (validValues != null) {</span>
//ok we have some work to do
<span class="nc" id="L156"> boolean valid = false;</span>
<span class="nc bnc" id="L157" title="All 2 branches missed."> for (int k = 0; k &lt; validValues.size(); k++) {</span>
<span class="nc bnc" id="L158" title="All 2 branches missed."> if (validValues.get(k).equals(items.get(i).getKeyValue())) {</span>
<span class="nc" id="L159"> valid = true;</span>
}
}
<span class="nc bnc" id="L162" title="All 2 branches missed."> if (!valid) {</span>
<span class="nc" id="L163"> err.append(xpath + &quot;keyedReference(&quot; + i + &quot;) &quot;);</span>
}
}
}
<span class="nc bnc" id="L167" title="All 2 branches missed."> if (err.length() &gt; 0) {</span>
<span class="nc" id="L168"> throw new InvalidValueException(new ErrorMessage(&quot;errors.valuesetvalidation.invalidcontent&quot;, err.toString()));</span>
}
<span class="nc" id="L170"> }</span>
@Override
public void validateTmodelInstanceDetails(List&lt;TModelInstanceInfo&gt; tModelInstanceInfo, String xpath) throws DispositionReportFaultMessage {
<span class="nc bnc" id="L174" title="All 2 branches missed."> if (tModelInstanceInfo == null) {</span>
<span class="nc" id="L175"> return;</span>
}
<span class="nc bnc" id="L177" title="All 2 branches missed."> for (int k = 0; k &lt; tModelInstanceInfo.size(); k++) {</span>
<span class="nc bnc" id="L178" title="All 2 branches missed."> if (getMyKey().equalsIgnoreCase(tModelInstanceInfo.get(k).getTModelKey())) {</span>
<span class="nc" id="L179"> throw new InvalidValueException(new ErrorMessage(&quot;errors.valuesetvalidation.invalidcontent&quot;, &quot;not allowed on tModel instance info&quot;));</span>
}
}
<span class="nc" id="L182"> }</span>
@Override
public void validateValuesTModel(List&lt;TModel&gt; items) throws DispositionReportFaultMessage {
<span class="pc bpc" id="L186" title="1 of 2 branches missed."> if (items == null) {</span>
<span class="nc" id="L187"> return;</span>
}
<span class="fc" id="L189"> EntityManager em = PersistenceManager.getEntityManager();</span>
<span class="fc" id="L190"> EntityTransaction tx = em.getTransaction();</span>
try {
<span class="pc bpc" id="L192" title="1 of 2 branches missed."> for (int i = 0; i &lt; items.size(); i++) {</span>
<span class="pc bpc" id="L193" title="1 of 2 branches missed."> if (items.get(i).getCategoryBag() != null) {</span>
<span class="pc bpc" id="L194" title="1 of 2 branches missed."> for (int k = 0; k &lt; items.get(i).getCategoryBag().getKeyedReference().size(); k++) {</span>
<span class="pc bpc" id="L195" title="1 of 2 branches missed."> if (getMyKey().equalsIgnoreCase(items.get(i).getCategoryBag().getKeyedReference().get(k).getTModelKey())) {</span>
//TODO look up value
<span class="fc" id="L197"> Tmodel find = em.find(org.apache.juddi.model.Tmodel.class, items.get(i).getCategoryBag().getKeyedReference().get(k).getKeyValue());</span>
<span class="pc bpc" id="L198" title="1 of 2 branches missed."> if (find == null) {</span>
<span class="fc" id="L199"> throw new InvalidValueException(new ErrorMessage(&quot;errors.valuesetvalidation.invalidcontent&quot;, &quot;Referenced key &quot; + items.get(i).getCategoryBag().getKeyedReference().get(k).getKeyValue() + &quot; does not exist&quot;));</span>
}
}
}
}
<span class="nc bnc" id="L204" title="All 2 branches missed."> if (items.get(i).getIdentifierBag() != null) {</span>
<span class="nc" id="L205"> AbstractSimpleValidator.validateKeyNotPresentKeyRef(items.get(i).getIdentifierBag().getKeyedReference(), getMyKey(), &quot;tmodel identbag&quot;);</span>
}
}
<span class="fc" id="L208"> } catch (DispositionReportFaultMessage d) {</span>
<span class="fc" id="L209"> throw d;</span>
} finally {
<span class="pc bpc" id="L211" title="3 of 4 branches missed."> if (tx.isActive()) {</span>
<span class="nc" id="L212"> tx.rollback();</span>
}
<span class="pc" id="L214"> em.close();</span>
<span class="nc" id="L215"> }</span>
<span class="nc" id="L216"> }</span>
@Override
public List&lt;String&gt; getValidValues() {
<span class="nc" id="L220"> return Collections.EMPTY_LIST;</span>
}
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.7.9.201702052155</span></div></body></html>