Project

General

Profile

Download (5.64 KB) Statistics
| Branch: | Tag: | Revision:
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.model.agent.AgentBase;
34
import eu.etaxonomy.cdm.model.name.Rank;
35
import eu.etaxonomy.cdm.model.taxon.TaxonNodeAgentRelation;
36
import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;
37
import eu.etaxonomy.cdm.remote.editor.RankPropertyEditor;
38
import io.swagger.annotations.Api;
39

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

    
75
    private static final Logger logger = Logger.getLogger(AgentController.class);
76

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

    
83
    public List<String> getTaxonNodeAgentRelationsInitStrategy() {
84
        return TAXONNODEAGENTRELATIONS_INIT_STRATEGY;
85
    }
86

    
87
    @Autowired
88
    private ITaxonNodeService nodeService;
89

    
90
    @Autowired
91
    @Override
92
    public void setService(IAgentService service) {
93
        this.service = service;
94
    }
95

    
96
    @Override
97
    @InitBinder
98
    public void initBinder(WebDataBinder binder) {
99
        super.initBinder(binder);
100
        binder.registerCustomEditor(Rank.class, new RankPropertyEditor());
101
    }
102

    
103
    /**
104
     *
105
     * See also {@link TaxonController#doGetTaxonNodeAgentRelations(UUID, UUID, Integer, Integer, HttpServletRequest, HttpServletResponse)}
106
     *
107
     * @param uuid
108
     * @param classificationUuid
109
     * @param pageNumber
110
     * @param pageSize
111
     * @param request
112
     * @param response
113
     * @return
114
     * @throws IOException
115
     *
116
     */
117
    @RequestMapping(value = "taxonNodeAgentRelations", method = RequestMethod.GET)
118
    public Pager<TaxonNodeAgentRelation>  doGetTaxonNodeAgentRelations(
119
            @PathVariable("uuid") UUID uuid,
120
            @RequestParam(value = "classification_uuid" , required = false) UUID classificationUuid,
121
            @RequestParam(value = "taxon_uuid" , required = false) UUID taxonUuid,
122
            @RequestParam(value = "relType_uuid" , required = false) UUID relTypeUuid,
123
            @RequestParam(value = "rank" , required = false) Rank rank,
124
            @RequestParam(value = "pageNumber", required = false) Integer pageNumber,
125
            @RequestParam(value = "pageSize", required = false) Integer pageSize,
126
            HttpServletRequest request,
127
            HttpServletResponse response) throws IOException {
128

    
129
        logger.info("doGetTaxonNodeAgentRelations" + requestPathAndQuery(request));
130

    
131
        PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);
132
        pagerParams.normalizeAndValidate(response);
133

    
134
        UUID rankUuid = null;
135
        if(rank != null) {
136
            rankUuid = rank.getUuid();
137
        }
138
        Pager<TaxonNodeAgentRelation> pager = nodeService.pageTaxonNodeAgentRelations(taxonUuid, classificationUuid, uuid,
139
                rankUuid, relTypeUuid, pagerParams.getPageSize(), pagerParams.getPageIndex(), getTaxonNodeAgentRelationsInitStrategy());
140
        return pager;
141
    }
142

    
143
}
(5-5/75)