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
= false) Class
<?
extends CdmBase
>[] types
,
121 @RequestParam(value
= "priority", required
= false) Integer priority
,
122 HttpServletRequest request
, HttpServletResponse response
)
125 indexer
.clearIndexedClasses();
127 for (Class
<?
extends CdmBase
> type
: types
) {
129 indexer
.addToIndexedClasses(type
);
134 String processLabel
= "Re-indexing";
135 ProgressMonitorUtil progressUtil
= new ProgressMonitorUtil(
136 progressMonitorController
);
138 if (!progressMonitorController
.isMonitorRunning(indexMonitorUuid
)) {
139 indexMonitorUuid
= progressUtil
.registerNewMonitor();
140 Thread subThread
= new Thread() {
143 indexer
.reindex(progressMonitorController
144 .getMonitor(indexMonitorUuid
));
147 if (priority
== null) {
148 priority
= AbstractController
.DEFAULT_BATCH_THREAD_PRIORITY
;
150 subThread
.setPriority(priority
);
153 // send redirect "see other"
154 return progressUtil
.respondWithMonitor(frontendBaseUrl
, request
,
155 response
, processLabel
, indexMonitorUuid
);
160 * Create dictionaries for all cdm entities listed in
161 * {@link ICdmMassIndexer#dictionaryClasses()}. Re-dicting will not purge
164 * @param frontendBaseUrl
165 * if the CDM server is running behind a reverse proxy you need
166 * to supply the base URL of web service front-end which is
167 * provided by the proxy server.
173 @RequestMapping(value
= { "redict" }, method
= RequestMethod
.GET
)
174 public ModelAndView
doRedict(
175 @RequestParam(value
= "frontendBaseUrl", required
= false) String frontendBaseUrl
,
176 @RequestParam(value
= "priority", required
= false) Integer priority
,
177 HttpServletRequest request
, HttpServletResponse response
)
180 String processLabel
= "Re-Dicting";
181 ProgressMonitorUtil progressUtil
= new ProgressMonitorUtil(
182 progressMonitorController
);
184 if (!progressMonitorController
.isMonitorRunning(indexMonitorUuid
)) {
185 indexMonitorUuid
= progressUtil
.registerNewMonitor();
186 Thread subThread
= new Thread() {
189 indexer
.createDictionary(progressMonitorController
190 .getMonitor(indexMonitorUuid
));
193 if (priority
== null) {
194 priority
= AbstractController
.DEFAULT_BATCH_THREAD_PRIORITY
;
196 subThread
.setPriority(priority
);
199 // send redirect "see other"
200 return progressUtil
.respondWithMonitor(frontendBaseUrl
, request
,
201 response
, processLabel
, indexMonitorUuid
);
205 * This will wipe out the index.
212 @RequestMapping(value
= { "purge" }, method
= RequestMethod
.GET
)
213 public ModelAndView
doPurge(
214 @RequestParam(value
= "frontendBaseUrl", required
= false) String frontendBaseUrl
,
215 @RequestParam(value
= "priority", required
= false) Integer priority
,
216 HttpServletRequest request
, HttpServletResponse response
)
219 String processLabel
= "Purging";
221 ProgressMonitorUtil progressUtil
= new ProgressMonitorUtil(
222 progressMonitorController
);
224 if (!progressMonitorController
.isMonitorRunning(indexMonitorUuid
)) {
225 indexMonitorUuid
= progressUtil
.registerNewMonitor();
226 Thread subThread
= new Thread() {
229 indexer
.purge(progressMonitorController
230 .getMonitor(indexMonitorUuid
));
233 if (priority
== null) {
234 priority
= AbstractController
.DEFAULT_BATCH_THREAD_PRIORITY
;
236 subThread
.setPriority(priority
);
240 // send redirect "see other"
241 return progressUtil
.respondWithMonitor(frontendBaseUrl
, request
,
242 response
, processLabel
, indexMonitorUuid
);