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.bind.annotation.RequestParam;
|
29
|
|
30
|
import eu.etaxonomy.cdm.api.service.IAgentService;
|
31
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
32
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
33
|
import eu.etaxonomy.cdm.database.UpdatableRoutingDataSource;
|
34
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
35
|
import eu.etaxonomy.cdm.model.name.Rank;
|
36
|
import eu.etaxonomy.cdm.model.taxon.TaxonNodeAgentRelation;
|
37
|
import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;
|
38
|
import eu.etaxonomy.cdm.remote.editor.RankPropertyEditor;
|
39
|
import io.swagger.annotations.Api;
|
40
|
|
41
|
/**
|
42
|
* The AgentController class is a Spring MVC Controller.
|
43
|
* <p>
|
44
|
* The syntax of the mapped service URIs contains the the {datasource-name} path element.
|
45
|
* The available {datasource-name}s are defined in a configuration file which
|
46
|
* is loaded by the {@link UpdatableRoutingDataSource}. If the
|
47
|
* UpdatableRoutingDataSource is not being used in the actual application
|
48
|
* context any arbitrary {datasource-name} may be used.
|
49
|
* <p>
|
50
|
* Methods mapped at type level, inherited from super classes ({@link BaseController}):
|
51
|
* <blockquote>
|
52
|
* URI: <b>/{datasource-name}/agent/name/{agent-uuid}</b>
|
53
|
*
|
54
|
* Get the {@link AgentBase} instance identified by the <code>{agent-uuid}</code>.
|
55
|
* The returned AgentBase is initialized by
|
56
|
* the default initialization strategy: {@link #DEFAULT_INIT_STRATEGY}
|
57
|
* </blockquote>
|
58
|
* <blockquote>
|
59
|
* URI: <b>/{datasource-name}/agent/name/{agent-uuid}/annotation</b>
|
60
|
*
|
61
|
* Returns a {@link Pager} on the {@link Annotation}s for the {@link AgentBase} instance identified by the
|
62
|
* <code>{agent-uuid}</code>.
|
63
|
* The returned AgentBase instances are initialized by
|
64
|
* the following strategy: {@link #ANNOTATION_INIT_STRATEGY}
|
65
|
* </blockquote>
|
66
|
*
|
67
|
* @author a.kohlbecker
|
68
|
* @since 24.03.2009
|
69
|
*/
|
70
|
@Controller
|
71
|
@Api(value = "agent")
|
72
|
@RequestMapping(value = {"/agent/{uuid}"})
|
73
|
public class AgentController extends AbstractIdentifiableController<AgentBase, IAgentService>
|
74
|
{
|
75
|
|
76
|
private static final Logger logger = Logger.getLogger(AgentController.class);
|
77
|
|
78
|
private static final List<String> TAXONNODEAGENTRELATIONS_INIT_STRATEGY = Arrays.asList(new String[]{
|
79
|
// NOTE: all other cases are covered in the TaxonNodeDaoHibernateImpl method
|
80
|
// which is using join fetches
|
81
|
"taxonNode.taxon.name.nomenclaturalSource.citation",
|
82
|
});
|
83
|
|
84
|
public List<String> getTaxonNodeAgentRelationsInitStrategy() {
|
85
|
return TAXONNODEAGENTRELATIONS_INIT_STRATEGY;
|
86
|
}
|
87
|
|
88
|
@Autowired
|
89
|
private ITaxonNodeService nodeService;
|
90
|
|
91
|
@Autowired
|
92
|
@Override
|
93
|
public void setService(IAgentService service) {
|
94
|
this.service = service;
|
95
|
}
|
96
|
|
97
|
@Override
|
98
|
@InitBinder
|
99
|
public void initBinder(WebDataBinder binder) {
|
100
|
super.initBinder(binder);
|
101
|
binder.registerCustomEditor(Rank.class, new RankPropertyEditor());
|
102
|
}
|
103
|
|
104
|
/**
|
105
|
*
|
106
|
* See also {@link TaxonController#doGetTaxonNodeAgentRelations(UUID, UUID, Integer, Integer, HttpServletRequest, HttpServletResponse)}
|
107
|
*
|
108
|
* @param uuid
|
109
|
* @param classificationUuid
|
110
|
* @param pageIndex
|
111
|
* @param pageSize
|
112
|
* @param request
|
113
|
* @param response
|
114
|
* @return
|
115
|
* @throws IOException
|
116
|
*
|
117
|
*/
|
118
|
@RequestMapping(value = "taxonNodeAgentRelations", method = RequestMethod.GET)
|
119
|
public Pager<TaxonNodeAgentRelation> doGetTaxonNodeAgentRelations(
|
120
|
@PathVariable("uuid") UUID uuid,
|
121
|
@RequestParam(value = "classification_uuid" , required = false) UUID classificationUuid,
|
122
|
@RequestParam(value = "taxon_uuid" , required = false) UUID taxonUuid,
|
123
|
@RequestParam(value = "relType_uuid" , required = false) UUID relTypeUuid,
|
124
|
@RequestParam(value = "rank" , required = false) Rank rank,
|
125
|
@RequestParam(value = "pageIndex", required = false) Integer pageIndex,
|
126
|
@RequestParam(value = "pageSize", required = false) Integer pageSize,
|
127
|
HttpServletRequest request,
|
128
|
HttpServletResponse response) throws IOException {
|
129
|
|
130
|
logger.info("doGetTaxonNodeAgentRelations" + requestPathAndQuery(request));
|
131
|
|
132
|
PagerParameters pagerParams = new PagerParameters(pageSize, pageIndex);
|
133
|
pagerParams.normalizeAndValidate(response);
|
134
|
|
135
|
UUID rankUuid = null;
|
136
|
if(rank != null) {
|
137
|
rankUuid = rank.getUuid();
|
138
|
}
|
139
|
Pager<TaxonNodeAgentRelation> pager = nodeService.pageTaxonNodeAgentRelations(taxonUuid, classificationUuid, uuid,
|
140
|
rankUuid, relTypeUuid, pagerParams.getPageSize(), pagerParams.getPageIndex(), getTaxonNodeAgentRelationsInitStrategy());
|
141
|
return pager;
|
142
|
}
|
143
|
|
144
|
}
|