1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2009 EDIT European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version
|
7
|
* 1.1 See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.remote.controller;
|
11
|
|
12
|
import java.awt.Color;
|
13
|
import java.io.IOException;
|
14
|
import java.util.Arrays;
|
15
|
import java.util.EnumSet;
|
16
|
import java.util.List;
|
17
|
import java.util.Map;
|
18
|
import java.util.Set;
|
19
|
import java.util.UUID;
|
20
|
|
21
|
import javax.servlet.http.HttpServletRequest;
|
22
|
import javax.servlet.http.HttpServletResponse;
|
23
|
|
24
|
import org.springframework.beans.factory.annotation.Autowired;
|
25
|
import org.springframework.stereotype.Controller;
|
26
|
import org.springframework.web.bind.WebDataBinder;
|
27
|
import org.springframework.web.bind.annotation.InitBinder;
|
28
|
import org.springframework.web.bind.annotation.PathVariable;
|
29
|
import org.springframework.web.bind.annotation.RequestMapping;
|
30
|
import org.springframework.web.bind.annotation.RequestMethod;
|
31
|
import org.springframework.web.bind.annotation.RequestParam;
|
32
|
import org.springframework.web.servlet.ModelAndView;
|
33
|
|
34
|
import com.fasterxml.jackson.core.JsonParseException;
|
35
|
import com.fasterxml.jackson.databind.JsonMappingException;
|
36
|
|
37
|
import eu.etaxonomy.cdm.api.service.IDescriptionService;
|
38
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
39
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
40
|
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
41
|
import eu.etaxonomy.cdm.api.service.description.TransmissionEngineDistribution;
|
42
|
import eu.etaxonomy.cdm.api.service.description.TransmissionEngineDistribution.AggregationMode;
|
43
|
import eu.etaxonomy.cdm.api.service.dto.DistributionInfoDTO;
|
44
|
import eu.etaxonomy.cdm.api.service.dto.DistributionInfoDTO.InfoPart;
|
45
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
46
|
import eu.etaxonomy.cdm.ext.geo.CondensedDistributionRecipe;
|
47
|
import eu.etaxonomy.cdm.ext.geo.EditGeoServiceUtilities;
|
48
|
import eu.etaxonomy.cdm.ext.geo.IEditGeoService;
|
49
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
50
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
51
|
import eu.etaxonomy.cdm.model.description.Feature;
|
52
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
|
53
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
54
|
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
|
55
|
import eu.etaxonomy.cdm.model.location.NamedAreaType;
|
56
|
import eu.etaxonomy.cdm.model.name.Rank;
|
57
|
import eu.etaxonomy.cdm.persistence.dto.TermDto;
|
58
|
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
59
|
import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;
|
60
|
import eu.etaxonomy.cdm.remote.controller.util.ProgressMonitorUtil;
|
61
|
import eu.etaxonomy.cdm.remote.editor.DefinedTermBaseList;
|
62
|
import eu.etaxonomy.cdm.remote.editor.TermBaseListPropertyEditor;
|
63
|
import eu.etaxonomy.cdm.remote.editor.TermBasePropertyEditor;
|
64
|
import eu.etaxonomy.cdm.remote.l10n.LocaleContext;
|
65
|
import io.swagger.annotations.Api;
|
66
|
|
67
|
/**
|
68
|
* TODO write controller documentation
|
69
|
*
|
70
|
* @author a.kohlbecker
|
71
|
* @date 24.03.2009
|
72
|
*/
|
73
|
@Controller
|
74
|
@Api("description")
|
75
|
@RequestMapping(value = {"/description"})
|
76
|
public class DescriptionListController extends IdentifiableListController<DescriptionBase, IDescriptionService> {
|
77
|
|
78
|
|
79
|
@Autowired
|
80
|
private ITermService termService;
|
81
|
|
82
|
@Autowired
|
83
|
private IVocabularyService vocabularyService ;
|
84
|
|
85
|
@Autowired
|
86
|
private ITaxonService taxonService;
|
87
|
|
88
|
@Autowired
|
89
|
private IEditGeoService geoService;
|
90
|
|
91
|
@Autowired
|
92
|
public TransmissionEngineDistribution transmissionEngineDistribution;
|
93
|
|
94
|
@Autowired
|
95
|
public ProgressMonitorController progressMonitorController;
|
96
|
|
97
|
protected static final List<String> DESCRIPTION_ELEMENT_INIT_STRATEGY = Arrays.asList(new String []{
|
98
|
"$",
|
99
|
"multilanguageText",
|
100
|
});
|
101
|
|
102
|
/**
|
103
|
* There should only be one longtime processes
|
104
|
* therefore the according progress monitor uuid is stored in
|
105
|
* this static field.
|
106
|
*/
|
107
|
private static UUID transmissionEngineMonitorUuid = null;
|
108
|
|
109
|
|
110
|
@Override
|
111
|
@Autowired
|
112
|
public void setService(IDescriptionService service) {
|
113
|
this.service = service;
|
114
|
}
|
115
|
|
116
|
@InitBinder
|
117
|
@Override
|
118
|
public void initBinder(WebDataBinder binder) {
|
119
|
super.initBinder(binder);
|
120
|
binder.registerCustomEditor(DefinedTermBaseList.class, new TermBaseListPropertyEditor<Feature>(termService));
|
121
|
binder.registerCustomEditor(NamedAreaLevel.class, new TermBasePropertyEditor<NamedAreaLevel>(termService));
|
122
|
binder.registerCustomEditor(Rank.class, new TermBasePropertyEditor<Rank>(termService));
|
123
|
}
|
124
|
|
125
|
protected List<String> getDescriptionInfoInitStrategy(){
|
126
|
return getInitializationStrategy();
|
127
|
}
|
128
|
|
129
|
|
130
|
/**
|
131
|
* Runs the {@link TransmissionEngineDistribution} in a separate Thread and
|
132
|
* responds with a redirect to a progress monitor REST service end point.
|
133
|
* <p>
|
134
|
*
|
135
|
* @param mode
|
136
|
* one of <code>byAreas</code>, <code>byRanks</code>,
|
137
|
* <code>byAreasAndRanks</code>
|
138
|
* @param frontendBaseUrl
|
139
|
* the cdm server instance base URL, this is needed for the a
|
140
|
* proper redirect URL when the service is running behind a
|
141
|
* reverse HTTP proxy
|
142
|
* @param priority
|
143
|
* the priority for the Thread to spawn, see
|
144
|
* {@link Thread#setPriority(int)}, defaults to 3
|
145
|
* @param targetAreaLevel
|
146
|
* The level of target areas to project the distributions to.
|
147
|
* @param lowerRank
|
148
|
* @param upperRank
|
149
|
*
|
150
|
* @param request
|
151
|
* @param response
|
152
|
* @return
|
153
|
* @throws IOException
|
154
|
*/
|
155
|
@RequestMapping(value = { "accumulateDistributions" }, method = RequestMethod.GET)
|
156
|
public ModelAndView doAccumulateDistributions(
|
157
|
@RequestParam(value= "mode", required = true) final AggregationMode mode,
|
158
|
@RequestParam(value = "frontendBaseUrl", required = false) String frontendBaseUrl,
|
159
|
@RequestParam(value = "priority", required = false) Integer priority,
|
160
|
@RequestParam(value = "targetAreaLevel", required = true) final NamedAreaLevel targetAreaLevel,
|
161
|
@RequestParam(value = "lowerRank", required = false) Rank lowerRank,
|
162
|
@RequestParam(value = "upperRank", required = false) Rank upperRank,
|
163
|
HttpServletRequest request,
|
164
|
HttpServletResponse response) throws IOException {
|
165
|
|
166
|
logger.info("doAccumulateDistributions()" + request.getRequestURI());
|
167
|
|
168
|
// transmissionEngineDistribution.updatePriorities();
|
169
|
|
170
|
String processLabel = "accumulating distributions";
|
171
|
|
172
|
final Rank _lowerRank = lowerRank != null ? lowerRank : Rank.UNKNOWN_RANK(); // this is the lowest rank
|
173
|
final Rank _upperRank = upperRank != null ? upperRank : Rank.GENUS();
|
174
|
|
175
|
ProgressMonitorUtil progressUtil = new ProgressMonitorUtil(progressMonitorController);
|
176
|
|
177
|
final List<String> term_init_strategy = Arrays.asList(new String []{
|
178
|
"representations"
|
179
|
});
|
180
|
|
181
|
if (!progressMonitorController.isMonitorRunning(transmissionEngineMonitorUuid)) {
|
182
|
transmissionEngineMonitorUuid = progressUtil.registerNewMonitor();
|
183
|
Thread subThread = new Thread() {
|
184
|
@Override
|
185
|
public void run() {
|
186
|
Pager<NamedArea> areaPager = termService.list(targetAreaLevel, (NamedAreaType) null,
|
187
|
null, null, (List<OrderHint>) null, term_init_strategy);
|
188
|
transmissionEngineDistribution.accumulate(mode, areaPager.getRecords(), _lowerRank, _upperRank,
|
189
|
null, progressMonitorController.getMonitor(transmissionEngineMonitorUuid));
|
190
|
}
|
191
|
};
|
192
|
if(priority == null) {
|
193
|
priority = AbstractController.DEFAULT_BATCH_THREAD_PRIORITY;
|
194
|
}
|
195
|
subThread.setPriority(priority);
|
196
|
subThread.start();
|
197
|
}
|
198
|
|
199
|
// send redirect "see other"
|
200
|
return progressUtil.respondWithMonitor(frontendBaseUrl, request, response, processLabel, transmissionEngineMonitorUuid);
|
201
|
}
|
202
|
|
203
|
@RequestMapping(value = "namedAreasInUse", method = RequestMethod.GET)
|
204
|
public Pager<TermDto> doPageNamedAreasInUse(
|
205
|
@RequestParam(value = "includeAllParents", required = false) boolean includeAllParents,
|
206
|
@RequestParam(value = "pageSize", required = false) Integer pageSize,
|
207
|
@RequestParam(value = "pageNumber", required = false) Integer pageNumber, HttpServletRequest request,
|
208
|
HttpServletResponse response) throws IOException {
|
209
|
|
210
|
logger.info("doPageNamedAreasInUse : " + requestPathAndQuery(request));
|
211
|
|
212
|
PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);
|
213
|
pagerParams.normalizeAndValidate(response);
|
214
|
|
215
|
Pager<TermDto> pager = service.pageNamedAreasInUse(includeAllParents, pagerParams.getPageSize(), pagerParams.getPageIndex());
|
216
|
|
217
|
localizeTerms(pager);
|
218
|
|
219
|
return pager;
|
220
|
}
|
221
|
|
222
|
/**
|
223
|
* @param taxonUuid
|
224
|
* @param parts
|
225
|
* possible values: condensedStatus, tree, mapUriParams,
|
226
|
* elements,
|
227
|
* @param subAreaPreference
|
228
|
* @param statusOrderPreference
|
229
|
* @param hideMarkedAreasList
|
230
|
* @param omitLevels
|
231
|
* @param request
|
232
|
* @param response
|
233
|
* @param recipe
|
234
|
* The recipe for creating the condensed distribution status
|
235
|
* @return
|
236
|
* @throws IOException
|
237
|
* @throws JsonMappingException
|
238
|
* @throws JsonParseException
|
239
|
*/
|
240
|
@RequestMapping(value = "distributionInfoFor/{uuid}", method = RequestMethod.GET)
|
241
|
public ModelAndView doGetDistributionInfo(
|
242
|
@PathVariable("uuid") UUID taxonUuid,
|
243
|
@RequestParam("part") Set<InfoPart> partSet,
|
244
|
@RequestParam(value = "subAreaPreference", required = false) boolean subAreaPreference,
|
245
|
@RequestParam(value = "statusOrderPreference", required = false) boolean statusOrderPreference,
|
246
|
@RequestParam(value = "hiddenAreaMarkerType", required = false) DefinedTermBaseList<MarkerType> hideMarkedAreasList,
|
247
|
@RequestParam(value = "omitLevels", required = false) Set<NamedAreaLevel> omitLevels,
|
248
|
@RequestParam(value = "statusColors", required = false) String statusColorsString,
|
249
|
@RequestParam(value = "recipe", required = false, defaultValue="EuroPlusMed") CondensedDistributionRecipe recipe,
|
250
|
HttpServletRequest request,
|
251
|
HttpServletResponse response) throws JsonParseException, JsonMappingException, IOException {
|
252
|
|
253
|
logger.info("doGetDistributionInfo() - " + requestPathAndQuery(request));
|
254
|
|
255
|
ModelAndView mv = new ModelAndView();
|
256
|
|
257
|
Set<MarkerType> hideMarkedAreas = null;
|
258
|
if(hideMarkedAreasList != null){
|
259
|
hideMarkedAreas = hideMarkedAreasList.asSet();
|
260
|
}
|
261
|
|
262
|
EnumSet<InfoPart> parts = EnumSet.copyOf(partSet);
|
263
|
|
264
|
Map<PresenceAbsenceTerm, Color> presenceAbsenceTermColors = EditGeoServiceUtilities.buildStatusColorMap(statusColorsString, termService, vocabularyService);
|
265
|
|
266
|
DistributionInfoDTO dto = geoService.composeDistributionInfoFor(parts, taxonUuid,
|
267
|
subAreaPreference, statusOrderPreference, hideMarkedAreas, omitLevels,
|
268
|
presenceAbsenceTermColors, LocaleContext.getLanguages(),
|
269
|
getDescriptionInfoInitStrategy(), recipe, null);
|
270
|
|
271
|
mv.addObject(dto);
|
272
|
|
273
|
return mv;
|
274
|
}
|
275
|
|
276
|
}
|