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 public class ClassificationPortalListController
extends IdentifiableListController
<Classification
,IClassificationService
> {
48 private static final List
<String
> CLASSIFICATION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
49 "reference.authorTeam"
52 private static final List
<String
> NODE_INIT_STRATEGY
= Arrays
.asList(new String
[]{
58 public static final Logger logger
= Logger
.getLogger(ClassificationPortalListController
.class);
60 private ITaxonService taxonService
;
62 private IClassificationService service
;
64 private ITermService termService
;
67 public void setService(IClassificationService service
) {
68 this.service
= service
;
72 public void setTermService(ITermService termService
) {
73 this.termService
= termService
;
77 public void setTaxonService(ITaxonService taxonService
) {
78 this.taxonService
= taxonService
;
84 public void initBinder(WebDataBinder binder
) {
85 super.initBinder(binder
);
86 binder
.registerCustomEditor(Rank
.class, new RankPropertyEditor());
91 * Lists all available {@link Classification}s.
93 * URI: <b>/{datasource-name}/portal/classification</b>
97 * @return a list of {@link Classification}s initialized by
98 * the {@link #CLASSIFICATION_INIT_STRATEGY}
101 @RequestMapping(value
= { "/portal/classification" }, method
= RequestMethod
.GET
)
102 public List
<Classification
> getClassifications(HttpServletRequest request
, HttpServletResponse response
)
104 logger
.info("getClassification() " + request
.getServletPath());
105 return service
.list(null, null, null,null, CLASSIFICATION_INIT_STRATEGY
);
113 * @throws IOException
116 value
= {"/portal/classification/{treeUuid}/childNodes"},
117 method
= RequestMethod
.GET
)
118 public List
<TaxonNode
> getChildNodes(
119 @PathVariable("treeUuid") UUID treeUuid
,
120 HttpServletRequest request
,
121 HttpServletResponse response
122 ) throws IOException
{
124 return getChildNodesAtRank(treeUuid
, null, request
, response
);
129 value
= {"/portal/classification/{treeUuid}/childNodesAt/{rankUuid}"},
130 method
= RequestMethod
.GET
)
131 public List
<TaxonNode
> getChildNodesAtRank(
132 @PathVariable("treeUuid") UUID treeUuid
,
133 @PathVariable("rankUuid") UUID rankUuid
,
134 HttpServletRequest request
,
135 HttpServletResponse response
136 ) throws IOException
{
138 logger
.info("getChildNodesAtRank() " + request
.getServletPath());
139 Classification tree
= null;
141 if(treeUuid
!= null){
143 tree
= service
.find(treeUuid
);
146 response
.sendError(404 , "Classification not found using " + treeUuid
);
150 rank
= findRank(rankUuid
);
152 return service
.loadRankSpecificRootNodes(tree
, rank
, NODE_INIT_STRATEGY
);
159 * Lists all child-{@link TaxonNode}s of the specified {@link Taxon} in the {@link Classification}. The
160 * a given {@link Rank} is ignored in this method but for consistency reasons it has been allowed to included it into the URI.
162 * URI: <b>/portal/classification/{treeUuid}/childNodesOf/{taxonUuid}</b>
164 * <b>URI elements:</b>
166 * <li><b>{tree-uuid}</b> identifies the {@link Classification} by its UUID - <i>required</i>.
167 * <li><b>{taxon-uuid}</b> identifies the {@link Taxon} by its UUID. - <i>required</i>.
172 * @return a List of {@link TaxonNode} entities initialized by
173 * the {@link #NODE_INIT_STRATEGY}
176 value
= {"/portal/classification/{treeUuid}/childNodesOf/{taxonUuid}"},
177 method
= RequestMethod
.GET
)
178 public List
<TaxonNode
> getChildNodesOfTaxon(
179 @PathVariable("treeUuid") UUID treeUuid
,
180 @PathVariable("taxonUuid") UUID taxonUuid
,
181 HttpServletRequest request
,
182 HttpServletResponse response
) throws IOException
{
183 logger
.info("getChildNodesOfTaxon() " + request
.getServletPath());
185 Classification tree
= service
.find(treeUuid
);
186 Taxon taxon
= (Taxon
) taxonService
.load(taxonUuid
);
187 List
<TaxonNode
> childs
= service
.loadChildNodesOfTaxon(taxon
, tree
, NODE_INIT_STRATEGY
);
193 * Provides path of {@link TaxonNode}s from the base node to the node of the specified taxon.
195 * URI:<b>/portal/classification/{treeUuid}/pathFrom/{taxonUuid}/toRank/{rankUuid}</b>
197 * <b>URI elements:</b>
199 * <li><b>{treeUuid}</b> identifies the {@link Classification} by its UUID - <i>required</i>.
200 * <li><b>{taxonUuid}</b> identifies the {@link Rank}
201 * <li><b>{rankUuid}</b> identifies the {@link Taxon} by its UUID. - <i>required</i>.
206 * @return a List of {@link TaxonNode} entities initialized by
207 * the {@link #NODE_INIT_STRATEGY}
210 value
= {"/portal/classification/{treeUuid}/pathFrom/{taxonUuid}/toRank/{rankUuid}"},
211 method
= RequestMethod
.GET
)
212 public List
<TaxonNode
> getPathFromTaxonToRank(
213 @PathVariable("treeUuid") UUID treeUuid
,
214 @PathVariable("taxonUuid") UUID taxonUuid
,
215 @PathVariable("rankUuid") UUID rankUuid
,
216 HttpServletRequest request
,
217 HttpServletResponse response
) throws IOException
{
218 logger
.info("getPathFromTaxonToRank() " + request
.getServletPath());
220 Classification tree
= service
.find(treeUuid
);
221 Rank rank
= findRank(rankUuid
);
222 Taxon taxon
= (Taxon
) taxonService
.load(taxonUuid
);
224 return service
.loadTreeBranchToTaxon(taxon
, tree
, rank
, NODE_INIT_STRATEGY
);
228 * Provides path of {@link TaxonNode}s from the base node to the node of the specified taxon.
230 * URI:<b>/portal/classification/{treeUuid}/pathFrom/{taxonUuid}</b>
232 * <b>URI elements:</b>
234 * <li><b>{treeUuid}</b> identifies the {@link Classification} by its UUID - <i>required</i>.
235 * <li><b>{rankUuid}</b> identifies the {@link Taxon} by its UUID. - <i>required</i>.
240 * @return a List of {@link TaxonNode} entities initialized by
241 * the {@link #NODE_INIT_STRATEGY}
244 value
= {"/portal/classification/{treeUuid}/pathFrom/{taxonUuid}"},
245 method
= RequestMethod
.GET
)
246 public List
<TaxonNode
> getPathFromTaxon(
247 @PathVariable("treeUuid") UUID treeUuid
,
248 @PathVariable("taxonUuid") UUID taxonUuid
,
249 HttpServletRequest request
,
250 HttpServletResponse response
) throws IOException
{
252 return getPathFromTaxonToRank(treeUuid
, taxonUuid
, null, request
, response
);
256 private Rank
findRank(UUID rankUuid
) {
258 if(rankUuid
!= null){
259 DefinedTermBase dt
= termService
.find(rankUuid
);
260 if(dt
instanceof Rank
){
263 new IllegalArgumentException("DefinedTermBase is not a Rank");