Changeset 515
- Timestamp:
- Jun 3, 2010, 9:48:33 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/RestController.groovy
r480 r515 1 1 /** 2 * RestController Controler2 * ModuleCommunicationController Controler 3 3 * 4 * Description this is for testing the dbNP.rest.CCMCommunicationManager only and should be removed, 5 * once the CCMCommunicationManager works with an exteneral server (nbx5)!!!! 4 * This controler provides a REST service. 5 * The names of the RESET resources are the same as the names of this 6 * controller's actions. E.g., the resources called getStudies simply 7 * corresponds to the action getStudies. Some of the resources are parameterized. 8 * The parameters are passed as parameters in the url and are available in the 9 * params respecting Grails' conventions. In this file, we adher to the javadoc 10 * convention for describing parameters ("@param"), but actually we mean 11 * key-value pairs in the params object of each Grails action we comment on. 6 12 * 7 * This class renders two REST related requests (features and get_json). 8 * 9 * @author Jahn 10 * @since 20100526 13 * @author Jahn 14 * @since 20100601 11 15 * 12 16 */ 13 17 14 import grails.converters.JSON 18 import data.* 19 import dbnp.studycapturing.Study 20 import dbnp.studycapturing.Assay 21 import grails.converters.* 15 22 import org.codehaus.groovy.grails.web.json.* 16 import dbnp.studycapturing.TemplateFieldListItem 17 import dbnp.studycapturing.Template 18 import dbnp.rest.CCMCommunicationManager 23 19 24 20 25 … … 22 27 23 28 24 /** 25 * result of querying the Clinical Chemistry Module 26 * if assay in the database : return the Clinical Assay 27 * else : return the list of all Assays in the database 28 * @return Clinical Assay 29 */ 30 def features = { 31 //def items = TemplateFieldListItem.list() 32 def items = Template.list() 33 items.each{ render (it as JSON) } 34 render params 35 } 29 /* REST resources for Simple Assay Module (SAM) */ 36 30 37 31 38 /* Use a REST resource to get data using the CCMCommunicationManager */ 39 def get_json = { 40 def json_result = new CCMCommunicationManager().getFeatures() 41 json_result.each { render "Value : ${it}\n"} 42 } 32 /** 33 * REST resource for the Simple Assay Module. 34 * Provide a list of all studies. 35 * 36 * 37 * Examlpe call of the getAssays REST resource: http://localhost:8080/gscf/rest/getAssays/json?externalStudyID=1 38 * 39 * @return as JSON object list of members externalStudyID, and title for all studies 40 */ 41 def getStudies = { 42 List studies = [] 43 Study.list().each { study -> 44 studies.push( [ 'externalStudyID': study.externalStudyID, 'name':study.title ] ) 45 } 46 render studies as JSON 47 } 48 49 50 /** 51 * REST resource for the Simple Assay Module. 52 * Provide a list of all assays for a given study 53 * 54 * Example for calling this resource: http://localhost:8080/gscf/rest/getAssays/json?externalStudyID=2 55 * 56 * @param externalStudyID 57 * @return list of assays as JSON object 58 */ 59 def getAssays = { 60 List assays = [] 61 if( params.externalStudyID ) { 62 def id = Long.parseLong(params.externalStudyID) 63 def study = Study.find( "from Study as s where s.externalStudyID=?", [id]) 64 study.assays.each{ assay -> assays.push assay.externalAssayID } 65 } 66 render assays as JSON 67 } 68 69 70 /** 71 * REST resource for the Simple Assay Module. 72 * Provide all samples of a given Assay. The result is an enriched list with additional informatin on a sample. 73 * 74 * Example for calling this resource: http://localhost:8080/gscf/rest/getAssays/json?externalStudyID=2 75 * 76 * @param assayID (externalAssayID of some Assay in GSCF) 77 * @return list of element of Sample.name x Sample.material x Sample.subject.name x Sample.Event.name x Sample.Event.time 78 */ 79 def getSamples = { 80 def items = [] 81 if( params.externalAssayID ) { 82 def id = Long.parseLong(params.externalAssayID) 83 Assay.find( "from Assay as a where externalAssayID=?",[id]).getSamples().each { sample -> 84 def item = [ 85 'name' : sample.name, 86 'material' : sample.material.name, 87 'subject' : sample.parentSubject.name, 88 //'event' : sample.parentEvent.name, // get the freaking name 89 'startTime' : sample.parentEvent.startTime 90 ] 91 items.push item 92 } 93 } 94 render items as JSON 95 } 43 96 44 97 } -
trunk/src/groovy/dbnp/rest/CCMCommunicationManager.groovy
r491 r515 11 11 12 12 13 14 /** CCMCommunicationManager 15 * 16 * This class implements a REST client to fetch data from the Clinical Chemistry Module (CCM). 17 * The communicatino manager provides methods for accessing each resources. 18 * Every REST resource corresponds to exactly one method in this class that makes 19 * the communication with the resource available. 20 * 21 * For instance, the getSearchable() method calls the getMeasurements resource of the CCM 22 * by passing arguments to it and returning the result of the calling that resource. 23 */ 24 25 13 26 class CCMCommunicationManager implements CleanDataLayer { 14 27 28 29 /** ServerULR contains a string that represents the URL of the 30 * rest resources that this communication manager connects to. 31 */ 32 def static ServerURL = "http://nbx5.nugo.org:8182/ClinicalChemistry/rest"; 15 33 //def static ServerURL = "http://localhost:8080/gscf/rest"; 16 def static ServerURL = "http://nbx5.nugo.org:8182/ClinicalChemistry/rest";17 34 18 35 … … 43 60 44 61 45 46 47 48 62 /** 49 63 * Testing REST. Remove when connection to nbx5 is established. … … 52 66 */ 53 67 public Object getFeatures() { 54 def url = new URL( ServerURL + "/features" )55 return JSON.parse(url.newReader())68 // return request( "features" ) 69 return getStudiesForKeyword("ldl") 56 70 } 57 71 58 72 59 73 /** 60 * Testing REST. Remove when connection to nbx5 is established. 74 * For a string for the searchable plugin. 75 * This works for one keyeword, but protection should be built in using 76 * the methods that searchable uses for building query strings. 61 77 * 62 78 * @return list of ClinicalFloatData 63 79 */ 64 80 private String getSearchable( keyword ) { 65 return "submit=Query&q=" + keyword81 return "?submit=Query&q=" + keyword 66 82 } 67 83 68 84 69 85 /** 70 * Testing REST. Remove when connection to nbx5 is established.86 * Get all meassurements that contain a given keyword as feature. 71 87 * 88 * @param keyword, the keyword used 72 89 * @return list of ClinicalFloatData 73 90 */ 74 91 public String getStudiesForKeyword( String keyword ) { 92 def resource = "getMeasurementsForValue" 93 request( resource + getSearchable(keyword) ) 75 94 } 76 95 77 96 97 /** 98 * Get all meassurements that contain a given keyword as feature. 99 * 100 * @param keyword, the keyword used 101 * @return list of ClinicalFloatData 102 */ 78 103 public Object getMeasurementsResource( String keyword ) { 79 104 def url = new URL( ServerURL + "/" + getSearchable(keyword) ) … … 94 119 95 120 121 122 123 124 96 125 /** Send a request for the REST resource to the server and deliver the 97 * resulting JSON object. 126 * resulting JSON object. (This is just a convenience method.) 98 127 * 99 128 * @param resource: the name of the resource including parameters 100 129 * @return JSON object 101 130 */ 102 private Object reques Service( String resource ) {131 private Object request( String resource ) { 103 132 def url = new URL( ServerURL + "/" + resource ); 104 133 return JSON.parse( url.newReader() ); 105 134 } 106 135 136 137 138 139 107 140 }
Note: See TracChangeset
for help on using the changeset viewer.