View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/ebxml/BusinessQueryManagerImpl.java,v 1.24 2003/08/13 16:59:19 farrukh_najmi Exp $ 3 * 4 * 5 */ 6 7 package com.sun.xml.registry.ebxml; 8 9 import com.sun.xml.registry.ebxml.infomodel.*; 10 11 import javax.xml.registry.*; 12 import java.util.*; 13 import java.io.*; 14 15 import javax.xml.registry.infomodel.*; 16 17 /*** 18 * Class Declaration for Class1 19 */ 20 public class BusinessQueryManagerImpl extends QueryManagerImpl implements BusinessQueryManager { 21 22 private static final String WHERE_KEYWORD = "WHERE"; 23 private static final String PRIMARY_TABLE_NAME = "ptn"; 24 25 com.sun.xml.registry.ebxml.util.QueryUtil qu = com.sun.xml.registry.ebxml.util.QueryUtil.getInstance(); 26 27 private static HashMap schemeNameToIdMap = new HashMap(); 28 29 static { 30 schemeNameToIdMap.put("ObjectType", "urn:uuid:3188a449-18ac-41fb-be9f-99a1adca02cb"); 31 schemeNameToIdMap.put("PhoneType", "urn:uuid:de95a42e-a0e3-40a3-abcc-ee6d88492639"); 32 schemeNameToIdMap.put("AssociationType", "urn:uuid:6902675f-2f18-44b8-888b-c91db8b96b4d"); 33 schemeNameToIdMap.put("URLType", "urn:uuid:7817755e-8842-44b2-84f4-bf8a765619be"); //??Only needed for UDDI providers. Need to fix JAXR spec and TCK 34 schemeNameToIdMap.put("PostalAddressAttributes", "ClassScheme"); //??Only needed for UDDI providers. Need to fix JAXR spec and TCK 35 } 36 37 BusinessQueryManagerImpl(RegistryServiceImpl regService, 38 BusinessLifeCycleManagerImpl lcm) throws JAXRException { 39 40 super(regService, lcm, (DeclarativeQueryManagerImpl)(regService.getDeclarativeQueryManager())); 41 } 42 43 44 public BulkResponse findAssociations(Collection findQualifiers, 45 String sourceObjectId, 46 String targetObjectId, 47 Collection associationTypes) throws JAXRException { 48 String queryStr = "SELECT * FROM Association WHERE "; 49 50 String andStr = ""; 51 if (sourceObjectId != null) { 52 queryStr += " (sourceObject = '" + sourceObjectId + "') "; 53 andStr = " AND "; 54 } 55 56 if (targetObjectId != null) { 57 queryStr += andStr + " (targetObject = '" + targetObjectId + "') "; 58 andStr = " AND "; 59 } 60 61 if (associationTypes != null) { 62 /* 63 ??Unimplemented 64 queryStr += andStr + " ("; 65 66 Iterator iter = associationTypes.iterator(); 67 while (iter.hasNext()) { 68 69 } 70 */ 71 } 72 73 Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, queryStr); 74 BulkResponse resp = dqm.executeQuery(query); 75 76 return resp; 77 } 78 79 public BulkResponse findCallerAssociations( 80 Collection findQualifiers, 81 Boolean confirmedByCaller, 82 Boolean confirmedByOtherParty, 83 Collection associationTypes) throws JAXRException 84 { 85 // ??eeg ToDO implement findQualifiers and associationTypes 86 if (confirmedByCaller == null && confirmedByOtherParty == null) { 87 return new BulkResponseImpl(); 88 } 89 90 User user = getCallersUser(); 91 String userId = user.getKey().getId(); 92 String qs = "SELECT * FROM Association a, AuditableEvent e WHERE " + 93 "e.user = '" + userId + "' AND e.eventType = Created"; 94 if (confirmedByCaller != null) { 95 String confirmedByCallerStr = confirmedByCaller.toString(); 96 qs += " AND (e.registryObject = a.sourceObject AND " + 97 "a.isConfirmedBySourceOwner = " + confirmedByCallerStr + 98 " OR e.registryObject = a.targetObject AND " + 99 "a.isConfirmedByTargetOwner = " + confirmedByCallerStr + ")"; 100 } 101 if (confirmedByOtherParty != null) { 102 String confirmedByOtherStr = confirmedByOtherParty.toString(); 103 qs += " AND (e.registryObject = a.sourceObject AND " + 104 "a.isConfirmedByTargetOwner = " + confirmedByOtherStr + 105 " OR e.registryObject = a.targetObject AND " + 106 "a.isConfirmedBySourceOwner = " + confirmedByOtherStr + ")"; 107 } 108 109 Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, qs); 110 return dqm.executeQuery(query); 111 } 112 113 //??JAXR 2.0 114 public BulkResponse findObjects(String objectType, 115 Collection findQualifiers, 116 Collection namePatterns, 117 Collection classifications, 118 Collection specifications, 119 Collection externalIdentifiers, 120 Collection externalLinks) throws JAXRException { 121 122 if (objectType.equals("Concept")) { 123 objectType = "ClassificationNode"; 124 } 125 Query query = createQueryByName(findQualifiers, objectType, namePatterns); 126 query = addClassifications(query, classifications); 127 return dqm.executeQuery(query); 128 } 129 130 /*** 131 * Finds all Organizations that match ALL of the criteria specified by 132 * the parameters of this call. This is a Logical AND operation 133 * between all non-null parameters. 134 * 135 * <p><DL><DT><B>Capability Level: 0 </B></DL> 136 * 137 * @return BulkResponse containing Collection of Organizations 138 * 139 */ 140 public BulkResponse findOrganizations(Collection findQualifiers, 141 Collection namePatterns, 142 Collection classifications, 143 Collection specifications, 144 Collection externalIdentifiers, 145 Collection externalLinks) throws JAXRException { 146 147 Query query = createQueryByName(findQualifiers, "Organization", namePatterns); 148 query = addClassifications(query, classifications); 149 return dqm.executeQuery(query); 150 } 151 152 /*** 153 * Finds all Services that match ALL of the criteria specified by the 154 * parameters of this call. This is a Logical AND operation between 155 * all non-null parameters. 156 * 157 * <p><DL><DT><B>Capability Level: 0 </B></DL> 158 * 159 * 160 * @param orgKey Key identifying an Organization. Required for UDDI 161 * providers. 162 */ 163 public BulkResponse findServices(Key orgKey, 164 Collection findQualifiers, 165 Collection namePatterns, 166 Collection classifications, 167 Collection specifications) throws JAXRException { 168 169 Query query = createQueryByName(findQualifiers, "Service", namePatterns); 170 query = addClassifications(query, classifications); 171 return dqm.executeQuery(query); 172 } 173 174 /*** 175 * Finds all ServiceBindings that match ALL of the criteria specified by the parameters of this call. 176 * This is a Logical AND operation between all non-null parameters. 177 * 178 * 179 * <p><DL><DT><B>Capability Level: 0 </B></DL> 180 * 181 * @param serviceKey Key identifying a Service. Required for UDDI providers. 182 * 183 * 184 * @return BulkResponse containing Collection of ServiceBindings 185 */ 186 public BulkResponse findServiceBindings(Key serviceKey, 187 Collection findQualifiers, 188 Collection classifications, 189 Collection specifications) throws JAXRException { 190 191 Query query = createQueryByName(findQualifiers, "ServiceBinding", null); 192 query = addClassifications(query, classifications); 193 return dqm.executeQuery(query); 194 } 195 196 /*** 197 * Finds all ClassificationSchemes that match ALL of the criteria 198 * specified by the parameters of this call. This is a Logical AND 199 * operation between all non-null parameters. 200 * 201 * <p><DL><DT><B>Capability Level: 0 </B></DL> 202 * 203 * @return BulkResponse containing Collection of ClassificationSchemes 204 */ 205 public BulkResponse findClassificationSchemes(Collection findQualifiers, 206 Collection namePatterns, 207 Collection classifications, 208 Collection externalLinks) throws JAXRException { 209 210 Query query = createQueryByName(findQualifiers, "ClassificationScheme", namePatterns); 211 query = addClassifications(query, classifications); 212 return dqm.executeQuery(query); 213 } 214 215 /*** 216 * Find a ClassificationScheme by name based on the specified name pattern. 217 * 218 * 219 * <p><DL><DT><B>Capability Level: 0 </B></DL> 220 * 221 * @param namePattern Is a String that is a partial or full 222 * name pattern with wildcard searching as specified by the SQL-92 LIKE 223 * specification. 224 * 225 * @return The ClassificationScheme matching the namePattern. If none match 226 * return null. If multiple match then throw an InvalidRequestException. 227 * 228 */ 229 public ClassificationScheme findClassificationSchemeByName(Collection findQualifiers, 230 String namePattern) throws JAXRException { 231 232 Collection namePatterns = new ArrayList(); 233 namePatterns.add(namePattern); 234 Query query = createQueryByName(findQualifiers, "ClassificationScheme", namePatterns); 235 BulkResponse br = dqm.executeQuery(query); 236 237 Iterator i = br.getCollection().iterator(); 238 ClassificationScheme cs = null; 239 if (i.hasNext()) { 240 cs = (ClassificationScheme)i.next(); 241 } 242 243 // needs to check if more then 1 return and raise InvalidRequestException 244 if (i.hasNext()) { 245 throw new InvalidRequestException("Error: findClassificationSchemeByName call cannot match more than one ClassificationScheme"); 246 } 247 248 return cs; 249 } 250 251 /*** 252 * Finds all Concepts that match ALL of the criteria specified by the 253 * parameters of this call. This is a Logical AND operation between 254 * all non-null parameters. 255 * 256 * 257 * <p><DL><DT><B>Capability Level: 0 </B></DL> 258 * 259 * @param findQualifier specifies qualifiers that effect string 260 * matching, sorting etc. 261 * 262 * 263 * @return BulkResponse containing Collection of Concepts 264 */ 265 public BulkResponse findConcepts(Collection findQualifiers, 266 Collection namePatterns, 267 Collection classifications, 268 Collection externalIdentifiers, 269 Collection externalLinks) throws JAXRException { 270 271 Query query = createQueryByName(findQualifiers, "ClassificationNode", namePatterns); 272 query = addClassifications(query, classifications); 273 return dqm.executeQuery(query); 274 } 275 276 /*** 277 * Find a Concept based on the path specified. 278 * If specified path matches more than one ClassificationScheme then 279 * the one that is most general (higher in the concept hierarchy) is returned. 280 * 281 * 282 * 283 * <p><DL><DT><B>Capability Level: 0 </B></DL> 284 * 285 * @param path Is a canonical path expression as defined in the JAXR specification that identifies the Concept. 286 * 287 */ 288 public Concept findConceptByPath(String path) throws JAXRException { 289 //Kludge to work around JAXR 1.0 spec wierdness 290 path = fixConceptPathForEbXML(path); 291 292 String likeOrEqual = "="; 293 if (path.indexOf('%') != -1) { 294 likeOrEqual = "LIKE"; 295 } 296 Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, "SELECT * from ClassificationNode WHERE path " + likeOrEqual + " '" + path + "'"); 297 BulkResponse resp = dqm.executeQuery(query); 298 299 return (Concept)(((BulkResponseImpl)resp).getRegistryObject()); 300 } 301 302 /*** 303 * Handles a quirk of theJAXR spec. Fix in JAXR 2.0 spec?? 304 * Replace schemeName with schemeId. 305 * Prefix value with wild card to account for fact that it may be in different place in ebXML Registry 306 * 307 */ 308 private String fixConceptPathForEbXML(String path) { 309 String newPath = path; 310 311 //Get the first element of the path. 312 StringTokenizer st = new StringTokenizer(path, "/"); 313 int cnt = st.countTokens(); 314 315 316 //JAXR 1.0 assumes only a single level below root scheme 317 if (cnt == 2) { 318 319 String fistElem = st.nextToken(); 320 321 //Replace fistElem with schemeId if fistElem is a pre-defined concept 322 //name as defined in Appendix A of the JAXR specification. 323 //Prefix value with wild card to account for fact that it may be in different place in ebXML Registry 324 if (!(fistElem.startsWith("urn:"))) { 325 String schemeId = (String)(schemeNameToIdMap.get(fistElem)); 326 if (schemeId != null) { 327 String value = st.nextToken(); 328 newPath = "/" + schemeId + "%/" + value; 329 } 330 } 331 } 332 333 return newPath; 334 } 335 336 /*** 337 * Find all Concept that match the path specified. For JAXR 2.0?? 338 * 339 * <p><DL><DT><B>Capability Level: 0 </B></DL> 340 * 341 * @param path Is a canonical path expression as defined in the JAXR specification that identifies the Concept. 342 * 343 */ 344 public Collection findConceptsByPath(String path) throws JAXRException { 345 String likeOrEqual = "="; 346 if (path.indexOf('%') != -1) { 347 likeOrEqual = "LIKE"; 348 } 349 Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, "SELECT * from ClassificationNode WHERE path " + likeOrEqual + " '" + path + "'"); 350 BulkResponse resp = dqm.executeQuery(query); 351 352 return resp.getCollection(); 353 } 354 355 /*** 356 * Finds all RegistryPackages that match ALL of the criteria specified by the parameters of this call. 357 * This is a Logical AND operation between all non-null parameters. 358 * 359 * <p><DL><DT><B>Capability Level: 1 </B></DL> 360 * 361 * 362 * @param findQualifier specifies qualifiers that effect string matching, sorting etc. 363 * 364 * @return BulkResponse containing Collection of RegistryPackages 365 */ 366 public BulkResponse findRegistryPackages(Collection findQualifiers, 367 Collection namePatterns, 368 Collection classifications, 369 Collection externalLinks) throws JAXRException { 370 371 Query query = createQueryByName(findQualifiers, "RegistryPackage", namePatterns); 372 query = addClassifications(query, classifications); 373 return dqm.executeQuery(query); 374 } 375 376 static private String namePatternsToLikeExpr(Collection namePatterns, 377 String term, boolean caseSensitive) { 378 // XXX Assumes namePatterns are Strings 379 if (namePatterns == null || namePatterns.size() == 0) { 380 return null; 381 } 382 else if (namePatterns.size() == 1) { 383 Object[] namesArray = namePatterns.toArray(); 384 385 if (namesArray[0].equals("%")) { 386 return null; 387 } 388 } 389 Iterator i = namePatterns.iterator(); 390 StringBuffer result = new StringBuffer( 391 "(" + caseSensitise(term, caseSensitive) + " LIKE " + caseSensitise("'"+ (String)i.next() + "'", caseSensitive)); 392 while (i.hasNext()) { 393 result.append(" OR " + caseSensitise(term, caseSensitive) + " LIKE " + caseSensitise("'"+ (String)i.next() + "'", caseSensitive)); 394 } 395 return result.append(")").toString(); 396 } 397 398 public static String caseSensitise(String term, boolean caseSensitive) { 399 String newTerm = term; 400 401 if (!caseSensitive) { 402 newTerm = "UPPER(" + term + ")"; 403 } 404 405 return newTerm; 406 } 407 408 static private String classificationToConceptId(Object obj) 409 throws JAXRException { 410 if (!(obj instanceof Classification)) { 411 throw new UnexpectedObjectException( 412 "Expected Collection object type to be Classification"); 413 } 414 Classification cl = (Classification)obj; 415 if (cl.isExternal()) { 416 throw new JAXRException( 417 "External classification qualifiers not yet supported"); 418 } 419 Concept concept = cl.getConcept(); 420 if (concept == null) { 421 throw new JAXRException( 422 "Concept of internal Classification is null"); 423 } 424 return concept.getKey().getId(); 425 } 426 427 private Query createQueryByName(Collection findQualifiers, String tableName, Collection namePatterns) throws JAXRException { 428 429 boolean caseSensitive = false; 430 431 if ((findQualifiers != null) && (findQualifiers.contains(FindQualifier.CASE_SENSITIVE_MATCH))) { 432 caseSensitive = true; 433 } 434 435 StringBuffer qs = new StringBuffer("SELECT * FROM " + tableName + " " + PRIMARY_TABLE_NAME); 436 String likeExpr = namePatternsToLikeExpr(namePatterns, "n.value", caseSensitive); 437 438 if (likeExpr != null) { 439 qs.append(", Name n " + WHERE_KEYWORD + " " + likeExpr + " AND n.parent = " + PRIMARY_TABLE_NAME + ".id"); 440 } 441 442 return dqm.createQuery(Query.QUERY_TYPE_SQL, qs.toString()); 443 } 444 445 446 private Query addClassifications(Query query, Collection classifications) throws JAXRException { 447 448 String q = query.toString(); 449 StringBuffer qs = new StringBuffer(q); 450 String clExpr = qu.classificationsToPred(classifications, PRIMARY_TABLE_NAME + ".id"); 451 452 if (clExpr != null) { 453 if (q.indexOf(WHERE_KEYWORD) != -1) { 454 // where clause already created 455 qs.append(" AND "); 456 } 457 else { 458 qs.append(" " + WHERE_KEYWORD + " "); 459 } 460 qs.append(clExpr); 461 } 462 else { 463 // No qualifiers are specified 464 } 465 466 return dqm.createQuery(Query.QUERY_TYPE_SQL, qs.toString()); 467 } 468 }

This page was automatically generated by Maven