1 /* 2 * Copyright 2001-2008 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 */ 17 18 package org.apache.juddi.query; 19 20 import java.util.List; 21 22 import javax.persistence.EntityManager; 23 24 import org.apache.juddi.query.util.DynamicQuery; 25 import org.apache.juddi.query.util.FindQualifiers; 26 import org.uddi.api_v3.CategoryBag; 27 28 /** 29 * Returns the list of service keys possessing the keyedReferences in the passed category bag. 30 * Output is restricted by list of service keys passed in. If null, all business services are searched. 31 * Output is produced by building the appropriate JPA query based on input and find qualifiers. 32 * 33 * From specification: 34 * From specification: 35 * "combineCategoryBags: this may only be used in the find_business and find_service calls. In the case of 36 * find_business, this qualifier makes the categoryBag entries for the full businessEntity element behave as though all 37 * categoryBag elements found at the businessEntity level and in all contained or referenced businessService elements 38 * and bindingTemplate elements were combined. Searching for a category will yield a positive match on a registered 39 * business if any of the categoryBag elements contained within the full businessEntity element (including the 40 * categoryBag elements within contained or referenced businessService elements or bindingTemplate elements) 41 * contains the filter criteria. 42 * 43 * In the case of find_service, this qualifier makes the categoryBag entries 44 * for the full businessService element behave as though all categoryBag elements found at the businessService level 45 * and in all contained or referenced elements in the bindingTemplate elements were combined. Searching for a category 46 * will yield a positive match on a registered service if any of the categoryBag elements contained within the 47 * full businessService element (including the categoryBag elements within contained or referenced bindingTemplate 48 * elements) contains the filter criteria. 49 * 50 * This find qualifier does not cause the keyedReferences in categoryBags 51 * to be combined with the keyedReferences in keyedReferenceGroups in categoryBags when performing the comparison. 52 * The keyedReferences are combined with each other, and the keyedReferenceGroups are combined with each other." 53 * 54 * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a> 55 * @author <a href="mailto:tcunning@apache.org">Tom Cunningham</a> 56 * @author <a href="mailto:kstam@apache.org">Kurt Stam</a> 57 */ 58 public class FindServiceByCombinedCategoryQuery { 59 60 private static final String ENTITY_NAME_CHILD = "ServiceCategoryBag"; 61 private static final String ENTITY_FIELD2 = "bindingTemplate." + BusinessServiceQuery.ENTITY_FIELD; 62 private static final String ENTITY_NAME_CHILD2 = "BindingCategoryBag"; 63 64 private static final FindEntityByCombinedCategoryQuery findQuery; 65 66 static { 67 findQuery = new FindEntityByCombinedCategoryQuery(BusinessServiceQuery.ENTITY_NAME, 68 BusinessServiceQuery.ENTITY_ALIAS, 69 BusinessServiceQuery.KEY_NAME, 70 BusinessServiceQuery.ENTITY_FIELD, 71 ENTITY_NAME_CHILD, 72 ENTITY_FIELD2, 73 ENTITY_NAME_CHILD2, 74 null, 75 null, 76 BusinessServiceQuery.SIGNATURE_PRESENT); 77 } 78 79 public static List<Object> select(EntityManager em, FindQualifiers fq, CategoryBag categoryBag, String parentKey, List<Object> keysIn) { 80 if (parentKey != null && parentKey.length() > 0) { 81 DynamicQuery.Parameter param = new DynamicQuery.Parameter(BusinessServiceQuery.ENTITY_ALIAS + "." + BusinessServiceQuery.KEY_NAME_PARENT, parentKey, DynamicQuery.PREDICATE_EQUALS); 82 return findQuery.select(em, fq, categoryBag, keysIn, param); 83 } 84 else 85 return findQuery.select(em, fq, categoryBag, keysIn); 86 } 87 }