3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.remote
.controller
;
13 import java
.util
.UUID
;
15 import javax
.servlet
.http
.HttpServletRequest
;
16 import javax
.servlet
.http
.HttpServletResponse
;
18 import org
.apache
.log4j
.Logger
;
19 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
20 import org
.springframework
.stereotype
.Controller
;
21 import org
.springframework
.web
.bind
.WebDataBinder
;
22 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
23 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
24 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
25 import org
.springframework
.web
.bind
.annotation
.RequestParam
;
26 import org
.springframework
.web
.servlet
.ModelAndView
;
28 import eu
.etaxonomy
.cdm
.api
.service
.search
.ICdmMassIndexer
;
29 import eu
.etaxonomy
.cdm
.database
.DataSourceInfo
;
30 import eu
.etaxonomy
.cdm
.database
.DataSourceReloader
;
31 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
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
;
37 @RequestMapping(value
= { "/manage" })
38 public class ManagementController
{
39 public static final Logger logger
= Logger
40 .getLogger(ManagementController
.class);
43 private DataSourceReloader datasoucrceLoader
;
46 public ICdmMassIndexer indexer
;
49 public ProgressMonitorController progressMonitorController
;
52 * There should only be one processes operating on the lucene index
53 * therefore the according progress monitor uuid is stored in this static
56 private static UUID indexMonitorUuid
= null;
59 public void initIndexClassBinder(WebDataBinder binder
) {
60 binder
.registerCustomEditor(Class
.class, new CdmTypePropertyEditor());
64 public void initIndexArrayBinder(WebDataBinder binder
) {
65 binder
.registerCustomEditor(Class
[].class, new CdmTypePropertyEditor());
69 * return page not found http error (404) for unknown or incorrect UUIDs
73 * org.springframework.web.servlet.mvc.AbstractController#handleRequestInternal
74 * (javax.servlet.http.HttpServletRequest,
75 * javax.servlet.http.HttpServletResponse)
77 // @RequestMapping(value = { "/manager/datasources/list" }, method =
79 protected ModelAndView
doList(HttpServletRequest request
,
80 HttpServletResponse respone
) throws Exception
{
82 ModelAndView mv
= new ModelAndView();
83 Map
<String
, DataSourceInfo
> dataSourceInfos
= datasoucrceLoader
.test();
84 mv
.addObject(dataSourceInfos
);
89 // @RequestMapping(value = { "/manager/datasources/reload" }, method =
91 public ModelAndView
doReload(HttpServletRequest request
,
92 HttpServletResponse respone
) throws Exception
{
94 ModelAndView mv
= new ModelAndView();
95 Map
<String
, DataSourceInfo
> dataSourceInfos
= datasoucrceLoader
97 mv
.addObject(dataSourceInfos
);
104 * Reindex all cdm entities listed in
105 * {@link ICdmMassIndexer#indexedClasses()}. Re-indexing will not purge the
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.
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
)
125 indexer
.clearIndexedClasses();
126 for (Class
<?
extends CdmBase
> type
: types
) {
128 indexer
.addToIndexedClasses(type
);
132 String processLabel
= "Re-indexing";
133 ProgressMonitorUtil progressUtil
= new ProgressMonitorUtil(
134 progressMonitorController
);
136 if (!progressMonitorController
.isMonitorRunning(indexMonitorUuid
)) {
137 indexMonitorUuid
= progressUtil
.registerNewMonitor();
138 Thread subThread
= new Thread() {
141 indexer
.reindex(progressMonitorController
142 .getMonitor(indexMonitorUuid
));
145 if (priority
== null) {
146 priority
= AbstractController
.DEFAULT_BATCH_THREAD_PRIORITY
;
148 subThread
.setPriority(priority
);
151 // send redirect "see other"
152 return progressUtil
.respondWithMonitor(frontendBaseUrl
, request
,
153 response
, processLabel
, indexMonitorUuid
);
158 * Create dictionaries for all cdm entities listed in
159 * {@link ICdmMassIndexer#dictionaryClasses()}. Re-dicting will not purge
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.
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
)
178 String processLabel
= "Re-Dicting";
179 ProgressMonitorUtil progressUtil
= new ProgressMonitorUtil(
180 progressMonitorController
);
182 if (!progressMonitorController
.isMonitorRunning(indexMonitorUuid
)) {
183 indexMonitorUuid
= progressUtil
.registerNewMonitor();
184 Thread subThread
= new Thread() {
187 indexer
.createDictionary(progressMonitorController
188 .getMonitor(indexMonitorUuid
));
191 if (priority
== null) {
192 priority
= AbstractController
.DEFAULT_BATCH_THREAD_PRIORITY
;
194 subThread
.setPriority(priority
);
197 // send redirect "see other"
198 return progressUtil
.respondWithMonitor(frontendBaseUrl
, request
,
199 response
, processLabel
, indexMonitorUuid
);
203 * This will wipe out the index.
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
)
217 String processLabel
= "Purging";
219 ProgressMonitorUtil progressUtil
= new ProgressMonitorUtil(
220 progressMonitorController
);
222 if (!progressMonitorController
.isMonitorRunning(indexMonitorUuid
)) {
223 indexMonitorUuid
= progressUtil
.registerNewMonitor();
224 Thread subThread
= new Thread() {
227 indexer
.purge(progressMonitorController
228 .getMonitor(indexMonitorUuid
));
231 if (priority
== null) {
232 priority
= AbstractController
.DEFAULT_BATCH_THREAD_PRIORITY
;
234 subThread
.setPriority(priority
);
238 // send redirect "see other"
239 return progressUtil
.respondWithMonitor(frontendBaseUrl
, request
,
240 response
, processLabel
, indexMonitorUuid
);