1 | package eu.clarin.cmdi.mdservice.action; |
---|
2 | |
---|
3 | import java.net.URL; |
---|
4 | |
---|
5 | import org.apache.log4j.Logger; |
---|
6 | import eu.clarin.cmdi.mdservice.model.Diagnostic; |
---|
7 | import eu.clarin.cmdi.mdservice.model.Query; |
---|
8 | import eu.clarin.cmdi.mdservice.model.WorkspaceProfile; |
---|
9 | import eu.clarin.cmdi.mdservice.proxy.MDRepoProxy; |
---|
10 | import eu.clarin.cmdi.mdservice.proxy.Pz2Proxy; |
---|
11 | import 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 | */ |
---|
25 | public 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 | } |
---|