3 * Copyright (C) 2009 EDIT European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 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
.HttpServletRequest
;
18 import javax
.servlet
.http
.HttpServletResponse
;
20 import org
.apache
.log4j
.Logger
;
21 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
22 import org
.springframework
.stereotype
.Controller
;
23 import org
.springframework
.web
.bind
.WebDataBinder
;
24 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
25 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
26 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
27 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
29 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
30 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
31 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
32 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
33 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
34 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
35 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
36 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
37 import eu
.etaxonomy
.cdm
.remote
.editor
.RankPropertyEditor
;
40 * The ClassificationController class is a Spring MVC Controller.
41 * @author a.kohlbecker
45 @RequestMapping(value
="/portal/classification")
46 public class ClassificationPortalListController
extends IdentifiableListController
<Classification
,IClassificationService
> {
49 private static final List
<String
> CLASSIFICATION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
50 "reference.authorTeam"
54 private static final List
<String
> NODE_INIT_STRATEGY
= Arrays
.asList(new String
[]{
60 public static final Logger logger
= Logger
.getLogger(ClassificationPortalListController
.class);
62 private ITaxonService taxonService
;
64 private ITermService termService
;
66 public ClassificationPortalListController() {
67 setInitializationStrategy(CLASSIFICATION_INIT_STRATEGY
);
72 public void setService(IClassificationService service
) {
73 this.service
= service
;
77 public void setTermService(ITermService termService
) {
78 this.termService
= termService
;
82 public void setTaxonService(ITaxonService taxonService
) {
83 this.taxonService
= taxonService
;
89 public void initBinder(WebDataBinder binder
) {
90 super.initBinder(binder
);
91 binder
.registerCustomEditor(Rank
.class, new RankPropertyEditor());
102 value
= {"{treeUuid}/childNodes"},
103 method
= RequestMethod
.GET
)
104 public List
<TaxonNode
> getChildNodes(
105 @PathVariable("treeUuid") UUID treeUuid
,
106 HttpServletRequest request
,
107 HttpServletResponse response
108 ) throws IOException
{
110 return getChildNodesAtRank(treeUuid
, null, request
, response
);
115 value
= {"{treeUuid}/childNodesAt/{rankUuid}"},
116 method
= RequestMethod
.GET
)
117 public List
<TaxonNode
> getChildNodesAtRank(
118 @PathVariable("treeUuid") UUID treeUuid
,
119 @PathVariable("rankUuid") UUID rankUuid
,
120 HttpServletRequest request
,
121 HttpServletResponse response
122 ) throws IOException
{
124 logger
.info("getChildNodesAtRank() " + request
.getRequestURI());
125 Classification tree
= null;
127 if(treeUuid
!= null){
129 tree
= service
.find(treeUuid
);
132 response
.sendError(404 , "Classification not found using " + treeUuid
);
136 rank
= findRank(rankUuid
);
138 return service
.listRankSpecificRootNodes(tree
, rank
, null, null, NODE_INIT_STRATEGY
);
145 * Lists all child-{@link TaxonNode}s of the specified {@link Taxon} in the {@link Classification}. The
146 * a given {@link Rank} is ignored in this method but for consistency reasons it has been allowed to included it into the URI.
148 * URI: <b>/portal/classification/{treeUuid}/childNodesOf/{taxonUuid}</b>
150 * <b>URI elements:</b>
152 * <li><b>{tree-uuid}</b> identifies the {@link Classification} by its UUID - <i>required</i>.
153 * <li><b>{taxon-uuid}</b> identifies the {@link Taxon} by its UUID. - <i>required</i>.
158 * @return a List of {@link TaxonNode} entities initialized by
159 * the {@link #NODE_INIT_STRATEGY}
162 value
= {"{treeUuid}/childNodesOf/{taxonUuid}"},
163 method
= RequestMethod
.GET
)
164 public List
<TaxonNode
> getChildNodesOfTaxon(
165 @PathVariable("treeUuid") UUID treeUuid
,
166 @PathVariable("taxonUuid") UUID taxonUuid
,
167 HttpServletRequest request
,
168 HttpServletResponse response
) throws IOException
{
169 logger
.info("getChildNodesOfTaxon() " + request
.getRequestURI());
172 List
<TaxonNode
> childs
= service
.listChildNodesOfTaxon(taxonUuid
, treeUuid
, null, null, NODE_INIT_STRATEGY
);
178 * Provides path of {@link TaxonNode}s from the base node to the node of the specified taxon.
180 * URI:<b>/portal/classification/{treeUuid}/pathFrom/{taxonUuid}/toRank/{rankUuid}</b>
182 * <b>URI elements:</b>
184 * <li><b>{treeUuid}</b> identifies the {@link Classification} by its UUID - <i>required</i>.
185 * <li><b>{taxonUuid}</b> identifies the {@link Rank}
186 * <li><b>{rankUuid}</b> identifies the {@link Taxon} by its UUID. - <i>required</i>.
191 * @return a List of {@link TaxonNode} entities initialized by
192 * the {@link #NODE_INIT_STRATEGY}
195 value
= {"{treeUuid}/pathFrom/{taxonUuid}/toRank/{rankUuid}"},
196 method
= RequestMethod
.GET
)
197 public List
<TaxonNode
> getPathFromTaxonToRank(
198 @PathVariable("treeUuid") UUID treeUuid
,
199 @PathVariable("taxonUuid") UUID taxonUuid
,
200 @PathVariable("rankUuid") UUID rankUuid
,
201 HttpServletRequest request
,
202 HttpServletResponse response
) throws IOException
{
203 logger
.info("getPathFromTaxonToRank() " + request
.getRequestURI());
205 Classification tree
= service
.find(treeUuid
);
206 Rank rank
= findRank(rankUuid
);
207 Taxon taxon
= (Taxon
) taxonService
.load(taxonUuid
);
209 return service
.loadTreeBranchToTaxon(taxon
, tree
, rank
, NODE_INIT_STRATEGY
);
213 * Provides path of {@link TaxonNode}s from the base node to the node of the specified taxon.
215 * URI:<b>/portal/classification/{treeUuid}/pathFrom/{taxonUuid}</b>
217 * <b>URI elements:</b>
219 * <li><b>{treeUuid}</b> identifies the {@link Classification} by its UUID - <i>required</i>.
220 * <li><b>{rankUuid}</b> identifies the {@link Taxon} by its UUID. - <i>required</i>.
225 * @return a List of {@link TaxonNode} entities initialized by
226 * the {@link #NODE_INIT_STRATEGY}
229 value
= {"{treeUuid}/pathFrom/{taxonUuid}"},
230 method
= RequestMethod
.GET
)
231 public List
<TaxonNode
> getPathFromTaxon(
232 @PathVariable("treeUuid") UUID treeUuid
,
233 @PathVariable("taxonUuid") UUID taxonUuid
,
234 HttpServletRequest request
,
235 HttpServletResponse response
) throws IOException
{
237 return getPathFromTaxonToRank(treeUuid
, taxonUuid
, null, request
, response
);
241 private Rank
findRank(UUID rankUuid
) {
243 if(rankUuid
!= null){
244 DefinedTermBase dt
= termService
.find(rankUuid
);
245 if(dt
instanceof Rank
){
248 new IllegalArgumentException("DefinedTermBase is not a Rank");