#5890 Add new controller method to get the root node for a given
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 27 Jun 2016 13:21:04 +0000 (15:21 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 27 Jun 2016 13:21:04 +0000 (15:21 +0200)
classification

cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/ClassificationPortalController.java

index 3e2779a79161cbd1f9eda97bb4a3d0d251e1f9cf..0f40f507831773e98d4fd6f226b6ce7960b81069 100644 (file)
-// $Id$\r
-/**\r
- * Copyright (C) 2009 EDIT European Distributed Institute of Taxonomy\r
- * http://www.e-taxonomy.eu\r
- *\r
- * The contents of this file are subject to the Mozilla Public License Version\r
- * 1.1 See LICENSE.TXT at the top of this package for the full license terms.\r
- */\r
-\r
-package eu.etaxonomy.cdm.remote.controller;\r
-\r
-import io.swagger.annotations.Api;\r
-\r
-import java.util.Arrays;\r
-import java.util.List;\r
-\r
-import org.apache.log4j.Logger;\r
-import org.springframework.beans.factory.annotation.Autowired;\r
-import org.springframework.stereotype.Controller;\r
-import org.springframework.web.bind.WebDataBinder;\r
-import org.springframework.web.bind.annotation.InitBinder;\r
-import org.springframework.web.bind.annotation.RequestMapping;\r
-\r
-import eu.etaxonomy.cdm.api.service.IClassificationService;\r
-import eu.etaxonomy.cdm.database.UpdatableRoutingDataSource;\r
-import eu.etaxonomy.cdm.model.name.Rank;\r
-import eu.etaxonomy.cdm.model.taxon.Classification;\r
-import eu.etaxonomy.cdm.remote.editor.RankPropertyEditor;\r
-\r
-/**\r
- * The ClassificationController class is a Spring MVC Controller.\r
- * <p>\r
- * The syntax of the mapped service URIs contains the the {datasource-name} path element.\r
- * The available {datasource-name}s are defined in a configuration file which\r
- * is loaded by the {@link UpdatableRoutingDataSource}. If the\r
- * UpdatableRoutingDataSource is not being used in the actual application\r
- * context any arbitrary {datasource-name} may be used.\r
- * <p>\r
- * @author a.kohlbecker\r
- * @date 20.03.2009\r
- *\r
- * TODO this controller should be a portal controller!!\r
- */\r
-@Controller\r
-@Api("portal_classification")\r
-@RequestMapping(value = {"/portal/classification/{uuid}"})\r
-public class ClassificationPortalController extends BaseController<Classification,IClassificationService> {\r
-\r
-\r
-    private static final List<String> CLASSIFICATION_INIT_STRATEGY = Arrays.asList(new String[]{\r
-            "reference.authorship",\r
-            "childNodes"\r
-    });\r
-\r
-    public static final Logger logger = Logger.getLogger(ClassificationPortalController.class);\r
-\r
-    @Override\r
-    @Autowired\r
-    public void setService(IClassificationService service) {\r
-        this.service = service;\r
-    }\r
-\r
-\r
-\r
-    @InitBinder\r
-    @Override\r
-    public void initBinder(WebDataBinder binder) {\r
-        super.initBinder(binder);\r
-        binder.registerCustomEditor(Rank.class, new RankPropertyEditor());\r
-    }\r
-\r
-    /**\r
-     *\r
-     */\r
-    public ClassificationPortalController() {\r
-        super();\r
-        setInitializationStrategy(CLASSIFICATION_INIT_STRATEGY);\r
-    }\r
-\r
-\r
+// $Id$
+/**
+ * Copyright (C) 2009 EDIT European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 See LICENSE.TXT at the top of this package for the full license terms.
+ */
+
+package eu.etaxonomy.cdm.remote.controller;
+
+import io.swagger.annotations.Api;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.UUID;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.log4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.WebDataBinder;
+import org.springframework.web.bind.annotation.InitBinder;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+import eu.etaxonomy.cdm.api.service.IClassificationService;
+import eu.etaxonomy.cdm.database.UpdatableRoutingDataSource;
+import eu.etaxonomy.cdm.model.name.Rank;
+import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.cdm.remote.editor.RankPropertyEditor;
+
+/**
+ * The ClassificationController class is a Spring MVC Controller.
+ * <p>
+ * The syntax of the mapped service URIs contains the the {datasource-name} path element.
+ * The available {datasource-name}s are defined in a configuration file which
+ * is loaded by the {@link UpdatableRoutingDataSource}. If the
+ * UpdatableRoutingDataSource is not being used in the actual application
+ * context any arbitrary {datasource-name} may be used.
+ * <p>
+ * @author a.kohlbecker
+ * @date 20.03.2009
+ *
+ * TODO this controller should be a portal controller!!
+ */
+@Controller
+@Api("portal_classification")
+@RequestMapping(value = {"/portal/classification/{uuid}"})
+public class ClassificationPortalController extends BaseController<Classification,IClassificationService> {
+
+
+    private static final List<String> CLASSIFICATION_INIT_STRATEGY = Arrays.asList(new String[]{
+            "reference.authorship",
+            "childNodes"
+    });
+
+    public static final Logger logger = Logger.getLogger(ClassificationPortalController.class);
+
+    @Override
+    @Autowired
+    public void setService(IClassificationService service) {
+        this.service = service;
+    }
+
+
+
+    @InitBinder
+    @Override
+    public void initBinder(WebDataBinder binder) {
+        super.initBinder(binder);
+        binder.registerCustomEditor(Rank.class, new RankPropertyEditor());
+    }
+
+    /**
+     *
+     */
+    public ClassificationPortalController() {
+        super();
+        setInitializationStrategy(CLASSIFICATION_INIT_STRATEGY);
+    }
+
+    @RequestMapping(value = { "classificationRootNode" }, method = RequestMethod.GET)
+    public TaxonNode getClassificationRootNode(@PathVariable("uuid") UUID uuid, HttpServletRequest request,
+            HttpServletResponse response) throws IOException {
+
+        Classification classification = doGet(uuid, request, response);
+        if(classification!=null){
+            return classification.getRootNode();
+        }
+        return null;
+    }
+
+
 }
\ No newline at end of file