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 java
.io
.IOException
;
12 import java
.util
.ArrayList
;
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
.exception
.UnpublishedException
;
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
;
39 import io
.swagger
.annotations
.Api
;
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 AbstractIdentifiableListController
<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
);
153 boolean includeUnpublished
= NO_UNPUBLISHED
;
154 // long start = System.currentTimeMillis();
155 List
<TaxonNode
> rootNodes
= service
.listRankSpecificRootNodes(tree
, rank
, includeUnpublished
, null, null, NODE_INIT_STRATEGY
);
156 // System.err.println("service.listRankSpecificRootNodes() " + (System.currentTimeMillis() - start));
162 * Lists all child-{@link TaxonNode}s of the specified {@link Taxon} in the {@link Classification}. The
163 * a given {@link Rank} is ignored in this method but for consistency reasons it has been allowed to included it into the URI.
165 * URI: <b>/portal/classification/{treeUuid}/childNodesOf/{taxonUuid}</b>
167 * <b>URI elements:</b>
169 * <li><b>{tree-uuid}</b> identifies the {@link Classification} by its UUID - <i>required</i>.
170 * <li><b>{taxon-uuid}</b> identifies the {@link Taxon} by its UUID. - <i>required</i>.
175 * @return a List of {@link TaxonNode} entities initialized by
176 * the {@link #NODE_INIT_STRATEGY}
179 value
= {"{treeUuid}/childNodesOf/{taxonUuid}"},
180 method
= RequestMethod
.GET
)
181 public List
<TaxonNode
> getChildNodesOfTaxon(
182 @PathVariable("treeUuid") UUID treeUuid
,
183 @PathVariable("taxonUuid") UUID taxonUuid
,
184 HttpServletRequest request
,
185 HttpServletResponse response
) throws IOException
{
186 logger
.info("getChildNodesOfTaxon() " + request
.getRequestURI());
188 boolean includeUnpublished
= NO_UNPUBLISHED
; //for now we do not allow any remote service to publish unpublished data
190 List
<TaxonNode
> children
= service
.listChildNodesOfTaxon(taxonUuid
, treeUuid
,
191 includeUnpublished
, null, null, NODE_INIT_STRATEGY
);
197 value
= {"{treeUuid}/siblingsOf/{taxonUuid}"},
198 method
= RequestMethod
.GET
)
199 public List
<TaxonNode
> getSiblingsOfTaxon(
200 @PathVariable("treeUuid") UUID treeUuid
,
201 @PathVariable("taxonUuid") UUID taxonUuid
,
202 HttpServletRequest request
,
203 HttpServletResponse response
) throws IOException
{
204 logger
.info("getSiblingsOfTaxon() " + request
.getRequestURI());
206 boolean includeUnpublished
= NO_UNPUBLISHED
;
208 List
<TaxonNode
> childs
= service
.listSiblingsOfTaxon(taxonUuid
, treeUuid
, includeUnpublished
, null, null, NODE_INIT_STRATEGY
);
214 * Provides path of {@link TaxonNode}s from the base node to the node of the specified taxon.
216 * URI:<b>/portal/classification/{treeUuid}/pathFrom/{taxonUuid}/toRank/{rankUuid}</b>
218 * <b>URI elements:</b>
220 * <li><b>{treeUuid}</b> identifies the {@link Classification} by its UUID - <i>required</i>.
221 * <li><b>{taxonUuid}</b> identifies the {@link Rank}
222 * <li><b>{rankUuid}</b> identifies the {@link Taxon} by its UUID. - <i>required</i>.
227 * @return a List of {@link TaxonNode} entities initialized by
228 * the {@link #NODE_INIT_STRATEGY}
231 value
= {"{treeUuid}/pathFrom/{taxonUuid}/toRank/{rankUuid}"},
232 method
= RequestMethod
.GET
)
233 public List
<TaxonNode
> getPathFromTaxonToRank(
234 @PathVariable("treeUuid") UUID treeUuid
,
235 @PathVariable("taxonUuid") UUID taxonUuid
,
236 @PathVariable("rankUuid") UUID rankUuid
,
237 HttpServletRequest request
,
238 HttpServletResponse response
) {
239 logger
.info("getPathFromTaxonToRank() " + request
.getRequestURI());
241 boolean includeUnpublished
= NO_UNPUBLISHED
;
243 Classification tree
= service
.find(treeUuid
);
244 Rank rank
= findRank(rankUuid
);
245 Taxon taxon
= (Taxon
) taxonService
.load(taxonUuid
);
248 return service
.loadTreeBranchToTaxon(taxon
, tree
, rank
, includeUnpublished
, NODE_INIT_STRATEGY
);
249 } catch (UnpublishedException e
) {
250 return new ArrayList
<>();
255 * Provides path of {@link TaxonNode}s from the base node to the node of the specified taxon.
257 * URI:<b>/portal/classification/{treeUuid}/pathFrom/{taxonUuid}</b>
259 * <b>URI elements:</b>
261 * <li><b>{treeUuid}</b> identifies the {@link Classification} by its UUID - <i>required</i>.
262 * <li><b>{rankUuid}</b> identifies the {@link Taxon} by its UUID. - <i>required</i>.
267 * @return a List of {@link TaxonNode} entities initialized by
268 * the {@link #NODE_INIT_STRATEGY}
271 value
= {"{treeUuid}/pathFrom/{taxonUuid}"},
272 method
= RequestMethod
.GET
)
273 public List
<TaxonNode
> getPathFromTaxon(
274 @PathVariable("treeUuid") UUID treeUuid
,
275 @PathVariable("taxonUuid") UUID taxonUuid
,
276 HttpServletRequest request
,
277 HttpServletResponse response
) {
279 return getPathFromTaxonToRank(treeUuid
, taxonUuid
, null, request
, response
);
283 private Rank
findRank(UUID rankUuid
) {
285 if(rankUuid
!= null){
286 DefinedTermBase
<?
> dt
= termService
.find(rankUuid
);
287 if(dt
instanceof Rank
){
290 new IllegalArgumentException("DefinedTermBase is not a Rank");