Changeset 1913 for trunk/src/groovy/dbnp/query/Criterion.groovy
- Timestamp:
- Jun 6, 2011, 2:47:23 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/groovy/dbnp/query/Criterion.groovy
r1904 r1913 3 3 import java.text.SimpleDateFormat 4 4 import org.dbnp.gdt.* 5 import dbnp.studycapturing.* 5 6 import org.apache.commons.logging.LogFactory; 6 7 … … 386 387 } 387 388 } 389 390 // Wildcard searches must also search the fixed domain fields of all entities. 391 if( this.field == '*' ) { 392 def condition = wildcardDomainFields( prefix, objectToSearchIn ) 393 394 whereClause += condition[ "where" ]; 395 condition[ "parameters" ].each { 396 parameters[ it.key ] = it.value; 397 } 398 } 388 399 389 400 def where = whereClause?.findAll { it } ? "( " + whereClause.join( " OR " ) + " )" : "" 390 401 391 402 return [ "join": joinClause, "where": where , "parameters": parameters ]; 403 } 404 405 protected Map wildcardDomainFields( String prefix, String objectToSearchIn ) { 406 def whereClause = []; 407 def parameters = [:]; 408 409 // Determine all domain fields 410 def domainFields 411 412 switch( objectToSearchIn.toLowerCase() ) { 413 case "study": domainFields = Study.giveDomainFields(); break; 414 case "subject": domainFields = Subject.giveDomainFields(); break; 415 case "event": domainFields = Event.giveDomainFields(); break; 416 case "sample": domainFields = Sample.giveDomainFields(); break; 417 case "assay": domainFields = Assay.giveDomainFields(); break; 418 case "samplingevent": domainFields = SamplingEvent.giveDomainFields(); break; 419 } 420 421 domainFields.each { field -> 422 def criterionType = field.type?.casedName; 423 424 def fieldName = field.name; 425 426 if( ( objectToSearchIn.toLowerCase() == "subject" && fieldName.toLowerCase() == "species" ) || 427 ( objectToSearchIn.toLowerCase() == "sample" && fieldName.toLowerCase() == "material" ) || 428 ( objectToSearchIn.toLowerCase() == "assay" && fieldName.toLowerCase() == "module" ) || 429 ( objectToSearchIn.toLowerCase() == "samplingevent" && fieldName.toLowerCase() == "sampletemplate" ) ) { 430 fieldName += ".name" 431 } 432 433 // Search in template name 434 def condition = extendWhereClause( "( %s )", objectToSearchIn + "." + fieldName, prefix, criterionType, castValue( criterionType ) ); 435 whereClause += condition[ "where" ]; 436 437 condition[ "parameters" ].each { 438 parameters[ it.key ] = it.value; 439 } 440 } 441 442 // Also search in template name 443 def condition = extendWhereClause( "( %s )", objectToSearchIn + ".template.name", prefix, "String", castValue( "String" ) ); 444 whereClause += condition[ "where" ]; 445 446 condition[ "parameters" ].each { 447 parameters[ it.key ] = it.value; 448 } 449 450 return [ "where": whereClause, "parameters": parameters] 392 451 } 393 452
Note: See TracChangeset
for help on using the changeset viewer.