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

Last change on this file since 1613 was 1613, checked in by vronk, 13 years ago

various small changes, clean up code

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