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
;
12 import java
.util
.HashSet
;
15 import java
.util
.UUID
;
17 import javax
.servlet
.http
.HttpServletRequest
;
18 import javax
.servlet
.http
.HttpServletResponse
;
20 import org
.apache
.log4j
.Logger
;
21 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
22 import org
.springframework
.stereotype
.Controller
;
23 import org
.springframework
.web
.bind
.WebDataBinder
;
24 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
25 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
26 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
27 import org
.springframework
.web
.bind
.annotation
.RequestParam
;
28 import org
.springframework
.web
.servlet
.ModelAndView
;
30 import eu
.etaxonomy
.cdm
.api
.service
.search
.ICdmMassIndexer
;
31 import eu
.etaxonomy
.cdm
.database
.DataSourceInfo
;
32 import eu
.etaxonomy
.cdm
.database
.DataSourceReloader
;
33 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
34 import eu
.etaxonomy
.cdm
.remote
.controller
.util
.ProgressMonitorUtil
;
35 import eu
.etaxonomy
.cdm
.remote
.editor
.CdmTypePropertyEditor
;
38 @RequestMapping(value
= { "/manage" })
39 public class ManagementController
{
40 public static final Logger logger
= Logger
41 .getLogger(ManagementController
.class);
44 private DataSourceReloader datasoucrceLoader
;
47 public ICdmMassIndexer indexer
;
50 public ProgressMonitorController progressMonitorController
;
53 * There should only be one processes operating on the lucene index
54 * therefore the according progress monitor uuid is stored in this static
57 private static UUID indexMonitorUuid
= null;
60 public void initIndexClassBinder(WebDataBinder binder
) {
61 binder
.registerCustomEditor(Class
.class, new CdmTypePropertyEditor());
65 public void initIndexArrayBinder(WebDataBinder binder
) {
66 binder
.registerCustomEditor(Class
[].class, new CdmTypePropertyEditor());
70 * return page not found http error (404) for unknown or incorrect UUIDs
74 * org.springframework.web.servlet.mvc.AbstractController#handleRequestInternal
75 * (javax.servlet.http.HttpServletRequest,
76 * javax.servlet.http.HttpServletResponse)
78 // @RequestMapping(value = { "/manager/datasources/list" }, method =
80 protected ModelAndView
doList(HttpServletRequest request
,
81 HttpServletResponse respone
) throws Exception
{
83 ModelAndView mv
= new ModelAndView();
84 Map
<String
, DataSourceInfo
> dataSourceInfos
= datasoucrceLoader
.test();
85 mv
.addObject(dataSourceInfos
);
90 // @RequestMapping(value = { "/manager/datasources/reload" }, method =
92 public ModelAndView
doReload(HttpServletRequest request
,
93 HttpServletResponse respone
) throws Exception
{
95 ModelAndView mv
= new ModelAndView();
96 Map
<String
, DataSourceInfo
> dataSourceInfos
= datasoucrceLoader
98 mv
.addObject(dataSourceInfos
);
105 * Reindex all cdm entities listed in
106 * {@link ICdmMassIndexer#indexedClasses()}. Re-indexing will not purge the
109 * @param frontendBaseUrl
110 * if the CDM server is running behind a reverse proxy you need
111 * to supply the base URL of web service front-end which is
112 * provided by the proxy server.
118 @RequestMapping(value
= { "reindex" }, method
= RequestMethod
.GET
)
119 public synchronized ModelAndView
doReindex(
120 @RequestParam(value
= "frontendBaseUrl", required
= false) String frontendBaseUrl
,
121 @RequestParam(value
= "type", required
= false) Class
<?
extends CdmBase
>[] types
,
122 @RequestParam(value
= "priority", required
= false) Integer priority
,
123 HttpServletRequest request
, HttpServletResponse response
)
126 final Set
<Class
<?
extends CdmBase
>> typeSet
= asList(types
);
128 String processLabel
= "Re-indexing";
129 ProgressMonitorUtil progressUtil
= new ProgressMonitorUtil(
130 progressMonitorController
);
132 if (!progressMonitorController
.isMonitorRunning(indexMonitorUuid
)) {
133 indexMonitorUuid
= progressUtil
.registerNewMonitor();
134 Thread subThread
= new Thread() {
137 indexer
.reindex(typeSet
, progressMonitorController
.getMonitor(indexMonitorUuid
));
140 if (priority
== null) {
141 priority
= AbstractController
.DEFAULT_BATCH_THREAD_PRIORITY
;
143 subThread
.setPriority(priority
);
146 // send redirect "see other"
147 return progressUtil
.respondWithMonitor(frontendBaseUrl
, request
,
148 response
, processLabel
, indexMonitorUuid
);
154 private Set
<Class
<?
extends CdmBase
>> asList(Class
<?
extends CdmBase
>[] types
) {
155 Set
<Class
<?
extends CdmBase
>> typeSet
= null;
157 typeSet
= new HashSet
<Class
<?
extends CdmBase
>>();
158 for (Class
<?
extends CdmBase
> type
: types
) {
169 * Create dictionaries for all cdm entities listed in
170 * {@link ICdmMassIndexer#dictionaryClasses()}. Re-dicting will not purge
173 * @param frontendBaseUrl
174 * if the CDM server is running behind a reverse proxy you need
175 * to supply the base URL of web service front-end which is
176 * provided by the proxy server.
182 @RequestMapping(value
= { "redict" }, method
= RequestMethod
.GET
)
183 public synchronized ModelAndView
doRedict(
184 @RequestParam(value
= "frontendBaseUrl", required
= false) String frontendBaseUrl
,
185 @RequestParam(value
= "priority", required
= false) Integer priority
,
186 HttpServletRequest request
, HttpServletResponse response
)
189 String processLabel
= "Re-Dicting";
190 ProgressMonitorUtil progressUtil
= new ProgressMonitorUtil(
191 progressMonitorController
);
193 if (!progressMonitorController
.isMonitorRunning(indexMonitorUuid
)) {
194 indexMonitorUuid
= progressUtil
.registerNewMonitor();
195 Thread subThread
= new Thread() {
198 indexer
.createDictionary(progressMonitorController
199 .getMonitor(indexMonitorUuid
));
202 if (priority
== null) {
203 priority
= AbstractController
.DEFAULT_BATCH_THREAD_PRIORITY
;
205 subThread
.setPriority(priority
);
208 // send redirect "see other"
209 return progressUtil
.respondWithMonitor(frontendBaseUrl
, request
,
210 response
, processLabel
, indexMonitorUuid
);
214 * This will wipe out the index.
221 @RequestMapping(value
= { "purge" }, method
= RequestMethod
.GET
)
222 public synchronized ModelAndView
doPurge(
223 @RequestParam(value
= "frontendBaseUrl", required
= false) String frontendBaseUrl
,
224 @RequestParam(value
= "priority", required
= false) Integer priority
,
225 HttpServletRequest request
, HttpServletResponse response
)
228 String processLabel
= "Purging";
230 ProgressMonitorUtil progressUtil
= new ProgressMonitorUtil(
231 progressMonitorController
);
233 if (!progressMonitorController
.isMonitorRunning(indexMonitorUuid
)) {
234 indexMonitorUuid
= progressUtil
.registerNewMonitor();
235 Thread subThread
= new Thread() {
238 indexer
.purge(progressMonitorController
239 .getMonitor(indexMonitorUuid
));
242 if (priority
== null) {
243 priority
= AbstractController
.DEFAULT_BATCH_THREAD_PRIORITY
;
245 subThread
.setPriority(priority
);
249 // send redirect "see other"
250 return progressUtil
.respondWithMonitor(frontendBaseUrl
, request
,
251 response
, processLabel
, indexMonitorUuid
);