Project

General

Profile

Download (6.66 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

    
11
package eu.etaxonomy.cdm.remote.controller;
12

    
13
import io.swagger.annotations.Api;
14

    
15
import java.io.IOException;
16
import java.util.Arrays;
17
import java.util.List;
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.WebDataBinder;
26
import org.springframework.web.bind.annotation.InitBinder;
27
import org.springframework.web.bind.annotation.PathVariable;
28
import org.springframework.web.bind.annotation.RequestMapping;
29
import org.springframework.web.bind.annotation.RequestMethod;
30
import org.springframework.web.bind.annotation.RequestParam;
31
import org.springframework.web.servlet.ModelAndView;
32

    
33
import eu.etaxonomy.cdm.api.service.IAgentService;
34
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
35
import eu.etaxonomy.cdm.api.service.pager.Pager;
36
import eu.etaxonomy.cdm.database.UpdatableRoutingDataSource;
37
import eu.etaxonomy.cdm.model.agent.AgentBase;
38
import eu.etaxonomy.cdm.model.common.Annotation;
39
import eu.etaxonomy.cdm.model.name.Rank;
40
import eu.etaxonomy.cdm.model.taxon.TaxonNodeAgentRelation;
41
import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;
42
import eu.etaxonomy.cdm.remote.editor.RankPropertyEditor;
43

    
44
/**
45
 * The AgentController class is a Spring MVC Controller.
46
 * <p>
47
 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
48
 * The available {datasource-name}s are defined in a configuration file which
49
 * is loaded by the {@link UpdatableRoutingDataSource}. If the
50
 * UpdatableRoutingDataSource is not being used in the actual application
51
 * context any arbitrary {datasource-name} may be used.
52
 * <p>
53
 * Methods mapped at type level, inherited from super classes ({@link BaseController}):
54
 * <blockquote>
55
 * URI: <b>&#x002F;{datasource-name}&#x002F;agent&#x002F;name&#x002F;{agent-uuid}</b>
56
 *
57
 * Get the {@link AgentBase} instance identified by the <code>{agent-uuid}</code>.
58
 * The returned AgentBase is initialized by
59
 * the default initialization strategy: {@link #DEFAULT_INIT_STRATEGY}
60
 * </blockquote>
61
 * <blockquote>
62
 * URI: <b>&#x002F;{datasource-name}&#x002F;agent&#x002F;name&#x002F;{agent-uuid}&#x002F;annotation</b>
63
 *
64
 * Returns a {@link Pager} on the {@link Annotation}s for the {@link AgentBase} instance identified by the
65
 * <code>{agent-uuid}</code>.
66
 * The returned AgentBase instances are initialized by
67
 * the following strategy: {@link #ANNOTATION_INIT_STRATEGY}
68
 * </blockquote>
69
 *
70
 * @author a.kohlbecker
71
 * @date 24.03.2009
72
 */
73
@Controller
74
@Api(value = "agent")
75
@RequestMapping(value = {"/agent/{uuid}"})
76
public class AgentController extends BaseController<AgentBase, IAgentService>
77
{
78

    
79
    private static final List<String> TAXONNODEAGENTRELATIONS_INIT_STRATEGY = Arrays.asList(new String[]{
80
            // NOTE: all other cases are covered in the TaxonNodeDaoHibernateImpl method
81
            // which is using join fetches
82
            "taxonNode.taxon.name.nomenclaturalReference",
83
            });
84

    
85
    public List<String> getTaxonNodeAgentRelationsInitStrategy() {
86
        return TAXONNODEAGENTRELATIONS_INIT_STRATEGY;
87
    }
88

    
89
    @Autowired
90
    private ITaxonNodeService nodeService;
91

    
92
    /* (non-Javadoc)
93
     * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
94
     */
95
    @Autowired
96
    @Override
97
    public void setService(IAgentService service) {
98
        this.service = service;
99
    }
100

    
101
    @Override
102
    @InitBinder
103
    public void initBinder(WebDataBinder binder) {
104
        super.initBinder(binder);
105
        binder.registerCustomEditor(Rank.class, new RankPropertyEditor());
106
    }
107

    
108
    /**
109
     * This method is only needed for
110
     * {@link eu.etaxonomy.cdm.model.agent.TeamOrPersonBase} or sub classes
111
     * which are also handled by this controller.
112
     *
113
     * The method
114
     * {@link eu.etaxonomy.cdm.model.agent.TeamOrPersonBase#getTitleCache() } is
115
     * annotated with @Transient and thus it is not automatically made available
116
     * by the BaseController.
117
     *
118
     * @param uuid
119
     * @param request
120
     * @param response
121
     * @return
122
     * @throws IOException
123
     */
124
    @RequestMapping(value = {"titleCache"}, method = RequestMethod.GET)
125
    public ModelAndView doGetTitleCache(@PathVariable("uuid") UUID uuid,
126
            HttpServletRequest request, HttpServletResponse response) throws IOException {
127
        ModelAndView mv = new ModelAndView();
128
        AgentBase<?> agentbase = service.load(uuid);
129
        mv.addObject(agentbase.getTitleCache());
130
        return mv;
131

    
132
    }
133
    /**
134
     *
135
     * See also {@link TaxonController#doGetTaxonNodeAgentRelations(UUID, UUID, Integer, Integer, HttpServletRequest, HttpServletResponse)}
136
     *
137
     * @param uuid
138
     * @param classificationUuid
139
     * @param pageNumber
140
     * @param pageSize
141
     * @param request
142
     * @param response
143
     * @return
144
     * @throws IOException
145
     *
146
     */
147
    @RequestMapping(value = "taxonNodeAgentRelations", method = RequestMethod.GET)
148
    public Pager<TaxonNodeAgentRelation>  doGetTaxonNodeAgentRelations(
149
            @PathVariable("uuid") UUID uuid,
150
            @RequestParam(value = "classification_uuid" , required = false) UUID classificationUuid,
151
            @RequestParam(value = "taxon_uuid" , required = false) UUID taxonUuid,
152
            @RequestParam(value = "relType_uuid" , required = false) UUID relTypeUuid,
153
            @RequestParam(value = "rank" , required = false) Rank rank,
154
            @RequestParam(value = "pageNumber", required = false) Integer pageNumber,
155
            @RequestParam(value = "pageSize", required = false) Integer pageSize,
156
            HttpServletRequest request,
157
            HttpServletResponse response) throws IOException {
158

    
159
        PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);
160
        pagerParams.normalizeAndValidate(response);
161

    
162
        UUID rankUuid = null;
163
        if(rank != null) {
164
            rankUuid = rank.getUuid();
165
        }
166
        Pager<TaxonNodeAgentRelation> pager = nodeService.pageTaxonNodeAgentRelations(taxonUuid, classificationUuid, uuid,
167
                rankUuid, relTypeUuid, pagerParams.getPageSize(), pagerParams.getPageIndex(), getTaxonNodeAgentRelationsInitStrategy());
168
        return pager;
169
    }
170

    
171
}
(3-3/63)