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

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

x-context replaced $repository, fcs/xsl's used

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