ref #6967 implementing /registration/{identifier} in RegistrationController
[cdmlib.git] / cdmlib-remote / src / main / java / eu / etaxonomy / cdm / remote / controller / DescriptionPortalController.java
index 1895926534f5c9c98ea43530fe10aedd8413669c..c4ef336aaa49690be62077c23fcdd22ef2e8eafb 100644 (file)
-// $Id$\r
-/**\r
-* Copyright (C) 2007 EDIT\r
-* 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 1.1\r
-* 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 java.io.IOException;\r
-import java.util.Arrays;\r
-import java.util.HashSet;\r
-import java.util.List;\r
-import java.util.Set;\r
-import java.util.UUID;\r
-\r
-import javax.servlet.http.HttpServletRequest;\r
-import javax.servlet.http.HttpServletResponse;\r
-\r
-import org.apache.commons.lang.ObjectUtils;\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.PathVariable;\r
-import org.springframework.web.bind.annotation.RequestMapping;\r
-import org.springframework.web.bind.annotation.RequestMethod;\r
-import org.springframework.web.bind.annotation.RequestParam;\r
-\r
-import eu.etaxonomy.cdm.api.service.DistributionTree;\r
-import eu.etaxonomy.cdm.api.service.IDescriptionService;\r
-import eu.etaxonomy.cdm.api.service.IFeatureTreeService;\r
-import eu.etaxonomy.cdm.api.service.pager.Pager;\r
-import eu.etaxonomy.cdm.model.common.Annotation;\r
-import eu.etaxonomy.cdm.model.description.DescriptionBase;\r
-import eu.etaxonomy.cdm.model.description.DescriptionElementBase;\r
-import eu.etaxonomy.cdm.model.description.FeatureTree;\r
-import eu.etaxonomy.cdm.model.description.TaxonDescription;\r
-import eu.etaxonomy.cdm.model.location.NamedAreaLevel;\r
-import eu.etaxonomy.cdm.remote.editor.NamedAreaLevelPropertyEditor;\r
-import eu.etaxonomy.cdm.remote.editor.UUIDListPropertyEditor;\r
-import eu.etaxonomy.cdm.remote.editor.UuidList;\r
-\r
-/**\r
- * TODO write controller documentation\r
- *\r
- * @author a.kohlbecker\r
- * @date 24.03.2009\r
- */\r
-\r
-@Controller\r
-@RequestMapping(value = {"/portal/description/{uuid}", "/portal/description/{uuid_list}", "/portal/descriptionElement/{descriptionelement_uuid}", "/portal/featureTree/{featuretree_uuid}"})\r
-public class DescriptionPortalController extends BaseController<DescriptionBase, IDescriptionService>\r
-{\r
-    @Autowired\r
-    private IFeatureTreeService featureTreeService;\r
-\r
-    private static final List<String> FEATURETREE_INIT_STRATEGY = Arrays.asList(\r
-            new String[]{\r
-                "representations",\r
-                "root.feature.representations",\r
-                "root.children.feature.representations",\r
-            });\r
-\r
-    private static final List<String> DESCRIPTIONS_DISTRIBUTION_INIT_STRATEGY = Arrays.asList(new String []{\r
-            "elements.sources.citation.$",\r
-            "elements.area.$",\r
-            });\r
-\r
-    protected static final List<String> DESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{\r
-            "$",\r
-            "elements.$",\r
-            "elements.sources.citation.authorTeam.$",\r
-            "elements.sources.nameUsedInSource.originalNameString",\r
-            "elements.area.level",\r
-            "elements.modifyingText",\r
-            "elements.states.*",\r
-            "elements.media",\r
-    });\r
-\r
-\r
-    public DescriptionPortalController() {\r
-        super();\r
-        setInitializationStrategy(DESCRIPTION_INIT_STRATEGY);\r
-    }\r
-\r
-    @InitBinder\r
-    @Override\r
-    public void initBinder(WebDataBinder binder) {\r
-        super.initBinder(binder);\r
-        binder.registerCustomEditor(UuidList.class, new UUIDListPropertyEditor());\r
-        binder.registerCustomEditor(NamedAreaLevel.class, new NamedAreaLevelPropertyEditor());\r
-    }\r
-\r
-    /* (non-Javadoc)\r
-     * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)\r
-     */\r
-    @Autowired\r
-    @Override\r
-    public void setService(IDescriptionService service) {\r
-        this.service = service;\r
-    }\r
-\r
-    /**\r
-     * TODO write controller method documentation\r
-     *\r
-     * @param request\r
-     * @param response\r
-     * @return\r
-     * @throws IOException\r
-     */\r
-\r
-    @RequestMapping(value = {"/portal/featureTree/{featuretree_uuid}"}, method = RequestMethod.GET)\r
-    public FeatureTree doGetFeatureTree(\r
-            @PathVariable("featuretree_uuid") UUID featureUuid,\r
-            HttpServletRequest request,\r
-            HttpServletResponse response)throws IOException {\r
-        //UUID featureTreeUuid = readValueUuid(request, null);\r
-        FeatureTree featureTree = featureTreeService.load(featureUuid, FEATURETREE_INIT_STRATEGY);\r
-        if(featureTree == null){\r
-            HttpStatusMessage.UUID_NOT_FOUND.send(response);\r
-        }\r
-        return featureTree;\r
-    }\r
-\r
-    @RequestMapping(value = "/portal/descriptionElement/{descriptionelement_uuid}/annotation", method = RequestMethod.GET)\r
-    public Pager<Annotation> getAnnotations(\r
-            @PathVariable("descriptionelement_uuid") UUID uuid,\r
-            HttpServletRequest request,\r
-            HttpServletResponse response) throws IOException {\r
-        logger.info("getAnnotations() - " + request.getRequestURI());\r
-        DescriptionElementBase annotatableEntity = service.getDescriptionElementByUuid(uuid);\r
-        Pager<Annotation> annotations = service.getDescriptionElementAnnotations(annotatableEntity, null, null, 0, null, DEFAULT_INIT_STRATEGY);\r
-        return annotations;\r
-    }\r
-\r
-    @RequestMapping(value = "/portal/description/{uuid_list}/DistributionTree", method = RequestMethod.GET)\r
-    public DistributionTree doGetOrderedDistributionsB(\r
-            @PathVariable("uuid_list") UuidList descriptionUuidList,\r
-            @RequestParam(value = "omitLevels", required = false) Set<NamedAreaLevel> levels,\r
-            HttpServletRequest request, HttpServletResponse response) {\r
-        logger.info("getOrderedDistributionsB(" + ObjectUtils.toString(levels) + ") - " + request.getRequestURI());\r
-        Set<TaxonDescription> taxonDescriptions = new HashSet<TaxonDescription>();\r
-        TaxonDescription description;\r
-        for (UUID descriptionUuid : descriptionUuidList) {\r
-            description = (TaxonDescription) service.load(descriptionUuid, DESCRIPTION_INIT_STRATEGY);\r
-            taxonDescriptions.add(description);\r
-        }\r
-        DistributionTree distTree = service.getOrderedDistributions(taxonDescriptions, levels, DESCRIPTION_INIT_STRATEGY);\r
-        return distTree;\r
-    }\r
-\r
-}\r
+/**
+* Copyright (C) 2007 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 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.transaction.annotation.Transactional;
+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.IDescriptionService;
+import eu.etaxonomy.cdm.api.service.ITermService;
+import eu.etaxonomy.cdm.api.service.IVocabularyService;
+import eu.etaxonomy.cdm.api.service.pager.Pager;
+import eu.etaxonomy.cdm.ext.geo.IEditGeoService;
+import eu.etaxonomy.cdm.model.common.Annotation;
+import eu.etaxonomy.cdm.model.common.MarkerType;
+import eu.etaxonomy.cdm.model.description.DescriptionBase;
+import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
+import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
+import eu.etaxonomy.cdm.remote.editor.DefinedTermBaseList;
+import eu.etaxonomy.cdm.remote.editor.NamedAreaLevelPropertyEditor;
+import eu.etaxonomy.cdm.remote.editor.TermBaseListPropertyEditor;
+import eu.etaxonomy.cdm.remote.editor.UUIDListPropertyEditor;
+import eu.etaxonomy.cdm.remote.editor.UuidList;
+import io.swagger.annotations.Api;
+
+/**
+ *
+ * @author a.kohlbecker
+ * @since Jun 25, 2013
+ *
+ */
+@Controller
+@Api("portal_description")
+@Transactional(readOnly=true)
+@RequestMapping(value = {
+            "/portal/description/{uuid}",
+            "/portal/description/{uuid_list}"})
+public class DescriptionPortalController extends BaseController<DescriptionBase, IDescriptionService> {
+
+    private static final Logger logger = Logger.getLogger(DescriptionPortalController.class);
+
+    protected static final List<String> DESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{
+            "$",
+            "elements.$",
+            "elements.multilanguageText.*",
+            "elements.annotations",
+            "elements.sources.citation.authorship.$",
+            "elements.sources.nameUsedInSource",
+            "elements.area.level",
+            "elements.modifyingText",
+            "elements.stateData.*",
+            "elements.statisticalValues.*",
+            "elements.unit",
+            "elements.media",
+            "elements.kindOfUnit"
+
+    });
+
+    protected static final List<String> ORDERED_DISTRIBUTION_INIT_STRATEGY = Arrays.asList(new String []{
+            "elements.$",
+            "elements.annotations",
+            "elements.markers",
+            "elements.sources.citation.authorship.$",
+            "elements.sources.nameUsedInSource",
+            "elements.area.level",
+    });
+
+    protected static final List<String> DISTRIBUTION_INFO_INIT_STRATEGY = Arrays.asList(new String []{
+            "sources.citation.authorship.$",
+            "sources.nameUsedInSource",
+            "annotations"
+    });
+
+    @Autowired
+    private ITermService termService;
+
+    @Autowired
+    private IVocabularyService vocabularyService ;
+
+
+    @Autowired
+    private IEditGeoService geoService;
+
+
+    public DescriptionPortalController() {
+        super();
+        setInitializationStrategy(DESCRIPTION_INIT_STRATEGY);
+    }
+
+    @InitBinder
+    @Override
+    public void initBinder(WebDataBinder binder) {
+        super.initBinder(binder);
+        binder.registerCustomEditor(UuidList.class, new UUIDListPropertyEditor());
+        binder.registerCustomEditor(NamedAreaLevel.class, new NamedAreaLevelPropertyEditor());
+        binder.registerCustomEditor(DefinedTermBaseList.class, new TermBaseListPropertyEditor<MarkerType>(termService));
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
+     */
+    @Autowired
+    @Override
+    public void setService(IDescriptionService service) {
+        this.service = service;
+    }
+
+    @RequestMapping(value = "//portal/descriptionElement/{descriptionelement_uuid}/annotation", method = RequestMethod.GET) // mapped as absolute path, see CdmAntPathMatcher
+    public Pager<Annotation> getAnnotations(
+            @PathVariable("descriptionelement_uuid") UUID uuid,
+            HttpServletRequest request,
+            HttpServletResponse response) throws IOException {
+        logger.info("getAnnotations() - " + requestPathAndQuery(request) );
+        DescriptionElementBase annotatableEntity = service.getDescriptionElementByUuid(uuid);
+        Pager<Annotation> annotations = service.getDescriptionElementAnnotations(annotatableEntity, null, null, 0, null, getInitializationStrategy());
+        return annotations;
+    }
+
+}