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.ArrayList;
|
14
|
import java.util.Arrays;
|
15
|
import java.util.HashSet;
|
16
|
import java.util.List;
|
17
|
import java.util.Set;
|
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.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.INameService;
|
31
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
32
|
import eu.etaxonomy.cdm.model.name.Registration;
|
33
|
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
|
34
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
35
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
36
|
import io.swagger.annotations.Api;
|
37
|
|
38
|
/**
|
39
|
* TODO write controller documentation
|
40
|
*
|
41
|
* @author a.kohlbecker
|
42
|
* @since 24.03.2009
|
43
|
*/
|
44
|
|
45
|
@Controller
|
46
|
@Api("name")
|
47
|
@RequestMapping(value = {"/name/{uuid}"})
|
48
|
public class NameController extends AbstractIdentifiableController<TaxonName, INameService>{
|
49
|
|
50
|
private static final List<String> TYPEDESIGNATION_INIT_STRATEGY = Arrays.asList(new String []{
|
51
|
"typeStatus.representations",
|
52
|
"typifiedNames",
|
53
|
"typeSpecimen",
|
54
|
"typeName",
|
55
|
"citation",
|
56
|
"citation.authorship.$",
|
57
|
});
|
58
|
|
59
|
private static final List<String> NAME_CACHE_INIT_STRATEGY = Arrays.asList(new String []{
|
60
|
|
61
|
});
|
62
|
|
63
|
private static final List<String> NAME_REGISTRATIONS_INIT_STRATEGY = Arrays.asList(new String []{
|
64
|
"registrations.typeDesignations.$",
|
65
|
"registrations.institution"
|
66
|
});
|
67
|
|
68
|
public NameController(){
|
69
|
super();
|
70
|
setInitializationStrategy(Arrays.asList(new String[]{"$"})); //TODO still needed????
|
71
|
}
|
72
|
|
73
|
@Autowired
|
74
|
@Override
|
75
|
public void setService(INameService service) {
|
76
|
this.service = service;
|
77
|
}
|
78
|
|
79
|
|
80
|
/**
|
81
|
* Get the list of {@link TypeDesignationBase}s of the
|
82
|
* {@link TaxonName} instance identified by the <code>{name-uuid}</code>.
|
83
|
* <p>
|
84
|
* URI: <b>/{datasource-name}/name/{name-uuid}/typeDesignations</b>
|
85
|
*
|
86
|
* @param request
|
87
|
* @param response
|
88
|
* @return a List of {@link TypeDesignationBase} entities which are initialized
|
89
|
* using the {@link #TYPEDESIGNATION_INIT_STRATEGY}
|
90
|
* @throws IOException
|
91
|
*
|
92
|
* TODO obsolete method?
|
93
|
*/
|
94
|
@RequestMapping(value = { "typeDesignations" }, method = RequestMethod.GET)
|
95
|
public List<TypeDesignationBase> doGetNameTypeDesignations(
|
96
|
@PathVariable("uuid") UUID uuid, HttpServletRequest request,
|
97
|
HttpServletResponse response) throws IOException {
|
98
|
|
99
|
if (request != null) {
|
100
|
logger.info("doGetTypeDesignations()" + requestPathAndQuery(request));
|
101
|
}
|
102
|
TaxonName tnb = getCdmBaseInstance(uuid, response,
|
103
|
(List<String>) null);
|
104
|
Pager<TypeDesignationBase> p = service.getTypeDesignations(tnb, null,
|
105
|
null, null, TYPEDESIGNATION_INIT_STRATEGY);
|
106
|
return p.getRecords();
|
107
|
}
|
108
|
|
109
|
@RequestMapping(
|
110
|
value = {"nameCache"},
|
111
|
method = RequestMethod.GET)
|
112
|
public List<String> doGetNameCache(@PathVariable("uuid") UUID uuid,
|
113
|
HttpServletRequest request, HttpServletResponse response)throws IOException {
|
114
|
|
115
|
logger.info("doGetNameCache()" + requestPathAndQuery(request));
|
116
|
TaxonName tnb = getCdmBaseInstance(uuid, response, NAME_CACHE_INIT_STRATEGY);
|
117
|
String nameCacheString = tnb.getNameCache();
|
118
|
List<String> result = new ArrayList<>();
|
119
|
result.add(nameCacheString);
|
120
|
return result;
|
121
|
|
122
|
}
|
123
|
|
124
|
@RequestMapping(value = "taggedName", method = RequestMethod.GET)
|
125
|
public ModelAndView doGetTaggedName(
|
126
|
@PathVariable("uuid") UUID uuid,
|
127
|
HttpServletRequest request,
|
128
|
HttpServletResponse response) throws IOException {
|
129
|
logger.info("doGetDescriptionElementsByType() - " + requestPathAndQuery(request));
|
130
|
|
131
|
ModelAndView mv = new ModelAndView();
|
132
|
mv.addObject(service.getTaggedName(uuid));
|
133
|
return mv;
|
134
|
}
|
135
|
|
136
|
@RequestMapping(
|
137
|
value = {"registrations"},
|
138
|
method = RequestMethod.GET)
|
139
|
public Set<Registration> doGetRegistrations(@PathVariable("uuid") UUID uuid,
|
140
|
HttpServletRequest request, HttpServletResponse response)throws IOException {
|
141
|
|
142
|
logger.info("doGetRegistrations" + requestPathAndQuery(request));
|
143
|
TaxonName tnb = getCdmBaseInstance(uuid, response, NAME_REGISTRATIONS_INIT_STRATEGY);
|
144
|
Set<Registration> regs = tnb.getRegistrations();
|
145
|
if(regs != null && regs.size() > 0){
|
146
|
Set<Registration> regsFiltered = new HashSet<>(regs.size());
|
147
|
for(Registration reg : regs){
|
148
|
if(userIsAutheticated() && userIsAnnonymous() && reg.getStatus().equals(RegistrationStatus.PUBLISHED)) {
|
149
|
regsFiltered.add(reg);
|
150
|
} else {
|
151
|
logger.debug("skipping unpublished registration");
|
152
|
}
|
153
|
}
|
154
|
return regsFiltered;
|
155
|
}
|
156
|
return null;
|
157
|
}
|
158
|
|
159
|
|
160
|
}
|