| <?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>FindBusinessByDiscoveryURLQuery.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 Services</a> > <a href="index.source.html" class="el_package">org.apache.juddi.query</a> > <span class="el_source">FindBusinessByDiscoveryURLQuery.java</span></div><h1>FindBusinessByDiscoveryURLQuery.java</h1><pre class="source lang-java linenums">/* |
| * Copyright 2001-2008 The Apache Software Foundation. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * 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 "AS IS" 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.query; |
| |
| import java.util.List; |
| import javax.persistence.EntityManager; |
| |
| import org.apache.commons.logging.Log; |
| import org.apache.commons.logging.LogFactory; |
| import org.apache.juddi.query.util.DynamicQuery; |
| import org.apache.juddi.query.util.FindQualifiers; |
| import org.uddi.api_v3.DiscoveryURLs; |
| import org.uddi.api_v3.DiscoveryURL; |
| |
| /** |
| * |
| * Returns the list of business keys possessing the DiscoveryUrls in the passed DiscoveryUrl list. |
| * Output is restricted by list of business keys passed in. If null, all businesses are searched. |
| * Output is produced by building the appropriate JPA query based on input and find qualifiers. |
| * |
| * From specification: |
| * "This is a list of discoveryURL structures to be matched against the discoveryURL data associated with registered businessEntity |
| * information. To search for URL without regard to useType attribute values, omit the useType attribute or pass it as an empty |
| * attribute. If useType values are included, the match occurs only on registered information that matches both the useType and |
| * URL value. The returned businessList contains businessInfo structures matching any of the URL's passed (logical OR)." |
| * |
| * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a> |
| */ |
| <span class="nc" id="L44">public class FindBusinessByDiscoveryURLQuery extends BusinessEntityQuery {</span> |
| |
| @SuppressWarnings("unused") |
| <span class="fc" id="L47"> private static Log log = LogFactory.getLog(FindBusinessByDiscoveryURLQuery.class);</span> |
| |
| private static final String ENTITY_NAME_CHILD = "DiscoveryUrl"; |
| |
| private static final String entityAliasChild;; |
| |
| static { |
| <span class="fc" id="L54"> entityAliasChild = buildAlias(ENTITY_NAME_CHILD);</span> |
| <span class="fc" id="L55"> }</span> |
| |
| public static List<Object> select(EntityManager em, FindQualifiers fq, DiscoveryURLs discURLs, |
| List<Object> keysIn, DynamicQuery.Parameter... restrictions) { |
| // If keysIn is not null and empty, then search is over. |
| <span class="fc bfc" id="L60" title="All 4 branches covered."> if ((keysIn != null) && (keysIn.size() == 0))</span> |
| <span class="fc" id="L61"> return keysIn;</span> |
| |
| <span class="fc bfc" id="L63" title="All 2 branches covered."> if (discURLs == null)</span> |
| <span class="fc" id="L64"> return keysIn;</span> |
| |
| <span class="fc" id="L66"> List<DiscoveryURL> discURLlist = discURLs.getDiscoveryURL();</span> |
| <span class="pc bpc" id="L67" title="2 of 4 branches missed."> if (discURLlist == null || discURLlist.size() == 0)</span> |
| <span class="nc" id="L68"> return keysIn;</span> |
| |
| <span class="fc" id="L70"> DynamicQuery dynamicQry = new DynamicQuery(selectSQL);</span> |
| <span class="fc" id="L71"> appendConditions(dynamicQry, fq, discURLlist);</span> |
| <span class="pc bpc" id="L72" title="2 of 4 branches missed."> if (restrictions != null && restrictions.length > 0)</span> |
| <span class="nc" id="L73"> dynamicQry.AND().pad().appendGroupedAnd(restrictions);</span> |
| |
| <span class="fc" id="L75"> return getQueryResult(em, dynamicQry, keysIn, ENTITY_ALIAS + "." + KEY_NAME);</span> |
| } |
| |
| /* |
| * Appends the conditions to the query based on the discovery url list. By default, the urls are OR'd and this cannot be changed. |
| * |
| */ |
| public static void appendConditions(DynamicQuery qry, FindQualifiers fq, List<DiscoveryURL> discURLs) { |
| |
| // Append the necessary tables (one will always be added connecting the entity to its discovery url table). |
| <span class="fc" id="L85"> appendJoinTables(qry, fq, discURLs);</span> |
| <span class="fc" id="L86"> qry.AND().pad().openParen().pad();</span> |
| |
| <span class="fc" id="L88"> int count = 0;</span> |
| <span class="fc bfc" id="L89" title="All 2 branches covered."> for(DiscoveryURL discURL : discURLs) {</span> |
| <span class="fc" id="L90"> String urlTerm = entityAliasChild + ".url";</span> |
| <span class="fc" id="L91"> String urlValue = discURL.getValue();</span> |
| |
| <span class="pc bpc" id="L93" title="2 of 4 branches missed."> if (discURL.getUseType() == null || discURL.getUseType().length() == 0 ) {</span> |
| <span class="nc" id="L94"> qry.appendGroupedAnd(new DynamicQuery.Parameter(urlTerm, urlValue, DynamicQuery.PREDICATE_LIKE));</span> |
| } |
| else { |
| <span class="fc" id="L97"> qry.appendGroupedAnd(new DynamicQuery.Parameter(urlTerm, urlValue, DynamicQuery.PREDICATE_LIKE), </span> |
| <span class="fc" id="L98"> new DynamicQuery.Parameter(entityAliasChild + ".useType", discURL.getUseType(), DynamicQuery.PREDICATE_EQUALS));</span> |
| } |
| |
| <span class="fc bfc" id="L101" title="All 2 branches covered."> if (count + 1 < discURLs.size())</span> |
| <span class="fc" id="L102"> qry.OR().pad();</span> |
| |
| <span class="fc" id="L104"> count++;</span> |
| <span class="fc" id="L105"> }</span> |
| <span class="fc" id="L106"> qry.closeParen().pad();</span> |
| |
| <span class="fc" id="L108"> }</span> |
| |
| /* |
| * Appends the necessary join table for the child entity |
| */ |
| public static void appendJoinTables(DynamicQuery qry, FindQualifiers fq, List<DiscoveryURL> discURLs) { |
| <span class="fc" id="L114"> qry.comma().pad().append(ENTITY_NAME_CHILD + " " + entityAliasChild).pad();</span> |
| <span class="fc" id="L115"> qry.WHERE().pad().openParen().pad();</span> |
| <span class="fc" id="L116"> qry.append(ENTITY_ALIAS + "." + KEY_NAME + " = " + entityAliasChild + "." + ENTITY_FIELD + "." + KEY_NAME + " ");</span> |
| <span class="fc" id="L117"> qry.closeParen().pad();</span> |
| <span class="fc" id="L118"> }</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> |