// $Id$\r
/**\r
* Copyright (C) 2007 EDIT\r
-* European Distributed Institute of Taxonomy \r
+* European Distributed Institute of Taxonomy\r
* http://www.e-taxonomy.eu\r
-* \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
package eu.etaxonomy.cdm.remote.controller;\r
\r
import java.io.IOException;\r
+import java.util.ArrayList;\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
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.annotation.PathVariable;\r
import org.springframework.web.bind.annotation.RequestMapping;\r
import org.springframework.web.bind.annotation.RequestMethod;\r
+import org.springframework.web.servlet.ModelAndView;\r
\r
+import eu.etaxonomy.cdm.api.service.INameService;\r
+import eu.etaxonomy.cdm.api.service.IOccurrenceService;\r
import eu.etaxonomy.cdm.api.service.ITaxonService;\r
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;\r
import eu.etaxonomy.cdm.model.taxon.Synonym;\r
import eu.etaxonomy.cdm.model.taxon.Taxon;\r
import eu.etaxonomy.cdm.model.taxon.TaxonBase;\r
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;\r
+import eu.etaxonomy.cdm.persistence.query.OrderHint;\r
+import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;\r
\r
/**\r
* TODO write controller documentation\r
- * \r
+ *\r
* @author a.kohlbecker\r
* @date 20.07.2009\r
*\r
*/\r
@Controller\r
-@RequestMapping(value = {"/*/taxon/*","/*/taxon/*/*", "/*/taxon/*/annotation"})\r
-public class TaxonController extends AnnotatableController<TaxonBase, ITaxonService>\r
+@RequestMapping(value = {"/taxon/{uuid}"})\r
+public class TaxonController extends BaseController<TaxonBase, ITaxonService>\r
{\r
- public static final Logger logger = Logger.getLogger(TaxonController.class);\r
- \r
- public TaxonController(){\r
- super();\r
- setUuidParameterPattern("^/(?:[^/]+)/taxon/([^/?#&\\.]+).*");\r
- setInitializationStrategy(Arrays.asList(new String[]{"$","name.nomenclaturalReference"}));\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(ITaxonService service) {\r
- this.service = service;\r
- }\r
- \r
-\r
- /**\r
- * Get the set of accepted {@link Taxon} entities for a given\r
- * {@link TaxonBase} entity identified by the <code>{taxon-uuid}</code>.\r
- * <p>\r
- * URI: <b>/{datasource-name}/taxon/{taxon-uuid}/accepted</b>\r
- * \r
- * @param request\r
- * @param response\r
- * @return a set on a list of {@link Taxon} entities which are initialized\r
- * using the following initialization strategy:\r
- * {@link #DEFAULT_INIT_STRATEGY}\r
- * @throws IOException\r
- */\r
- @RequestMapping(value = "/*/taxon/*/accepted", method = RequestMethod.GET)\r
- public Set<TaxonBase> getAccepted(HttpServletRequest request, HttpServletResponse response) throws IOException {\r
- logger.info("getAccepted() " + request.getServletPath());\r
- TaxonBase tb = doGet(request, response);\r
- HashSet<TaxonBase> resultset = new HashSet<TaxonBase>();\r
- if(tb instanceof Taxon){\r
- //the taxon already is accepted\r
- //FIXME take the current view into account once views are implemented!!!\r
- resultset.add((Taxon)tb);\r
- } else {\r
- Synonym syn = (Synonym)tb;\r
- resultset.addAll(syn.getAcceptedTaxa());\r
- //TODO init Synonyms\r
- }\r
- return resultset;\r
- }\r
+ public static final Logger logger = Logger.getLogger(TaxonController.class);\r
+\r
+ @Autowired\r
+ private IOccurrenceService occurrenceService;\r
+ @Autowired\r
+ private INameService nameService;\r
+ @Autowired \r
+ private ITaxonService taxonService; \r
+ \r
+\r
+ protected static final List<String> TAXONNODE_INIT_STRATEGY = Arrays.asList(new String []{\r
+ "taxonNodes"\r
+ });\r
+\r
+ public TaxonController(){\r
+ super();\r
+ setInitializationStrategy(Arrays.asList(new String[]{"$","name.nomenclaturalReference"}));\r
+ }\r
+\r
+\r
+ @Autowired\r
+ public void setService(ITaxonService service) {\r
+ this.service = service;\r
+ }\r
+\r
+\r
+ /**\r
+ * Get the set of accepted {@link Taxon} entities for a given\r
+ * {@link TaxonBase} entity identified by the <code>{taxon-uuid}</code>.\r
+ * <p>\r
+ * URI: <b>/{datasource-name}/taxon/{taxon-uuid}/accepted</b>\r
+ *\r
+ * @param request\r
+ * @param response\r
+ * @return a set on a list of {@link Taxon} entities which are initialized\r
+ * using the following initialization strategy:\r
+ * {@link #DEFAULT_INIT_STRATEGY}\r
+ * @throws IOException\r
+ */\r
+ @RequestMapping(value = "accepted", method = RequestMethod.GET)\r
+ public Set<TaxonBase> doGetAccepted(\r
+ @PathVariable("uuid") UUID uuid,\r
+ HttpServletRequest request,\r
+ HttpServletResponse response) throws IOException {\r
+ logger.info("getAccepted() " + request.getServletPath());\r
+ TaxonBase tb = service.load(uuid);\r
+ HashSet<TaxonBase> resultset = new HashSet<TaxonBase>();\r
+ if(tb instanceof Taxon){\r
+ //the taxon already is accepted\r
+ //FIXME take the current view into account once views are implemented!!!\r
+ resultset.add((Taxon)tb);\r
+ } else {\r
+ Synonym syn = (Synonym)tb;\r
+ resultset.addAll(syn.getAcceptedTaxa());\r
+ //TODO init Synonyms\r
+ }\r
+ return resultset;\r
+ }\r
+\r
+ @RequestMapping(value = "taxonNodes", method = RequestMethod.GET)\r
+ public Set<TaxonNode> doGetTaxonNodes(\r
+ @PathVariable("uuid") UUID uuid,\r
+ HttpServletRequest request,\r
+ HttpServletResponse response) throws IOException {\r
+ TaxonBase tb = service.load(uuid, TAXONNODE_INIT_STRATEGY);\r
+ if(tb instanceof Taxon){\r
+ return ((Taxon)tb).getTaxonNodes();\r
+ } else {\r
+ HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);\r
+ return null;\r
+ }\r
+ }\r
+ \r
+\r
+ @RequestMapping(value = "specimensOrObersvations", method = RequestMethod.GET)\r
+ public ModelAndView doListSpecimensOrObersvations(\r
+ @PathVariable("uuid") UUID uuid,\r
+ HttpServletRequest request,\r
+ HttpServletResponse response) throws IOException {\r
+ logger.info("doListSpecimensOrObersvations() - " + request.getServletPath());\r
+\r
+ ModelAndView mv = new ModelAndView();\r
+\r
+ TaxonBase tb = service.load(uuid);\r
+\r
+ List<OrderHint> orderHints = new ArrayList<OrderHint>();\r
+ orderHints.add(new OrderHint("titleCache", SortOrder.DESCENDING));\r
+\r
+ if(tb instanceof Taxon){\r
+ List<SpecimenOrObservationBase> specimensOrObersvations = occurrenceService.listByAnyAssociation(\r
+ null, (Taxon)tb, null, 0, orderHints, null);\r
+ mv.addObject(specimensOrObersvations);\r
+ } else {\r
+ HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);\r
+ return null;\r
+ }\r
+\r
+ return mv;\r
+ }\r
+\r
+ @RequestMapping(value = "taggedName", method = RequestMethod.GET)\r
+ public ModelAndView doGetTaggedName(\r
+ @PathVariable("uuid") UUID uuid,\r
+ HttpServletRequest request,\r
+ HttpServletResponse response) throws IOException {\r
+ logger.info("doGetDescriptionElementsByType() - " + request.getServletPath());\r
+\r
+ ModelAndView mv = new ModelAndView();\r
+\r
+ TaxonBase tb = service.load(uuid, Arrays.asList(new String[] {"name"}));\r
+ mv.addObject(nameService.getTaggedName(tb.getName().getUuid()));\r
+ return mv;\r
+ }\r
+ \r
+ /**\r
+ * FIXME change @RequestMapping to /taxon/findBestMatchingTaxon and also move into TaxonListController\r
+ */\r
+ @RequestMapping(value = "/bestMatchingTaxon/{taxonName}", method = RequestMethod.GET)\r
+ public TaxonBase doFindBestMatchingTaxon(\r
+ @PathVariable("taxonName") String taxonName,\r
+ HttpServletRequest request, \r
+ HttpServletResponse response)throws IOException {\r
\r
+ Taxon bestMatchingTaxon = taxonService.findBestMatchingTaxon(taxonName);\r
+ \r
+ return bestMatchingTaxon;\r
+ \r
+ \r
+ }\r
\r
- \r
-}\r
+}
\ No newline at end of file