1 | package eu.clarin.cmdi.mdservice.action; |
---|
2 | |
---|
3 | import java.io.ByteArrayInputStream; |
---|
4 | import java.io.IOException; |
---|
5 | import java.net.MalformedURLException; |
---|
6 | import java.net.URL; |
---|
7 | import java.text.DateFormat; |
---|
8 | import java.text.SimpleDateFormat; |
---|
9 | import java.util.Date; |
---|
10 | import java.util.HashMap; |
---|
11 | |
---|
12 | import net.sf.json.JSONObject; |
---|
13 | import net.sf.json.xml.XMLSerializer; |
---|
14 | |
---|
15 | /* |
---|
16 | * import org.jzkit.service.*; |
---|
17 | import org.jzkit.search.provider.iface.Searchable; |
---|
18 | import org.jzkit.search.provider.iface.SearchableFactory; |
---|
19 | */ |
---|
20 | |
---|
21 | /** |
---|
22 | * This is meant for administrative tasks. Currently only action is related to <code>cache</code> viewing and clearing. |
---|
23 | * |
---|
24 | */ |
---|
25 | public class AdminAction extends GenericProxyAction { |
---|
26 | |
---|
27 | private static final long serialVersionUID = 1L; |
---|
28 | |
---|
29 | private String proxy_key = "admin"; |
---|
30 | private String date; |
---|
31 | private String datefrom; |
---|
32 | private String dateto; |
---|
33 | |
---|
34 | @Override |
---|
35 | protected void initialize(){ |
---|
36 | setRepositoryByIndex(0); |
---|
37 | } |
---|
38 | public String getDate() { |
---|
39 | return date; |
---|
40 | } |
---|
41 | |
---|
42 | public void setDate(String date) { |
---|
43 | this.date = date; |
---|
44 | } |
---|
45 | |
---|
46 | public String getDatefrom() { |
---|
47 | return datefrom; |
---|
48 | } |
---|
49 | |
---|
50 | public void setDatefrom(String datefrom) { |
---|
51 | this.datefrom = datefrom; |
---|
52 | } |
---|
53 | |
---|
54 | public String getDateto() { |
---|
55 | return dateto; |
---|
56 | } |
---|
57 | |
---|
58 | public void setDateto(String dateto) { |
---|
59 | this.dateto = dateto; |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | @Override |
---|
64 | public String getFullFormat() { |
---|
65 | return "admin2" + getFormat(); |
---|
66 | } |
---|
67 | |
---|
68 | @Override |
---|
69 | public String getProxyKey() { |
---|
70 | return proxy_key; |
---|
71 | } |
---|
72 | |
---|
73 | public String getBaseURI() { |
---|
74 | String uri = "file:/" + Cache.getCache().getCacheIndexPath(); |
---|
75 | return uri; |
---|
76 | } |
---|
77 | |
---|
78 | public String del() throws Exception { |
---|
79 | |
---|
80 | //String connection_descriptor_string = ""; |
---|
81 | //SearchableFactory sf = app_ctx.getBean("SearchableFactory"); |
---|
82 | //Searchable z3950_target = sf.create(connection_descriptor_string);//create(new IRServiceDescriptor("proto=z3950,addr=www.lcweb.gov:210,code=LC,shortname=\"Library of congress\",longname="\"Library of congress\"")); |
---|
83 | |
---|
84 | //getServletRequest().getRemoteUser() |
---|
85 | if (getServletRequest().getRemoteUser() != null){ |
---|
86 | if ( getServletRequest().getRemoteUser().toLowerCase().equals("admin")){ |
---|
87 | HashMap<String,String> clear_params = new HashMap<String,String>(); |
---|
88 | if (this.getActionkey() != null){ |
---|
89 | clear_params.put("type", getActionkey()); |
---|
90 | } |
---|
91 | if (this.getRepository() != null){ |
---|
92 | clear_params.put("repository", String.valueOf(getRepository())); |
---|
93 | } |
---|
94 | if (this.getDate() != null){ |
---|
95 | clear_params.put("date", getDate()); |
---|
96 | } |
---|
97 | if (this.getDatefrom() != null){ |
---|
98 | clear_params.put("datefrom", getDatefrom()); |
---|
99 | } |
---|
100 | if (this.getDateto() != null){ |
---|
101 | clear_params.put("dateto", getDateto()); |
---|
102 | } |
---|
103 | //int removed; |
---|
104 | this.setResultStream(Cache.getCache().clear(clear_params)); |
---|
105 | |
---|
106 | //String ret = "1"; |
---|
107 | //this.setResultStream( new ByteArrayInputStream(String.valueOf(removed).getBytes())); |
---|
108 | |
---|
109 | return SUCCESS; |
---|
110 | |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | return ERROR; |
---|
115 | |
---|
116 | } |
---|
117 | |
---|
118 | } |
---|