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