Changeset 224 for trunk/grails-app/domain
- Timestamp:
- Mar 2, 2010, 6:10:52 PM (13 years ago)
- Location:
- trunk/grails-app/domain/dbnp/studycapturing
- Files:
-
- 2 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/domain/dbnp/studycapturing/Sample.groovy
r190 r224 9 9 static searchable = true 10 10 11 // TODO: should Sample also carry a reference to its parent study, 12 // or should this be inferred via the parent SamplingEvent? 11 13 12 14 13 String name // should be unique with respect to the parent study (which can be inferred) 15 14 Term material 16 // don't we need a member that describes the quantity of the sample? 15 // don't we need a member that describes the quantity of the sample? --> should be in the templates 17 16 18 17 static constraints = { -
trunk/grails-app/domain/dbnp/studycapturing/Study.groovy
r212 r224 20 20 Date lastUpdated 21 21 Date startDate 22 Template template23 22 24 23 static hasMany = [ … … 29 28 events: Event, 30 29 samplingEvents: SamplingEvent, 30 samples: Sample, 31 31 assays: Assay, 32 32 persons: StudyPerson, … … 50 50 } 51 51 52 def giveAllFields() {53 return template.studyFields;54 }55 56 def giveSamples() {57 return samplingEvents*.samples;58 }59 52 } -
trunk/grails-app/domain/dbnp/studycapturing/Subject.groovy
r212 r224 13 13 class Subject extends TemplateEntity implements Serializable { 14 14 static searchable = true 15 Template template16 15 String name 17 16 Term species -
trunk/grails-app/domain/dbnp/studycapturing/Template.groovy
r212 r224 12 12 */ 13 13 class Template implements Serializable { 14 14 15 String name 16 Class entity 15 17 //nimble.User owner 16 18 17 static hasMany = [ studyFields: TemplateStudyField, subjectFields: TemplateSubjectField]19 static hasMany = [fields: TemplateField] 18 20 19 21 static constraints = { 20 name(unique: true) 22 name(unique:['entity']) 23 21 24 } 22 25 … … 30 33 * @return The type (static member of TemplateFieldType) of the field, or null of the field does not exist 31 34 */ 32 def TemplateFieldType get SubjectFieldType(String fieldName) {33 def field = subjectFields.find {35 def TemplateFieldType getFieldType(String fieldName) { 36 def field = fields.find { 34 37 it.name == fieldName 35 38 } 36 39 field?.type 37 40 } 41 42 def getFieldsByType(TemplateFieldType fieldType) { 43 def result = fields.findAll { 44 it.type == fieldType 45 } 46 return result; 47 } 38 48 } -
trunk/grails-app/domain/dbnp/studycapturing/TemplateEntity.groovy
r212 r224 2 2 3 3 import dbnp.data.Term 4 import org.codehaus.groovy.runtime.NullObject 4 5 5 6 class TemplateEntity { 6 7 8 Template template 9 7 10 Map templateStringFields 11 Map templateStringListFields 8 12 Map templateIntegerFields 9 13 Map templateFloatFields … … 13 17 14 18 static hasMany = [ 15 templateStringFields: String, // stores both STRING and STRINGLIST items (latter should be checked against the list) 19 templateStringFields: String, 20 templateStringListFields: TemplateFieldListItem, 16 21 templateIntegerFields: int, 17 22 templateFloatFields: float, … … 31 36 */ 32 37 def getFieldValue(String fieldName) { 33 TemplateFieldType fieldType = template.get SubjectFieldType(fieldName)38 TemplateFieldType fieldType = template.getFieldType(fieldName) 34 39 if (!fieldType) throw new NoSuchFieldException("Field name ${fieldName} not recognized") 35 40 switch(fieldType) { 36 41 case [TemplateFieldType.STRING, TemplateFieldType.STRINGLIST]: 37 42 return templateStringFields[fieldName] 43 case [TemplateFieldType.STRINGLIST]: 44 return templateStringListFields[fieldName] 38 45 case TemplateFieldType.INTEGER: 39 46 return templateIntegerFields[fieldName] … … 52 59 53 60 def setFieldValue(String fieldName, value) { 54 this.properties.each { println it}55 61 if (this.properties.containsKey(fieldName)) { 56 62 this[fieldName] = value 57 63 } 58 else if (templateStringFields.containsKey(fieldName) && value.class == String) { 59 this.templateStringFields[fieldName] = value 60 } 61 else if (templateIntegerFields.containsKey(fieldName) && value.class == Integer) { 62 this.templateIntegerFields[fieldName] = value 63 } 64 else if (templateFloatFields.containsKey(fieldName) && value.class == Float) { 65 this.templateFloatFields[fieldName] = value 66 } 67 else if (templateDoubleFields.containsKey(fieldName) && value.class == Double) { 68 this.templateDoubleFields[fieldName] = value 69 } 70 else if (templateDateFields.containsKey(fieldName) && value.class == Date) { 71 this.templateDateFields[fieldName] = value 72 } 73 else if (templateTermFields.containsKey(fieldName) && value.class == Term) { 74 this.templateTermFields[fieldName] = value 64 else 65 if (template == null) { 66 throw new NoSuchFieldException("Field ${fieldName} not found in class properties") 75 67 } 76 68 else { 77 println "Field ${fieldName} not found" 69 if (templateStringFields.containsKey(fieldName) && value.class == String) { 70 this.templateStringFields[fieldName] = value 71 } 72 if (templateStringListFields.containsKey(fieldName) && value.class == TemplateFieldListItem) { 73 this.templateStringFields[fieldName] = value 74 } 75 else if (templateIntegerFields.containsKey(fieldName) && value.class == Integer) { 76 this.templateIntegerFields[fieldName] = value 77 } 78 else if (templateFloatFields.containsKey(fieldName) && value.class == Float) { 79 this.templateFloatFields[fieldName] = value 80 } 81 else if (templateDoubleFields.containsKey(fieldName) && value.class == Double) { 82 this.templateDoubleFields[fieldName] = value 83 } 84 else if (templateDateFields.containsKey(fieldName) && value.class == Date) { 85 this.templateDateFields[fieldName] = value 86 } 87 else if (templateTermFields.containsKey(fieldName) && value.class == Term) { 88 this.templateTermFields[fieldName] = value 89 } 90 else { 91 throw new NoSuchFieldException("Field ${fieldName} not found in class properties or template fields") 92 } 78 93 } 79 94 } 80 95 96 def Set<TemplateField> giveFields() { 97 return this.template.fields; 98 } 99 100 @Override 101 void setTemplate(Template newTemplate) { 102 103 // Contrary to expectation, this method does not cause an infinite loop but calls the super method 104 // whereas super.setTemplate(newTemplate) leads to errors concerning NullObject values 105 this.template = newTemplate 106 107 // TODO: initialize all template fields with the necessary keys and null values 108 109 println "Setting template " + newTemplate 110 /*if (template == null || template instanceof NullObject) {} else{ // negation doesn't seem to work well 111 def stringFields = template.getFieldsByType(TemplateFieldType.STRINGLIST) 112 println stringFields*.name 113 if (stringFields.size() > 0) { 114 templateStringFields = new HashMap<String,String>() 115 templateStringFields.keyset.add stringFields*.name; 116 println templateStringFields 117 } 118 }*/ 119 } 120 81 121 } -
trunk/grails-app/domain/dbnp/studycapturing/TemplateField.groovy
r190 r224 9 9 * $Date$ 10 10 */ 11 abstractclass TemplateField implements Serializable {11 class TemplateField implements Serializable { 12 12 String name 13 13 TemplateFieldType type … … 15 15 16 16 static hasMany = [listEntries : String] // to store the entries to choose from when the type is 'item from predefined list' 17 //TODO: make TemplateFieldListItem and make a convenience setter for a string array 17 18 18 19 static constraints = {
Note: See TracChangeset
for help on using the changeset viewer.