1 | package eu.clarin.cmdi.mdservice.proxy; |
---|
2 | |
---|
3 | import java.io.IOException; |
---|
4 | import java.net.URL; |
---|
5 | |
---|
6 | import org.apache.log4j.Logger; |
---|
7 | |
---|
8 | import eu.clarin.cmdi.mdservice.internal.CQLParseException; |
---|
9 | import eu.clarin.cmdi.mdservice.model.Diagnostic; |
---|
10 | import eu.clarin.cmdi.mdservice.model.Query; |
---|
11 | import eu.clarin.cmdi.mdservice.model.Repositories; |
---|
12 | import eu.clarin.cmdi.mdservice.model.WorkspaceProfile; |
---|
13 | |
---|
14 | |
---|
15 | public class SRUProxy extends RepoProxy |
---|
16 | { |
---|
17 | |
---|
18 | private static final long serialVersionUID = 1L; |
---|
19 | |
---|
20 | private String proxy_key = "sru"; |
---|
21 | private static Logger log = Logger.getLogger("SRUProxy"); |
---|
22 | |
---|
23 | public SRUProxy(Query q) { |
---|
24 | super(q); |
---|
25 | // TODO Auto-generated constructor stub |
---|
26 | } |
---|
27 | |
---|
28 | @Override |
---|
29 | public String getProxyKey() { |
---|
30 | return proxy_key; |
---|
31 | } |
---|
32 | |
---|
33 | @Override |
---|
34 | public void checkParams() { |
---|
35 | // required Params |
---|
36 | // check and set defaults |
---|
37 | if (getParam("operation").equals("")) { |
---|
38 | //getSourceAction().setParam("operation","searchRetrieve"); |
---|
39 | getSourceAction().getDiagnostics().Add(Diagnostic.MANDATORY_NOTSUPPLIED, "operation"); |
---|
40 | } |
---|
41 | if (getParam("version").equals("")) { |
---|
42 | //getSourceAction().setParam("version","1.2"); |
---|
43 | getSourceAction().getDiagnostics().Add(Diagnostic.MANDATORY_NOTSUPPLIED, "version"); |
---|
44 | } |
---|
45 | if (getParam("query").equals("") && getParam("operation").equals("searchRetrieve")) { |
---|
46 | getSourceAction().getDiagnostics().Add(Diagnostic.MANDATORY_NOTSUPPLIED, "query"); |
---|
47 | } |
---|
48 | if (getParam("scanClause").equals("") && getParam("operation").equals("scan")) { |
---|
49 | getSourceAction().getDiagnostics().Add(Diagnostic.MANDATORY_NOTSUPPLIED, "scan"); |
---|
50 | } |
---|
51 | |
---|
52 | |
---|
53 | } |
---|
54 | |
---|
55 | @Override |
---|
56 | public String getBaseURI() { |
---|
57 | log.debug("SRU-repositorypath:" + Repositories.getRepositories().getRepositoryPath(getSourceAction().getRepository())); |
---|
58 | String uri = Repositories.getRepositories().getRepositoryPath(getSourceAction().getRepository());//Utils.getConfig).getProperty(getProxyKey() + ".uri"); |
---|
59 | return uri; |
---|
60 | } |
---|
61 | |
---|
62 | @Override |
---|
63 | public URL getTargetRequest() throws IOException, CQLParseException { |
---|
64 | |
---|
65 | log.debug("SRUP.getQuery:" + getParam("query")); |
---|
66 | log.debug("SRUP.getActionkey:" + getSourceAction().getActionkey()); |
---|
67 | |
---|
68 | // check if the query could get parsed |
---|
69 | if (getQuery().isStatus(Query.PARSEERROR)) { |
---|
70 | log.debug("SRUP.query.PARSEERROR:" + getQuery().getMsg()); |
---|
71 | throw new CQLParseException("SRUP.query.PARSEERROR:" + getQuery().getMsg()); |
---|
72 | } else { |
---|
73 | |
---|
74 | URL targetURL = null; |
---|
75 | URL tmp = getBaseURL(); |
---|
76 | targetURL =new URL( tmp.toExternalForm() + getQuery().toURLParam()); |
---|
77 | |
---|
78 | log.debug("SRUPA.targetURL:" + targetURL); |
---|
79 | |
---|
80 | return targetURL; |
---|
81 | } |
---|
82 | |
---|
83 | } |
---|
84 | } |
---|