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
{
44 public static final Logger logger
= Logger
.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
76 * org.springframework.web.servlet.mvc.AbstractController#handleRequestInternal
77 * (javax.servlet.http.HttpServletRequest,
78 * javax.servlet.http.HttpServletResponse)
80 // @RequestMapping(value = { "/manager/datasources/list" }, method =
82 protected ModelAndView
doList(HttpServletRequest request
,
83 HttpServletResponse respone
) throws Exception
{
85 ModelAndView mv
= new ModelAndView();
86 Map
<String
, DataSourceInfo
> dataSourceInfos
= datasoucrceLoader
.test();
87 mv
.addObject(dataSourceInfos
);
92 // @RequestMapping(value = { "/manager/datasources/reload" }, method =
94 public ModelAndView
doReload(HttpServletRequest request
,
95 HttpServletResponse respone
) throws Exception
{
97 ModelAndView mv
= new ModelAndView();
98 Map
<String
, DataSourceInfo
> dataSourceInfos
= datasoucrceLoader
100 mv
.addObject(dataSourceInfos
);
107 * Reindex all cdm entities listed in
108 * {@link ICdmMassIndexer#indexedClasses()}. Re-indexing will not purge the
111 * @param frontendBaseUrl
112 * if the CDM server is running behind a reverse proxy you need
113 * to supply the base URL of web service front-end which is
114 * provided by the proxy server.
120 @RequestMapping(value
= { "reindex" }, method
= {RequestMethod
.GET
, RequestMethod
.OPTIONS
})
121 public synchronized ModelAndView
doReindex(
122 @RequestParam(value
= "frontendBaseUrl", required
= false) String frontendBaseUrl
,
123 @RequestParam(value
= "type", required
= false) Class
<?
extends CdmBase
>[] types
,
124 @RequestParam(value
= "priority", required
= false) Integer priority
,
125 @RequestParam(value
= "dataRedirect", required
= false) boolean dataRedirect
,
126 HttpServletRequest request
, HttpServletResponse response
)
129 final List
<Class
<?
extends CdmBase
>> typeSet
= asList(types
);
131 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(typeSet
, progressMonitorController
.getMonitor(indexMonitorUuid
));
144 if (priority
== null) {
145 priority
= AbstractController
.DEFAULT_BATCH_THREAD_PRIORITY
;
147 subThread
.setPriority(priority
);
150 // send redirect "see other"
151 return progressUtil
.respondWithMonitor(frontendBaseUrl
, processLabel
,
152 indexMonitorUuid
, dataRedirect
, request
, response
);
155 private List
<Class
<?
extends CdmBase
>> asList(Class
<?
extends CdmBase
>[] types
) {
157 List
<Class
<?
extends CdmBase
>> typeList
= null;
159 typeList
= new ArrayList
<Class
<?
extends CdmBase
>>();
160 for (Class
<?
extends CdmBase
> type
: types
) {
161 if(type
!= null && ! typeList
.contains(type
)) {
171 * Create dictionaries for all cdm entities listed in
172 * {@link ICdmMassIndexer#dictionaryClasses()}. Re-dicting will not purge
175 * @param frontendBaseUrl
176 * if the CDM server is running behind a reverse proxy you need
177 * to supply the base URL of web service front-end which is
178 * provided by the proxy server.
184 @RequestMapping(value
= { "redict" }, method
= {RequestMethod
.GET
, RequestMethod
.OPTIONS
})
185 public synchronized ModelAndView
doRedict(
186 @RequestParam(value
= "frontendBaseUrl", required
= false) String frontendBaseUrl
,
187 @RequestParam(value
= "priority", required
= false) Integer priority
,
188 @RequestParam(value
= "dataRedirect", required
= false) boolean dataRedirect
,
189 HttpServletRequest request
, HttpServletResponse response
)
192 String processLabel
= "Re-Dicting";
193 ProgressMonitorUtil progressUtil
= new ProgressMonitorUtil(
194 progressMonitorController
);
196 if (!progressMonitorController
.isMonitorRunning(indexMonitorUuid
)) {
197 indexMonitorUuid
= progressUtil
.registerNewMonitor();
198 Thread subThread
= new Thread() {
201 indexer
.createDictionary(progressMonitorController
202 .getMonitor(indexMonitorUuid
));
205 if (priority
== null) {
206 priority
= AbstractController
.DEFAULT_BATCH_THREAD_PRIORITY
;
208 subThread
.setPriority(priority
);
211 // send redirect "see other"
212 return progressUtil
.respondWithMonitor(frontendBaseUrl
, processLabel
,
213 indexMonitorUuid
, dataRedirect
, request
, response
);
217 * This will wipe out the index.
224 @RequestMapping(value
= { "purge" }, method
= {RequestMethod
.GET
, RequestMethod
.OPTIONS
})
225 public synchronized ModelAndView
doPurge(
226 @RequestParam(value
= "frontendBaseUrl", required
= false) String frontendBaseUrl
,
227 @RequestParam(value
= "priority", required
= false) Integer priority
,
228 @RequestParam(value
= "dataRedirect", required
= false) boolean dataRedirect
,
229 HttpServletRequest request
, HttpServletResponse response
)
232 String processLabel
= "Purging";
234 ProgressMonitorUtil progressUtil
= new ProgressMonitorUtil(
235 progressMonitorController
);
237 if (!progressMonitorController
.isMonitorRunning(indexMonitorUuid
)) {
238 indexMonitorUuid
= progressUtil
.registerNewMonitor();
239 Thread subThread
= new Thread() {
242 indexer
.purge(progressMonitorController
243 .getMonitor(indexMonitorUuid
));
246 if (priority
== null) {
247 priority
= AbstractController
.DEFAULT_BATCH_THREAD_PRIORITY
;
249 subThread
.setPriority(priority
);
253 // send redirect "see other"
254 return progressUtil
.respondWithMonitor(frontendBaseUrl
, processLabel
,
255 indexMonitorUuid
, dataRedirect
, request
, response
);