- binder.registerCustomEditor(UUID.class, new UUIDPropertyEditor());\r
- }\r
- \r
- \r
- @Override\r
- @RequestMapping(method = RequestMethod.GET)\r
- public TaxonBase doGet(HttpServletRequest request, HttpServletResponse response)throws IOException {\r
- TaxonBase tb = getCdmBase(request, response, TAXON_INIT_STRATEGY, TaxonBase.class);\r
- return tb;\r
- }\r
- \r
- @RequestMapping(method = RequestMethod.GET,\r
- value = {"/*/portal/taxon/find"}) //TODO map to path /*/portal/taxon/ \r
- public Pager<IdentifiableEntity> doFind(\r
- @RequestParam(value = "q", required = false) String query,\r
- @RequestParam(value = "page", required = false) Integer page,\r
- @RequestParam(value = "pageSize", required = false) Integer pageSize,\r
- @RequestParam(value = "doTaxa", required = false) Boolean doTaxa,\r
- @RequestParam(value = "doSynonyms", required = false) Boolean doSynonyms,\r
- @RequestParam(value = "doTaxaByCommonNames", required = false) Boolean doTaxaByCommonNames,\r
- @RequestParam(value = "secUuid", required = false) UUID secUuid) throws IOException {\r
- \r
- if(page == null){ page = BaseListController.DEFAULT_PAGE;}\r
- if(pageSize == null){ pageSize = BaseListController.DEFAULT_PAGESIZE;}\r
- \r
- ITaxonServiceConfigurator config = new TaxonServiceConfiguratorImpl();\r
- config.setPageNumber(page);\r
- config.setPageSize(pageSize);\r
- config.setSearchString(query);\r
- config.setDoTaxa(doTaxa!= null ? doTaxa : Boolean.FALSE );\r
- config.setDoSynonyms(doSynonyms != null ? doSynonyms : Boolean.FALSE );\r
- config.setDoTaxaByCommonNames(doTaxaByCommonNames != null ? doTaxaByCommonNames : Boolean.FALSE );\r
- config.setMatchMode(MatchMode.BEGINNING);\r
- config.setTaxonPropertyPath(SIMPLE_TAXON_INIT_STRATEGY);\r
- if(secUuid != null){\r
- ReferenceBase sec = referenceService.findByUuid(secUuid);\r
- config.setSec(sec);\r
- }\r
- \r
- return (Pager<IdentifiableEntity>) service.findTaxaAndNames(config);\r
- }\r
-\r
- \r
- @RequestMapping(\r
- value = {"/*/portal/taxon/*/synonymy"},\r
- method = RequestMethod.GET)\r
- public ModelAndView doGetSynonymy(HttpServletRequest request, HttpServletResponse response)throws IOException {\r
- ModelAndView mv = new ModelAndView();\r
- TaxonBase tb = getCdmBase(request, response, null, Taxon.class);\r
- Taxon taxon = (Taxon)tb;\r
- Map<String, List<?>> synonymy = new Hashtable<String, List<?>>();\r
- synonymy.put("homotypicSynonymsByHomotypicGroup", service.getHomotypicSynonymsByHomotypicGroup(taxon, SYNONYMY_INIT_STRATEGY));\r
- synonymy.put("heterotypicSynonymyGroups", service.getHeterotypicSynonymyGroups(taxon, SYNONYMY_INIT_STRATEGY));\r
- mv.addObject(synonymy);\r
- return mv;\r
- }\r
- \r
- @RequestMapping(\r
- value = {"/*/portal/taxon/*/taxonRelationships"},\r
- method = RequestMethod.GET)\r
- public List<TaxonRelationship> doGetTaxonRelations(HttpServletRequest request, HttpServletResponse response)throws IOException {\r
-\r
- TaxonBase tb = getCdmBase(request, response, null, Taxon.class);\r
- Taxon taxon = (Taxon)tb;\r
- List<TaxonRelationship> relations = new ArrayList<TaxonRelationship>();\r
- List<TaxonRelationship> results = service.listToTaxonRelationships(taxon, TaxonRelationshipType.MISAPPLIED_NAME_FOR(), null, null, null, TAXONRELATIONSHIP_INIT_STRATEGY);\r
- relations.addAll(results);\r
- results = service.listToTaxonRelationships(taxon, TaxonRelationshipType.INVALID_DESIGNATION_FOR(), null, null, null, TAXONRELATIONSHIP_INIT_STRATEGY);\r
- relations.addAll(results);\r
-\r
- return relations;\r
- }\r
- \r
- @RequestMapping(\r
- value = {"/*/portal/taxon/*/nameRelationships"},\r
- method = RequestMethod.GET)\r
- public List<NameRelationship> doGetNameRelations(HttpServletRequest request, HttpServletResponse response)throws IOException {\r
- TaxonBase tb = getCdmBase(request, response, SIMPLE_TAXON_INIT_STRATEGY, Taxon.class);\r
- List<NameRelationship> list = nameService.listToNameRelationships(tb.getName(), null, null, null, null, NAMERELATIONSHIP_INIT_STRATEGY);\r
- return list;\r
- }\r
- \r
- @RequestMapping(\r
- value = {"/*/portal/name/*/descriptions"},\r
- method = RequestMethod.GET)\r
- public List<TaxonNameDescription> doGetNameDescriptions(HttpServletRequest request, HttpServletResponse response)throws IOException {\r
- UUID nameUuuid = readValueUuid(request, null);\r
- TaxonNameBase tnb = nameService.load(nameUuuid, null);\r
- Pager<TaxonNameDescription> p = descriptionService.getTaxonNameDescriptions(tnb, null, null, NAMEDESCRIPTION_INIT_STRATEGY);\r
- return p.getRecords();\r
- }\r
- \r
- @RequestMapping(\r
- value = {"/*/portal/taxon/*/nameTypeDesignations"},\r
- method = RequestMethod.GET)\r
- public List<TypeDesignationBase> doGetNameTypeDesignations(HttpServletRequest request, HttpServletResponse response)throws IOException {\r
- TaxonBase tb = getCdmBase(request, response, SIMPLE_TAXON_INIT_STRATEGY, Taxon.class);\r
- Pager<TypeDesignationBase> p = nameService.getTypeDesignations(tb.getName(), null, null, null, TYPEDESIGNATION_INIT_STRATEGY);\r
- return p.getRecords();\r
- }\r
- \r
- @RequestMapping(\r
- value = {"/*/portal/taxon/*/descriptions"},\r
- method = RequestMethod.GET)\r
- public List<TaxonDescription> doGetDescriptions(HttpServletRequest request, HttpServletResponse response)throws IOException {\r
- Taxon t = getCdmBase(request, response, null, Taxon.class);\r
- Pager<TaxonDescription> p = descriptionService.getTaxonDescriptions(t, null, null, null, null, TAXONDESCRIPTION_INIT_STRATEGY);\r
- return p.getRecords();\r
- }\r
-\r
- /**\r
- * Usage /*/portal/name/{taxon\r
- * uuid}/media/{mime type\r
- * list}/{size}[,[widthOrDuration}][,{height}]/\r
- * \r
- * Whereas\r
- * <ul>\r
- * <li><b>{mime type list}</b>: a comma separated list of mime types, in the\r
- * order of preference. The forward slashes contained in the mime types must\r
- * be replaced by a colon. Regular expressions can be used. Each media\r
- * associated with this given taxon is being searched whereas the first\r
- * matching mime type matching a representation always rules.</li>\r
- * <li><b>{size},{widthOrDuration},{height}</b>: <i>not jet implemented</i>\r
- * valid values are an integer or the asterisk '*' as a wildcard</li>\r
- * </ul>\r
- * \r
- * @param request\r
- * @param response\r
- * @return\r
- * @throws IOException\r
- */\r
- @RequestMapping(\r
- value = {"/*/portal/taxon/*/media/*/*"},\r
- method = RequestMethod.GET)\r
- public List<Media> doGetMedia(HttpServletRequest request, HttpServletResponse response)throws IOException {\r
- Taxon t = getCdmBase(request, response, null, Taxon.class);\r
- Pager<TaxonDescription> p = descriptionService.getTaxonDescriptions(t, null, null, null, null, TAXONDESCRIPTION_INIT_STRATEGY);\r
- \r
- // pars the media and quality parameters\r
- \r
- \r
- // collect all media of the given taxon\r
- boolean limitToGalleries = false;\r
- List<Media> taxonMedia = new ArrayList<Media>();\r
- for(TaxonDescription desc : p.getRecords()){\r
- if(!limitToGalleries || desc.isImageGallery()){\r
- for(DescriptionElementBase element : desc.getElements()){\r
- for(Media media : element.getMedia()){\r
- taxonMedia.add(media);\r
- }\r
- }\r
- }\r
- }\r
- \r
- // find best matching representations of each media\r
- String path = request.getServletPath();\r
- String[] pathTokens = path.split("/");\r
- String[] mimeTypes = pathTokens[6].split(",");\r
- String[] sizeTokens = pathTokens[7].split(",");\r
- Integer widthOrDuration = null;\r
- Integer height = null;\r
- Integer size = null;\r
- \r
- for(int i=0; i<mimeTypes.length; i++){\r
- mimeTypes[i] = mimeTypes[i].replace(':', '/');\r
- }\r
- \r
- if(sizeTokens.length > 0){\r
- try {\r
- size = Integer.valueOf(sizeTokens[0]);\r
- } catch (NumberFormatException nfe) {\r
- /* IGNORE */\r
- }\r
- }\r
- if(sizeTokens.length > 1){\r
- try {\r
- widthOrDuration = Integer.valueOf(sizeTokens[1]);\r
- } catch (NumberFormatException nfe) {\r
- /* IGNORE */\r
- }\r
- }\r
- if(sizeTokens.length > 2){\r
- try {\r
- height = Integer.valueOf(sizeTokens[2]);\r
- } catch (NumberFormatException nfe) {\r
- /* IGNORE */\r
- }\r
- }\r
- \r
- List<Media> returnMedia = new ArrayList<Media>(taxonMedia.size());\r
- for(Media media : taxonMedia){\r
- SortedMap<String, MediaRepresentation> prefRepresentations = orderMediaRepresentations(media, mimeTypes, size, widthOrDuration, height);\r
- try {\r
- // take first one and remove all other representations\r
- MediaRepresentation prefOne = prefRepresentations.get(prefRepresentations.firstKey());\r
- for (MediaRepresentation representation : media.getRepresentations()) {\r
- if (representation != prefOne) {\r
- media.removeRepresentation(representation);\r
- }\r
- }\r
- returnMedia.add(media);\r
- } catch (NoSuchElementException nse) {\r
- /* IGNORE */\r
- }\r
- }\r
- \r
- return returnMedia;\r
- }\r
-\r
- /**\r
- * @param media\r
- * @param mimeTypeRegexes\r
- * @param size\r
- * @param widthOrDuration\r
- * @param height\r
- * @return\r
- * \r
- * TODO move into a media utils class\r
- * TODO implement the quality filter \r
- */\r
- private SortedMap<String, MediaRepresentation> orderMediaRepresentations(Media media, String[] mimeTypeRegexes,\r
- Integer size, Integer widthOrDuration, Integer height) {\r
-\r
- SortedMap<String, MediaRepresentation> prefRepr = new TreeMap<String, MediaRepresentation>();\r
- for (String mimeTypeRegex : mimeTypeRegexes) {\r
- // getRepresentationByMimeType\r
- Pattern mimeTypePattern = Pattern.compile(mimeTypeRegex);\r
- int representationCnt = 0;\r
- for (MediaRepresentation representation : media.getRepresentations()) {\r
- Matcher mather = mimeTypePattern.matcher(representation.getMimeType());\r
- if (mather.matches()) {\r
- int dwa = 0;\r
-\r
- /* TODO the quality filter part is being skipped \r
- * // look for representation with the best matching parts\r
- for (MediaRepresentationPart part : representation.getParts()) {\r
- if (part instanceof ImageFile) {\r
- ImageFile image = (ImageFile) part;\r
- int dw = image.getWidth() * image.getHeight() - height * widthOrDuration;\r
- if (dw < 0) {\r
- dw *= -1;\r
- }\r
- dwa += dw;\r
- }\r
- dwa = (representation.getParts().size() > 0 ? dwa / representation.getParts().size() : 0);\r
- }*/\r
- prefRepr.put((dwa + representationCnt++) + '_' + representation.getMimeType(), representation);\r
- \r
- // preferred mime type found => end loop\r
- break;\r
- }\r
- }\r
- }\r
- return prefRepr;\r
- }\r
- \r
+ super.initBinder(binder);\r
+ binder.registerCustomEditor(NamedArea.class, new NamedAreaPropertyEditor());\r
+ binder.registerCustomEditor(MatchMode.class, new MatchModePropertyEditor());\r
+ binder.registerCustomEditor(Class.class, new CdmTypePropertyEditor());\r
+ binder.registerCustomEditor(UuidList.class, new UUIDListPropertyEditor());\r
+\r
+ }\r
+\r
+\r
+ /* (non-Javadoc)\r
+ * @see eu.etaxonomy.cdm.remote.controller.BaseController#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)\r
+\r
+ @Override\r
+ @RequestMapping(method = RequestMethod.GET)\r
+ public TaxonBase doGet(HttpServletRequest request, HttpServletResponse response)throws IOException {\r
+ logger.info("doGet()");\r
+ TaxonBase tb = getCdmBase(request, response, TAXON_INIT_STRATEGY, TaxonBase.class);\r
+ return tb;\r
+ }\r
+ */\r
+ /**\r
+ * Find Taxa, Synonyms, Common Names by name, either globally or in a specific geographic area.\r
+ * <p>\r
+ * URI: <b>/{datasource-name}/portal/taxon/find</b>\r
+ *\r
+ * @param query\r
+ * the string to query for. Since the wildcard character '*'\r
+ * internally always is appended to the query string, a search\r
+ * always compares the query string with the beginning of a name.\r
+ * - <i>required parameter</i>\r
+ * @param treeUuid\r
+ * the {@link UUID} of a {@link Classification} to which the\r
+ * search is to be restricted. - <i>optional parameter</i>\r
+ * @param areas\r
+ * restrict the search to a set of geographic {@link NamedArea}s.\r
+ * The parameter currently takes a list of TDWG area labels.\r
+ * - <i>optional parameter</i>\r
+ * @param pageNumber\r
+ * the number of the page to be returned, the first page has the\r
+ * pageNumber = 1 - <i>optional parameter</i>\r
+ * @param pageSize\r
+ * the maximum number of entities returned per page (can be -1\r
+ * to return all entities in a single page) - <i>optional parameter</i>\r
+ * @param doTaxa\r
+ * weather to search for instances of {@link Taxon} - <i>optional parameter</i>\r
+ * @param doSynonyms\r
+ * weather to search for instances of {@link Synonym} - <i>optional parameter</i>\r
+ * @param doTaxaByCommonNames\r
+ * for instances of {@link Taxon} by a common name used - <i>optional parameter</i>\r
+ * @param matchMode\r
+ * valid values are "EXACT", "BEGINNING", "ANYWHERE", "END" (case sensitive !!!)\r
+ * @return a Pager on a list of {@link IdentifiableEntity}s initialized by\r
+ * the following strategy {@link #SIMPLE_TAXON_INIT_STRATEGY}\r
+ * @throws IOException\r
+ */\r
+ @RequestMapping(method = RequestMethod.GET,\r
+ value = {"/portal/taxon/find"}) //TODO map to path /*/portal/taxon/\r
+ public Pager<IdentifiableEntity> doFind(\r
+ @RequestParam(value = "query", required = false) String query,\r
+ @RequestParam(value = "tree", required = false) UUID treeUuid,\r
+ @RequestParam(value = "area", required = false) Set<NamedArea> areas,\r
+ @RequestParam(value = "pageNumber", required = false) Integer pageNumber,\r
+ @RequestParam(value = "pageSize", required = false) Integer pageSize,\r
+ @RequestParam(value = "doTaxa", required = false) Boolean doTaxa,\r
+ @RequestParam(value = "doSynonyms", required = false) Boolean doSynonyms,\r
+ @RequestParam(value = "doMisappliedNames", required = false) Boolean doMisappliedNames,\r
+ @RequestParam(value = "doTaxaByCommonNames", required = false) Boolean doTaxaByCommonNames,\r
+ @RequestParam(value = "matchMode", required = false) MatchMode matchMode,\r
+ HttpServletRequest request,\r
+ HttpServletResponse response\r
+ )\r
+ throws IOException {\r
+\r
+ logger.info("doFind : " + request.getRequestURI() + "?" + request.getQueryString() );\r
+\r
+ PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);\r
+ pagerParams.normalizeAndValidate(response);\r
+\r
+ IFindTaxaAndNamesConfigurator config = new FindTaxaAndNamesConfiguratorImpl();\r
+ config.setPageNumber(pagerParams.getPageIndex());\r
+ config.setPageSize(pagerParams.getPageSize());\r
+ config.setTitleSearchString(query);\r
+ config.setDoTaxa(doTaxa!= null ? doTaxa : Boolean.FALSE );\r
+ config.setDoSynonyms(doSynonyms != null ? doSynonyms : Boolean.FALSE );\r
+ config.setDoMisappliedNames(doMisappliedNames != null ? doMisappliedNames : Boolean.FALSE);\r
+ config.setDoTaxaByCommonNames(doTaxaByCommonNames != null ? doTaxaByCommonNames : Boolean.FALSE );\r
+ config.setMatchMode(matchMode != null ? matchMode : MatchMode.BEGINNING);\r
+ config.setTaxonPropertyPath(SIMPLE_TAXON_INIT_STRATEGY);\r
+ config.setNamedAreas(areas);\r
+ if(treeUuid != null){\r
+ Classification classification = classificationService.find(treeUuid);\r
+ config.setClassification(classification);\r
+ }\r
+\r
+ return (Pager<IdentifiableEntity>) service.findTaxaAndNames(config);\r
+ }\r
+\r
+ /**\r
+ * @param clazz\r
+ * @param queryString\r
+ * @param treeUuid\r
+ * @param languages\r
+ * @param features one or more feature uuids\r
+ * @param pageNumber\r
+ * @param pageSize\r
+ * @param request\r
+ * @param response\r
+ * @return\r
+ * @throws IOException\r
+ * @throws ParseException\r
+ */\r
+ @RequestMapping(method = RequestMethod.GET, value={"/portal/taxon/findByDescriptionElementFullText"})\r
+ public Pager<SearchResult<TaxonBase>> dofindByDescriptionElementFullText(\r
+ @RequestParam(value = "clazz", required = false) Class clazz,\r
+ @RequestParam(value = "query", required = true) String queryString,\r
+ @RequestParam(value = "tree", required = false) UUID treeUuid,\r
+ @RequestParam(value = "features", required = false) UuidList featureUuids,\r
+ @RequestParam(value = "languages", required = false) List<Language> languages,\r
+ @RequestParam(value = "hl", required = false) Boolean highlighting,\r
+ @RequestParam(value = "pageNumber", required = false) Integer pageNumber,\r
+ @RequestParam(value = "pageSize", required = false) Integer pageSize,\r
+ HttpServletRequest request,\r
+ HttpServletResponse response\r
+ )\r
+ throws IOException, ParseException {\r
+\r
+ logger.info("findByDescriptionElementFullText : " + request.getRequestURI() + "?" + request.getQueryString() );\r
+\r
+ PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);\r
+ pagerParams.normalizeAndValidate(response);\r
+\r
+ if(highlighting == null){\r
+ highlighting = false;\r
+ }\r
+\r
+ Classification classification = null;\r
+ if(treeUuid != null){\r
+ classification = classificationService.find(treeUuid);\r
+ }\r
+\r
+ List<Feature> features = null;\r
+ if(featureUuids != null){\r
+ features = new ArrayList<Feature>(featureUuids.size());\r
+ for(UUID uuid : featureUuids){\r
+ features.add((Feature) termService.find(uuid));\r
+ }\r
+ }\r
+\r
+ Pager<SearchResult<TaxonBase>> pager = service.findByDescriptionElementFullText(clazz, queryString, classification, features, languages, highlighting, pagerParams.getPageSize(), pagerParams.getPageIndex(), ((List<OrderHint>)null), SIMPLE_TAXON_INIT_STRATEGY);\r
+ return pager;\r
+ }\r
+\r
+ /**\r
+ * Get the synonymy for a taxon identified by the <code>{taxon-uuid}</code>.\r
+ * The synonymy consists\r
+ * of two parts: The group of homotypic synonyms of the taxon and the\r
+ * heterotypic synonymy groups of the taxon. The synonymy is ordered\r
+ * historically by the type designations and by the publication date of the\r
+ * nomenclatural reference\r
+ * <p>\r
+ * URI:\r
+ * <b>/{datasource-name}/portal/taxon/{taxon-uuid}/synonymy</b>\r
+ *\r
+ *\r
+ * @param request\r
+ * @param response\r
+ * @return a Map with to entries which are mapped by the following keys:\r
+ * "homotypicSynonymsByHomotypicGroup", "heterotypicSynonymyGroups",\r
+ * containing lists of {@link Synonym}s which are initialized using the\r
+ * following initialization strategy: {@link #SYNONYMY_INIT_STRATEGY}\r
+ *\r
+ * @throws IOException\r
+ */\r
+ @RequestMapping(\r
+ value = {"synonymy"},\r
+ method = RequestMethod.GET)\r
+ public ModelAndView doGetSynonymy(@PathVariable("uuid") UUID uuid,\r
+ HttpServletRequest request, HttpServletResponse response)throws IOException {\r
+\r
+ if(request != null){\r
+ logger.info("doGetSynonymy() " + request.getServletPath());\r
+ }\r
+ ModelAndView mv = new ModelAndView();\r
+ Taxon taxon = getCdmBaseInstance(Taxon.class, uuid, response, (List<String>)null);\r
+ Map<String, List<?>> synonymy = new Hashtable<String, List<?>>();\r
+ synonymy.put("homotypicSynonymsByHomotypicGroup", service.getHomotypicSynonymsByHomotypicGroup(taxon, SYNONYMY_INIT_STRATEGY));\r
+ synonymy.put("heterotypicSynonymyGroups", service.getHeterotypicSynonymyGroups(taxon, SYNONYMY_INIT_STRATEGY));\r
+ mv.addObject(synonymy);\r
+ return mv;\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}/portal/taxon/{taxon-uuid}/accepted</b>\r
+ *\r
+ * @param request\r
+ * @param response\r
+ * @return a Set of {@link Taxon} entities which are initialized\r
+ * using the following initialization strategy:\r
+ * {@link #SYNONYMY_INIT_STRATEGY}\r
+ * @throws IOException\r
+ */\r
+ @RequestMapping(value = "accepted/{classification_uuid}", method = RequestMethod.GET)\r
+ public Set<TaxonBase> getAccepted(\r
+ @PathVariable("uuid") UUID uuid,\r
+ @PathVariable("classification_uuid") UUID classification_uuid,\r
+ HttpServletRequest request,\r
+ HttpServletResponse response)\r
+ throws IOException {\r
+\r
+ if(request != null){\r
+ logger.info("getAccepted() " + request.getServletPath());\r
+ }\r
+\r
+ TaxonBase tb = service.load(uuid, SYNONYMY_WITH_NODES_INIT_STRATEGY);\r
+ if(tb == null){\r
+ response.sendError(HttpServletResponse.SC_NOT_FOUND, "A taxon with the uuid " + uuid + " does not exist");\r
+ return null;\r
+ }\r
+\r
+ HashSet<TaxonBase> resultset = new HashSet<TaxonBase>();\r
+\r
+ if (tb instanceof Taxon){\r
+ Taxon taxon = (Taxon) tb;\r
+ Set<TaxonNode> nodes = taxon.getTaxonNodes();\r
+ for (TaxonNode taxonNode : nodes) {\r
+ if (taxonNode.getClassification().compareTo(classification_uuid) == 0){\r
+ resultset.add((Taxon) tb);\r
+ }\r
+ }\r
+ if (resultset.size() > 1){\r
+ //error!! A taxon is not allow to have more taxonnodes for a given classification\r
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,\r
+ "A taxon with the uuid " + uuid + " has more than one taxon node for the given classification" + classification_uuid);\r
+ }\r
+ }else{\r
+ Synonym syn = (Synonym) tb;\r
+ for(TaxonBase accepted : syn.getAcceptedTaxa()){\r
+ tb = service.load(accepted.getUuid(), SIMPLE_TAXON_WITH_NODES_INIT_STRATEGY);\r
+ if (tb instanceof Taxon){\r
+ Taxon taxon = (Taxon) tb;\r
+ Set<TaxonNode> nodes = taxon.getTaxonNodes();\r
+ for (TaxonNode taxonNode : nodes) {\r
+ if (taxonNode.getClassification().compareTo(classification_uuid) == 0){\r
+ resultset.add((Taxon) tb);\r
+ }\r
+ }\r
+ if (resultset.size() > 1){\r
+ //error!! A taxon is not allow to have more taxonnodes for a given classification\r
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,\r
+ "A taxon with the uuid " + uuid + " has more than one taxon node for the given classification" + classification_uuid);\r
+ }\r
+ }else{\r
+ //ERROR!! perhaps missapplied name????\r
+ //syn.getRelationType((Taxon)accepted);\r
+ }\r
+ }\r
+ }\r
+/**\r
+ * OLD CODE!!\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
+ for(TaxonBase accepted : syn.getAcceptedTaxa()){\r
+ accepted = service.load(accepted.getUuid(), SIMPLE_TAXON_INIT_STRATEGY);\r
+ resultset.add(accepted);\r
+ }\r
+ }\r
+*/\r
+ return resultset;\r
+ }\r
+\r
+ /**\r
+ * Get the list of {@link TaxonRelationship}s for the given\r
+ * {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.\r
+ * <p>\r
+ * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/taxonRelationships</b>\r
+ *\r
+ * @param request\r
+ * @param response\r
+ * @return a List of {@link TaxonRelationship} entities which are initialized\r
+ * using the following initialization strategy:\r
+ * {@link #TAXONRELATIONSHIP_INIT_STRATEGY}\r
+ * @throws IOException\r
+ */\r
+ @RequestMapping(\r
+ value = {"taxonRelationships"},\r
+ method = RequestMethod.GET)\r
+ public List<TaxonRelationship> doGetTaxonRelations(@PathVariable("uuid") UUID uuid,\r
+ HttpServletRequest request, HttpServletResponse response)throws IOException {\r
+\r
+ logger.info("doGetTaxonRelations()" + request.getServletPath());\r
+ Taxon taxon = getCdmBaseInstance(Taxon.class, uuid, response, (List<String>)null);\r
+ List<TaxonRelationship> toRelationships = service.listToTaxonRelationships(taxon, null, null, null, null, TAXONRELATIONSHIP_INIT_STRATEGY);\r
+ List<TaxonRelationship> fromRelationships = service.listFromTaxonRelationships(taxon, null, null, null, null, TAXONRELATIONSHIP_INIT_STRATEGY);\r
+\r
+ List<TaxonRelationship> allRelationships = new ArrayList<TaxonRelationship>(toRelationships.size() + fromRelationships.size());\r
+ allRelationships.addAll(toRelationships);\r
+ allRelationships.addAll(fromRelationships);\r
+\r
+ return allRelationships;\r
+ }\r
+\r
+ /**\r
+ * Get the list of {@link NameRelationship}s of the Name associated with the\r
+ * {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.\r
+ * <p>\r
+ * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/nameRelationships</b>\r
+ *\r
+ * @param request\r
+ * @param response\r
+ * @return a List of {@link NameRelationship} entities which are initialized\r
+ * using the following initialization strategy:\r
+ * {@link #NAMERELATIONSHIP_INIT_STRATEGY}\r
+ * @throws IOException\r
+ */\r
+ @RequestMapping(\r
+ value = {"toNameRelationships"},\r
+ method = RequestMethod.GET)\r
+ public List<NameRelationship> doGetToNameRelations(@PathVariable("uuid") UUID uuid,\r
+ HttpServletRequest request, HttpServletResponse response)throws IOException {\r
+ logger.info("doGetNameRelations()" + request.getServletPath());\r
+ TaxonBase taxonBase = getCdmBaseInstance(TaxonBase.class, uuid, response, (List<String>)null);\r
+ List<NameRelationship> list = nameService.listNameRelationships(taxonBase.getName(), Direction.relatedTo, null, null, 0, null, NAMERELATIONSHIP_INIT_STRATEGY);\r
+ //List<NameRelationship> list = nameService.listToNameRelationships(taxonBase.getName(), null, null, null, null, NAMERELATIONSHIP_INIT_STRATEGY);\r
+ return list;\r
+ }\r
+\r
+ /**\r
+ * Get the list of {@link NameRelationship}s of the Name associated with the\r
+ * {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.\r
+ * <p>\r
+ * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/nameRelationships</b>\r
+ *\r
+ * @param request\r
+ * @param response\r
+ * @return a List of {@link NameRelationship} entities which are initialized\r
+ * using the following initialization strategy:\r
+ * {@link #NAMERELATIONSHIP_INIT_STRATEGY}\r
+ * @throws IOException\r
+ */\r
+ @RequestMapping(\r
+ value = {"fromNameRelationships"},\r
+ method = RequestMethod.GET)\r
+ public List<NameRelationship> doGetFromNameRelations(@PathVariable("uuid") UUID uuid,\r
+ HttpServletRequest request, HttpServletResponse response)throws IOException {\r
+ logger.info("doGetNameFromNameRelations()" + request.getServletPath());\r
+\r
+ TaxonBase taxonbase = getCdmBaseInstance(TaxonBase.class, uuid, response, SIMPLE_TAXON_INIT_STRATEGY);\r
+ List<NameRelationship> list = nameService.listNameRelationships(taxonbase.getName(), Direction.relatedFrom, null, null, 0, null, NAMERELATIONSHIP_INIT_STRATEGY);\r
+ //List<NameRelationship> list = nameService.listFromNameRelationships(taxonbase.getName(), null, null, null, null, NAMERELATIONSHIP_INIT_STRATEGY);\r
+ return list;\r
+ }\r
+\r
+ /**\r
+ * Get the list of {@link TypeDesignationBase}s of the\r
+ * {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.\r
+ * <p>\r
+ * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/nameTypeDesignations</b>\r
+ *\r
+ * @param request\r
+ * @param response\r
+ * @return a List of {@link TypeDesignationBase} entities which are initialized\r
+ * using the following initialization strategy:\r
+ * {@link #TYPEDESIGNATION_INIT_STRATEGY}\r
+ * @throws IOException\r
+ * @Deprecated use /name/{uuid}/typeDesignations & /derivedunitfacade/{uuid} instead\r
+ * also see http://dev.e-taxonomy.eu/trac/ticket/2280\r
+ */\r
+ @Deprecated\r
+ @RequestMapping(\r
+ value = {"nameTypeDesignations"},\r
+ method = RequestMethod.GET)\r
+ public List<TypeDesignationBase> doGetNameTypeDesignations(@PathVariable("uuid") UUID uuid,\r
+ HttpServletRequest request, HttpServletResponse response)throws IOException {\r
+ logger.info("doGetNameTypeDesignations()" + request.getServletPath());\r
+ Taxon taxon = getCdmBaseInstance(Taxon.class, uuid, response, SIMPLE_TAXON_INIT_STRATEGY);\r
+ Pager<TypeDesignationBase> p = nameService.getTypeDesignations(taxon.getName(), null, null, null, TYPEDESIGNATION_INIT_STRATEGY);\r
+ return p.getRecords();\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
+ * Get the list of {@link TaxonDescription}s of the\r
+ * {@link Taxon} instance identified by the <code>{taxon-uuid}</code>.\r
+ * <p>\r
+ * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/descriptions</b>\r
+ *\r
+ * @param request\r
+ * @param response\r
+ * @return a List of {@link TaxonDescription} entities which are initialized\r
+ * using the following initialization strategy:\r
+ * {@link #TAXONDESCRIPTION_INIT_STRATEGY}\r
+ * @throws IOException\r
+ */\r
+ @RequestMapping(\r
+ value = {"descriptions"},\r
+ method = RequestMethod.GET)\r
+ public List<TaxonDescription> doGetDescriptions(\r
+ @PathVariable("uuid") UUID uuid,\r
+ @RequestParam(value = "markerTypes", required = false) UuidList markerTypeUUIDs,\r
+ HttpServletRequest request,\r
+ HttpServletResponse response)throws IOException {\r
+ if(request != null){\r
+ logger.info("doGetDescriptions()" + request.getServletPath());\r
+ }\r
+ List<DefinedTermBase> markerTypeTerms = null;\r
+ Set<UUID> sMarkerTypeUUIDs = null;\r
+\r
+ if(markerTypeUUIDs != null && !markerTypeUUIDs.isEmpty()){\r
+ sMarkerTypeUUIDs = new HashSet<UUID>(markerTypeUUIDs);\r
+ markerTypeTerms = termService.find(sMarkerTypeUUIDs);\r
+ } else if(markerTypeUUIDs != null && markerTypeUUIDs.isEmpty()){\r
+ markerTypeTerms = new ArrayList<DefinedTermBase>();\r
+ }\r
+ Set<MarkerType> markerTypes = new HashSet<MarkerType>();\r
+ List<TaxonDescription> descriptions = new ArrayList<TaxonDescription>();\r
+ if (markerTypeTerms != null) {\r
+ for (DefinedTermBase markerTypeTerm : markerTypeTerms) {\r
+ markerTypes.add((MarkerType)markerTypeTerm);\r
+ }\r
+ }\r
+ Taxon t = getCdmBaseInstance(Taxon.class, uuid, response, (List<String>)null);\r
+ if (markerTypeTerms == null) {\r
+\r
+ Pager<TaxonDescription> p = descriptionService.getTaxonDescriptions(t, null, null, null, null, TAXONDESCRIPTION_INIT_STRATEGY);\r
+ descriptions = p.getRecords();\r
+ }\r
+\r
+ else if (markerTypeTerms != null && markerTypeTerms.isEmpty()) {\r
+ descriptions = descriptionService.listTaxonDescriptions(t, null, null, markerTypes, null, null, TAXONUSEDESCRIPTION_INIT_STRATEGY);\r
+\r
+ }\r
+ else {\r
+ descriptions = descriptionService.listTaxonDescriptions(t, null, null, markerTypes, null, null, TAXONUSEDESCRIPTION_INIT_STRATEGY);\r
+ /*for (TaxonDescription description: descriptions) {\r
+ for (IdentifiableSource source :description.getSources()) {\r
+ if (source.getOriginalNameString() != null) {\r
+ description.\r
+ }\r
+\r
+ }\r
+\r
+\r
+ }*/\r
+ }\r
+ return descriptions;\r
+ }\r
+\r
+ @RequestMapping(value = "useDescriptions", method = RequestMethod.GET)\r
+ public List<TaxonDescription> doGetUseDescriptions(\r
+ @PathVariable("uuid") UUID uuid,\r
+ HttpServletRequest request,\r
+ HttpServletResponse response) throws IOException {\r
+ logger.info("doGetDescriptionElements() - " + request.getServletPath());\r
+\r
+ //ModelAndView mv = new ModelAndView();\r
+ Taxon t = getCdmBaseInstance(Taxon.class, uuid, response, (List<String>)null);\r
+\r
+ //MarkerType useMarkerType = (MarkerType) markerTypeService.find(UUID.fromString("2e6e42d9-e92a-41f4-899b-03c0ac64f059"));\r
+ MarkerType useMarkerType = (MarkerType) termService.find(UUID.fromString("2e6e42d9-e92a-41f4-899b-03c0ac64f039"));\r
+\r
+ //find(UUID.fromString("2e6e42d9-e92a-41f4-899b-03c0ac64f059"));\r
+ Set<MarkerType> markerTypes = new HashSet<MarkerType>();\r
+ markerTypes.add(useMarkerType);\r
+ List<TaxonDescription> descriptionElements = descriptionService.listTaxonDescriptions(t, null, null, markerTypes, null, null, TAXONUSEDESCRIPTION_INIT_STRATEGY);\r
+ //getDescriptionElements(description, features, type, pageSize, pageNumber, propertyPaths) load(uuid);\r
+\r
+ /*if(!(description instanceof TaxonDescription)){\r
+ HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);\r
+ // will terminate thread\r
+ }*/\r
+\r
+ //boolean hasStructuredData = service. hasStructuredData(description);\r
+\r
+ //mv.addObject(hasStructuredData);\r
+\r
+ return descriptionElements;\r
+ }\r
+\r
+ @RequestMapping(value = "descriptions/elementsByType/{classSimpleName}", method = RequestMethod.GET)\r
+ public ModelAndView doGetDescriptionElementsByType(\r
+ @PathVariable("uuid") UUID uuid,\r
+ @PathVariable("classSimpleName") String classSimpleName,\r
+ @RequestParam(value = "markerTypes", required = false) UuidList markerTypeUUIDs,\r
+ @RequestParam(value = "count", required = false, defaultValue = "false") Boolean doCount,\r
+ HttpServletRequest request,\r
+ HttpServletResponse response) throws IOException {\r
+ logger.info("doGetDescriptionElementsByType() - " + request.getServletPath());\r
+\r
+ ModelAndView mv = new ModelAndView();\r
+\r
+ List<DescriptionElementBase> allElements = new ArrayList<DescriptionElementBase>();\r
+ List<DescriptionElementBase> elements;\r
+ int count = 0;\r
+\r
+ List<String> initStrategy = doCount ? null : DESCRIPTION_ELEMENT_INIT_STRATEGY;\r
+\r
+ List<TaxonDescription> taxonDescriptions = doGetDescriptions(uuid, markerTypeUUIDs, request, response);\r
+ try {\r
+ Class type;\r
+ type = Class.forName("eu.etaxonomy.cdm.model.description."\r
+ + classSimpleName);\r
+ if (taxonDescriptions != null) {\r
+ for (TaxonDescription description : taxonDescriptions) {\r
+ elements = descriptionService.listDescriptionElements(description, null, type, null, 0, initStrategy);\r
+ allElements.addAll(elements);\r
+ count += elements.size();\r
+ }\r
+\r
+ }\r
+ } catch (ClassNotFoundException e) {\r
+ HttpStatusMessage.fromString(e.getLocalizedMessage()).send(response);\r
+ }\r
+ if(doCount){\r
+ mv.addObject(count);\r
+ } else {\r
+ mv.addObject(allElements);\r
+ }\r
+ return mv;\r
+ }\r
+\r
+// @RequestMapping(value = "specimens", method = RequestMethod.GET)\r
+// public ModelAndView doGetSpecimens(\r
+// @PathVariable("uuid") UUID uuid,\r
+// HttpServletRequest request,\r
+// HttpServletResponse response) throws IOException, ClassNotFoundException {\r
+// logger.info("doGetSpecimens() - " + request.getServletPath());\r
+//\r
+// ModelAndView mv = new ModelAndView();\r
+//\r
+// List<DerivedUnitFacade> derivedUnitFacadeList = new ArrayList<DerivedUnitFacade>();\r
+//\r
+// // find speciemens in the TaxonDescriptions\r
+// List<TaxonDescription> taxonDescriptions = doGetDescriptions(uuid, request, response);\r
+// if (taxonDescriptions != null) {\r
+//\r
+// for (TaxonDescription description : taxonDescriptions) {\r
+// derivedUnitFacadeList.addAll( occurrenceService.listDerivedUnitFacades(description, null) );\r
+// }\r
+// }\r
+// // TODO find speciemens in the NameDescriptions ??\r
+//\r
+// // TODO also find type specimens\r
+//\r
+// mv.addObject(derivedUnitFacadeList);\r
+//\r
+// return mv;\r
+// }\r
+\r
+ /**\r
+ * Get the {@link Media} attached to the {@link Taxon} instance\r
+ * identified by the <code>{taxon-uuid}</code>.\r
+ *\r
+ * Usage /{datasource-name}/portal/taxon/{taxon-\r
+ * uuid}/media/{mime type\r
+ * list}/{size}[,[widthOrDuration}][,{height}]/\r
+ *\r
+ * Whereas\r
+ * <ul>\r
+ * <li><b>{mime type list}</b>: a comma separated list of mime types, in the\r
+ * order of preference. The forward slashes contained in the mime types must\r
+ * be replaced by a colon. Regular expressions can be used. Each media\r
+ * associated with this given taxon is being searched whereas the first\r
+ * matching mime type matching a representation always rules.</li>\r
+ * <li><b>{size},{widthOrDuration},{height}</b>: <i>not jet implemented</i>\r
+ * valid values are an integer or the asterisk '*' as a wildcard</li>\r
+ * </ul>\r
+ *\r
+ * @param request\r
+ * @param response\r
+ * @return a List of {@link Media} entities which are initialized\r
+ * using the following initialization strategy:\r
+ * {@link #TAXONDESCRIPTION_INIT_STRATEGY}\r
+ * @throws IOException\r
+ */\r
+ @RequestMapping(\r
+ value = {"media"},\r
+ method = RequestMethod.GET)\r
+ public List<Media> doGetMedia(\r
+ @PathVariable("uuid") UUID uuid,\r
+ @RequestParam(value = "type", required = false) Class<? extends MediaRepresentationPart> type,\r
+ @RequestParam(value = "mimeTypes", required = false) String[] mimeTypes,\r
+ @RequestParam(value = "widthOrDuration", required = false) Integer widthOrDuration,\r
+ @RequestParam(value = "height", required = false) Integer height,\r
+ @RequestParam(value = "size", required = false) Integer size,\r
+ HttpServletRequest request, HttpServletResponse response) throws IOException {\r
+\r
+ logger.info("doGetMedia()" + request.getServletPath());\r
+ Taxon t = getCdmBaseInstance(Taxon.class, uuid, response, (List<String>)null);\r
+ String path = request.getServletPath();\r
+ List<Media> returnMedia = getMediaForTaxon(t, type, mimeTypes, widthOrDuration, height, size);\r
+ return returnMedia;\r
+ }\r
+\r
+ @RequestMapping(\r
+ value = {"subtree/media"},\r
+ method = RequestMethod.GET)\r
+ public List<Media> doGetSubtreeMedia(\r
+ @PathVariable("uuid") UUID uuid,\r
+ @RequestParam(value = "type", required = false) Class<? extends MediaRepresentationPart> type,\r
+ @RequestParam(value = "mimeTypes", required = false) String[] mimeTypes,\r
+ @RequestParam(value = "widthOrDuration", required = false) Integer widthOrDuration,\r
+ @RequestParam(value = "height", required = false) Integer height,\r
+ @RequestParam(value = "size", required = false) Integer size,\r
+ HttpServletRequest request, HttpServletResponse response)throws IOException {\r
+ logger.info("doGetMedia()" + request.getServletPath());\r
+ Taxon taxon = getCdmBaseInstance(Taxon.class, uuid, response, TAXON_WITH_NODES_INIT_STRATEGY);\r
+ String requestPath = request.getServletPath();\r
+ List<Media> returnMedia = getMediaForTaxon(taxon, type, mimeTypes, widthOrDuration, height, size);\r
+ TaxonNode node;\r
+ //looking for all medias of genus\r
+ if (taxon.getTaxonNodes().size()>0){\r
+ Set<TaxonNode> nodes = taxon.getTaxonNodes();\r
+ Iterator<TaxonNode> iterator = nodes.iterator();\r
+ //TaxonNode holen\r
+ node = iterator.next();\r
+ //Check if TaxonNode belongs to the current tree\r
+\r
+ node = classificationService.loadTaxonNode(node, TAXONNODE_WITHTAXON_INIT_STRATEGY);\r
+ Set<TaxonNode> children = node.getChildNodes();\r
+ Taxon childTaxon;\r
+ for (TaxonNode child : children){\r
+ childTaxon = child.getTaxon();\r
+ childTaxon = (Taxon)taxonService.load(childTaxon.getUuid(), null);\r
+ returnMedia.addAll(getMediaForTaxon(childTaxon, type, mimeTypes, widthOrDuration, height, size));\r
+ }\r
+ }\r
+ return returnMedia;\r
+ }\r
+\r
+\r
+ private List<Media> getMediaForTaxon(Taxon taxon, Class<? extends MediaRepresentationPart> type, String[] mimeTypes,\r
+ Integer widthOrDuration, Integer height, Integer size){\r
+\r
+ List<Media> taxonGalleryMedia = service.listTaxonDescriptionMedia(taxon, false, TAXONDESCRIPTION_MEDIA_INIT_STRATEGY);\r
+\r
+ Map<Media, MediaRepresentation> mediaRepresentationMap = MediaUtils.findPreferredMedia(taxonGalleryMedia, type,\r
+ mimeTypes, null, widthOrDuration, height, size);\r
+\r
+ List<Media> filteredMedia = new ArrayList<Media>(mediaRepresentationMap.size());\r
+ for(Media media : mediaRepresentationMap.keySet()){\r
+ media.getRepresentations().clear();\r
+ media.addRepresentation(mediaRepresentationMap.get(media));\r
+ filteredMedia.add(media);\r
+ }\r
+\r
+ return filteredMedia;\r
+ }\r
+\r
+\r
+// ---------------------- code snippet preserved for possible later use --------------------\r