blob: f0ca010ca93584cd51188f2ca1e36b1b03a767b7 [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>AbstractSimpleValidator.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">AbstractSimpleValidator.java</span></div><h1>AbstractSimpleValidator.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.ArrayList;
import java.util.List;
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.KeyedReferenceGroup;
import org.uddi.api_v3.PublisherAssertion;
import org.uddi.api_v3.TModel;
import org.uddi.api_v3.TModelInstanceInfo;
import org.uddi.v3_service.DispositionReportFaultMessage;
/**
* A simple base class for the validator interface that lets you define a simple
* set of allowed values. All other values will be rejected. Valid values apply
* to all UDDI elements
*
* @author Alex O'Ree
* @since 3.2.1
*
*/
<span class="fc" id="L41">public abstract class AbstractSimpleValidator implements ValueSetValidator {</span>
public abstract String getMyKey();
@Override
public void validateValuesBindingTemplate(List&lt;BindingTemplate&gt; items, String xpath) throws DispositionReportFaultMessage {
<span class="pc bpc" id="L47" title="1 of 2 branches missed."> if (items == null) {</span>
<span class="nc" id="L48"> return;</span>
}
<span class="pc bpc" id="L50" title="1 of 2 branches missed."> for (int i = 0; i &lt; items.size(); i++) {</span>
<span class="nc bnc" id="L51" title="All 2 branches missed."> if (items.get(i).getCategoryBag() != null) {</span>
<span class="nc" id="L52"> validatedValuesKeyRef(items.get(i).getCategoryBag().getKeyedReference(), xpath + &quot;bindingTemplate(&quot; + i + &quot;).categoryBag.&quot;);</span>
<span class="nc" id="L53"> validatedValuesKeyRefGrp(items.get(i).getCategoryBag().getKeyedReferenceGroup(), xpath + &quot;bindingTemplate(&quot; + i + &quot;).categoryBag.&quot;);</span>
}
<span class="nc bnc" id="L55" title="All 2 branches missed."> if (items.get(i).getTModelInstanceDetails() != null) {</span>
<span class="nc" id="L57"> validateTmodelInstanceDetails(items.get(i).getTModelInstanceDetails().getTModelInstanceInfo(), xpath + &quot;bindingTemplate(&quot; + i + &quot;).tModelInstanceDetails.&quot;);</span>
}
}
<span class="fc" id="L60"> }</span>
@Override
public void validateValuesBusinessEntity(List&lt;BusinessEntity&gt; items) throws DispositionReportFaultMessage {
<span class="pc bpc" id="L64" title="1 of 2 branches missed."> if (items == null) {</span>
<span class="nc" id="L65"> return;</span>
}
<span class="pc bfc" id="L67" title="All 2 branches covered."> for (int i = 0; i &lt; items.size(); i++) {</span>
<span class="pc bpc" id="L68" title="1 of 2 branches missed."> if (items.get(i).getCategoryBag() != null) {</span>
<span class="nc" id="L69"> validatedValuesKeyRef(items.get(i).getCategoryBag().getKeyedReference(), &quot;businessEntity(&quot; + i + &quot;).categoryBag.&quot;);</span>
<span class="nc" id="L70"> validatedValuesKeyRefGrp(items.get(i).getCategoryBag().getKeyedReferenceGroup(), &quot;businessEntity(&quot; + i + &quot;).categoryBagGroup.&quot;);</span>
}
<span class="nc bnc" id="L72" title="All 2 branches missed."> if (items.get(i).getIdentifierBag() != null) {</span>
<span class="nc" id="L73"> validatedValuesKeyRef(items.get(i).getIdentifierBag().getKeyedReference(), &quot;businessEntity(&quot; + i + &quot;).identifierBag.&quot;);</span>
}
<span class="nc bnc" id="L75" title="All 2 branches missed."> if (items.get(i).getBusinessServices() != null) {</span>
<span class="nc" id="L76"> validateValuesBusinessService(items.get(i).getBusinessServices().getBusinessService(), &quot;businessEntity(&quot; + i + &quot;).&quot;);</span>
}
}
<span class="fc" id="L79"> }</span>
@Override
public void validateValuesBusinessService(List&lt;BusinessService&gt; items, String xpath) throws DispositionReportFaultMessage {
<span class="pc bpc" id="L83" title="1 of 2 branches missed."> if (items == null) {</span>
<span class="nc" id="L84"> return;</span>
}
<span class="pc bpc" id="L86" title="1 of 2 branches missed."> for (int i = 0; i &lt; items.size(); i++) {</span>
<span class="nc bnc" id="L87" title="All 2 branches missed."> if (items.get(i).getCategoryBag() != null) {</span>
<span class="nc" id="L88"> validatedValuesKeyRef(items.get(i).getCategoryBag().getKeyedReference(), xpath + &quot;businessService(&quot; + i + &quot;).categoryBag.&quot;);</span>
<span class="nc" id="L89"> validatedValuesKeyRefGrp(items.get(i).getCategoryBag().getKeyedReferenceGroup(), xpath + &quot;businessService(&quot; + i + &quot;).categoryBag.&quot;);</span>
}
<span class="nc bnc" id="L91" title="All 2 branches missed."> if (items.get(i).getBindingTemplates() != null) {</span>
<span class="nc" id="L92"> validateValuesBindingTemplate(items.get(i).getBindingTemplates().getBindingTemplate(), xpath + xpath + &quot;businessService(&quot; + i + &quot;).&quot;);</span>
}
}
<span class="fc" id="L95"> }</span>
@Override
public void validateValuesPublisherAssertion(List&lt;PublisherAssertion&gt; items) throws DispositionReportFaultMessage {
<span class="pc bpc" id="L99" title="1 of 2 branches missed."> if (items == null) {</span>
<span class="nc" id="L100"> return;</span>
}
<span class="pc bpc" id="L102" title="1 of 2 branches missed."> for (int i = 0; i &lt; items.size(); i++) {</span>
<span class="nc bnc" id="L103" title="All 2 branches missed."> if (items.get(i).getKeyedReference() != null) {</span>
<span class="nc" id="L104"> List&lt;KeyedReference&gt; temp = new ArrayList&lt;KeyedReference&gt;();</span>
<span class="nc" id="L105"> temp.add(items.get(i).getKeyedReference());</span>
<span class="nc" id="L106"> validatedValuesKeyRef(temp, &quot;publisherAssertion(&quot; + i + &quot;).&quot;);</span>
}
}
<span class="fc" id="L109"> }</span>
private void validatedValuesKeyRef(List&lt;KeyedReference&gt; items, String xpath) throws DispositionReportFaultMessage {
<span class="pc bpc" id="L112" title="1 of 2 branches missed."> if (items == null) {</span>
<span class="nc" id="L113"> return;</span>
}
//StringBuilder badvalues=new StringBuilder();
<span class="fc" id="L116"> StringBuilder err = new StringBuilder();</span>
<span class="fc bfc" id="L117" title="All 2 branches covered."> for (int i = 0; i &lt; items.size(); i++) {</span>
<span class="pc bpc" id="L118" title="1 of 2 branches missed."> if (items.get(i).getTModelKey().equalsIgnoreCase(getMyKey())) {</span>
<span class="fc" id="L119"> List&lt;String&gt; validValues = getValidValues();</span>
<span class="pc bpc" id="L120" title="1 of 2 branches missed."> if (validValues != null) {</span>
//ok we have some work to do
//boolean valid = false;
<span class="fc" id="L123"> boolean localfound = false;</span>
<span class="fc bfc" id="L124" title="All 2 branches covered."> for (int k = 0; k &lt; validValues.size(); k++) {</span>
<span class="fc bfc" id="L125" title="All 2 branches covered."> if (validValues.get(k).equals(items.get(i).getKeyValue())) {</span>
// valid = true;
<span class="fc" id="L127"> localfound = true;</span>
}
}
<span class="fc bfc" id="L130" title="All 2 branches covered."> if (!localfound) {</span>
//badvalues.append(items.get(i).getKeyValue()).append(&quot; &quot;);
<span class="fc" id="L132"> err.append(xpath).append(&quot;keyedReference(&quot;).append(i).append(&quot;)=&quot;).append(items.get(i).getKeyValue()).append(&quot; &quot;);</span>
}
}
}
}
<span class="fc bfc" id="L137" title="All 2 branches covered."> if (err.length() &gt; 0) {</span>
<span class="fc" id="L138"> throw new InvalidValueException(new ErrorMessage(&quot;errors.valuesetvalidation.invalidcontent&quot;, err.toString() + getPrintableValidValues()));</span>
}
<span class="fc" id="L140"> }</span>
private void validatedValuesKeyRefGrp(List&lt;KeyedReferenceGroup&gt; items, String xpath) throws DispositionReportFaultMessage {
<span class="pc bpc" id="L143" title="1 of 2 branches missed."> if (items == null) {</span>
<span class="nc" id="L144"> return;</span>
}
<span class="pc bpc" id="L146" title="1 of 2 branches missed."> for (int i = 0; i &lt; items.size(); i++) {</span>
<span class="nc" id="L147"> validatedValuesKeyRef(items.get(i).getKeyedReference(), xpath + &quot;keyReferenceGroup(&quot; + i + &quot;).&quot;);</span>
}
<span class="fc" id="L149"> }</span>
@Override
public void validateTmodelInstanceDetails(List&lt;TModelInstanceInfo&gt; tModelInstanceInfo, String xpath) throws DispositionReportFaultMessage {
<span class="nc" id="L154"> }</span>
@Override
public abstract List&lt;String&gt; getValidValues();
@Override
public void validateValuesTModel(List&lt;TModel&gt; items) throws DispositionReportFaultMessage {
<span class="pc bpc" id="L161" title="1 of 2 branches missed."> if (items == null) {</span>
<span class="nc" id="L162"> return;</span>
}
<span class="fc bfc" id="L164" title="All 2 branches covered."> for (int i = 0; i &lt; items.size(); i++) {</span>
<span class="pc bpc" id="L165" title="1 of 2 branches missed."> if (items.get(i).getCategoryBag() != null) {</span>
<span class="fc" id="L166"> validatedValuesKeyRef(items.get(i).getCategoryBag().getKeyedReference(), &quot;tModel(&quot; + i + &quot;).categoryBag.&quot;);</span>
<span class="fc" id="L167"> validatedValuesKeyRefGrp(items.get(i).getCategoryBag().getKeyedReferenceGroup(), &quot;tModel(&quot; + i + &quot;).categoryBag.&quot;);</span>
}
<span class="pc bpc" id="L169" title="1 of 2 branches missed."> if (items.get(i).getIdentifierBag() != null) {</span>
<span class="nc" id="L170"> validatedValuesKeyRef(items.get(i).getIdentifierBag().getKeyedReference(), &quot;tModel(&quot; + i + &quot;).identifierBag.&quot;);</span>
}
}
<span class="fc" id="L173"> }</span>
public static void validateKeyNotPresentKeyRef(List&lt;KeyedReference&gt; items, String key, String itemtype) throws DispositionReportFaultMessage {
<span class="pc bpc" id="L176" title="1 of 2 branches missed."> if (items == null) {</span>
<span class="nc" id="L177"> return;</span>
}
<span class="pc bpc" id="L179" title="1 of 2 branches missed."> for (int i = 0; i &lt; items.size(); i++) {</span>
<span class="nc" id="L180"> validateKeyNotPresentKeyRef(items.get(i), key, itemtype);</span>
}
<span class="nc" id="L182"> }</span>
public static void validateKeyNotPresentKeyRef(KeyedReference item, String key, String itemtype) throws DispositionReportFaultMessage {
<span class="pc bpc" id="L185" title="1 of 2 branches missed."> if (item == null) {</span>
<span class="nc" id="L186"> return;</span>
}
<span class="pc bpc" id="L188" title="1 of 2 branches missed."> if (key.equalsIgnoreCase(item.getTModelKey())) {</span>
<span class="fc" id="L189"> throw new InvalidValueException(new ErrorMessage(&quot;errors.valuesetvalidation.invalidcontent&quot;, &quot;key &quot; + key + &quot; not allowed on &quot; + itemtype));</span>
}
<span class="nc" id="L191"> }</span>
public static void validateKeyNotPresentKeyRefGrp(List&lt;KeyedReferenceGroup&gt; items, String key, String itemtype) throws DispositionReportFaultMessage {
<span class="nc bnc" id="L194" title="All 2 branches missed."> if (items == null) {</span>
<span class="nc" id="L195"> return;</span>
}
<span class="nc bnc" id="L197" title="All 2 branches missed."> for (int i = 0; i &lt; items.size(); i++) {</span>
<span class="nc bnc" id="L198" title="All 2 branches missed."> if (key.equalsIgnoreCase(items.get(i).getTModelKey())) {</span>
<span class="nc" id="L199"> throw new InvalidValueException(new ErrorMessage(&quot;errors.valuesetvalidation.invalidcontent&quot;, &quot;key &quot; + key + &quot; not allowed on &quot; + itemtype));</span>
}
<span class="nc" id="L201"> validateKeyNotPresentKeyRef(items.get(i).getKeyedReference(), key, itemtype);</span>
}
<span class="nc" id="L203"> }</span>
private String getPrintableValidValues() {
<span class="fc" id="L206"> StringBuilder sb = new StringBuilder();</span>
<span class="fc" id="L207"> sb.append(&quot; Valid Values:[&quot;);</span>
<span class="fc" id="L208"> List&lt;String&gt; validValues = getValidValues();</span>
<span class="fc bfc" id="L209" title="All 2 branches covered."> for (int i = 0; i &lt; validValues.size(); i++) {</span>
<span class="fc" id="L210"> sb.append(validValues.get(i));</span>
<span class="fc bfc" id="L211" title="All 2 branches covered."> if (i + 1 &lt; validValues.size()) {</span>
<span class="fc" id="L212"> sb.append(&quot;,&quot;);</span>
}
}
<span class="fc" id="L215"> sb.append(&quot;]&quot;);</span>
<span class="fc" id="L216"> return sb.toString();</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>