source: MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/proxy/RepoProxy.java @ 1623

Last change on this file since 1623 was 1623, checked in by gaba, 13 years ago

query params

File size: 4.2 KB
Line 
1package eu.clarin.cmdi.mdservice.proxy;
2
3import java.io.IOException;
4import java.io.InputStream;
5import java.net.MalformedURLException;
6import java.net.URL;
7import java.util.Map;
8
9import org.apache.log4j.Logger;
10
11import eu.clarin.cmdi.mdservice.action.GenericAction;
12import eu.clarin.cmdi.mdservice.internal.CQLParseException;
13import eu.clarin.cmdi.mdservice.internal.NoStylesheetException;
14import eu.clarin.cmdi.mdservice.model.Diagnostic;
15import eu.clarin.cmdi.mdservice.model.Query;
16import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
17
18/**
19 * Base class for implementation of proxies to target systems.
20 * This is now (after rework 2011-09) decoupled from the called Action.
21 *
22 * Defines the methods used for retrieving the data
23 * and provides basic implementation where possible.
24 *
25 * In contrast to base class BasicProxy RepoProxy tries to get the base_uri from WorkspaceProfile (based on the repository-parameter)
26 * 
27 * @author vronk
28 *
29 */
30public class RepoProxy extends BasicProxy{
31
32        private static final long serialVersionUID = 1L;
33        private static Logger log = Logger.getLogger("RepoProxy");
34 
35        private String proxy_key = "repo";
36               
37        // should perhaps be RepoAction, but it gets complicated with the types
38        private GenericAction source_action;
39       
40        private Query query;
41       
42       
43       
44        public GenericAction getSourceAction() {
45                        return source_action;
46        }
47       
48/*      public RepoAction getSourceAction() {
49                return source_action;
50}*/
51       
52        @Override
53        public void setSourceAction(GenericAction action) {             
54                source_action = action;
55               
56        }
57       
58        /**
59         * Convenience function to access the request-parameters in the Action 
60         * @param key
61         * @return
62         */
63        /* This is already defined in BasicProxy! ?
64         public String getParam(String key) {
65         
66                return getSourceAction().getParam(key);
67        }
68        */
69       
70       
71        public void checkParams() {
72                // required Params
73                // check and set defaults
74                if (WorkspaceProfile.getRepositoryPath(getParam("repository")) == null) {
75                        getSourceAction().getDiagnostics().Add(Diagnostic.UNSUPPORTED_PARAMETERVALUE, "repository");
76                }
77                if (getParam("repository")=="") {
78                        getSourceAction().getDiagnostics().Add(Diagnostic.MANDATORY_NOTSUPPLIED, "repository");
79                }
80        }
81       
82       
83        /**
84         * identification of the target-proxy (type)
85         * base for finding the right base_url in the props
86         * subclass has to override with its specific proxykey
87         * @return
88         */
89        public String getProxyKey() {                           
90                        return proxy_key;               
91        }
92
93        /**
94         * Override of the basic method provided by the super-class:
95         * Read the repository-uri from the WorkspaceProfile based on the repository-parameter
96         */
97               
98        public String getBaseURI() {           
99                String uri = WorkspaceProfile.getRepositoryPath(getSourceAction().getRepository());             
100                return uri;
101        }
102
103        /**
104         * Provides the base-URL specific to given target repository or registry
105         * @return
106         * @throws MalformedURLException
107         */     
108        public URL getBaseURL() throws MalformedURLException {         
109                URL base_url = new URL(getBaseURI());           
110                return base_url;
111        }
112       
113       
114        public InputStream getSourceStream() throws IOException, NoStylesheetException, CQLParseException {
115                return getTargetRequest().openStream();         
116        }
117 
118         public String fullQueryString(){
119                String  full_query_string= "TODO: construct fullQueryString";
120               
121                /* matej 20110903
122                 *  String full_query_string= this.getQ();
123                       
124                if (!getSquery().equals("") && !this.getQ().equals("")){
125                                full_query_string = "(" + this.getSquery() + " ) and (" + this.getQ() + ")";
126                        } else if (!this.getSquery().equals("")) {
127                                full_query_string = this.getSquery();
128                        } else if (!this.getQ().equals("")){
129                                full_query_string = this.getQ();
130                        } else {
131                                full_query_string = "";
132                        }
133                */
134                return full_query_string;
135         }
136         
137
138        /**
139         * uses base_url + url_pattern (parametrized by actionkey) to form a url
140         * @return the full target-request URL to be sent to the target repository
141         * @throws CQLParseException
142         * @throws Exception
143         */     
144        public URL getTargetRequest() throws IOException, CQLParseException {
145                 
146               
147                //URL targetURL =new URL( getBaseURL(), urls.get(getActionkey()) + query.toURLParam() );
148                URL targetURL =getBaseURL();
149               
150                log.debug("getTargetRequest().targetURL:" + targetURL);
151            return targetURL;
152               
153        }
154
155        public void setQuery(Query query) {
156                this.query = query;
157        }
158
159        public Query getQuery() {
160                return query;
161        }
162
163       
164
165}       
Note: See TracBrowser for help on using the repository browser.