missing implementations for the generic controller architeture (works for data portal...
[cdmlib.git] / 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 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.description.TaxonNameDescription;
32 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
33 import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
34
35 /**
36 * The NamePortalController class is a Spring MVC Controller.
37 * <p>
38 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
39 * The available {datasource-name}s are defined in a configuration file which
40 * is loaded by the {@link UpdatableRoutingDataSource}. If the
41 * UpdatableRoutingDataSource is not being used in the actual application
42 * context any arbitrary {datasource-name} may be used.
43 * <p>
44 * Methods mapped at type level, inherited from super classes ({@link BaseController}):
45 * <blockquote>
46 * URI: <b>&#x002F;{datasource-name}&#x002F;portal&#x002F;name&#x002F;{name-uuid}</b>
47 *
48 * Get the {@link TaxonNameBase} instance identified by the <code>{name-uuid}</code>.
49 * The returned TaxonNameBase is initialized by
50 * the following strategy: -- NONE --
51 * </blockquote>
52 *
53 * @author a.kohlbecker
54 * @date 24.03.2009
55 */
56
57 @Controller
58 @RequestMapping(value = {"/portal/name/{uuid}"})
59 public class NamePortalController extends BaseController<TaxonNameBase, INameService>
60 {
61
62 private static final List<String> TYPEDESIGNATION_INIT_STRATEGY = Arrays.asList(new String []{
63 "typeName.$",
64 "typeName.titleCache",
65 "typeSpecimen.titleCache",
66 "typeStatus.representations",
67 "typeStatus.representations",
68 "typifiedNames.titleCache",
69 "citation",
70 "citation.authorTeam.$",
71 "typeSpecimen.media.representations.parts"
72 });
73
74
75 private static final List<String> NAMEDESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{
76 "uuid",
77 "feature",
78 "elements.$",
79 "elements.multilanguageText",
80 "elements.media.representations.parts",
81 "elements.media.title",
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 ModelAndView 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 mv.addObject(p.getRecords());
125 return mv;
126 }
127
128 /**
129 * Get the list of {@link TaxonNameDescription}s of the Name associated with the
130 * {@link TaxonNameBase} instance identified by the <code>{name-uuid}</code>.
131 * <p>
132 * URI: <b>&#x002F;{datasource-name}&#x002F;portal&#x002F;name&#x002F;{name-uuid}&#x002F;descriptions</b>
133 *
134 * @param request
135 * @param response
136 * @return a List of {@link TaxonNameDescription} entities which are initialized
137 * using the following initialization strategy:
138 * {@link #NAMEDESCRIPTION_INIT_STRATEGY}
139 * @throws IOException
140 */
141 @RequestMapping(
142 value = {"taxonNameDescriptions"},
143 method = RequestMethod.GET)
144 public List<TaxonNameDescription> doGetNameDescriptions(@PathVariable("uuid") UUID uuid,
145 HttpServletRequest request, HttpServletResponse response)throws IOException {
146 logger.info("doGetNameDescriptions()" + request.getServletPath());
147 TaxonNameBase tnb = service.load(uuid, null);
148 Pager<TaxonNameDescription> p = descriptionService.getTaxonNameDescriptions(tnb, null, null, NAMEDESCRIPTION_INIT_STRATEGY);
149 return p.getRecords();
150 }
151
152
153 }