- Timestamp:
- Dec 9, 2010, 9:12:10 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/domain/dbnp/studycapturing/Template.groovy
r1027 r1257 123 123 124 124 /** 125 * Check whether the contents of the other template and the current template are equal. 126 * For this check the name, description and owner don't matter. Also, the order of 127 * template fields doesn't matter 128 * 129 * @return true iff this template and the other template are used for the same entity and 130 * the template contain the same template fields 131 */ 132 public boolean contentEquals( Template otherTemplate ) { 133 if( otherTemplate == this ) 134 return true 135 136 if( otherTemplate == null ) 137 return false 138 139 if( otherTemplate.entity != this.entity ) 140 return false 141 142 // Check all template fields 143 if( otherTemplate.fields?.size() != this.fields?.size() ) 144 return false 145 146 if( otherTemplate.fields != null && this.fields != null ) { 147 for( def field in this.fields ) { 148 def fieldFound = false; 149 for( def otherField in otherTemplate.fields ) { 150 if( otherField.contentEquals( field ) ) { 151 fieldFound = true; 152 break 153 } 154 } 155 156 if( !fieldFound ) { 157 return false 158 } 159 } 160 } 161 162 // If all tests pass, the objects are content-equal 163 return true 164 } 165 166 /** 125 167 * Look up the type of a certain template subject field 126 168 * @param String fieldName The name of the template field … … 210 252 return results 211 253 } 254 255 /** 256 * Create a new template based on the parsed XML object. 257 * 258 * @see grails.converters.XML#parse(java.lang.String) 259 * @throws IllegalArgumentException 260 * @throws ClassNotFoundException 261 * 262 */ 263 public static parse(Object xmlObject, SecUser loggedInUser) { 264 def t = new Template(); 265 t.name = xmlObject?.name?.text() 266 t.description = xmlObject?.description?.text() 267 268 // Check whether a correct entity is given. The parseEntity method might 269 // throw a ClassNotFoundException, but that is OK, it should be thrown if the class 270 // doesn't exist. 271 def entity = TemplateEntity.parseEntity( xmlObject.entity?.text() ); 272 if( !entity ) { 273 throw new Exception( "Incorrect entity given" ); 274 } 275 276 t.entity = entity 277 278 // Set the owner to the currently logged in user 279 t.owner = loggedInUser 280 281 // Set all template fields 282 xmlObject.templateFields.templateField.each { 283 def field = TemplateField.parse( it, entity ); 284 285 // Check whether a similar field already exists. For that, we search in all 286 // template fields with the same name, in order to have as little comparisons 287 // as possible 288 for( def otherField in TemplateField.findAllByName( field.name ) ) { 289 if( field.contentEquals( otherField ) ) { 290 field = otherField; 291 break; 292 } 293 } 294 295 t.addToFields( field ); 296 } 297 298 return t 299 } 212 300 }
Note: See TracChangeset
for help on using the changeset viewer.