Project

General

Profile

« Previous | Next » 

Revision b8b8ed11

Added by Andreas Müller over 8 years ago

Fix test in dataportal with strict bean initalization #5077

View differences:

cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/NamePortalController.java
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 java.io.IOException;
14
import java.util.Arrays;
15
import java.util.List;
16
import java.util.UUID;
17

  
18
import javax.servlet.http.HttpServletRequest;
19
import javax.servlet.http.HttpServletResponse;
20

  
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 com.wordnik.swagger.annotations.Api;
29

  
30
import eu.etaxonomy.cdm.api.service.IDescriptionService;
31
import eu.etaxonomy.cdm.api.service.INameService;
32
import eu.etaxonomy.cdm.api.service.pager.Pager;
33
import eu.etaxonomy.cdm.database.UpdatableRoutingDataSource;
34
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
35
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
36
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
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 TaxonNameBase} instance identified by the <code>{name-uuid}</code>.
52
 * The returned TaxonNameBase is initialized by
53
 * the following strategy: -- NONE --
54
 * </blockquote>
55
 *
56
 * @author a.kohlbecker
57
 * @date 24.03.2009
58
 */
59

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

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

  
75

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

  
84

  
85
//	public NamePortalController(){
86
//		super();
87
//		setInitializationStrategy(Arrays.asList(new String[]{"$"})); //TODO required???
88
//	}
89

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

  
99
    @Autowired
100
    private IDescriptionService descriptionService;
101

  
102
    /**
103
     * Get the list of {@link TypeDesignationBase}s of the
104
     * {@link TaxonNameBase} instance identified by the <code>{name-uuid}</code>.
105
     * <p>
106
     * URI: <b>&#x002F;{datasource-name}&#x002F;portal&#x002F;name&#x002F;{name-uuid}&#x002F;typeDesignations</b>
107
     *
108
     * @param request
109
     * @param response
110
     * @return a List of {@link TypeDesignationBase} entities which are initialized
111
     *         using the following initialization strategy:
112
     *         {@link #TYPEDESIGNATION_INIT_STRATEGY}
113
     * @throws IOException
114
     */
115
    @SuppressWarnings("unchecked")
116
    @RequestMapping(
117
            value = {"typeDesignations"},
118
            method = RequestMethod.GET)
119
    public List<TypeDesignationBase> doGetTypeDesignations(@PathVariable("uuid") UUID uuid,
120
            HttpServletRequest request, HttpServletResponse response)throws IOException {
121
        ModelAndView mv = new ModelAndView();
122
        TaxonNameBase tnb = getCdmBaseInstance(uuid, response, (List<String>)null);
123
        Pager<TypeDesignationBase> p = service.getTypeDesignations(tnb,  null, null, null, TYPEDESIGNATION_INIT_STRATEGY);
124
        return p.getRecords();
125
    }
126

  
127
    /**
128
     * Get the list of {@link TaxonNameDescription}s of the Name associated with the
129
     * {@link TaxonNameBase} instance identified by the <code>{name-uuid}</code>.
130
     * <p>
131
     * URI: <b>&#x002F;{datasource-name}&#x002F;portal&#x002F;name&#x002F;{name-uuid}&#x002F;descriptions</b>
132
     *
133
     * @param request
134
     * @param response
135
     * @return a List of {@link TaxonNameDescription} entities which are initialized
136
     *         using the following initialization strategy:
137
     *         {@link #NAMEDESCRIPTION_INIT_STRATEGY}
138
     * @throws IOException
139
     */
140
    @RequestMapping(
141
            value = {"taxonNameDescriptions"},
142
            method = RequestMethod.GET)
143
    public List<TaxonNameDescription> doGetNameDescriptions(@PathVariable("uuid") UUID uuid,
144
            HttpServletRequest request, HttpServletResponse response)throws IOException {
145
        logger.info("doGetNameDescriptions()" + request.getRequestURI());
146
        TaxonNameBase tnb = service.load(uuid, null);
147
        Pager<TaxonNameDescription> p = descriptionService.getTaxonNameDescriptions(tnb, null, null, NAMEDESCRIPTION_INIT_STRATEGY);
148
        return p.getRecords();
149
    }
