1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.cdm.remote.controller;
|
12
|
|
13
|
import io.swagger.annotations.Api;
|
14
|
|
15
|
import java.io.IOException;
|
16
|
import java.util.Arrays;
|
17
|
import java.util.List;
|
18
|
import java.util.UUID;
|
19
|
|
20
|
import javax.servlet.http.HttpServletRequest;
|
21
|
import javax.servlet.http.HttpServletResponse;
|
22
|
|
23
|
import org.springframework.beans.factory.annotation.Autowired;
|
24
|
import org.springframework.stereotype.Controller;
|
25
|
import org.springframework.web.bind.WebDataBinder;
|
26
|
import org.springframework.web.bind.annotation.InitBinder;
|
27
|
import org.springframework.web.bind.annotation.PathVariable;
|
28
|
import org.springframework.web.bind.annotation.RequestMapping;
|
29
|
import org.springframework.web.bind.annotation.RequestMethod;
|
30
|
import org.springframework.web.servlet.ModelAndView;
|
31
|
|
32
|
import eu.etaxonomy.cdm.api.service.IDescriptionService;
|
33
|
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
|
34
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
35
|
import eu.etaxonomy.cdm.model.common.Language;
|
36
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
37
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
38
|
import eu.etaxonomy.cdm.model.description.Feature;
|
39
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
40
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
41
|
import eu.etaxonomy.cdm.model.description.TextData;
|
42
|
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
|
43
|
import eu.etaxonomy.cdm.remote.editor.DefinedTermBaseList;
|
44
|
import eu.etaxonomy.cdm.remote.editor.NamedAreaLevelPropertyEditor;
|
45
|
import eu.etaxonomy.cdm.remote.editor.TermBaseListPropertyEditor;
|
46
|
import eu.etaxonomy.cdm.remote.editor.UUIDListPropertyEditor;
|
47
|
import eu.etaxonomy.cdm.remote.editor.UuidList;
|
48
|
import eu.etaxonomy.cdm.remote.l10n.LocaleContext;
|
49
|
|
50
|
/**
|
51
|
* TODO write controller documentation
|
52
|
*
|
53
|
* @author a.kohlbecker
|
54
|
* @date 24.03.2009
|
55
|
*/
|
56
|
|
57
|
@Controller
|
58
|
@Api("description")
|
59
|
@RequestMapping(value = {"/description/{uuid}", "/description/{uuid_list}"})
|
60
|
public class DescriptionController extends BaseController<DescriptionBase, IDescriptionService>
|
61
|
{
|
62
|
@Autowired
|
63
|
private IFeatureTreeService featureTreeService;
|
64
|
|
65
|
@Autowired
|
66
|
private ITermService termService;
|
67
|
|
68
|
protected static final List<String> TAXONDESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{
|
69
|
"$",
|
70
|
"elements.$",
|
71
|
"elements.sources.citation.authorship",
|
72
|
"elements.sources.nameUsedInSource",
|
73
|
"elements.multilanguageText",
|
74
|
"elements.media",
|
75
|
});
|
76
|
|
77
|
@InitBinder
|
78
|
@Override
|
79
|
public void initBinder(WebDataBinder binder) {
|
80
|
super.initBinder(binder);
|
81
|
binder.registerCustomEditor(UuidList.class, new UUIDListPropertyEditor());
|
82
|
binder.registerCustomEditor(NamedAreaLevel.class, new NamedAreaLevelPropertyEditor());
|
83
|
binder.registerCustomEditor(DefinedTermBaseList.class, new TermBaseListPropertyEditor<MarkerType>(termService));
|
84
|
}
|
85
|
|
86
|
/* (non-Javadoc)
|
87
|
* @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
|
88
|
*/
|
89
|
@Autowired
|
90
|
@Override
|
91
|
public void setService(IDescriptionService service) {
|
92
|
this.service = service;
|
93
|
}
|
94
|
|
95
|
@RequestMapping(value = "hasStructuredData", method = RequestMethod.GET)
|
96
|
public ModelAndView doHasStructuredData(
|
97
|
@PathVariable("uuid") UUID uuid,
|
98
|
HttpServletRequest request,
|
99
|
HttpServletResponse response) throws IOException {
|
100
|
logger.info("doHasStructuredData() - " + request.getRequestURI());
|
101
|
|
102
|
ModelAndView mv = new ModelAndView();
|
103
|
|
104
|
DescriptionBase description = service.load(uuid);
|
105
|
|
106
|
if(!(description instanceof TaxonDescription)){
|
107
|
HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
|
108
|
// will terminate thread
|
109
|
}
|
110
|
|
111
|
boolean hasStructuredData = service.hasStructuredData(description);
|
112
|
|
113
|
mv.addObject(hasStructuredData);
|
114
|
return mv;
|
115
|
}
|
116
|
|
117
|
/*
|
118
|
@RequestMapping(value = "{uuid_list}/namedAreaTree", method = RequestMethod.GET)
|
119
|
public NamedAreaTree doGetOrderedDistributions(
|
120
|
@PathVariable("uuid_list") UuidList descriptionUuidList,
|
121
|
@RequestParam(value = "omitLevels", required = false) Set<NamedAreaLevel> levels,
|
122
|
//@ModelAttribute("omitLevels") HashSet<NamedAreaLevel> levels,
|
123
|
HttpServletRequest request, HttpServletResponse response) {
|
124
|
logger.info("getOrderedDistributions(" + ObjectUtils.toString(levels) + ") - " + request.getRequestURI());
|
125
|
Set<TaxonDescription> taxonDescriptions = new HashSet<TaxonDescription>();
|
126
|
TaxonDescription description;
|
127
|
for (UUID descriptionUuid : descriptionUuidList) {
|
128
|
description = (TaxonDescription) service.load(descriptionUuid);
|
129
|
taxonDescriptions.add(description);
|
130
|
}
|
131
|
NamedAreaTree areaTree = service.getOrderedDistributions(taxonDescriptions, levels);
|
132
|
return areaTree;
|
133
|
}
|
134
|
*/
|
135
|
|
136
|
@RequestMapping(value = "naturalLanguageDescription/{featuretree_uuid}", method = RequestMethod.GET) // mapped as absolute path, see CdmAntPathMatcher
|
137
|
public ModelAndView doGenerateNaturalLanguageDescription(
|
138
|
@PathVariable("uuid") UUID uuid,
|
139
|
@PathVariable("featuretree_uuid") UUID featureTreeUuid,
|
140
|
HttpServletRequest request,
|
141
|
HttpServletResponse response) throws IOException {
|
142
|
logger.info("doGenerateNaturalLanguageDescription() - " + request.getRequestURI());
|
143
|
|
144
|
DescriptionBase description = service.load(uuid);
|
145
|
|
146
|
ModelAndView mv = new ModelAndView();
|
147
|
|
148
|
List<Language> languages = LocaleContext.getLanguages();
|
149
|
|
150
|
if(!(description instanceof TaxonDescription)){
|
151
|
HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
|
152
|
// will terminate thread
|
153
|
}
|
154
|
|
155
|
FeatureTree featureTree = featureTreeService.load(featureTreeUuid, null);
|
156
|
if(featureTree == null){
|
157
|
HttpStatusMessage.UUID_NOT_FOUND.send(response);
|
158
|
// will terminate thread
|
159
|
}
|
160
|
|
161
|
String naturalLanguageDescription = service.generateNaturalLanguageDescription(
|
162
|
featureTree,
|
163
|
(TaxonDescription)description,
|
164
|
languages,
|
165
|
", ");
|
166
|
TextData textData = TextData.NewInstance(Feature.DESCRIPTION());
|
167
|
textData.putText(Language.DEFAULT(), naturalLanguageDescription);
|
168
|
mv.addObject(textData);
|
169
|
return mv;
|
170
|
}
|
171
|
|
172
|
|
173
|
|
174
|
}
|