Changeset 1717
- Timestamp:
- Apr 6, 2011, 5:24:14 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/query/AdvancedQueryController.groovy
r1678 r1717 322 322 def templateFields = TemplateField.findAllByEntity( entity ) 323 323 324 def fieldNames = ( domainFields + templateFields ).collect { it.name }.unique() + 'Template' 325 326 fields[ it ] = fieldNames.sort { a, b -> a[0].toUpperCase() + a[1..-1] <=> b[0].toUpperCase() + b[1..-1] }; 324 def fieldNames = ( domainFields + templateFields ).collect { it.name }.unique() + 'Template' + '*' 325 326 fields[ it ] = fieldNames.sort { a, b -> 327 def aUC = a.size() > 1 ? a[0].toUpperCase() + a[1..-1] : a; 328 def bUC = b.size() > 1 ? b[0].toUpperCase() + b[1..-1] : b; 329 aUC <=> bUC 330 }; 327 331 } 328 332 } … … 346 350 def moduleName = module.name.replace( 'module', '' ).trim() 347 351 348 fields[ moduleName ] = moduleFields.unique() ;352 fields[ moduleName ] = moduleFields.unique() + '*'; 349 353 } catch( Exception e ) { 350 354 log.error( "Error while retrieving queryable fields from " + module.name + ": " + e.getMessage() ) -
trunk/grails-app/views/advancedQuery/_criteria.gsp
r1581 r1717 5 5 <g:each in="${criteria}" var="criterion" status="j"> 6 6 <li> 7 <span class="entityfield">${criterion. entityField().toLowerCase()}</span>7 <span class="entityfield">${criterion.humanReadableEntityField().toLowerCase()}</span> 8 8 <span class="operator">${criterion.operator}</span> 9 9 <span class="value"> -
trunk/grails-app/views/advancedQuery/index.gsp
r1649 r1717 15 15 <g:if test="${j > 0}">,</g:if> 16 16 { 17 label: "${entity.key.toString().encodeAsJavaScript()}.${field.toString().encodeAsJavaScript()} ${entity.key.toString().encodeAsJavaScript()} ${field.toString().encodeAsJavaScript()}", 18 show: "${(field[0].toUpperCase() + field[1..-1]).encodeAsJavaScript()}", 17 label: "${( 18 entity.key.toString() + '.' + field.toString() + ' ' + 19 entity.key.toString() + ' ' + field.toString() + ' ' + 20 (field == '*' ? 'any field' : '') 21 ).encodeAsJavaScript()}", 22 show: "${ 23 (field == '*' ? 24 '[Any field in ' + entity.key.toString() + ']' : 25 (field?.size() > 1 ? 26 field[0].toUpperCase() + field[1..-1] : 27 field) 28 ).encodeAsJavaScript()}", 19 29 value: "${entity.key.toString().encodeAsJavaScript()}.${field.toString().encodeAsJavaScript()}", 20 30 entity: "${entity.key.toString().encodeAsJavaScript()}" … … 78 88 <g:each in="${entity.value}" var="field"> 79 89 <option value="${entity.key}.${field}"> 80 ${field[0].toUpperCase() + field[1..-1]} 90 <g:if test="${field?.size() > 1}"> 91 ${field[0].toUpperCase() + field[1..-1]} 92 </g:if> 93 <g:else> 94 ${field} 95 </g:else> 81 96 </option> 82 97 </g:each> -
trunk/src/groovy/dbnp/query/Criterion.groovy
r1482 r1717 38 38 39 39 /** 40 * Retrieves a human readable description of the combination of the entity and field 41 * @return 42 */ 43 public String humanReadableEntityField() { 44 if( field == '*' ) { 45 return "any field in " + entity.toString(); 46 } else { 47 return entityField(); 48 } 49 } 50 51 /** 40 52 * Retrieves the correct value for this criterion in the given object (with template) 41 53 * … … 54 66 } else if( field == "Template" ) { 55 67 fieldValue = entity.template?.name 68 } else if( field == "*" ) { 69 fieldValue = entity.giveFields().collect{ 70 if( it && it.name ) { 71 Search.prepare( entity.getFieldValue( it.name ), entity.giveFieldType( it.name ) ) 72 } 73 } 56 74 } else { 57 75 fieldValue = Search.prepare( entity.getFieldValue( field ), entity.giveFieldType( field ) ) 58 76 } 59 77 60 78 return fieldValue 61 79 } catch( Exception e ) { … … 73 91 * @return True iff there the entity satisfies the given criterion. 74 92 */ 75 public boolean match Entity( TemplateEntity entity ) {93 public boolean matchOneEntity( TemplateEntity entity ) { 76 94 def fieldValue = this.getFieldValue( entity ); 77 95 … … 163 181 classname = classname[classname.lastIndexOf( '.' ) + 1..-1].toLowerCase(); 164 182 183 def matches = false; 165 184 try { 166 185 switch( classname ) { 167 case "integer": return longCompare( new Long( fieldValue.longValue() ) );168 case "long": return longCompare( fieldValue );169 case "float": return doubleCompare( new Long( fieldValue.doubleValue() ) );170 case "double": return doubleCompare( fieldValue );171 case "boolean": return booleanCompare( fieldValue );172 case "date": return dateCompare( fieldValue);173 case "reltime": return relTimeCompare( fieldValue );186 case "integer": matches = longCompare( new Long( fieldValue.longValue() ) ); break; 187 case "long": matches = longCompare( fieldValue ); break; 188 case "float": matches = doubleCompare( new Long( fieldValue.doubleValue() ) ); break; 189 case "double": matches = doubleCompare( fieldValue ); break; 190 case "boolean": matches = booleanCompare( fieldValue ); break; 191 case "date": matches = dateCompare( fieldValue); break; 192 case "reltime": matches = relTimeCompare( fieldValue ); break; 174 193 case "assaymodule": 175 194 case "template": … … 177 196 case "templatefieldlistitem": 178 197 case "string": 179 default: return compareValues( fieldValue.toString().trim().toLowerCase(), this.operator, value.toString().toLowerCase().trim() );198 default: matches = compareValues( fieldValue.toString().trim().toLowerCase(), this.operator, value.toString().toLowerCase().trim() ); break; 180 199 } 200 201 return matches; 181 202 } catch( Exception e ) { 182 203 log.error e.class.getName() + ": " + e.getMessage(); … … 252 273 longCriterion = new Long( doubleCriterion.longValue() ); 253 274 } catch( Exception e2 ) { 254 log. errore2.class.getName() + ": " + e2.getMessage();275 log.debug "Can't convert value to long for comparison: " + e2.class.getName() + ": " + e2.getMessage(); 255 276 return false; 256 277 } … … 270 291 return compareValues( fieldValue, this.operator, doubleCriterion ); 271 292 } catch( Exception e ) { 272 log. errore.class.getName() + ": " + e.getMessage();293 log.debug "Can't convert value to double for comparison: " + e.class.getName() + ": " + e.getMessage(); 273 294 return false; 274 295 } … … 284 305 protected boolean booleanCompare( Boolean fieldValue ) { 285 306 try { 307 // The comparison should only be performed iff the value 308 // contains 'true' or 'false' (case insensitive) 309 def lowerCaseValue = value.toString().toLowerCase(); 310 if( lowerCaseValue != 'true' && lowerCaseValue != 'false' ) 311 return false; 312 286 313 Boolean booleanCriterion = Boolean.parseBoolean( value ); 287 314 return compareValues( fieldValue, this.operator, booleanCriterion ); 288 315 } catch( Exception e ) { 289 log. errore.class.getName() + ": " + e.getMessage();316 log.debug "Can't convert value to boolean for comparison: " + e.class.getName() + ": " + e.getMessage(); 290 317 return false; 291 318 } … … 311 338 return compareValues( fieldValue, this.operator, rt ); 312 339 } catch( Exception e ) { 313 log. errore.class.getName() + ": " + e.getMessage();340 log.debug "Can't convert value to reltime for comparison: " + e.class.getName() + ": " + e.getMessage(); 314 341 return false; 315 342 } -
trunk/src/groovy/dbnp/query/SampleSearch.groovy
r1526 r1717 232 232 return false 233 233 234 return criterion.match Entity( assay );234 return criterion.matchOneEntity( assay ); 235 235 }); 236 236 -
trunk/src/groovy/dbnp/query/Search.groovy
r1596 r1717 303 303 case TemplateFieldType.DATE: 304 304 try { 305 return new SimpleDateFormat( "yyyy-MM-dd" ).parse( value )305 return new SimpleDateFormat( "yyyy-MM-dd" ).parse( value.toString() ) 306 306 } catch( Exception e ) { 307 307 return value.toString(); … … 580 580 // JSON object 581 581 def token = entity.giveUUID() 582 if( !json[ token ] || json[ token ][ criterion.field ] == null ) 583 return false; 584 585 // Check whether a list or string is given 586 def value = json[ token ][ criterion.field ]; 587 588 // Save the value of this entity for later use 589 saveResultField( entity.id, criterion.entity + " " + criterion.field, value ) 590 591 if( !( value instanceof Collection ) ) { 592 value = [ value ]; 582 def value 583 584 if( criterion.field == '*' ) { 585 // Collect the values from all fields 586 value = []; 587 json[ token ].each { field -> 588 if( field.value instanceof Collection ) { 589 field.value.each { value << it } 590 } else { 591 value << field.value; 592 } 593 } 594 } else { 595 if( !json[ token ] || json[ token ][ criterion.field ] == null ) 596 return false; 597 598 // Check whether a list or string is given 599 value = json[ token ][ criterion.field ]; 600 601 // Save the value of this entity for later use 602 saveResultField( entity.id, criterion.entity + " " + criterion.field, value ) 603 604 if( !( value instanceof Collection ) ) { 605 value = [ value ]; 606 } 593 607 } 594 608 … … 626 640 def callUrl = 'entity=' + this.entity 627 641 tokens.sort().each { callUrl += "&tokens=" + it.encodeAsURL() } 628 fields.sort().each { callUrl += "&fields=" + it.encodeAsURL() } 642 643 // If all fields are searched, all fields should be retrieved 644 if( fields.contains( '*' ) ) { 645 646 } else { 647 fields.sort().each { callUrl += "&fields=" + it.encodeAsURL() } 648 } 629 649 630 650 return callUrl; … … 647 667 648 668 criteria.each { criterion -> 649 if( criterion.field ) {669 if( criterion.field && criterion.field != '*' ) { 650 670 def valueCallback = valueCallback( criterion.entity ); 651 671 … … 672 692 for( criterion in criteria ) { 673 693 for( entity in entities ) { 674 if( criterion.field )694 if( criterion.field && criterion.field != '*' ) 675 695 saveResultField( entity.id, criterion.entity + ' ' + criterion.field, valueCallback( entity, criterion ) ) 676 696 } … … 692 712 if( value == null ) 693 713 value = ""; 694 714 715 if( fieldName == "*" ) 716 return; 717 695 718 if( value instanceof Collection ) { 696 719 value = value.findAll { it != null } 697 720 } 698 721 699 722 resultFields[ id ][ fieldName ] = value; 700 723 } -
trunk/web-app/css/default_style.css
r1704 r1717 8 8 9 9 .container { margin: 0 auto; text-align: left; } 10 .ui-widget { text-align: left; } 10 11 11 12 /*a:link, a:visited, a:hover {
Note: See TracChangeset
for help on using the changeset viewer.