150

  
151

  
152
}
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 java.io.IOException;
14
import java.util.Arrays;
15
import java.util.List;
16
import java.util.UUID;
17

  
18
import javax.servlet.http.HttpServletRequest;
19
import javax.servlet.http.HttpServletResponse;
20

  
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 com.wordnik.swagger.annotations.Api;
29

  
30
import eu.etaxonomy.cdm.api.service.IDescriptionService;
31
import eu.etaxonomy.cdm.api.service.INameService;
32
import eu.etaxonomy.cdm.api.service.pager.Pager;
33
import eu.etaxonomy.cdm.database.UpdatableRoutingDataSource;
34
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
35
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
36
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
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 TaxonNameBase} instance identified by the <code>{name-uuid}</code>.
52
 * The returned TaxonNameBase is initialized by
53
 * the following strategy: -- NONE --
54
 * </blockquote>
55
 *
56
 * @author a.kohlbecker
57
 * @date 24.03.2009
58
 */
59

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

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

  
75

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

  
82

  
83
//	public NamePortalController(){
84
//		super();
85
//		setInitializationStrategy(Arrays.asList(new String[]{"$"})); //TODO required???
86
//	}
87

  
88
    /* (non-Javadoc)
89
     * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
90
     */
91
    @Autowired
92
    @Override
93
    public void setService(INameService service) {
94
        this.service = service;
95
    }
96

  
97
    @Autowired
98
    private IDescriptionService descriptionService;
99

  
100
    /**
101
     * Get the list of {@link TypeDesignationBase}s of the
102
     * {@link TaxonNameBase} instance identified by the <code>{name-uuid}</code>.
103
     * <p>
104
     * URI: <b>&#x002F;{datasource-name}&#x002F;portal&#x002F;name&#x002F;{name-uuid}&#x002F;typeDesignations</b>
105
     *
106
     * @param request
107
     * @param response
108
     * @return a List of {@link TypeDesignationBase} entities which are initialized
109
     *         using the following initialization strategy:
110
     *         {@link #TYPEDESIGNATION_INIT_STRATEGY}
111
     * @throws IOException
112
     */
113
    @SuppressWarnings("unchecked")
114
    @RequestMapping(
115
            value = {"typeDesignations"},
116
            method = RequestMethod.GET)
117
    public List<TypeDesignationBase> doGetTypeDesignations(@PathVariable("uuid") UUID uuid,
118
            HttpServletRequest request, HttpServletResponse response)throws IOException {
119
        ModelAndView mv = new ModelAndView();
120
        TaxonNameBase tnb = getCdmBaseInstance(uuid, response, (List<String>)null);
121
        Pager<TypeDesignationBase> p = service.getTypeDesignations(tnb,  null, null, null, TYPEDESIGNATION_INIT_STRATEGY);
122
        return p.getRecords();
123
    }
124

  
125
    /**
126
     * Get the list of {@link TaxonNameDescription}s of the Name associated with the
127
     * {@link TaxonNameBase} instance identified by the <code>{name-uuid}</code>.
128
     * <p>
129
     * URI: <b>&#x002F;{datasource-name}&#x002F;portal&#x002F;name&#x002F;{name-uuid}&#x002F;descriptions</b>
130
     *
131
     * @param request
132
     * @param response
133
     * @return a List of {@link TaxonNameDescription} entities which are initialized
134
     *         using the following initialization strategy:
135
     *         {@link #NAMEDESCRIPTION_INIT_STRATEGY}
136
     * @throws IOException
137
     */
138
    @RequestMapping(
139
            value = {"taxonNameDescriptions"},
140
            method = RequestMethod.GET)
141
    public List<TaxonNameDescription> doGetNameDescriptions(@PathVariable("uuid") UUID uuid,
142
            HttpServletRequest request, HttpServletResponse response)throws IOException {
143
        logger.info("doGetNameDescriptions()" + request.getRequestURI());
144
        TaxonNameBase tnb = service.load(uuid, null);
145
        Pager<TaxonNameDescription> p = descriptionService.getTaxonNameDescriptions(tnb, null, null, NAMEDESCRIPTION_INIT_STRATEGY);
146
        return p.getRecords();
147
    }
148

  
149

  
150
}

Also available in: Unified diff