Merge branch 'release/5.1.0'
[cdmlib.git] / cdmlib-remote / src / main / java / eu / etaxonomy / cdm / remote / controller / FeatureTreePortalController.java
1 /**
2 * Copyright (C) 2013 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.cdm.remote.controller;
10
11 import io.swagger.annotations.Api;
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.persistence.EntityNotFoundException;
20 import javax.servlet.http.HttpServletRequest;
21 import javax.servlet.http.HttpServletResponse;
22
23 import org.apache.log4j.Logger;
24 import org.springframework.stereotype.Controller;
25 import org.springframework.web.bind.annotation.PathVariable;
26 import org.springframework.web.bind.annotation.RequestMapping;
27 import org.springframework.web.bind.annotation.RequestMethod;
28
29 import eu.etaxonomy.cdm.model.description.FeatureTree;
30
31 /**
32 * @author a.kohlbecker
33 * @since Jun 24, 2013
34 *
35 */
36 @Controller
37 @Api("portal_featureTree")
38 @RequestMapping(value = {"/portal/featureTree/{uuid}"})
39 public class FeatureTreePortalController extends FeatureTreeController {
40
41 public static final Logger logger = Logger.getLogger(FeatureTreePortalController.class);
42
43
44 private static final List<String> FEATURETREE_INIT_STRATEGY = Arrays.asList(
45 new String[]{
46 "representations",
47 });
48
49 private List<String> featuretreeNodeInitStrategy = null;
50
51 public FeatureTreePortalController() {
52 setInitializationStrategy(FEATURETREE_INIT_STRATEGY);
53
54 featuretreeNodeInitStrategy = new ArrayList<String>(2);
55 // featuretreeNodeInitStrategy.add("representations");
56 featuretreeNodeInitStrategy.add("feature.representations");
57 }
58
59 @Override
60 @RequestMapping(method = RequestMethod.GET)
61 public FeatureTree doGet(@PathVariable("uuid") UUID uuid,
62 HttpServletRequest request,
63 HttpServletResponse response) throws IOException {
64 if(request != null) {
65 logger.info("doGet() " + request.getRequestURI());
66 }
67 FeatureTree featureTree = null;
68 try {
69 featureTree = service.loadWithNodes(uuid, getInitializationStrategy(), featuretreeNodeInitStrategy);
70 } catch(EntityNotFoundException e){
71 HttpStatusMessage.UUID_NOT_FOUND.send(response);
72 }
73 return featureTree;
74 }
75 }