source: trunk/src/groovy/dbnp/rest/CCMCommunicationManager.groovy @ 537

Last change on this file since 537 was 537, checked in by jahn, 10 years ago

Added empty method for providing query results of
a query on Simple Assays to the Query controller.

File size: 4.2 KB
Line 
1package dbnp.rest
2
3import java.util.Map 
4import java.util.List
5import java.util.HashMap
6import grails.converters.JSON
7import org.codehaus.groovy.grails.web.json.*
8import dbnp.studycapturing.TemplateFieldListItem
9import dbnp.studycapturing.Template
10import dbnp.data.CleanDataLayer
11import dbnp.studycapturing.Study 
12
13
14
15
16/**  CCMCommunicationManager
17 *
18 *   This class implements a REST client to fetch data from the Clinical Chemistry Module (CCM).
19 *   The communicatino manager provides methods for accessing each resources.
20 *   Every REST resource corresponds to exactly one method in this class that makes
21 *   the communication with the resource available.
22 *
23 *   For instance, the getSearchable() method calls the getMeasurements resource of the CCM
24 *   by passing arguments to it and returning the result of the calling that resource.
25 */
26
27
28class CCMCommunicationManager implements CleanDataLayer {
29
30   
31    /** ServerULR contains a string that represents the URL of the
32     *  rest resources that this communication manager connects to.
33     */ 
34    def static ServerURL = "http://nbx5.nugo.org:8182/ClinicalChemistry/rest";
35    //def static ServerURL = "http://localhost:8080/gscf/rest";
36
37
38    /* Methods implemented for CleanDataLayer */
39
40
41    /**
42     * Get the names of all quantitative features that are available for a certain assay
43     * @param assayID the module internal ID for the assay
44     * @return
45     */
46    public String[] getFeaturesQuantitative(long assayID) {
47         return new String [20];
48    }
49   
50
51
52    /**
53     * Get the data for a quantitative feature for a certain assay for a certain set of samples
54     * @param feature
55     * @param assayID
56     * @param sampleIDs
57     * @return Map
58     */
59    public Map getDataQuantitative(String feature, long assayID, String[] sampleIDs) {
60         return new HashMap(); 
61    }
62
63
64    /**
65     * Testing REST. Remove when connection to nbx5 is established.
66     *
67     * @return list of ClinicalFloatData
68     */
69    public Object getFeatures() {
70    //    return  request( "features" )
71        return  getStudiesForKeyword("ldl")
72    }
73
74
75    /**
76     * For a string for the searchable plugin.
77     * This works for one keyeword, but protection should be built in using
78     * the methods that searchable uses for building query strings.
79     *
80     * @return list of ClinicalFloatData
81     */
82    private String getSearchable( keyword ) {
83        return  "?submit=Query&q=" + keyword
84    }
85
86
87    /**
88     * Get all meassurements that contain a given keyword as feature.
89     *
90     * @param  keyword, the keyword used
91     * @return list of ClinicalFloatData
92     */
93    public String getStudiesForKeyword( String keyword ) {
94        def resource = "getMeasurementsForValue"
95        request( resource + getSearchable(keyword) )
96    }
97
98
99    /**
100     * Get all meassurements that contain a given keyword as feature.
101     *
102     * @param  keyword, the keyword used
103     * @return list of ClinicalFloatData
104     */
105    public Object getMeasurementsResource( String keyword ) {
106        def url = new URL( ServerURL + "/" + getSearchable(keyword) )
107        return  JSON.parse( url.newReader() )
108    }
109
110
111    public void getMeasurementsForValueResource() {
112    }
113
114
115    public void getMeasurementsForRangeResource() {
116    }
117
118
119    public void getDataSimple() {
120    }
121
122
123
124
125
126
127    /** Send a request for the REST resource to the server and deliver the
128     *  resulting JSON object. (This is just a convenience method.)
129     *
130     *  @param resource: the name of the resource including parameters
131     *  @return JSON object
132     */
133    private Object request( String resource ) { 
134        def url = new URL( ServerURL + "/" + resource );
135        return  JSON.parse( url.newReader() );
136    }
137
138
139
140    /** Send a request for the REST resource to SAM and deliver the
141     *  results for the Query controller.
142     *
143     *  @param  compound        a SAM compound, e.g., "ldl" or "weight"
144     *  @param  value           a SAM value of a measurement, e.g. "20" (without unit, please)
145     *  @param  opperator       a SAM operator, i.e., "=", "<", or ">"
146     *  @return List of matching studies
147     */
148    public List<Study> getSAMStudies( String compound, String value, String opperator ) {
149         return [] 
150    }
151
152
153}
Note: See TracBrowser for help on using the repository browser.