root/trunk/src/groovy/dbnp/rest/CCMCommunicationManager.groovy @ 515

Revision 515, 3.6 KB (checked in by jahn, 4 years ago)

REST resources for communicating with the Simple Assay Module.

Line 
1package dbnp.rest
2
3import java.util.Map;
4import java.util.HashMap;
5import grails.converters.JSON
6import org.codehaus.groovy.grails.web.json.*
7import dbnp.studycapturing.TemplateFieldListItem
8import dbnp.studycapturing.Template
9import dbnp.data.CleanDataLayer
10
11
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
26class CCMCommunicationManager implements CleanDataLayer {
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";
33    //def static ServerURL = "http://localhost:8080/gscf/rest";
34
35
36    /* Methods implemented for CleanDataLayer */
37
38
39    /**
40     * Get the names of all quantitative features that are available for a certain assay
41     * @param assayID the module internal ID for the assay
42     * @return
43     */
44    public String[] getFeaturesQuantitative(long assayID) {
45         return new String [20];
46    }
47   
48
49
50    /**
51     * Get the data for a quantitative feature for a certain assay for a certain set of samples
52     * @param feature
53     * @param assayID
54     * @param sampleIDs
55     * @return Map
56     */
57    public Map getDataQuantitative(String feature, long assayID, String[] sampleIDs) {
58         return new HashMap();
59    }
60
61
62    /**
63     * Testing REST. Remove when connection to nbx5 is established.
64     *
65     * @return list of ClinicalFloatData
66     */
67    public Object getFeatures() {
68    //    return  request( "features" )
69        return  getStudiesForKeyword("ldl")
70    }
71
72
73    /**
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.
77     *
78     * @return list of ClinicalFloatData
79     */
80    private String getSearchable( keyword ) {
81        return  "?submit=Query&q=" + keyword
82    }
83
84
85    /**
86     * Get all meassurements that contain a given keyword as feature.
87     *
88     * @param  keyword, the keyword used
89     * @return list of ClinicalFloatData
90     */
91    public String getStudiesForKeyword( String keyword ) {
92        def resource = "getMeasurementsForValue"
93        request( resource + getSearchable(keyword) )
94    }
95
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     */
103    public Object getMeasurementsResource( String keyword ) {
104        def url = new URL( ServerURL + "/" + getSearchable(keyword) )
105        return  JSON.parse( url.newReader() )
106    }
107
108
109    public void getMeasurementsForValueResource() {
110    }
111
112
113    public void getMeasurementsForRangeResource() {
114    }
115
116
117    public void getDataSimple() {
118    }
119
120
121
122
123
124
125    /** Send a request for the REST resource to the server and deliver the
126     *  resulting JSON object. (This is just a convenience method.)
127     *
128     *  @param resource: the name of the resource including parameters
129     *  @return JSON object
130     */
131    private Object request( String resource ) {
132        def url = new URL( ServerURL + "/" + resource );
133        return  JSON.parse( url.newReader() );
134    }
135
136
137
138
139
140}
Note: See TracBrowser for help on using the browser.