2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.remote
.controller
;
11 import java
.util
.ArrayList
;
12 import java
.util
.List
;
14 import java
.util
.UUID
;
16 import javax
.servlet
.http
.HttpServletRequest
;
17 import javax
.servlet
.http
.HttpServletResponse
;
19 import org
.apache
.log4j
.Logger
;
20 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
21 import org
.springframework
.stereotype
.Controller
;
22 import org
.springframework
.web
.bind
.WebDataBinder
;
23 import org
.springframework
.web
.bind
.annotation
.CrossOrigin
;
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
;
36 import io
.swagger
.annotations
.Api
;
40 @CrossOrigin(origins
="*")
41 @RequestMapping(value
= { "/manage" })
42 public class ManagementController
{
43 public static final Logger logger
= Logger
44 .getLogger(ManagementController
.class);
47 private DataSourceReloader datasoucrceLoader
;
50 public ICdmMassIndexer indexer
;
53 public ProgressMonitorController progressMonitorController
;
56 * There should only be one processes operating on the lucene index
57 * therefore the according progress monitor uuid is stored in this static
60 private static UUID indexMonitorUuid
= null;
63 public void initIndexClassBinder(WebDataBinder binder
) {
64 binder
.registerCustomEditor(Class
.class, new CdmTypePropertyEditor());
68 public void initIndexArrayBinder(WebDataBinder binder
) {
69 binder
.registerCustomEditor(Class
[].class, new CdmTypePropertyEditor());
73 * return page not found http error (404) for unknown or incorrect UUIDs
77 * org.springframework.web.servlet.mvc.AbstractController#handleRequestInternal
78 * (javax.servlet.http.HttpServletRequest,
79 * javax.servlet.http.HttpServletResponse)
81 // @RequestMapping(value = { "/manager/datasources/list" }, method =
83 protected ModelAndView
doList(HttpServletRequest request
,
84 HttpServletResponse respone
) throws Exception
{
86 ModelAndView mv
= new ModelAndView();
87 Map
<String
, DataSourceInfo
> dataSourceInfos
= datasoucrceLoader
.test();
88 mv
.addObject(dataSourceInfos
);
93 // @RequestMapping(value = { "/manager/datasources/reload" }, method =
95 public ModelAndView
doReload(HttpServletRequest request
,
96 HttpServletResponse respone
) throws Exception
{
98 ModelAndView mv
= new ModelAndView();
99 Map
<String
, DataSourceInfo
> dataSourceInfos
= datasoucrceLoader
101 mv
.addObject(dataSourceInfos
);
108 * Reindex all cdm entities listed in
109 * {@link ICdmMassIndexer#indexedClasses()}. Re-indexing will not purge the
112 * @param frontendBaseUrl
113 * if the CDM server is running behind a reverse proxy you need
114 * to supply the base URL of web service front-end which is
115 * provided by the proxy server.
121 @RequestMapping(value
= { "reindex" }, method
= {RequestMethod
.GET
, RequestMethod
.OPTIONS
})
122 public synchronized ModelAndView
doReindex(
123 @RequestParam(value
= "frontendBaseUrl", required
= false) String frontendBaseUrl
,
124 @RequestParam(value
= "type", required
= false) Class
<?
extends CdmBase
>[] types
,
125 @RequestParam(value
= "priority", required
= false) Integer priority
,
126 @RequestParam(value
= "dataRedirect", required
= false) boolean dataRedirect
,
127 HttpServletRequest request
, HttpServletResponse response
)
130 final List
<Class
<?
extends CdmBase
>> typeSet
= asList(types
);
132 String processLabel
= "Re-indexing";
134 ProgressMonitorUtil progressUtil
= new ProgressMonitorUtil(
135 progressMonitorController
);
137 if (!progressMonitorController
.isMonitorRunning(indexMonitorUuid
)) {
138 indexMonitorUuid
= progressUtil
.registerNewMonitor();
139 Thread subThread
= new Thread() {
142 indexer
.reindex(typeSet
, progressMonitorController
.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
, processLabel
,
153 indexMonitorUuid
, dataRedirect
, request
, response
);
159 private List
<Class
<?
extends CdmBase
>> asList(Class
<?
extends CdmBase
>[] types
) {
161 List
<Class
<?
extends CdmBase
>> typeList
= null;
163 typeList
= new ArrayList
<Class
<?
extends CdmBase
>>();
164 for (Class
<?
extends CdmBase
> type
: types
) {
165 if(type
!= null && ! typeList
.contains(type
)) {
175 * Create dictionaries for all cdm entities listed in
176 * {@link ICdmMassIndexer#dictionaryClasses()}. Re-dicting will not purge
179 * @param frontendBaseUrl
180 * if the CDM server is running behind a reverse proxy you need
181 * to supply the base URL of web service front-end which is
182 * provided by the proxy server.
188 @RequestMapping(value
= { "redict" }, method
= {RequestMethod
.GET
, RequestMethod
.OPTIONS
})
189 public synchronized ModelAndView
doRedict(
190 @RequestParam(value
= "frontendBaseUrl", required
= false) String frontendBaseUrl
,
191 @RequestParam(value
= "priority", required
= false) Integer priority
,
192 @RequestParam(value
= "dataRedirect", required
= false) boolean dataRedirect
,
193 HttpServletRequest request
, HttpServletResponse response
)
196 String processLabel
= "Re-Dicting";
197 ProgressMonitorUtil progressUtil
= new ProgressMonitorUtil(
198 progressMonitorController
);
200 if (!progressMonitorController
.isMonitorRunning(indexMonitorUuid
)) {
201 indexMonitorUuid
= progressUtil
.registerNewMonitor();
202 Thread subThread
= new Thread() {
205 indexer
.createDictionary(progressMonitorController
206 .getMonitor(indexMonitorUuid
));
209 if (priority
== null) {
210 priority
= AbstractController
.DEFAULT_BATCH_THREAD_PRIORITY
;
212 subThread
.setPriority(priority
);
215 // send redirect "see other"
216 return progressUtil
.respondWithMonitor(frontendBaseUrl
, processLabel
,
217 indexMonitorUuid
, dataRedirect
, request
, response
);
221 * This will wipe out the index.
228 @RequestMapping(value
= { "purge" }, method
= {RequestMethod
.GET
, RequestMethod
.OPTIONS
})
229 public synchronized ModelAndView
doPurge(
230 @RequestParam(value
= "frontendBaseUrl", required
= false) String frontendBaseUrl
,
231 @RequestParam(value
= "priority", required
= false) Integer priority
,
232 @RequestParam(value
= "dataRedirect", required
= false) boolean dataRedirect
,
233 HttpServletRequest request
, HttpServletResponse response
)
236 String processLabel
= "Purging";
238 ProgressMonitorUtil progressUtil
= new ProgressMonitorUtil(
239 progressMonitorController
);
241 if (!progressMonitorController
.isMonitorRunning(indexMonitorUuid
)) {
242 indexMonitorUuid
= progressUtil
.registerNewMonitor();
243 Thread subThread
= new Thread() {
246 indexer
.purge(progressMonitorController
247 .getMonitor(indexMonitorUuid
));
250 if (priority
== null) {
251 priority
= AbstractController
.DEFAULT_BATCH_THREAD_PRIORITY
;
253 subThread
.setPriority(priority
);
257 // send redirect "see other"
258 return progressUtil
.respondWithMonitor(frontendBaseUrl
, processLabel
,
259 indexMonitorUuid
, dataRedirect
, request
, response
);