Revision 6635b6cf
Added by Cherian Mathew about 11 years ago
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/ManagementController.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 2 |
/** |
3 |
* Copyright (C) 2007 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
3 |
* Copyright (C) 2007 EDIT
|
|
4 |
* European Distributed Institute of Taxonomy
|
|
5 |
* http://www.e-taxonomy.eu
|
|
6 |
*
|
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms.
|
|
9 |
*/
|
|
10 | 10 |
package eu.etaxonomy.cdm.remote.controller; |
11 | 11 |
|
12 | 12 |
import java.util.Map; |
... | ... | |
18 | 18 |
import org.apache.log4j.Logger; |
19 | 19 |
import org.springframework.beans.factory.annotation.Autowired; |
20 | 20 |
import org.springframework.stereotype.Controller; |
21 |
import org.springframework.web.bind.WebDataBinder; |
|
22 |
import org.springframework.web.bind.annotation.InitBinder; |
|
21 | 23 |
import org.springframework.web.bind.annotation.RequestMapping; |
22 | 24 |
import org.springframework.web.bind.annotation.RequestMethod; |
23 | 25 |
import org.springframework.web.bind.annotation.RequestParam; |
... | ... | |
26 | 28 |
import eu.etaxonomy.cdm.api.service.search.ICdmMassIndexer; |
27 | 29 |
import eu.etaxonomy.cdm.database.DataSourceInfo; |
28 | 30 |
import eu.etaxonomy.cdm.database.DataSourceReloader; |
31 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
29 | 32 |
import eu.etaxonomy.cdm.remote.controller.util.ProgressMonitorUtil; |
33 |
import eu.etaxonomy.cdm.remote.dto.common.ErrorResponse; |
|
34 |
import eu.etaxonomy.cdm.remote.editor.CdmTypePropertyEditor; |
|
30 | 35 |
|
31 | 36 |
@Controller |
32 |
@RequestMapping(value = {"/manage"}) |
|
33 |
public class ManagementController |
|
34 |
{ |
|
35 |
public static final Logger logger = Logger.getLogger(ManagementController.class); |
|
36 |
|
|
37 |
// @Autowired |
|
38 |
private DataSourceReloader datasoucrceLoader; |
|
39 |
|
|
40 |
@Autowired |
|
41 |
public ICdmMassIndexer indexer; |
|
42 |
|
|
43 |
@Autowired |
|
44 |
public ProgressMonitorController progressMonitorController; |
|
45 |
|
|
46 |
|
|
47 |
/** |
|
48 |
* There should only be one processes operating on the lucene index |
|
49 |
* therefore the according progress monitor uuid is stored in |
|
50 |
* this static field. |
|
51 |
*/ |
|
52 |
private static UUID indexMonitorUuid = null; |
|
53 |
|
|
54 |
/* |
|
55 |
* return page not found http error (404) for unknown or incorrect UUIDs |
|
56 |
* (non-Javadoc) |
|
57 |
* @see org.springframework.web.servlet.mvc.AbstractController#handleRequestInternal(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) |
|
58 |
*/ |
|
59 |
//@RequestMapping(value = { "/manager/datasources/list" }, method = RequestMethod.GET) |
|
60 |
protected ModelAndView doList(HttpServletRequest request, HttpServletResponse respone) throws Exception { |
|
61 |
|
|
62 |
ModelAndView mv = new ModelAndView(); |
|
63 |
Map<String, DataSourceInfo> dataSourceInfos = datasoucrceLoader.test(); |
|
64 |
mv.addObject(dataSourceInfos); |
|
65 |
|
|
66 |
return mv; |
|
67 |
} |
|
68 |
|
|
69 |
//@RequestMapping(value = { "/manager/datasources/reload" }, method = RequestMethod.GET) |
|
70 |
public ModelAndView doReload(HttpServletRequest request, HttpServletResponse respone) throws Exception { |
|
71 |
|
|
72 |
ModelAndView mv = new ModelAndView(); |
|
73 |
Map<String, DataSourceInfo> dataSourceInfos = datasoucrceLoader.reload(); |
|
74 |
mv.addObject(dataSourceInfos); |
|
75 |
|
|
76 |
return mv; |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* |
|
81 |
* Reindex all cdm entities listed in {@link ICdmMassIndexer#indexedClasses()}. |
|
82 |
* Re-indexing will not purge the index. |
|
83 |
* @param frontendBaseUrl if the CDM server is running behind a reverse proxy you need |
|
84 |
* to supply the base URL of web service front-end which is |
|
85 |
* provided by the proxy server. |
|
86 |
* @param request |
|
87 |
* @param respone |
|
88 |
* @return |
|
89 |
* @throws Exception |
|
90 |
*/ |
|
91 |
@RequestMapping(value = { "reindex" }, method = RequestMethod.GET) |
|
92 |
public ModelAndView doReindex( |
|
93 |
@RequestParam(value = "frontendBaseUrl", required = false) String frontendBaseUrl, |
|
94 |
@RequestParam(value = "priority", required = false) Integer priority, |
|
95 |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
|
96 |
|
|
97 |
|
|
98 |
String processLabel = "Re-indexing"; |
|
99 |
ProgressMonitorUtil progressUtil = new ProgressMonitorUtil(progressMonitorController); |
|
100 |
|
|
101 |
if(!progressMonitorController.isMonitorRunning(indexMonitorUuid)) { |
|
102 |
indexMonitorUuid = progressUtil.registerNewMonitor(); |
|
103 |
Thread subThread = new Thread(){ |
|
104 |
@Override |
|
105 |
public void run(){ |
|
106 |
indexer.reindex(progressMonitorController.getMonitor(indexMonitorUuid)); |
|
107 |
} |
|
108 |
}; |
|
109 |
if(priority == null) { |
|
110 |
priority = AbstractController.DEFAULT_BATCH_THREAD_PRIORITY; |
|
111 |
} |
|
112 |
subThread.setPriority(priority); |
|
113 |
subThread.start(); |
|
114 |
} |
|
115 |
// send redirect "see other" |
|
116 |
return progressUtil.respondWithMonitor(frontendBaseUrl, request, response, processLabel, indexMonitorUuid); |
|
117 |
} |
|
118 |
|
|
119 |
/** |
|
120 |
* |
|
121 |
* Create dictionaries for all cdm entities listed in {@link ICdmMassIndexer#dictionaryClasses()}. |
|
122 |
* Re-dicting will not purge the dictionaries. |
|
123 |
* @param frontendBaseUrl if the CDM server is running behind a reverse proxy you need |
|
124 |
* to supply the base URL of web service front-end which is |
|
125 |
* provided by the proxy server. |
|
126 |
* @param request |
|
127 |
* @param respone |
|
128 |
* @return |
|
129 |
* @throws Exception |
|
130 |
*/ |
|
131 |
@RequestMapping(value = { "redict" }, method = RequestMethod.GET) |
|
132 |
public ModelAndView doRedict( |
|
133 |
@RequestParam(value = "frontendBaseUrl", required = false) String frontendBaseUrl, |
|
134 |
@RequestParam(value = "priority", required = false) Integer priority, |
|
135 |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
|
136 |
|
|
137 |
|
|
138 |
String processLabel = "Re-Dicting"; |
|
139 |
ProgressMonitorUtil progressUtil = new ProgressMonitorUtil(progressMonitorController); |
|
140 |
|
|
141 |
if(!progressMonitorController.isMonitorRunning(indexMonitorUuid)) { |
|
142 |
indexMonitorUuid = progressUtil.registerNewMonitor(); |
|
143 |
Thread subThread = new Thread(){ |
|
144 |
@Override |
|
145 |
public void run(){ |
|
146 |
indexer.createDictionary(progressMonitorController.getMonitor(indexMonitorUuid)); |
|
147 |
} |
|
148 |
}; |
|
149 |
if(priority == null) { |
|
150 |
priority = AbstractController.DEFAULT_BATCH_THREAD_PRIORITY; |
|
151 |
} |
|
152 |
subThread.setPriority(priority); |
|
153 |
subThread.start(); |
|
154 |
} |
|
155 |
// send redirect "see other" |
|
156 |
return progressUtil.respondWithMonitor(frontendBaseUrl, request, response, processLabel, indexMonitorUuid); |
|
157 |
} |
|
158 |
|
|
159 |
/** |
|
160 |
* This will wipe out the index. |
|
161 |
* |
|
162 |
* @param request |
|
163 |
* @param respone |
|
164 |
* @return |
|
165 |
* @throws Exception |
|
166 |
*/ |
|
167 |
@RequestMapping(value = { "purge" }, method = RequestMethod.GET) |
|
168 |
public ModelAndView doPurge( |
|
169 |
@RequestParam(value = "frontendBaseUrl", required = false) String frontendBaseUrl, |
|
170 |
@RequestParam(value = "priority", required = false) Integer priority, |
|
171 |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
|
172 |
|
|
173 |
|
|
174 |
String processLabel = "Purging"; |
|
175 |
|
|
176 |
ProgressMonitorUtil progressUtil = new ProgressMonitorUtil(progressMonitorController); |
|
177 |
|
|
178 |
if(!progressMonitorController.isMonitorRunning(indexMonitorUuid)) { |
|
179 |
indexMonitorUuid = progressUtil.registerNewMonitor(); |
|
180 |
Thread subThread = new Thread(){ |
|
181 |
@Override |
|
182 |
public void run(){ |
|
183 |
indexer.purge(progressMonitorController.getMonitor(indexMonitorUuid)); |
|
184 |
} |
|
185 |
}; |
|
186 |
if(priority == null) { |
|
187 |
priority = AbstractController.DEFAULT_BATCH_THREAD_PRIORITY; |
|
188 |
} |
|
189 |
subThread.setPriority(priority); |
|
190 |
subThread.start(); |
|
191 |
} |
|
192 |
|
|
193 |
// send redirect "see other" |
|
194 |
return progressUtil.respondWithMonitor(frontendBaseUrl, request, response, processLabel, indexMonitorUuid); |
|
195 |
} |
|
37 |
@RequestMapping(value = { "/manage" }) |
|
38 |
public class ManagementController { |
|
39 |
public static final Logger logger = Logger |
|
40 |
.getLogger(ManagementController.class); |
|
41 |
|
|
42 |
// @Autowired |
|
43 |
private DataSourceReloader datasoucrceLoader; |
|
44 |
|
|
45 |
@Autowired |
|
46 |
public ICdmMassIndexer indexer; |
|
47 |
|
|
48 |
@Autowired |
|
49 |
public ProgressMonitorController progressMonitorController; |
|
50 |
|
|
51 |
/** |
|
52 |
* There should only be one processes operating on the lucene index |
|
53 |
* therefore the according progress monitor uuid is stored in this static |
|
54 |
* field. |
|
55 |
*/ |
|
56 |
private static UUID indexMonitorUuid = null; |
|
57 |
|
|
58 |
@InitBinder |
|
59 |
public void initIndexClassBinder(WebDataBinder binder) { |
|
60 |
binder.registerCustomEditor(Class.class, new CdmTypePropertyEditor()); |
|
61 |
} |
|
62 |
|
|
63 |
@InitBinder |
|
64 |
public void initIndexArrayBinder(WebDataBinder binder) { |
|
65 |
binder.registerCustomEditor(Class[].class, new CdmTypePropertyEditor()); |
|
66 |
} |
|
67 |
|
|
68 |
/* |
|
69 |
* return page not found http error (404) for unknown or incorrect UUIDs |
|
70 |
* (non-Javadoc) |
|
71 |
* |
|
72 |
* @see |
|
73 |
* org.springframework.web.servlet.mvc.AbstractController#handleRequestInternal |
|
74 |
* (javax.servlet.http.HttpServletRequest, |
|
75 |
* javax.servlet.http.HttpServletResponse) |
|
76 |
*/ |
|
77 |
// @RequestMapping(value = { "/manager/datasources/list" }, method = |
|
78 |
// RequestMethod.GET) |
|
79 |
protected ModelAndView doList(HttpServletRequest request, |
|
80 |
HttpServletResponse respone) throws Exception { |
|
81 |
|
|
82 |
ModelAndView mv = new ModelAndView(); |
|
83 |
Map<String, DataSourceInfo> dataSourceInfos = datasoucrceLoader.test(); |
|
84 |
mv.addObject(dataSourceInfos); |
|
85 |
|
|
86 |
return mv; |
|
87 |
} |
|
88 |
|
|
89 |
// @RequestMapping(value = { "/manager/datasources/reload" }, method = |
|
90 |
// RequestMethod.GET) |
|
91 |
public ModelAndView doReload(HttpServletRequest request, |
|
92 |
HttpServletResponse respone) throws Exception { |
|
93 |
|
|
94 |
ModelAndView mv = new ModelAndView(); |
|
95 |
Map<String, DataSourceInfo> dataSourceInfos = datasoucrceLoader |
|
96 |
.reload(); |
|
97 |
mv.addObject(dataSourceInfos); |
|
98 |
|
|
99 |
return mv; |
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* |
|
104 |
* Reindex all cdm entities listed in |
|
105 |
* {@link ICdmMassIndexer#indexedClasses()}. Re-indexing will not purge the |
|
106 |
* index. |
|
107 |
* |
|
108 |
* @param frontendBaseUrl |
|
109 |
* if the CDM server is running behind a reverse proxy you need |
|
110 |
* to supply the base URL of web service front-end which is |
|
111 |
* provided by the proxy server. |
|
112 |
* @param request |
|
113 |
* @param respone |
|
114 |
* @return |
|
115 |
* @throws Exception |
|
116 |
*/ |
|
117 |
@RequestMapping(value = { "reindex" }, method = RequestMethod.GET) |
|
118 |
public ModelAndView doReindex( |
|
119 |
@RequestParam(value = "frontendBaseUrl", required = false) String frontendBaseUrl, |
|
120 |
@RequestParam(value = "type", required = true) Class<? extends CdmBase>[] types, |
|
121 |
@RequestParam(value = "priority", required = false) Integer priority, |
|
122 |
HttpServletRequest request, HttpServletResponse response) |
|
123 |
throws Exception { |
|
124 |
|
|
125 |
indexer.clearIndexedClasses(); |
|
126 |
for (Class<? extends CdmBase> type : types) { |
|
127 |
if(type != null) { |
|
128 |
indexer.addToIndexedClasses(type); |
|
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
String processLabel = "Re-indexing"; |
|
133 |
ProgressMonitorUtil progressUtil = new ProgressMonitorUtil( |
|
134 |
progressMonitorController); |
|
135 |
|
|
136 |
if (!progressMonitorController.isMonitorRunning(indexMonitorUuid)) { |
|
137 |
indexMonitorUuid = progressUtil.registerNewMonitor(); |
|
138 |
Thread subThread = new Thread() { |
|
139 |
@Override |
|
140 |
public void run() { |
|
141 |
indexer.reindex(progressMonitorController |
|
142 |
.getMonitor(indexMonitorUuid)); |
|
143 |
} |
|
144 |
}; |
|
145 |
if (priority == null) { |
|
146 |
priority = AbstractController.DEFAULT_BATCH_THREAD_PRIORITY; |
|
147 |
} |
|
148 |
subThread.setPriority(priority); |
|
149 |
subThread.start(); |
|
150 |
} |
|
151 |
// send redirect "see other" |
|
152 |
return progressUtil.respondWithMonitor(frontendBaseUrl, request, |
|
153 |
response, processLabel, indexMonitorUuid); |
|
154 |
} |
|
155 |
|
|
156 |
/** |
|
157 |
* |
|
158 |
* Create dictionaries for all cdm entities listed in |
|
159 |
* {@link ICdmMassIndexer#dictionaryClasses()}. Re-dicting will not purge |
|
160 |
* the dictionaries. |
|
161 |
* |
|
162 |
* @param frontendBaseUrl |
|
163 |
* if the CDM server is running behind a reverse proxy you need |
|
164 |
* to supply the base URL of web service front-end which is |
|
165 |
* provided by the proxy server. |
|
166 |
* @param request |
|
167 |
* @param respone |
|
168 |
* @return |
|
169 |
* @throws Exception |
|
170 |
*/ |
|
171 |
@RequestMapping(value = { "redict" }, method = RequestMethod.GET) |
|
172 |
public ModelAndView doRedict( |
|
173 |
@RequestParam(value = "frontendBaseUrl", required = false) String frontendBaseUrl, |
|
174 |
@RequestParam(value = "priority", required = false) Integer priority, |
|
175 |
HttpServletRequest request, HttpServletResponse response) |
|
176 |
throws Exception { |
|
177 |
|
|
178 |
String processLabel = "Re-Dicting"; |
|
179 |
ProgressMonitorUtil progressUtil = new ProgressMonitorUtil( |
|
180 |
progressMonitorController); |
|
181 |
|
|
182 |
if (!progressMonitorController.isMonitorRunning(indexMonitorUuid)) { |
|
183 |
indexMonitorUuid = progressUtil.registerNewMonitor(); |
|
184 |
Thread subThread = new Thread() { |
|
185 |
@Override |
|
186 |
public void run() { |
|
187 |
indexer.createDictionary(progressMonitorController |
|
188 |
.getMonitor(indexMonitorUuid)); |
|
189 |
} |
|
190 |
}; |
|
191 |
if (priority == null) { |
|
192 |
priority = AbstractController.DEFAULT_BATCH_THREAD_PRIORITY; |
|
193 |
} |
|
194 |
subThread.setPriority(priority); |
|
195 |
subThread.start(); |
|
196 |
} |
|
197 |
// send redirect "see other" |
|
198 |
return progressUtil.respondWithMonitor(frontendBaseUrl, request, |
|
199 |
response, processLabel, indexMonitorUuid); |
|
200 |
} |
|
201 |
|
|
202 |
/** |
|
203 |
* This will wipe out the index. |
|
204 |
* |
|
205 |
* @param request |
|
206 |
* @param respone |
|
207 |
* @return |
|
208 |
* @throws Exception |
|
209 |
*/ |
|
210 |
@RequestMapping(value = { "purge" }, method = RequestMethod.GET) |
|
211 |
public ModelAndView doPurge( |
|
212 |
@RequestParam(value = "frontendBaseUrl", required = false) String frontendBaseUrl, |
|
213 |
@RequestParam(value = "priority", required = false) Integer priority, |
|
214 |
HttpServletRequest request, HttpServletResponse response) |
|
215 |
throws Exception { |
|
216 |
|
|
217 |
String processLabel = "Purging"; |
|
218 |
|
|
219 |
ProgressMonitorUtil progressUtil = new ProgressMonitorUtil( |
|
220 |
progressMonitorController); |
|
221 |
|
|
222 |
if (!progressMonitorController.isMonitorRunning(indexMonitorUuid)) { |
|
223 |
indexMonitorUuid = progressUtil.registerNewMonitor(); |
|
224 |
Thread subThread = new Thread() { |
|
225 |
@Override |
|
226 |
public void run() { |
|
227 |
indexer.purge(progressMonitorController |
|
228 |
.getMonitor(indexMonitorUuid)); |
|
229 |
} |
|
230 |
}; |
|
231 |
if (priority == null) { |
|
232 |
priority = AbstractController.DEFAULT_BATCH_THREAD_PRIORITY; |
|
233 |
} |
|
234 |
subThread.setPriority(priority); |
|
235 |
subThread.start(); |
|
236 |
} |
|
237 |
|
|
238 |
// send redirect "see other" |
|
239 |
return progressUtil.respondWithMonitor(frontendBaseUrl, request, |
|
240 |
response, processLabel, indexMonitorUuid); |
|
241 |
} |
|
242 |
|
|
243 |
|
|
196 | 244 |
|
197 | 245 |
} |
198 |
|
Also available in: Unified diff
ManagementController : updated reindex method to include multi-param 'type' which allows to choose the classes to be indexed,
also added init binder methods to bind the 'type' string input to cdmbase classes
CdmTypePropertyEditor : corrected fully qualified name creation for the 'eu.etaxonomy.cdm.model.name' package