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 io
.swagger
.annotations
.Api
;
14 import java
.io
.IOException
;
15 import java
.util
.Arrays
;
16 import java
.util
.List
;
17 import java
.util
.UUID
;
19 import javax
.servlet
.http
.HttpServletRequest
;
20 import javax
.servlet
.http
.HttpServletResponse
;
22 import org
.apache
.log4j
.Logger
;
23 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
24 import org
.springframework
.stereotype
.Controller
;
25 import org
.springframework
.web
.bind
.WebDataBinder
;
26 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
27 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
28 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
29 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
31 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
32 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
33 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
34 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
35 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
36 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
37 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
38 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
39 import eu
.etaxonomy
.cdm
.remote
.editor
.RankPropertyEditor
;
42 * The ClassificationController class is a Spring MVC Controller.
43 * @author a.kohlbecker
47 @Api("portal_classification")
48 @RequestMapping(value
="/portal/classification")
49 public class ClassificationPortalListController
extends IdentifiableListController
<Classification
,IClassificationService
> {
52 private static final List
<String
> CLASSIFICATION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
53 "reference.authorship"
57 private static final List
<String
> NODE_INIT_STRATEGY
= Arrays
.asList(new String
[]{
63 public static final Logger logger
= Logger
.getLogger(ClassificationPortalListController
.class);
65 private ITaxonService taxonService
;
67 private ITermService termService
;
69 public ClassificationPortalListController() {
70 setInitializationStrategy(CLASSIFICATION_INIT_STRATEGY
);
75 public void setService(IClassificationService service
) {
76 this.service
= service
;
80 public void setTermService(ITermService termService
) {
81 this.termService
= termService
;
85 public void setTaxonService(ITaxonService taxonService
) {
86 this.taxonService
= taxonService
;
92 public void initBinder(WebDataBinder binder
) {
93 super.initBinder(binder
);
94 binder
.registerCustomEditor(Rank
.class, new RankPropertyEditor());
102 * @throws IOException+
104 * @Deprecated use {@link ClassificationController#getChildNodes(UUID, HttpServletResponse)} instead
107 value
= {"{treeUuid}/childNodes"},
108 method
= RequestMethod
.GET
)
109 public List
<TaxonNode
> getChildNodes(
110 @PathVariable("treeUuid") UUID treeUuid
,
111 HttpServletRequest request
,
112 HttpServletResponse response
113 ) throws IOException
{
115 return getChildNodesAtRank(treeUuid
, null, request
, response
);
126 * @throws IOException
128 * @Deprecated use {@link ClassificationController#getChildNodesAtRank(UUID, UUID, HttpServletResponse)} instead
131 value
= {"{treeUuid}/childNodesAt/{rankUuid}"},
132 method
= RequestMethod
.GET
)
133 public List
<TaxonNode
> getChildNodesAtRank(
134 @PathVariable("treeUuid") UUID treeUuid
,
135 @PathVariable("rankUuid") UUID rankUuid
,
136 HttpServletRequest request
,
137 HttpServletResponse response
138 ) throws IOException
{
140 logger
.info("getChildNodesAtRank() " + request
.getRequestURI());
141 Classification tree
= null;
143 if(treeUuid
!= null){
145 tree
= service
.find(treeUuid
);
148 response
.sendError(404 , "Classification not found using " + treeUuid
);
152 rank
= findRank(rankUuid
);
154 // long start = System.currentTimeMillis();
155 List
<TaxonNode
> rootNodes
= service
.listRankSpecificRootNodes(tree
, rank
, null, null, NODE_INIT_STRATEGY
);
156 // System.err.println("service.listRankSpecificRootNodes() " + (System.currentTimeMillis() - start));
164 * Lists all child-{@link TaxonNode}s of the specified {@link Taxon} in the {@link Classification}. The
165 * a given {@link Rank} is ignored in this method but for consistency reasons it has been allowed to included it into the URI.
167 * URI: <b>/portal/classification/{treeUuid}/childNodesOf/{taxonUuid}</b>
169 * <b>URI elements:</b>
171 * <li><b>{tree-uuid}</b> identifies the {@link Classification} by its UUID - <i>required</i>.
172 * <li><b>{taxon-uuid}</b> identifies the {@link Taxon} by its UUID. - <i>required</i>.
177 * @return a List of {@link TaxonNode} entities initialized by
178 * the {@link #NODE_INIT_STRATEGY}
181 value
= {"{treeUuid}/childNodesOf/{taxonUuid}"},
182 method
= RequestMethod
.GET
)
183 public List
<TaxonNode
> getChildNodesOfTaxon(
184 @PathVariable("treeUuid") UUID treeUuid
,
185 @PathVariable("taxonUuid") UUID taxonUuid
,
186 HttpServletRequest request
,
187 HttpServletResponse response
) throws IOException
{
188 logger
.info("getChildNodesOfTaxon() " + request
.getRequestURI());
191 List
<TaxonNode
> childs
= service
.listChildNodesOfTaxon(taxonUuid
, treeUuid
, null, null, NODE_INIT_STRATEGY
);
197 * Provides path of {@link TaxonNode}s from the base node to the node of the specified taxon.
199 * URI:<b>/portal/classification/{treeUuid}/pathFrom/{taxonUuid}/toRank/{rankUuid}</b>
201 * <b>URI elements:</b>
203 * <li><b>{treeUuid}</b> identifies the {@link Classification} by its UUID - <i>required</i>.
204 * <li><b>{taxonUuid}</b> identifies the {@link Rank}
205 * <li><b>{rankUuid}</b> identifies the {@link Taxon} by its UUID. - <i>required</i>.
210 * @return a List of {@link TaxonNode} entities initialized by
211 * the {@link #NODE_INIT_STRATEGY}
214 value
= {"{treeUuid}/pathFrom/{taxonUuid}/toRank/{rankUuid}"},
215 method
= RequestMethod
.GET
)
216 public List
<TaxonNode
> getPathFromTaxonToRank(
217 @PathVariable("treeUuid") UUID treeUuid
,
218 @PathVariable("taxonUuid") UUID taxonUuid
,
219 @PathVariable("rankUuid") UUID rankUuid
,
220 HttpServletRequest request
,
221 HttpServletResponse response
) throws IOException
{
222 logger
.info("getPathFromTaxonToRank() " + request
.getRequestURI());
224 Classification tree
= service
.find(treeUuid
);
225 Rank rank
= findRank(rankUuid
);
226 Taxon taxon
= (Taxon
) taxonService
.load(taxonUuid
);
228 return service
.loadTreeBranchToTaxon(taxon
, tree
, rank
, NODE_INIT_STRATEGY
);
232 * Provides path of {@link TaxonNode}s from the base node to the node of the specified taxon.
234 * URI:<b>/portal/classification/{treeUuid}/pathFrom/{taxonUuid}</b>
236 * <b>URI elements:</b>
238 * <li><b>{treeUuid}</b> identifies the {@link Classification} by its UUID - <i>required</i>.
239 * <li><b>{rankUuid}</b> identifies the {@link Taxon} by its UUID. - <i>required</i>.
244 * @return a List of {@link TaxonNode} entities initialized by
245 * the {@link #NODE_INIT_STRATEGY}
248 value
= {"{treeUuid}/pathFrom/{taxonUuid}"},
249 method
= RequestMethod
.GET
)
250 public List
<TaxonNode
> getPathFromTaxon(
251 @PathVariable("treeUuid") UUID treeUuid
,
252 @PathVariable("taxonUuid") UUID taxonUuid
,
253 HttpServletRequest request
,
254 HttpServletResponse response
) throws IOException
{
256 return getPathFromTaxonToRank(treeUuid
, taxonUuid
, null, request
, response
);
260 private Rank
findRank(UUID rankUuid
) {
262 if(rankUuid
!= null){
263 DefinedTermBase dt
= termService
.find(rankUuid
);
264 if(dt
instanceof Rank
){
267 new IllegalArgumentException("DefinedTermBase is not a Rank");