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.springframework.beans.factory.annotation.Autowired;
|
21
|
import org.springframework.stereotype.Controller;
|
22
|
import org.springframework.web.bind.annotation.PathVariable;
|
23
|
import org.springframework.web.bind.annotation.RequestMapping;
|
24
|
import org.springframework.web.bind.annotation.RequestMethod;
|
25
|
import org.springframework.web.servlet.ModelAndView;
|
26
|
|
27
|
import eu.etaxonomy.cdm.api.service.IDescriptionService;
|
28
|
import eu.etaxonomy.cdm.api.service.INameService;
|
29
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
30
|
import eu.etaxonomy.cdm.database.UpdatableRoutingDataSource;
|
31
|
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
|
32
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
33
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
34
|
import io.swagger.annotations.Api;
|
35
|
|
36
|
/**
|
37
|
* The NamePortalController class is a Spring MVC Controller.
|
38
|
* <p>
|
39
|
* The syntax of the mapped service URIs contains the the {datasource-name} path element.
|
40
|
* The available {datasource-name}s are defined in a configuration file which
|
41
|
* is loaded by the {@link UpdatableRoutingDataSource}. If the
|
42
|
* UpdatableRoutingDataSource is not being used in the actual application
|
43
|
* context any arbitrary {datasource-name} may be used.
|
44
|
* <p>
|
45
|
* Methods mapped at type level, inherited from super classes ({@link BaseController}):
|
46
|
* <blockquote>
|
47
|
* URI: <b>/{datasource-name}/portal/name/{name-uuid}</b>
|
48
|
*
|
49
|
* Get the {@link TaxonName} instance identified by the <code>{name-uuid}</code>.
|
50
|
* The returned TaxonName is initialized by
|
51
|
* the following strategy: -- NONE --
|
52
|
* </blockquote>
|
53
|
*
|
54
|
* @author a.kohlbecker
|
55
|
* @date 24.03.2009
|
56
|
*/
|
57
|
|
58
|
@Controller
|
59
|
@Api("portal_name")
|
60
|
@RequestMapping(value = {"/portal/name/{uuid}"})
|
61
|
public class NamePortalController extends BaseController<TaxonName, INameService>
|
62
|
{
|
63
|
|
64
|
private static final List<String> TYPEDESIGNATION_INIT_STRATEGY = Arrays.asList(new String []{
|
65
|
"typeName.$",
|
66
|
"typeSpecimen",
|
67
|
"typeStatus.representations",
|
68
|
"typifiedNames.nomenclaturalReference.authorship",
|
69
|
"citation.authorship.$",
|
70
|
"typeSpecimen.media"
|
71
|
});
|
72
|
|
73
|
|
74
|
private static final List<String> NAMEDESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{
|
75
|
"elements.$",
|
76
|
"elements.multilanguageText",
|
77
|
"elements.media",
|
78
|
});
|
79
|
|
80
|
|
81
|
// public NamePortalController(){
|
82
|
// super();
|
83
|
// setInitializationStrategy(Arrays.asList(new String[]{"$"})); //TODO required???
|
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(INameService service) {
|
92
|
this.service = service;
|
93
|
}
|
94
|
|
95
|
@Autowired
|
96
|
private IDescriptionService descriptionService;
|
97
|
|
98
|
/**
|
99
|
* Get the list of {@link TypeDesignationBase}s of the
|
100
|
* {@link TaxonName} instance identified by the <code>{name-uuid}</code>.
|
101
|
* <p>
|
102
|
* URI: <b>/{datasource-name}/portal/name/{name-uuid}/typeDesignations</b>
|
103
|
*
|
104
|
* @param request
|
105
|
* @param response
|
106
|
* @return a List of {@link TypeDesignationBase} entities which are initialized
|
107
|
* using the following initialization strategy:
|
108
|
* {@link #TYPEDESIGNATION_INIT_STRATEGY}
|
109
|
* @throws IOException
|
110
|
*/
|
111
|
@SuppressWarnings("unchecked")
|
112
|
@RequestMapping(
|
113
|
value = {"typeDesignations"},
|
114
|
method = RequestMethod.GET)
|
115
|
public List<TypeDesignationBase> doGetTypeDesignations(@PathVariable("uuid") UUID uuid,
|
116
|
HttpServletRequest request, HttpServletResponse response)throws IOException {
|
117
|
ModelAndView mv = new ModelAndView();
|
118
|
TaxonName tnb = getCdmBaseInstance(uuid, response, (List<String>)null);
|
119
|
Pager<TypeDesignationBase> p = service.getTypeDesignations(tnb, null, null, null, TYPEDESIGNATION_INIT_STRATEGY);
|
120
|
return p.getRecords();
|
121
|
}
|
122
|
|
123
|
/**
|
124
|
* Get the list of {@link TaxonNameDescription}s of the Name associated with the
|
125
|
* {@link TaxonName} instance identified by the <code>{name-uuid}</code>.
|
126
|
* <p>
|
127
|
* URI: <b>/{datasource-name}/portal/name/{name-uuid}/descriptions</b>
|
128
|
*
|
129
|
* @param request
|
130
|
* @param response
|
131
|
* @return a List of {@link TaxonNameDescription} entities which are initialized
|
132
|
* using the following initialization strategy:
|
133
|
* {@link #NAMEDESCRIPTION_INIT_STRATEGY}
|
134
|
* @throws IOException
|
135
|
*/
|
136
|
@RequestMapping(
|
137
|
value = {"taxonNameDescriptions"},
|
138
|
method = RequestMethod.GET)
|
139
|
public List<TaxonNameDescription> doGetNameDescriptions(@PathVariable("uuid") UUID uuid,
|
140
|
HttpServletRequest request, HttpServletResponse response)throws IOException {
|
141
|
logger.info("doGetNameDescriptions()" + request.getRequestURI());
|
142
|
TaxonName tnb = service.load(uuid, null);
|
143
|
Pager<TaxonNameDescription> p = descriptionService.getTaxonNameDescriptions(tnb, null, null, NAMEDESCRIPTION_INIT_STRATEGY);
|
144
|
return p.getRecords();
|
145
|
}
|
146
|
|
147
|
|
148
|
}
|