+ 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
+}
\ No newline at end of file