optimizing initialization strategies
[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.PathVariable;
27 import org.springframework.web.bind.annotation.RequestMapping;
28 import org.springframework.web.bind.annotation.RequestMethod;
29
30 import eu.etaxonomy.cdm.api.service.INameService;
31 import eu.etaxonomy.cdm.api.service.pager.Pager;
32 import eu.etaxonomy.cdm.model.name.NonViralName;
33 import eu.etaxonomy.cdm.model.name.Rank;
34 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
35 import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
36 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
37 import eu.etaxonomy.cdm.remote.dto.tdwg.voc.TaxonName;
38 import eu.etaxonomy.cdm.remote.editor.RankPropertyEditor;
39 import eu.etaxonomy.cdm.remote.editor.UUIDPropertyEditor;
40
41 /**
42 * TODO write controller documentation
43 *
44 * @author a.kohlbecker
45 * @date 24.03.2009
46 */
47
48 @Controller
49 @RequestMapping(value = {"/name/{uuid}"})
50 public class NameController extends AnnotatableController<TaxonNameBase, INameService>
51 {
52
53 private static final List<String> TYPEDESIGNATION_INIT_STRATEGY = Arrays.asList(new String []{
54 "typeStatus.representations",
55 "typifiedNames",
56 "typeSpecimen",
57 "typeName",
58 "citation",
59 "citation.authorTeam.$",
60 });
61
62 private static final List<String> NAME_CACHE_INIT_STRATEGY = Arrays.asList(new String []{
63
64 });
65
66 public NameController(){
67 super();
68 setInitializationStrategy(Arrays.asList(new String[]{"$"})); //TODO still needed????
69 }
70
71 /* (non-Javadoc)
72 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
73 */
74 @Autowired
75 @Override
76 public void setService(INameService service) {
77 this.service = service;
78 }
79
80
81 /**
82 * Get the list of {@link TypeDesignationBase}s of the
83 * {@link TaxonNameBase} instance identified by the <code>{name-uuid}</code>.
84 * <p>
85 * URI: <b>&#x002F;{datasource-name}&#x002F;name&#x002F;{name-uuid}&#x002F;typeDesignations</b>
86 *
87 * @param request
88 * @param response
89 * @return a List of {@link TypeDesignationBase} entities which are initialized
90 * using the {@link #TYPEDESIGNATION_INIT_STRATEGY}
91 * @throws IOException
92 *///TODO obsolete method?
93 @RequestMapping(value = { "typeDesignations" }, method = RequestMethod.GET)
94 public List<TypeDesignationBase> doGetNameTypeDesignations(
95 @PathVariable("uuid") UUID uuid, HttpServletRequest request,
96 HttpServletResponse response) throws IOException {
97
98 logger.info("doGetTypeDesignations()" + request.getServletPath());
99 TaxonNameBase tnb = getCdmBaseInstance(uuid, response,
100 (List<String>) null);
101 Pager<TypeDesignationBase> p = service.getTypeDesignations(tnb, null,
102 null, null, TYPEDESIGNATION_INIT_STRATEGY);
103 return p.getRecords();
104
105 }
106
107 //TODO obsolete method?
108 @RequestMapping(
109 value = {"nameCache"},
110 method = RequestMethod.GET)
111 public List<String> doGetNameCache(@PathVariable("uuid") UUID uuid,
112 HttpServletRequest request, HttpServletResponse response)throws IOException {
113
114 logger.info("doGetNameCache()" + request.getServletPath());
115 TaxonNameBase tnb = getCdmBaseInstance(uuid, response, NAME_CACHE_INIT_STRATEGY);
116 NonViralName nvn = (NonViralName) tnb;
117 String nameCacheString = nvn.getNameCache();
118 List result = new ArrayList<String>();
119 result.add(nameCacheString);
120 return result;
121
122 }
123
124 }