Project

General

Profile

Download (6.94 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.annotation.PathVariable;
24
import org.springframework.web.bind.annotation.RequestMapping;
25
import org.springframework.web.bind.annotation.RequestMethod;
26
import org.springframework.web.servlet.ModelAndView;
27

    
28
import eu.etaxonomy.cdm.api.service.IDescriptionService;
29
import eu.etaxonomy.cdm.api.service.INameService;
30
import eu.etaxonomy.cdm.api.service.pager.Pager;
31
import eu.etaxonomy.cdm.model.common.CdmBase;
32
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
33
import eu.etaxonomy.cdm.model.name.TaxonName;
34
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
35
import eu.etaxonomy.cdm.persistence.dao.initializer.EntityInitStrategy;
36
import io.swagger.annotations.Api;
37

    
38
/**
39
 * The NamePortalController class is a Spring MVC Controller.
40
 * <p>
41
 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
42
 * The available {datasource-name}s are defined in a configuration file which
43
 * is loaded by the {@link UpdatableRoutingDataSource}. If the
44
 * UpdatableRoutingDataSource is not being used in the actual application
45
 * context any arbitrary {datasource-name} may be used.
46
 * <p>
47
 * Methods mapped at type level, inherited from super classes ({@link BaseController}):
48
 * <blockquote>
49
 * URI: <b>&#x002F;{datasource-name}&#x002F;portal&#x002F;name&#x002F;{name-uuid}</b>
50
 *
51
 * Get the {@link TaxonName} instance identified by the <code>{name-uuid}</code>.
52
 * The returned TaxonName is initialized by
53
 * the following strategy: -- NONE --
54
 * </blockquote>
55
 *
56
 * @author a.kohlbecker
57
 * @since 24.03.2009
58
 */
59

    
60
@Controller
61
@Api("portal_name")
62
@RequestMapping(value = {"/portal/name/{uuid}"})
63
public class NamePortalController extends BaseController<TaxonName, INameService> {
64

    
65
    private static final Logger logger = Logger.getLogger(NamePortalController.class);
66

    
67
    private static final List<String> TYPEDESIGNATION_INIT_STRATEGY = Arrays.asList(new String []{
68
            "typeName.$",
69
            "typeSpecimen",
70
            "typeStatus.representations",
71
            "typifiedNames.nomenclaturalReference.authorship",
72
            "citation.authorship.$",
73
            "typeSpecimen.media",
74
            "registrations.institution"
75
    });
76

    
77

    
78
    private static final List<String> NAMEDESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{
79
            "elements.$",
80
            "elements.multilanguageText",
81
            "elements.media",
82
    });
83

    
84
    @Override
85
    protected <CDM_BASE extends CdmBase> List<String> complementInitStrategy(Class<CDM_BASE> clazz,
86
            List<String> pathProperties) {
87

    
88
        if(pathProperties == null){
89
            return pathProperties;
90
        }
91

    
92
        EntityInitStrategy initStrategy = new EntityInitStrategy(pathProperties);
93

    
94
        if(pathProperties.contains("nameRelations")){
95
            // nameRelations is a transient property!
96
            initStrategy.getPropertyPaths().remove("nameRelations");
97
            initStrategy.extend("relationsFromThisName", TaxonPortalController.NAMERELATIONSHIP_INIT_STRATEGY, true);
98
            initStrategy.extend("relationsToThisName", TaxonPortalController.NAMERELATIONSHIP_INIT_STRATEGY, true);
99
        } else {
100
            if(pathProperties.contains("relationsFromThisName")){
101
                initStrategy.getPropertyPaths().remove("relationsFromThisName");
102
                initStrategy.extend("relationsFromThisName", TaxonPortalController.NAMERELATIONSHIP_INIT_STRATEGY, true);
103
            }
104
            if(pathProperties.contains("relationsToThisName")){
105
                initStrategy.getPropertyPaths().remove("relationsToThisName");
106
                initStrategy.extend("relationsToThisName", TaxonPortalController.NAMERELATIONSHIP_INIT_STRATEGY, true);
107
            }
108
        }
109

    
110
        return initStrategy.getPropertyPaths();
111
    }
112

    
113
    /* (non-Javadoc)
114
     * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
115
     */
116
    @Autowired
117
    @Override
118
    public void setService(INameService service) {
119
        this.service = service;
120
    }
121

    
122
    @Autowired
123
    private IDescriptionService descriptionService;
124

    
125
    /**
126
     * Get the list of {@link TypeDesignationBase}s of the
127
     * {@link TaxonName} instance identified by the <code>{name-uuid}</code>.
128
     * <p>
129
     * URI: <b>&#x002F;{datasource-name}&#x002F;portal&#x002F;name&#x002F;{name-uuid}&#x002F;typeDesignations</b>
130
     *
131
     * @param request
132
     * @param response
133
     * @return a List of {@link TypeDesignationBase} entities which are initialized
134
     *         using the following initialization strategy:
135
     *         {@link #TYPEDESIGNATION_INIT_STRATEGY}
136
     * @throws IOException
137
     */
138
    @SuppressWarnings("unchecked")
139
    @RequestMapping(
140
            value = {"typeDesignations"},
141
            method = RequestMethod.GET)
142
    public List<TypeDesignationBase> doGetTypeDesignations(@PathVariable("uuid") UUID uuid,
143
            HttpServletRequest request, HttpServletResponse response)throws IOException {
144
        ModelAndView mv = new ModelAndView();
145
        TaxonName tnb = getCdmBaseInstance(uuid, response, (List<String>)null);
146
        Pager<TypeDesignationBase> p = service.getTypeDesignations(tnb,  null, null, null, TYPEDESIGNATION_INIT_STRATEGY);
147
        return p.getRecords();
148
    }
149

    
150
    /**
151
     * Get the list of {@link TaxonNameDescription}s of the Name associated with the
152
     * {@link TaxonName} instance identified by the <code>{name-uuid}</code>.
153
     * <p>
154
     * URI: <b>&#x002F;{datasource-name}&#x002F;portal&#x002F;name&#x002F;{name-uuid}&#x002F;descriptions</b>
155
     *
156
     * @param request
157
     * @param response
158
     * @return a List of {@link TaxonNameDescription} entities which are initialized
159
     *         using the following initialization strategy:
160
     *         {@link #NAMEDESCRIPTION_INIT_STRATEGY}
161
     * @throws IOException
162
     */
163
    @RequestMapping(
164
            value = {"taxonNameDescriptions"},
165
            method = RequestMethod.GET)
166
    public List<TaxonNameDescription> doGetNameDescriptions(@PathVariable("uuid") UUID uuid,
167
            HttpServletRequest request, HttpServletResponse response)throws IOException {
168
        logger.info("doGetNameDescriptions()" + request.getRequestURI());
169
        TaxonName tnb = service.load(uuid, null);
170
        Pager<TaxonNameDescription> p = descriptionService.getTaxonNameDescriptions(tnb, null, null, NAMEDESCRIPTION_INIT_STRATEGY);
171
        return p.getRecords();
172
    }
173

    
174

    
175
}
(40-40/70)