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
.annotation
.RequestMapping
;
22 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
23 import org
.springframework
.web
.bind
.annotation
.RequestParam
;
24 import org
.springframework
.web
.servlet
.ModelAndView
;
26 import eu
.etaxonomy
.cdm
.api
.service
.search
.ICdmMassIndexer
;
27 import eu
.etaxonomy
.cdm
.database
.DataSourceInfo
;
28 import eu
.etaxonomy
.cdm
.database
.DataSourceReloader
;
29 import eu
.etaxonomy
.cdm
.remote
.controller
.util
.ProgressMonitorUtil
;
32 @RequestMapping(value
= {"/manage"})
33 public class ManagementController
35 public static final Logger logger
= Logger
.getLogger(ManagementController
.class);
38 private DataSourceReloader datasoucrceLoader
;
41 public ICdmMassIndexer indexer
;
44 public ProgressMonitorController progressMonitorController
;
48 * There should only be one processes operating on the lucene index
49 * therefore the according progress monitor uuid is stored in
52 private static UUID indexMonitorUuid
= null;
55 private static final int DEFAULT_PAGE_SIZE
= 25;
58 * return page not found http error (404) for unknown or incorrect UUIDs
60 * @see org.springframework.web.servlet.mvc.AbstractController#handleRequestInternal(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
62 //@RequestMapping(value = { "/manager/datasources/list" }, method = RequestMethod.GET)
63 protected ModelAndView
doList(HttpServletRequest request
, HttpServletResponse respone
) throws Exception
{
65 ModelAndView mv
= new ModelAndView();
66 Map
<String
, DataSourceInfo
> dataSourceInfos
= datasoucrceLoader
.test();
67 mv
.addObject(dataSourceInfos
);
72 //@RequestMapping(value = { "/manager/datasources/reload" }, method = RequestMethod.GET)
73 public ModelAndView
doReload(HttpServletRequest request
, HttpServletResponse respone
) throws Exception
{
75 ModelAndView mv
= new ModelAndView();
76 Map
<String
, DataSourceInfo
> dataSourceInfos
= datasoucrceLoader
.reload();
77 mv
.addObject(dataSourceInfos
);
84 * Reindex all cdm entities listed in {@link ICdmMassIndexer#indexedClasses()}.
85 * Re-indexing will not purge the index.
86 * @param frontendBaseUrl if the CDM server is running behind a reverse proxy you need
87 * to supply the base URL of web service front-end which is
88 * provided by the proxy server.
94 @RequestMapping(value
= { "reindex" }, method
= RequestMethod
.GET
)
95 public ModelAndView
doReindex(
96 @RequestParam(value
= "frontendBaseUrl", required
= false) String frontendBaseUrl
,
97 HttpServletRequest request
, HttpServletResponse response
) throws Exception
{
100 String processLabel
= "Re-indexing";
101 ProgressMonitorUtil progressUtil
= new ProgressMonitorUtil(progressMonitorController
);
103 if(!progressMonitorController
.isMonitorRunning(indexMonitorUuid
)) {
104 indexMonitorUuid
= progressUtil
.registerNewMonitor();
105 Thread subThread
= new Thread(){
108 indexer
.reindex(progressMonitorController
.getMonitor(indexMonitorUuid
));
113 // send redirect "see other"
114 return progressUtil
.respondWithMonitor(frontendBaseUrl
, request
, response
, processLabel
, indexMonitorUuid
);
119 * Create dictionaries for all cdm entities listed in {@link ICdmMassIndexer#dictionaryClasses()}.
120 * Re-dicting will not purge the dictionaries.
121 * @param frontendBaseUrl if the CDM server is running behind a reverse proxy you need
122 * to supply the base URL of web service front-end which is
123 * provided by the proxy server.
129 @RequestMapping(value
= { "redict" }, method
= RequestMethod
.GET
)
130 public ModelAndView
doRedict(
131 @RequestParam(value
= "frontendBaseUrl", required
= false) String frontendBaseUrl
,
132 HttpServletRequest request
, HttpServletResponse response
) throws Exception
{
135 String processLabel
= "Re-Dicting";
136 ProgressMonitorUtil progressUtil
= new ProgressMonitorUtil(progressMonitorController
);
138 if(!progressMonitorController
.isMonitorRunning(indexMonitorUuid
)) {
139 indexMonitorUuid
= progressUtil
.registerNewMonitor();
140 Thread subThread
= new Thread(){
143 indexer
.createDictionary(progressMonitorController
.getMonitor(indexMonitorUuid
));
148 // send redirect "see other"
149 return progressUtil
.respondWithMonitor(frontendBaseUrl
, request
, response
, processLabel
, indexMonitorUuid
);
153 * This will wipe out the index.
160 @RequestMapping(value
= { "purge" }, method
= RequestMethod
.GET
)
161 public ModelAndView
doPurge(
162 @RequestParam(value
= "frontendBaseUrl", required
= false) String frontendBaseUrl
,
163 HttpServletRequest request
, HttpServletResponse response
) throws Exception
{
166 String processLabel
= "Purging";
168 ProgressMonitorUtil progressUtil
= new ProgressMonitorUtil(progressMonitorController
);
170 if(!progressMonitorController
.isMonitorRunning(indexMonitorUuid
)) {
171 indexMonitorUuid
= progressUtil
.registerNewMonitor();
172 Thread subThread
= new Thread(){
175 indexer
.purge(progressMonitorController
.getMonitor(indexMonitorUuid
));
181 // send redirect "see other"
182 return progressUtil
.respondWithMonitor(frontendBaseUrl
, request
, response
, processLabel
, indexMonitorUuid
);