source: MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/RepoAction.java @ 1918

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

autocomplete - explain.xml

File size: 4.5 KB
Line 
1package eu.clarin.cmdi.mdservice.action;
2
3import java.net.URL;
4import java.util.HashMap;
5
6import org.apache.log4j.Logger;
7
8import eu.clarin.cmdi.mdservice.internal.Cache;
9import eu.clarin.cmdi.mdservice.model.Diagnostic;
10import eu.clarin.cmdi.mdservice.model.Query;
11import eu.clarin.cmdi.mdservice.model.Repositories;
12import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
13import eu.clarin.cmdi.mdservice.proxy.FCSProxy;
14import eu.clarin.cmdi.mdservice.proxy.MDRepoProxy;
15import eu.clarin.cmdi.mdservice.proxy.Pz2Proxy;
16import eu.clarin.cmdi.mdservice.proxy.SRUProxy;
17
18/**
19 * A Struts2 controller, responsible for calls to repositories.
20 * After 2011-09 rework Action and Proxy are decoupled.
21 * So Action calls appropriate Proxy based upon the target repository type
22 *
23 * responds to requests (collections, model, recordset)
24 * by dispatching the requests to appropriate Proxy and filling the inputStream with the result
25 * It is possible to switch target-repository dynamically  (on every request). I.e. the client explicitly selects one of the repositories.
26 *
27 * 
28 * @author vronk
29 */
30public class RepoAction extends GenericAction
31{
32
33        private static final long serialVersionUID = 1L;
34        private static Logger log = Logger.getLogger("RepoAction");
35       
36        protected URL base_url ;
37        //Query query;
38       
39        @Override
40        public String getFullFormat() {         
41                return getActionkey() + "2" + getFormat();
42        }
43
44        /*
45        @Override
46        protected void setDefaultParams() {     
47               
48               
49                // set defaults
50                /*
51                if ( params.get("version") == null){
52                        addParam("version","1.2");
53                }
54                if ( params.get("operation") == null){
55                        addParam("operation","searchRetrieve");
56                }
57                //q=query                       
58                if (getQ() != null) {
59                        addParam("q",getQ());
60                        addParam("query",getQ());
61                } else {
62                        addParam("q",this.getParam("query"));
63                }
64               
65                if ( params.get("startRecord") == null){
66                        addParam("startRecord","1");
67                }
68                if ( params.get("maximumRecords") == null){
69                        addParam("maximumRecords","50");
70                }
71               
72                if ( params.get("x-cmd-maxdepth") == null){
73                        if (params.get("maxdepth") == null){
74                                addParam("maxdepth","2");
75                        }
76                } else {
77                        addParam("maxdepth",params.get("x-cmd-maxdepth")[0]);
78                }
79               
80                if ( params.get("x-cmd-repository") == null){
81                        if (params.get("repository") == null){
82                                addParam("repository",WorkspaceProfile.getRepositoryByIndex(0));
83                        }
84                } else {
85                        addParam("repository",params.get("x-cmd-repository")[0]);
86                }
87               
88                if ( params.get("x-cmd-cache") == null){
89                        if (params.get("cache") == null){
90                                addParam("cache",Cache.SKIP);
91                        }
92                } else {
93                        addParam("cache",params.get("x-cmd-cache")[0]);
94                }
95               
96                if ( params.get("x-cmd-lang") == null){
97                        if (params.get("lang") == null){
98                                addParam("lang","en");
99                        }
100                } else {
101                        addParam("lang",params.get("x-cmd-lang")[0]);
102                }
103               
104                if ( params.get("x-cmd-format") == null){
105                        if (params.get("format") == null){
106                                if (this.format == null) {
107                                        addParam("format","xml");
108                                } else if (this.format.equals("")){
109                                        addParam("format","xml");
110                                } else {
111                                        addParam("format",this.format);
112                                }
113                        }
114                } else {
115                        addParam("format",params.get("x-cmd-format")[0]);
116                }
117
118                addParam("fullformat",getFullFormat());
119               
120        }
121*/
122        /**
123         * Based on the repository type - we create a typed Proxy, that will do the work.
124         * If the type is not recognized - that is a bad user error   
125         */
126        public void setTargetProxy(){
127                                               
128                        if (getRepository()==null) {
129                                getDiagnostics().Add(Diagnostic.MANDATORY_NOTSUPPLIED, "repository", "");
130                                return;
131                        }
132                       
133                        if (!Repositories.getRepositories().repositoryExists(getRepository())){
134                                getDiagnostics().Add(Diagnostic.UNSUPPORTED_PARAMETERVALUE, "repository", "repository=" + getRepository() );                                   
135                                return;
136                        }
137
138                        //Query query = new Query();
139                        switch (Repositories.RepositoryType.toRepositoryType(Repositories.getRepositories().getRepositoryType(getRepository())))
140                        {               
141                            case PAZPAR: 
142                                setTargetProxy(new Pz2Proxy(new Query(getActionkey(), this.getParams())));
143                                return;
144                            case SRU:
145                                setTargetProxy(new SRUProxy(new Query(Query.SRURECORDSET, this.getParams())));
146                                return;
147                            case FCS:
148                                setTargetProxy(new FCSProxy(new Query(Query.FCSRECORDSET, this.getParams())));
149                                return;
150                            case MD:
151                                setTargetProxy(new MDRepoProxy(new Query(getActionkey(), this.getParams())));
152                                return;
153                            default:
154                                //TODO error  = bad workspaceProfile configuration
155                                getDiagnostics().Add(Diagnostic.SYSTEM_ERROR, "Error in workspaceprofile configuration", "repository=" + getRepository() );
156                        }
157        }
158
159}
Note: See TracBrowser for help on using the repository browser.