source: MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/FCSAction.java @ 1866

Last change on this file since 1866 was 1866, checked in by gaba, 12 years ago

explain.xml in fcs

File size: 6.6 KB
Line 
1package eu.clarin.cmdi.mdservice.action;
2
3import java.io.BufferedReader;
4import java.io.ByteArrayInputStream;
5import java.io.File;
6import java.io.IOException;
7import java.io.InputStream;
8import java.io.InputStreamReader;
9import java.io.StringWriter;
10import java.io.UnsupportedEncodingException;
11import java.net.MalformedURLException;
12import java.net.URL;
13import java.util.HashMap;
14import java.util.Map;
15
16import javax.xml.parsers.ParserConfigurationException;
17import javax.xml.transform.TransformerConfigurationException;
18import javax.xml.transform.TransformerException;
19import javax.xml.transform.TransformerFactory;
20import javax.xml.transform.TransformerFactoryConfigurationError;
21import javax.xml.transform.dom.DOMSource;
22import javax.xml.transform.stream.StreamResult;
23
24import org.w3c.dom.Document;
25import org.w3c.dom.Node;
26
27import eu.clarin.cmdi.mdservice.internal.CQLParseException;
28import eu.clarin.cmdi.mdservice.internal.Cache;
29import eu.clarin.cmdi.mdservice.internal.NoStylesheetException;
30import eu.clarin.cmdi.mdservice.internal.Utils;
31import eu.clarin.cmdi.mdservice.model.Diagnostic;
32import eu.clarin.cmdi.mdservice.model.FCSRepositories;
33import eu.clarin.cmdi.mdservice.model.Query;
34import eu.clarin.cmdi.mdservice.model.Repositories;
35import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
36import eu.clarin.cmdi.mdservice.proxy.FCSProxy;
37import eu.clarin.cmdi.mdservice.proxy.LocalProxy;
38import eu.clarin.cmdi.mdservice.proxy.MDRepoProxy;
39import eu.clarin.cmdi.mdservice.proxy.Pz2Proxy;
40import eu.clarin.cmdi.mdservice.proxy.SRUProxy;
41import eu.clarin.cmdi.mdservice.proxy.WorkspaceProxy;
42
43
44
45
46public class FCSAction extends SRUAction
47{
48
49        private static final long serialVersionUID = 1L;
50       
51        /**
52         * Properties to be filled by Struts with according request-parameters
53         */     
54       
55        private String x_content;
56        private Map<String,String[]> fcsparams;
57       
58        private static int OP_SEARCHRETRIEVE = 1;
59        private static int OP_EXPLAIN = 2;
60        private static int OP_SCAN = 3;
61       
62       
63        //TODO cache after analysis ?
64        /*
65        @Override
66        public String getCache() {
67                return Cache.SKIP;
68        }
69        */
70       
71        @Override
72        public String getRepository() {
73                if (!getParam("x-context").equals("")){
74                        if (FCSRepositories.getFCSRepositories().getFCSMapping(params.get("x-context")[0]) == null){
75                                                return getParam("x-context");
76                                        } else {
77                                                return FCSRepositories.getFCSRepositories().getFCSMapping(params.get("x-context")[0]);
78                                        }
79                }
80                return getParam("x-context");
81
82        }
83
84         
85        /**
86         * primitive identification of the target-proxy
87         * base for finding the right base_url in the props
88         * subclass has to override with its specific proxykey
89         * @return
90         */
91        public String getProxyKey() {
92                return "";
93        }
94
95        @Override
96        public String getFullFormat() { 
97                //TODO how to get around ??
98                if (getActionkey().equals("static")){
99                        return getActionkey() +  "2" + getFormat(); 
100                }
101                return getActionkey() + getOperation() + "2" + getFormat();
102        }
103       
104        public void addFCSParam(String key, String value){
105                String[] sarr = new String[1];
106                sarr[0] = value;
107                fcsparams.put(key, sarr);       
108        }
109        public Map<String, String[]> getFCSParams(){
110                if (fcsparams == null){
111
112                        fcsparams = new HashMap<String, String[]>();
113                       
114                        if ( params.get("operation") != null){
115                                addFCSParam("operation",params.get("operation")[0]);
116                        }
117                        if ( params.get("scanClause") != null){
118                                addFCSParam("scanClause",params.get("scanClause")[0]);
119                        }
120                        if ( params.get("query") != null){
121                                addFCSParam("query",params.get("query")[0]);
122                        }
123                        if ( !this.getParam("x-context").equals("")){
124                                if (FCSRepositories.getFCSRepositories().getFCSMapping(params.get("x-context")[0]) != null){
125                                        addFCSParam("x-context",params.get("x-context")[0]);
126                                }
127                               
128                        }
129               
130                }
131               
132                return fcsparams;
133               
134        }
135       
136        @Override
137        public String getFormat() {
138                if (getParams().get("x-format") == null){
139                                return "xml";
140                }
141                return getParam("x-format");
142               
143        }
144       
145        @Override
146        protected void setDefaultParams(){
147                // set defaults
148               
149                if ((getParam("operation").equals("")) && (getParam("query").equals(""))){
150                        addParam("operation","explain");
151                }
152                if ( (getParam("operation").equals("explain")) && (getParam("query").equals(""))){
153                        addParam("q", "explain");
154                        //TODO how to get around ?
155                        this.setActionkey("static");
156                }
157                        if (params.get("x-context") != null){
158                               
159                                // not for scan operation , search in fcs-mapping
160                                if (!params.get("operation")[0].equals("scan")){
161                                        if (FCSRepositories.getFCSRepositories().getFCSMapping(params.get("x-context")[0]) == null){
162                                                addParam("repository",params.get("x-context")[0]);
163                                        } else {
164                                                addParam("repository",FCSRepositories.getFCSRepositories().getFCSMapping(params.get("x-context")[0]));
165                                        }
166                                }
167                        }       
168
169                addParam("fullformat",getFullFormat());
170               
171                if (params.get("scripts_url") == null){
172                        addParam("scripts_url",Utils.getConfig("webscripts.uri"));
173                }
174               
175                if (params.get("base_url") == null){
176                        addParam("base_url",Utils.getConfig("base.uri"));
177                }
178                if (params.get("cache") == null){
179                        addParam("cache",Cache.USE);
180                } 
181               
182                if ((getRepository().equals("")) && (getParam("operation").equals("scan"))){
183                        addParam("part","repositories");
184                        addParam("extradata","fcs.resource");
185                }
186        }
187       
188        @Override
189        public boolean checkTargetProxy(){
190                return false;
191        }
192       
193        @Override
194        public void checkParams(){
195                if (getTargetProxy() != null){
196                        getTargetProxy().checkParams(); 
197                }
198        }
199        @Override
200        public String getUserName(){
201               
202                return WorkspaceProfile.SERVER;
203        }
204        @Override
205        public void setTargetProxy(){
206               
207                //Query query = new Query();
208                //TODO case scan,explain
209               
210                if (getRepository().equals("")){
211                        if ((getParam("operation").equals("scan")) && (getParam("scanClause").equals("fcs.resource"))){
212                                setTargetProxy(new WorkspaceProxy());
213                        return;
214                        }
215                        if (getParam("operation").equals("explain")){
216                                setTargetProxy(new LocalProxy());
217                        return;
218                        }
219               
220                }
221               
222                switch (Repositories.RepositoryType.toRepositoryType(Repositories.getRepositories().getRepositoryType(getRepository())))
223                {               
224                    case PAZPAR: 
225                        setTargetProxy(new Pz2Proxy(new Query(getActionkey(), this.getParams())));
226                        return;
227                    case SRU:
228                        setTargetProxy(new SRUProxy(new Query(Query.SRUEXTERN,getParams())));
229                        return;
230                    case MD:
231                        setTargetProxy(new MDRepoProxy(new Query(Query.RECORDSET,getParams())));
232                        return; 
233                    case FCS:
234                        setTargetProxy(new FCSProxy(new Query(Query.FCSRECORDSET,getFCSParams())));
235                        return;
236                    case FCSRESOURCE:
237                        setTargetProxy(new FCSProxy(new Query(Query.FCSRECORDSET,getFCSParams())));
238                        return;
239                    default:
240                        //TODO error  = bad workspaceProfile configuration
241                        getDiagnostics().Add(Diagnostic.SYSTEM_ERROR, "Error in workspaceprofile configuration", "repository=" + getRepository() );
242                }
243}
244}
Note: See TracBrowser for help on using the repository browser.