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

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

cache changes

File size: 6.0 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.MDRepoProxy;
38import eu.clarin.cmdi.mdservice.proxy.Pz2Proxy;
39import eu.clarin.cmdi.mdservice.proxy.SRUProxy;
40import eu.clarin.cmdi.mdservice.proxy.WorkspaceProxy;
41
42
43
44
45public class FCSAction extends SRUAction
46{
47
48        private static final long serialVersionUID = 1L;
49       
50        /**
51         * Properties to be filled by Struts with according request-parameters
52         */     
53       
54        private String x_content;
55        private Map<String,String[]> fcsparams;
56       
57        private static int OP_SEARCHRETRIEVE = 1;
58        private static int OP_EXPLAIN = 2;
59        private static int OP_SCAN = 3;
60       
61       
62        //TODO cache after analysis ?
63        /*
64        @Override
65        public String getCache() {
66                return Cache.SKIP;
67        }
68        */
69       
70        @Override
71        public String getRepository() {
72                if (!getParam("x-context").equals("")){
73                        if (FCSRepositories.getFCSRepositories().getFCSMapping(params.get("x-context")[0]) == null){
74                                                return getParam("x-context");
75                                        } else {
76                                                return FCSRepositories.getFCSRepositories().getFCSMapping(params.get("x-context")[0]);
77                                        }
78                }
79                return getParam("x-context");
80
81        }
82
83         
84        /**
85         * primitive identification of the target-proxy
86         * base for finding the right base_url in the props
87         * subclass has to override with its specific proxykey
88         * @return
89         */
90        public String getProxyKey() {
91                return "";
92        }
93
94        @Override
95        public String getFullFormat() {         
96                return getActionkey() + getOperation() + "2" + getFormat();
97        }
98       
99        public void addFCSParam(String key, String value){
100                String[] sarr = new String[1];
101                sarr[0] = value;
102                fcsparams.put(key, sarr);       
103        }
104        public Map<String, String[]> getFCSParams(){
105                if (fcsparams == null){
106
107                        fcsparams = new HashMap<String, String[]>();
108                       
109                        if ( params.get("operation") != null){
110                                addFCSParam("operation",params.get("operation")[0]);
111                        }
112                        if ( params.get("scanClause") != null){
113                                addFCSParam("scanClause",params.get("scanClause")[0]);
114                        }
115                        if ( params.get("query") != null){
116                                addFCSParam("query",params.get("query")[0]);
117                        }
118                        if ( !this.getParam("x-context").equals("")){
119                                if (FCSRepositories.getFCSRepositories().getFCSMapping(params.get("x-context")[0]) != null){
120                                        addFCSParam("x-context",params.get("x-context")[0]);
121                                }
122                               
123                        }
124               
125                }
126               
127                return fcsparams;
128               
129        }
130       
131        @Override
132        public String getFormat() {
133                if (getParams().get("x-format") == null){
134                                return "xml";
135                }
136                return getParam("x-format");
137               
138        }
139       
140        @Override
141        protected void setDefaultParams(){
142                // set defaults
143               
144                        if (params.get("x-context") != null){
145                               
146                                // not for scan operation , search in fcs-mapping
147                                if (!params.get("operation")[0].equals("scan")){
148                                        if (FCSRepositories.getFCSRepositories().getFCSMapping(params.get("x-context")[0]) == null){
149                                                addParam("repository",params.get("x-context")[0]);
150                                        } else {
151                                                addParam("repository",FCSRepositories.getFCSRepositories().getFCSMapping(params.get("x-context")[0]));
152                                        }
153                                }
154                        }       
155
156                addParam("fullformat",getFullFormat());
157               
158                if (params.get("scripts_url") == null){
159                        addParam("scripts_url",Utils.getConfig("webscripts.uri"));
160                }
161               
162                if (params.get("base_url") == null){
163                        addParam("base_url",Utils.getConfig("base.uri"));
164                }
165                if (params.get("cache") == null){
166                        addParam("cache",Cache.USE);
167                } 
168               
169                if ((getRepository().equals("")) && (getParam("operation").equals("scan"))){
170                        addParam("part","repositories");
171                        addParam("extradata","fcs.resource");
172                }
173        }
174       
175        @Override
176        public boolean checkTargetProxy(){
177                return false;
178        }
179       
180        @Override
181        public void checkParams(){
182                if (getTargetProxy() != null){
183                        getTargetProxy().checkParams(); 
184                }
185        }
186        @Override
187        public String getUserName(){
188               
189                return WorkspaceProfile.SERVER;
190        }
191        @Override
192        public void setTargetProxy(){
193               
194                //Query query = new Query();
195                //TODO case scan,explain
196               
197                if ((getRepository().equals("")) && (getParam("operation").equals("scan"))){
198                        setTargetProxy(new WorkspaceProxy());
199                return;
200                }
201               
202                switch (Repositories.RepositoryType.toRepositoryType(Repositories.getRepositories().getRepositoryType(getRepository())))
203                {               
204                    case PAZPAR: 
205                        setTargetProxy(new Pz2Proxy(new Query(getActionkey(), this.getParams())));
206                        return;
207                    case SRU:
208                        setTargetProxy(new SRUProxy(new Query(Query.SRUEXTERN,getParams())));
209                        return;
210                    case MD:
211                        setTargetProxy(new MDRepoProxy(new Query(Query.RECORDSET,getParams())));
212                        return; 
213                    case FCS:
214                        setTargetProxy(new FCSProxy(new Query(Query.FCSRECORDSET,getFCSParams())));
215                        return;
216                    case FCSRESOURCE:
217                        setTargetProxy(new FCSProxy(new Query(Query.FCSRECORDSET,getFCSParams())));
218                        return;
219                    default:
220                        //TODO error  = bad workspaceProfile configuration
221                        getDiagnostics().Add(Diagnostic.SYSTEM_ERROR, "Error in workspaceprofile configuration", "repository=" + getRepository() );
222                }
223}
224}
Note: See TracBrowser for help on using the repository browser.