3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.remote
.controller
;
12 import java
.io
.IOException
;
13 import java
.util
.Arrays
;
14 import java
.util
.List
;
15 import java
.util
.UUID
;
17 import javax
.servlet
.http
.HttpServletResponse
;
19 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
20 import org
.springframework
.stereotype
.Controller
;
21 import org
.springframework
.web
.bind
.WebDataBinder
;
22 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
23 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
24 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
25 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
27 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonTreeService
;
28 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
29 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
30 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
31 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
32 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonomicTree
;
33 import eu
.etaxonomy
.cdm
.remote
.editor
.RankPropertyEditor
;
34 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDPropertyEditor
;
37 * @author a.kohlbecker
42 @RequestMapping(value
= {"/classification/{uuid}"})
43 public class ClassificationController
extends AnnotatableController
<TaxonomicTree
,ITaxonTreeService
> {
46 private ITermService termService
;
49 * @see eu.etaxonomy.cdm.remote.controller.BaseController#setService(eu.etaxonomy.cdm.api.service.IService)
53 public void setService(ITaxonTreeService service
) {
54 this.service
= service
;
58 public void setTermService(ITermService termService
) {
59 this.termService
= termService
;
65 public void initBinder(WebDataBinder binder
) {
66 binder
.registerCustomEditor(Rank
.class, new RankPropertyEditor());
69 private List
<String
> NODE_INIT_STRATEGY(){
70 return Arrays
.asList(new String
[]{
72 "taxon.name.taggedName",
73 // "taxon.name.combinationAuthorTeam.*",
74 // "taxon.name.exCombinationAuthorTeam.*",
75 // "taxon.name.basionymAuthorTeam.*",
76 // "taxon.name.exBasionymAuthorTeam.*",
77 "taxon.name.titleCache",
82 * @param classificationUuid
88 value
= {"childNodes/"},
89 method
= RequestMethod
.GET
)
90 public List
<TaxonNode
> getChildNodes(
91 @PathVariable("uuid") UUID classificationUuid
,
92 HttpServletResponse response
93 ) throws IOException
{
95 return getChildNodesAtRank(classificationUuid
, null, response
);
99 value
= {"childNodesAt/{rankUuid}/"},
100 method
= RequestMethod
.GET
)
101 public List
<TaxonNode
> getChildNodesAtRank(
102 @PathVariable("uuid") UUID classificationUuid
,
103 @PathVariable("rankUuid") UUID rankUuid
,
104 HttpServletResponse response
105 ) throws IOException
{
107 logger
.info("getChildNodesAtRank()");
108 TaxonomicTree tree
= null;
110 if(classificationUuid
!= null){
112 tree
= service
.find(classificationUuid
);
115 response
.sendError(404 , "Classification not found using " + classificationUuid
);
119 rank
= findRank(rankUuid
);
121 return service
.loadRankSpecificRootNodes(tree
, rank
, NODE_INIT_STRATEGY());
124 private Rank
findRank(UUID rankUuid
) {
126 if(rankUuid
!= null){
127 DefinedTermBase definedTermBase
= termService
.find(rankUuid
);
128 if(definedTermBase
instanceof Rank
){
129 rank
= (Rank
) definedTermBase
;
131 new IllegalArgumentException("DefinedTermBase is not a Rank");