source: MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/AdminAction.java @ 1273

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

query indices
VCR first version

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