- Timestamp:
- Jun 8, 2010, 11:18:27 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/studycapturing/WizardController.groovy
r535 r539 293 293 flash.errors = [:] 294 294 flash.values = params 295 def speciesTerm = Term.findByName(params.species) ;296 def subjectTemplateName = params.get('template') ;297 def subjectTemplate = Template.findByName(subjectTemplateName) ;295 def speciesTerm = Term.findByName(params.species) 296 def subjectTemplateName = params.get('template') 297 def subjectTemplate = Template.findByName(subjectTemplateName) 298 298 299 299 // add this subject template to the subject template array … … 330 330 331 331 flash.errors = [:] 332 def delete = params.get('do') as int ;332 def delete = params.get('do') as int 333 333 334 334 // remove subject … … 456 456 on("deleteEvent") { 457 457 flash.values = params 458 def delete = params.get('do') as int ;458 def delete = params.get('do') as int 459 459 460 460 // handle event groupings … … 506 506 on("deleteEventGroup") { 507 507 flash.values = params 508 def delete = params.get('do') as int ;508 def delete = params.get('do') as int 509 509 510 510 // handle event groupings … … 589 589 // iterate through events 590 590 flow.events.each() { event -> 591 println "bla"592 591 if (event instanceof SamplingEvent) { 593 //println event.getFieldValue('name')592 println event.template.name 594 593 println event.startTime 595 594 println event.endTime 595 def sampleName = (this.ucwords(subject.value.name) + '_' + this.ucwords(event.template.name) + ((event.startTime) ? '_' + event.startTime : '')).replaceAll("([ ]{1,})", "") 596 //.replaceAll("([^A-Za-z0-9_])", "") 597 println sampleName 596 598 } 597 598 599 } 599 600 } … … 718 719 def handleStudy(flow, flash, params) { 719 720 // create study instance if we have none 720 if (!flow.study) flow.study = new Study() ;721 if (!flow.study) flow.study = new Study() 721 722 722 723 // create date instance from date string? … … 743 744 } 744 745 745 746 747 746 // handle Publications and Contacts 747 handlePublications(flow, flash, params) 748 handleContacts(flow, flash, params) 748 749 749 750 // validate study … … 767 768 def handlePublications(flow, flash, params) { 768 769 // create study instance if we have none 769 if (!flow.study) flow.study = new Study() ;770 if (!flow.study.publications ) flow.study.publications = [];771 772 773 774 775 776 def publicationIDs = params.get( 'publication_ids' ); 777 if( publicationIDs) {778 779 publicationIDs = publicationIDs.split(',').collect { Integer.parseInt( it, 10 ) }; 780 781 782 783 784 785 786 if( !flow.study.publications.find { publication -> id == publication.id }) {787 def publication = Publication.get( id ); 788 if( publication) {789 flow.study.addToPublications( publication ); 790 791 println( 'Publication with ID ' + id + ' not found in database.' ); 792 793 794 795 796 797 println( 'No publications selected.')798 flow.study.publications.clear(); 799 770 if (!flow.study) flow.study = new Study() 771 if (!flow.study.publications) flow.study.publications = [] 772 773 // Check the ids of the pubblications that should be attached 774 // to this study. If they are already attached, keep 'm. If 775 // studies are attached that are not in the selected (i.e. the 776 // user deleted them), remove them 777 def publicationIDs = params.get('publication_ids') 778 if (publicationIDs) { 779 // Find the individual IDs and make integers 780 publicationIDs = publicationIDs.split(',').collect { Integer.parseInt(it, 10) } 781 782 // First remove the publication that are not present in the array 783 flow.study.publications.removeAll { publication -> !publicationIDs.find { id -> id == publication.id } } 784 785 // Add those publications not yet present in the database 786 publicationIDs.each { id -> 787 if (!flow.study.publications.find { publication -> id == publication.id }) { 788 def publication = Publication.get(id) 789 if (publication) { 790 flow.study.addToPublications(publication) 791 } else { 792 println('.publication with ID ' + id + ' not found in database.') 793 } 794 } 795 } 796 797 } else { 798 println('.no publications selected.') 799 flow.study.publications.clear() 800 } 800 801 801 802 } … … 810 811 def handleContacts(flow, flash, params) { 811 812 // create study instance if we have none 812 if (!flow.study) flow.study = new Study(); 813 if (!flow.study.persons ) flow.study.persons = []; 814 815 // Check the ids of the contacts that should be attached 816 // to this study. If they are already attached, keep 'm. If 817 // studies are attached that are not in the selected (i.e. the 818 // user deleted them), remove them 819 820 // Contacts are saved as [person_id]-[role_id] 821 println( params ); 822 def contactIDs = params.get( 'contacts_ids' ); 823 println( contactIDs ); 824 if( contactIDs ) { 825 // Find the individual IDs and make integers 826 contactIDs = contactIDs.split(',').collect { 827 def parts = it.split( '-' ); 828 return [ person: Integer.parseInt( parts[0] ), role: Integer.parseInt( parts[1] ) ]; 829 }; 830 831 // First remove the contacts that are not present in the array 832 flow.study.persons.removeAll { 833 studyperson -> !contactIDs.find { ids -> ( ids.person == studyperson.person.id ) && ( ids.role == studyperson.role.id ) } 834 }; 835 836 // Add those contacts not yet present in the database 837 contactIDs.each { ids -> 838 if( !flow.study.persons.find { studyperson -> ( ids.person == studyperson.person.id ) && ( ids.role == studyperson.role.id ) } ) { 839 def person = Person.get( ids.person ); 840 def role = PersonRole.get( ids.role ); 841 if( person && role ) { 842 // Find a studyperson object with these parameters 843 def studyPerson = StudyPerson.findAll().find { studyperson -> studyperson.person.id == person.id && studyperson.role.id == role.id }; 844 845 // If if does not yet exist, save the example 846 if( !studyPerson ) { 847 studyPerson = new StudyPerson( 848 person: person, 849 role: role 850 ); 851 studyPerson.save( flush: true ); 852 } 853 854 flow.study.addToPersons( studyPerson ); 855 } else { 856 println( 'Person ' + ids.person + ' or Role ' + ids.role + ' not found in database.' ); 857 } 858 } 859 } 860 861 } else { 862 println( 'No persons selected.') 863 flow.study.persons.clear(); 864 } 865 866 } 813 if (!flow.study) flow.study = new Study() 814 if (!flow.study.persons) flow.study.persons = [] 815 816 // Check the ids of the contacts that should be attached 817 // to this study. If they are already attached, keep 'm. If 818 // studies are attached that are not in the selected (i.e. the 819 // user deleted them), remove them 820 821 // Contacts are saved as [person_id]-[role_id] 822 def contactIDs = params.get('contacts_ids') 823 if (contactIDs) { 824 // Find the individual IDs and make integers 825 contactIDs = contactIDs.split(',').collect { 826 def parts = it.split('-') 827 return [person: Integer.parseInt(parts[0]), role: Integer.parseInt(parts[1])] 828 } 829 830 // First remove the contacts that are not present in the array 831 flow.study.persons.removeAll { 832 studyperson -> !contactIDs.find { ids -> (ids.person == studyperson.person.id) && (ids.role == studyperson.role.id) } 833 } 834 835 // Add those contacts not yet present in the database 836 contactIDs.each { ids -> 837 if (!flow.study.persons.find { studyperson -> (ids.person == studyperson.person.id) && (ids.role == studyperson.role.id) }) { 838 def person = Person.get(ids.person) 839 def role = PersonRole.get(ids.role) 840 if (person && role) { 841 // Find a studyperson object with these parameters 842 def studyPerson = StudyPerson.findAll().find { studyperson -> studyperson.person.id == person.id && studyperson.role.id == role.id } 843 844 // If if does not yet exist, save the example 845 if (!studyPerson) { 846 studyPerson = new StudyPerson( 847 person: person, 848 role: role 849 ) 850 studyPerson.save(flush: true) 851 } 852 853 flow.study.addToPersons(studyPerson) 854 } else { 855 println('.person ' + ids.person + ' or Role ' + ids.role + ' not found in database.') 856 } 857 } 858 } 859 } else { 860 println('.no persons selected.') 861 flow.study.persons.clear() 862 } 863 864 } 865 867 866 /** 868 867 * re-usable code for handling subject form data in a web flow … … 914 913 // handle the type of event 915 914 if (params.eventType == 'event') { 916 flow.event = new Event() ;915 flow.event = new Event() 917 916 template = params.remove('eventTemplate') 918 917 } else if (params.eventType == 'sample') { 919 flow.event = new SamplingEvent() ;918 flow.event = new SamplingEvent() 920 919 template = params.remove('sampleTemplate') 921 920 } … … 1014 1013 } 1015 1014 1015 1016 /** 1017 * groovy / java equivalent of php's ucwords function 1018 * 1019 * Capitalize all first letters of seperate words 1020 * 1021 * @param String 1022 * @return String 1023 */ 1024 def ucwords(String text) { 1025 def newText = '' 1026 1027 // change case to lowercase 1028 text = text.toLowerCase() 1029 1030 // iterate through words 1031 text.split(" ").each() { 1032 newText += it[0].toUpperCase() + it.substring(1) + " " 1033 } 1034 1035 return newText.substring(0, newText.size()-1) 1036 } 1037 1016 1038 /** 1017 1039 * return the object from a map of objects by searching for a name … … 1088 1110 def ajaxParseRelTime = { 1089 1111 if (params.reltime == null) { 1090 response.status = 400 ;1091 render('reltime parameter is expected') ;1112 response.status = 400 1113 render('reltime parameter is expected') 1092 1114 } 1093 1115 1094 1116 try { 1095 def reltime = RelTime.parseRelTime(params.reltime) ;1096 render reltime.toPrettyString() ;1117 def reltime = RelTime.parseRelTime(params.reltime) 1118 render reltime.toPrettyString() 1097 1119 } catch (IllegalArgumentException e) { 1098 response.status = 400 ;1099 render(e.getMessage()) ;1120 response.status = 400 1121 render(e.getMessage()) 1100 1122 } 1101 1123 }
Note: See TracChangeset
for help on using the changeset viewer.