2 * Copyright (C) 2009 EDIT European Distributed Institute of Taxonomy
3 * http://www.e-taxonomy.eu
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.remote
.controller
;
11 import io
.swagger
.annotations
.Api
;
13 import java
.io
.IOException
;
14 import java
.util
.Arrays
;
15 import java
.util
.List
;
16 import java
.util
.UUID
;
18 import javax
.servlet
.http
.HttpServletRequest
;
19 import javax
.servlet
.http
.HttpServletResponse
;
21 import org
.apache
.log4j
.Logger
;
22 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
23 import org
.springframework
.stereotype
.Controller
;
24 import org
.springframework
.web
.bind
.WebDataBinder
;
25 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
26 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
27 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
28 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
30 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
31 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
32 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
33 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
34 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
35 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
36 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
37 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
38 import eu
.etaxonomy
.cdm
.remote
.editor
.RankPropertyEditor
;
41 * The ClassificationController class is a Spring MVC Controller.
42 * @author a.kohlbecker
46 @Api("portal_classification")
47 @RequestMapping(value
="/portal/classification")
48 public class ClassificationPortalListController
extends AbstractIdentifiableListController
<Classification
,IClassificationService
> {
51 private static final List
<String
> CLASSIFICATION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
52 "reference.authorship"
56 private static final List
<String
> NODE_INIT_STRATEGY
= Arrays
.asList(new String
[]{
62 public static final Logger logger
= Logger
.getLogger(ClassificationPortalListController
.class);
64 private ITaxonService taxonService
;
66 private ITermService termService
;
68 public ClassificationPortalListController() {
69 setInitializationStrategy(CLASSIFICATION_INIT_STRATEGY
);
74 public void setService(IClassificationService service
) {
75 this.service
= service
;
79 public void setTermService(ITermService termService
) {
80 this.termService
= termService
;
84 public void setTaxonService(ITaxonService taxonService
) {
85 this.taxonService
= taxonService
;
91 public void initBinder(WebDataBinder binder
) {
92 super.initBinder(binder
);
93 binder
.registerCustomEditor(Rank
.class, new RankPropertyEditor());
101 * @throws IOException+
103 * @Deprecated use {@link ClassificationController#getChildNodes(UUID, HttpServletResponse)} instead
106 value
= {"{treeUuid}/childNodes"},
107 method
= RequestMethod
.GET
)
108 public List
<TaxonNode
> getChildNodes(
109 @PathVariable("treeUuid") UUID treeUuid
,
110 HttpServletRequest request
,
111 HttpServletResponse response
112 ) throws IOException
{
114 return getChildNodesAtRank(treeUuid
, null, request
, response
);
125 * @throws IOException
127 * @Deprecated use {@link ClassificationController#getChildNodesAtRank(UUID, UUID, HttpServletResponse)} instead
130 value
= {"{treeUuid}/childNodesAt/{rankUuid}"},
131 method
= RequestMethod
.GET
)
132 public List
<TaxonNode
> getChildNodesAtRank(
133 @PathVariable("treeUuid") UUID treeUuid
,
134 @PathVariable("rankUuid") UUID rankUuid
,
135 HttpServletRequest request
,
136 HttpServletResponse response
137 ) throws IOException
{
139 logger
.info("getChildNodesAtRank() " + request
.getRequestURI());
140 Classification tree
= null;
142 if(treeUuid
!= null){
144 tree
= service
.find(treeUuid
);
147 response
.sendError(404 , "Classification not found using " + treeUuid
);
151 rank
= findRank(rankUuid
);
153 // long start = System.currentTimeMillis();
154 List
<TaxonNode
> rootNodes
= service
.listRankSpecificRootNodes(tree
, rank
, null, null, NODE_INIT_STRATEGY
);
155 // System.err.println("service.listRankSpecificRootNodes() " + (System.currentTimeMillis() - start));
163 * Lists all child-{@link TaxonNode}s of the specified {@link Taxon} in the {@link Classification}. The
164 * a given {@link Rank} is ignored in this method but for consistency reasons it has been allowed to included it into the URI.
166 * URI: <b>/portal/classification/{treeUuid}/childNodesOf/{taxonUuid}</b>
168 * <b>URI elements:</b>
170 * <li><b>{tree-uuid}</b> identifies the {@link Classification} by its UUID - <i>required</i>.
171 * <li><b>{taxon-uuid}</b> identifies the {@link Taxon} by its UUID. - <i>required</i>.
176 * @return a List of {@link TaxonNode} entities initialized by
177 * the {@link #NODE_INIT_STRATEGY}
180 value
= {"{treeUuid}/childNodesOf/{taxonUuid}"},
181 method
= RequestMethod
.GET
)
182 public List
<TaxonNode
> getChildNodesOfTaxon(
183 @PathVariable("treeUuid") UUID treeUuid
,
184 @PathVariable("taxonUuid") UUID taxonUuid
,
185 HttpServletRequest request
,
186 HttpServletResponse response
) throws IOException
{
187 logger
.info("getChildNodesOfTaxon() " + request
.getRequestURI());
190 List
<TaxonNode
> childs
= service
.listChildNodesOfTaxon(taxonUuid
, treeUuid
, null, null, NODE_INIT_STRATEGY
);
196 value
= {"{treeUuid}/siblingsOf/{taxonUuid}"},
197 method
= RequestMethod
.GET
)
198 public List
<TaxonNode
> getSiblingsOfTaxon(
199 @PathVariable("treeUuid") UUID treeUuid
,
200 @PathVariable("taxonUuid") UUID taxonUuid
,
201 HttpServletRequest request
,
202 HttpServletResponse response
) throws IOException
{
203 logger
.info("getSiblingsOfTaxon() " + request
.getRequestURI());
206 List
<TaxonNode
> childs
= service
.listSiblingsOfTaxon(taxonUuid
, treeUuid
, null, null, NODE_INIT_STRATEGY
);
212 * Provides path of {@link TaxonNode}s from the base node to the node of the specified taxon.
214 * URI:<b>/portal/classification/{treeUuid}/pathFrom/{taxonUuid}/toRank/{rankUuid}</b>
216 * <b>URI elements:</b>
218 * <li><b>{treeUuid}</b> identifies the {@link Classification} by its UUID - <i>required</i>.
219 * <li><b>{taxonUuid}</b> identifies the {@link Rank}
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}/toRank/{rankUuid}"},
230 method
= RequestMethod
.GET
)
231 public List
<TaxonNode
> getPathFromTaxonToRank(
232 @PathVariable("treeUuid") UUID treeUuid
,
233 @PathVariable("taxonUuid") UUID taxonUuid
,
234 @PathVariable("rankUuid") UUID rankUuid
,
235 HttpServletRequest request
,
236 HttpServletResponse response
) throws IOException
{
237 logger
.info("getPathFromTaxonToRank() " + request
.getRequestURI());
239 Classification tree
= service
.find(treeUuid
);
240 Rank rank
= findRank(rankUuid
);
241 Taxon taxon
= (Taxon
) taxonService
.load(taxonUuid
);
243 return service
.loadTreeBranchToTaxon(taxon
, tree
, rank
, NODE_INIT_STRATEGY
);
247 * Provides path of {@link TaxonNode}s from the base node to the node of the specified taxon.
249 * URI:<b>/portal/classification/{treeUuid}/pathFrom/{taxonUuid}</b>
251 * <b>URI elements:</b>
253 * <li><b>{treeUuid}</b> identifies the {@link Classification} by its UUID - <i>required</i>.
254 * <li><b>{rankUuid}</b> identifies the {@link Taxon} by its UUID. - <i>required</i>.
259 * @return a List of {@link TaxonNode} entities initialized by
260 * the {@link #NODE_INIT_STRATEGY}
263 value
= {"{treeUuid}/pathFrom/{taxonUuid}"},
264 method
= RequestMethod
.GET
)
265 public List
<TaxonNode
> getPathFromTaxon(
266 @PathVariable("treeUuid") UUID treeUuid
,
267 @PathVariable("taxonUuid") UUID taxonUuid
,
268 HttpServletRequest request
,
269 HttpServletResponse response
) throws IOException
{
271 return getPathFromTaxonToRank(treeUuid
, taxonUuid
, null, request
, response
);
275 private Rank
findRank(UUID rankUuid
) {
277 if(rankUuid
!= null){
278 DefinedTermBase dt
= termService
.find(rankUuid
);
279 if(dt
instanceof Rank
){
282 new IllegalArgumentException("DefinedTermBase is not a Rank");