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