3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * 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
.HttpServletResponse
;
19 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
20 import org
.springframework
.stereotype
.Controller
;
21 import org
.springframework
.web
.bind
.WebDataBinder
;
22 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
23 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
24 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
25 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
27 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
28 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
29 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
30 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
31 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
32 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
33 import eu
.etaxonomy
.cdm
.remote
.editor
.RankPropertyEditor
;
36 * @author a.kohlbecker
41 @RequestMapping(value
= {"/classification/{uuid}"})
42 public class ClassificationController
extends BaseController
<Classification
,IClassificationService
> {
45 private ITermService termService
;
48 * @see eu.etaxonomy.cdm.remote.controller.BaseController#setService(eu.etaxonomy.cdm.api.service.IService)
52 public void setService(IClassificationService service
) {
53 this.service
= service
;
57 public void setTermService(ITermService termService
) {
58 this.termService
= termService
;
64 public void initBinder(WebDataBinder binder
) {
65 super.initBinder(binder
);
66 binder
.registerCustomEditor(Rank
.class, new RankPropertyEditor());
69 private List
<String
> NODE_INIT_STRATEGY(){
70 return Arrays
.asList(new String
[]{
77 * @param classificationUuid
83 value
= {"childNodes"},
84 method
= RequestMethod
.GET
)
85 public List
<TaxonNode
> getChildNodes(
86 @PathVariable("uuid") UUID classificationUuid
,
87 HttpServletResponse response
88 ) throws IOException
{
90 return getChildNodesAtRank(classificationUuid
, null, response
);
94 value
= {"childNodesAt/{rankUuid}"},
95 method
= RequestMethod
.GET
)
96 public List
<TaxonNode
> getChildNodesAtRank(
97 @PathVariable("uuid") UUID classificationUuid
,
98 @PathVariable("rankUuid") UUID rankUuid
,
99 HttpServletResponse response
100 ) throws IOException
{
102 logger
.info("getChildNodesAtRank()");
103 Classification tree
= null;
105 if(classificationUuid
!= null){
107 tree
= service
.find(classificationUuid
);
110 response
.sendError(404 , "Classification not found using " + classificationUuid
);
114 rank
= findRank(rankUuid
);
116 return service
.loadRankSpecificRootNodes(tree
, rank
, NODE_INIT_STRATEGY());
119 private Rank
findRank(UUID rankUuid
) {
121 if(rankUuid
!= null){
122 DefinedTermBase definedTermBase
= termService
.find(rankUuid
);
123 if(definedTermBase
instanceof Rank
){
124 rank
= (Rank
) definedTermBase
;
126 new IllegalArgumentException("DefinedTermBase is not a Rank");