dataportal/webservice release v2.0
[cdmlib.git] / cdmlib-remote / src / main / java / eu / etaxonomy / cdm / remote / controller / DescriptionController.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.RequestMapping;
24 import org.springframework.web.bind.annotation.RequestMethod;
25
26 import eu.etaxonomy.cdm.api.service.AnnotatableServiceBase;
27 import eu.etaxonomy.cdm.api.service.IDescriptionService;
28 import eu.etaxonomy.cdm.api.service.pager.Pager;
29 import eu.etaxonomy.cdm.model.description.DescriptionBase;
30 import eu.etaxonomy.cdm.model.description.FeatureTree;
31 import eu.etaxonomy.cdm.model.description.TaxonDescription;
32 import eu.etaxonomy.cdm.model.taxon.Taxon;
33 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
34 import eu.etaxonomy.cdm.persistence.dao.common.IAnnotatableDao;
35
36 /**
37 * @author a.kohlbecker
38 * @date 24.03.2009
39 */
40
41 @Controller
42 @RequestMapping(value = {"/*/description/*","/*/description/*/annotation", "/*/featuretree/*"})
43 public class DescriptionController extends AnnotatableController<DescriptionBase, IDescriptionService>
44 {
45
46 public DescriptionController(){
47 super();
48 setUuidParameterPattern("^/(?:[^/]+)/(?:[^/]+)/([^/?#&\\.]+).*");
49 }
50
51 private static final List<String> FEATURETREE_INIT_STRATEGY = Arrays.asList(
52 new String[]{
53 "representations",
54 "root.feature.representations",
55 "root.children.feature.representations",
56 //TODO implement recursive INIT_STRATEGY for children e.g:
57 // "root.children{<children;limit=0}.feature.representations",
58 });
59
60
61 /* (non-Javadoc)
62 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
63 */
64 @Autowired
65 @Override
66 public void setService(IDescriptionService service) {
67 this.service = service;
68 }
69
70 @RequestMapping(
71 value = {"/*/featuretree/*"},
72 method = RequestMethod.GET)
73 public FeatureTree doGetFeatureTree(HttpServletRequest request, HttpServletResponse response)throws IOException {
74 UUID featureTreeUuid = readValueUuid(request, null);
75 FeatureTree featureTree = service.loadFeatureTree(featureTreeUuid, FEATURETREE_INIT_STRATEGY);
76 if(featureTree == null){
77 HttpStatusMessage.UUID_NOT_FOUND.send(response);
78 }
79 return featureTree;
80 }
81
82 }