fixing problems with ordered Distributions (preliminar solution)
[cdmlib.git] / cdmlib-remote / src / main / java / eu / etaxonomy / cdm / remote / controller / NameController.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.ArrayList;
15 import java.util.Arrays;
16 import java.util.List;
17 import java.util.UUID;
18
19 import javax.servlet.http.HttpServletRequest;
20 import javax.servlet.http.HttpServletResponse;
21
22 import org.springframework.beans.factory.annotation.Autowired;
23 import org.springframework.stereotype.Controller;
24 import org.springframework.web.bind.WebDataBinder;
25 import org.springframework.web.bind.annotation.InitBinder;
26 import org.springframework.web.bind.annotation.RequestMapping;
27 import org.springframework.web.bind.annotation.RequestMethod;
28
29 import eu.etaxonomy.cdm.api.service.INameService;
30 import eu.etaxonomy.cdm.api.service.pager.Pager;
31 import eu.etaxonomy.cdm.model.name.NonViralName;
32 import eu.etaxonomy.cdm.model.name.Rank;
33 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
34 import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
35 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
36 import eu.etaxonomy.cdm.remote.dto.tdwg.voc.TaxonName;
37 import eu.etaxonomy.cdm.remote.editor.RankPropertyEditor;
38 import eu.etaxonomy.cdm.remote.editor.UUIDPropertyEditor;
39
40 /**
41 * TODO write controller documentation
42 *
43 * @author a.kohlbecker
44 * @date 24.03.2009
45 */
46
47 @Controller
48 @RequestMapping(value = {"/name/*", "/name/{uuid}"})
49 public class NameController extends AnnotatableController<TaxonNameBase, INameService>
50 {
51
52 private static final List<String> TYPEDESIGNATION_INIT_STRATEGY = Arrays.asList(new String []{
53 "$",
54 "citation.authorTeam",
55 "typifiedNames.taggedName"
56 });
57
58 private static final List<String> NAME_CACHE_INIT_STRATEGY = Arrays.asList(new String []{
59 "titleCache"
60 });
61
62 public NameController(){
63 super();
64 setUuidParameterPattern("^/name/([^/?#&\\.]+).*");
65 setInitializationStrategy(Arrays.asList(new String[]{"$"}));
66 }
67
68 /* (non-Javadoc)
69 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
70 */
71 @Autowired
72 @Override
73 public void setService(INameService service) {
74 this.service = service;
75 }
76
77 @InitBinder
78 public void initBinder(WebDataBinder binder) {
79 binder.registerCustomEditor(UUID.class, new UUIDPropertyEditor());
80 }
81
82 /**
83 * Get the list of {@link TypeDesignationBase}s of the
84 * {@link TaxonNameBase} instance identified by the <code>{name-uuid}</code>.
85 * <p>
86 * URI: <b>&#x002F;{datasource-name}&#x002F;name&#x002F;{name-uuid}&#x002F;typeDesignations</b>
87 *
88 * @param request
89 * @param response
90 * @return a List of {@link TypeDesignationBase} entities which are initialized
91 * using the {@link #TYPEDESIGNATION_INIT_STRATEGY}
92 * @throws IOException
93 */
94 @RequestMapping(
95 value = {"*/typeDesignations"},
96 method = RequestMethod.GET)
97 public List<TypeDesignationBase> doGetNameDesignations(HttpServletRequest request, HttpServletResponse response)throws IOException {
98 TaxonNameBase tnb = getCdmBase(request, response, null, TaxonNameBase.class);
99 Pager<TypeDesignationBase> p = service.getTypeDesignations(tnb, null, null, null, TYPEDESIGNATION_INIT_STRATEGY);
100 return p.getRecords();
101 }
102
103 @RequestMapping(
104 value = {"*/nameCache"},
105 method = RequestMethod.GET)
106 public List<String> doGetNameCache(HttpServletRequest request, HttpServletResponse response)throws IOException {
107 TaxonNameBase tnb = getCdmBase(request, response, NAME_CACHE_INIT_STRATEGY, TaxonNameBase.class);
108 NonViralName nvn = (NonViralName) tnb;
109 String nameCacheString = nvn.getNameCache();
110 List result = new ArrayList<String>();
111 result.add(nameCacheString);
112 return result;
113 }
114
115 }