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

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

query params

File size: 2.4 KB
Line 
1package eu.clarin.cmdi.mdservice.action;
2
3import java.net.URL;
4
5import org.apache.log4j.Logger;
6import eu.clarin.cmdi.mdservice.model.Diagnostic;
7import eu.clarin.cmdi.mdservice.model.Query;
8import eu.clarin.cmdi.mdservice.model.WorkspaceProfile;
9import eu.clarin.cmdi.mdservice.proxy.MDRepoProxy;
10import eu.clarin.cmdi.mdservice.proxy.Pz2Proxy;
11import eu.clarin.cmdi.mdservice.proxy.SRUProxy;
12
13/**
14 * A Struts2 controller, responsible for calls to repositories.
15 * After 2011-09 rework Action and Proxy are decoupled.
16 * So Action calls appropriate Proxy based upon the target repository type
17 *
18 * responds to requests (collections, model, recordset)
19 * by dispatching the requests to appropriate Proxy and filling the inputStream with the result
20 * It is possible to switch target-repository dynamically  (on every request). I.e. the client explicitly selects one of the repositories.
21 *
22 * 
23 * @author vronk
24 */
25public class RepoAction extends GenericAction
26{
27
28        private static final long serialVersionUID = 1L;
29        private static Logger log = Logger.getLogger("RepoAction");
30       
31        protected URL base_url ;
32        Query query;
33       
34        @Override
35        public String getFullFormat() {         
36                return getActionkey() + "2" + getFormat();
37        }
38
39        @Override
40        @SuppressWarnings("unchecked")
41        protected void loadParams() {   
42                super.loadParams();
43                query = new Query(getActionkey(), this.getParams());
44        }
45        /**
46         * Based on the repository type - we create a typed Proxy, that will do the work.
47         * If the type is not recognized - that is a bad user error   
48         */
49        public void setTargetProxy(){
50                                               
51                        if (getRepository()==null) {
52                                getDiagnostics().Add(Diagnostic.MANDATORY_NOTSUPPLIED, "repository", "");
53                                return;
54                        }
55                       
56                        if (!WorkspaceProfile.repositoryExists(getRepository())){
57                                getDiagnostics().Add(Diagnostic.UNSUPPORTED_PARAMETERVALUE, "repository", "repository=" + getRepository() );
58                                return;
59                        }
60                        //Query query = new Query();
61                        switch (WorkspaceProfile.RepositoryType.toRepositoryType(WorkspaceProfile.getRepositoryType(getRepository())))
62                        {               
63                            case PAZPAR: 
64                                setTargetProxy(new Pz2Proxy());
65                                return;
66                            case SRU:
67                                setTargetProxy(new SRUProxy(query));
68                                return;
69                            case MD:
70                                setTargetProxy(new MDRepoProxy(query));
71                                return;
72                            default:
73                                //TODO error  = bad workspaceProfile configuration
74                                getDiagnostics().Add(Diagnostic.SYSTEM_ERROR, "Error in workspaceprofile configuration", "repository=" + getRepository() );
75                        }
76        }
77
78}
Note: See TracBrowser for help on using the repository browser.