1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2009 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
package eu.etaxonomy.cdm.remote.controller;
|
11
|
|
12
|
import java.io.IOException;
|
13
|
import java.util.Arrays;
|
14
|
import java.util.List;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import javax.servlet.http.HttpServletResponse;
|
18
|
|
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;
|
26
|
|
27
|
import eu.etaxonomy.cdm.api.service.ITaxonTreeService;
|
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.TaxonomicTree;
|
33
|
import eu.etaxonomy.cdm.remote.editor.RankPropertyEditor;
|
34
|
import eu.etaxonomy.cdm.remote.editor.UUIDPropertyEditor;
|
35
|
|
36
|
/**
|
37
|
* @author a.kohlbecker
|
38
|
* @date 03.06.2010
|
39
|
*
|
40
|
*/
|
41
|
@Controller
|
42
|
@RequestMapping(value = {"/classification/*", "/classification/{uuid}"})
|
43
|
public class ClassificationController extends AnnotatableController<TaxonomicTree,ITaxonTreeService> {
|
44
|
|
45
|
|
46
|
private ITermService termService;
|
47
|
|
48
|
/* (non-Javadoc)
|
49
|
* @see eu.etaxonomy.cdm.remote.controller.BaseController#setService(eu.etaxonomy.cdm.api.service.IService)
|
50
|
*/
|
51
|
@Override
|
52
|
@Autowired
|
53
|
public void setService(ITaxonTreeService service) {
|
54
|
this.service = service;
|
55
|
}
|
56
|
|
57
|
@Autowired
|
58
|
public void setTermService(ITermService termService) {
|
59
|
this.termService = termService;
|
60
|
}
|
61
|
|
62
|
|
63
|
@InitBinder
|
64
|
@Override
|
65
|
public void initBinder(WebDataBinder binder) {
|
66
|
binder.registerCustomEditor(UUID.class, new UUIDPropertyEditor());
|
67
|
binder.registerCustomEditor(Rank.class, new RankPropertyEditor());
|
68
|
}
|
69
|
|
70
|
private List<String> NODE_INIT_STRATEGY(){
|
71
|
return Arrays.asList(new String[]{
|
72
|
"taxon.sec",
|
73
|
"taxon.name.taggedName",
|
74
|
// "taxon.name.combinationAuthorTeam.*",
|
75
|
// "taxon.name.exCombinationAuthorTeam.*",
|
76
|
// "taxon.name.basionymAuthorTeam.*",
|
77
|
// "taxon.name.exBasionymAuthorTeam.*",
|
78
|
"taxon.name.titleCache",
|
79
|
"taxonomicTree"
|
80
|
});}
|
81
|
|
82
|
public ClassificationController(){
|
83
|
super();
|
84
|
setUuidParameterPattern("^/(?:[^/]+)/([^/?#&\\.]+).*");
|
85
|
}
|
86
|
|
87
|
/**
|
88
|
* @param classificationUuid
|
89
|
* @param response
|
90
|
* @return
|
91
|
* @throws IOException
|
92
|
*/
|
93
|
@RequestMapping(
|
94
|
value = {"{uuid}/childNodes/"},
|
95
|
method = RequestMethod.GET)
|
96
|
public List<TaxonNode> getChildNodes(
|
97
|
@PathVariable("uuid") UUID classificationUuid,
|
98
|
HttpServletResponse response
|
99
|
) throws IOException {
|
100
|
|
101
|
return getChildNodesAtRank(classificationUuid, null, response);
|
102
|
}
|
103
|
|
104
|
@RequestMapping(
|
105
|
value = {"{uuid}/childNodesAt/{rankUuid}/"},
|
106
|
method = RequestMethod.GET)
|
107
|
public List<TaxonNode> getChildNodesAtRank(
|
108
|
@PathVariable("uuid") UUID classificationUuid,
|
109
|
@PathVariable("rankUuid") UUID rankUuid,
|
110
|
HttpServletResponse response
|
111
|
) throws IOException {
|
112
|
|
113
|
logger.info("getChildNodesAtRank()");
|
114
|
TaxonomicTree tree = null;
|
115
|
Rank rank = null;
|
116
|
if(classificationUuid != null){
|
117
|
// get view and rank
|
118
|
tree = service.find(classificationUuid);
|
119
|
|
120
|
if(tree == null) {
|
121
|
response.sendError(404 , "Classification not found using " + classificationUuid );
|
122
|
return null;
|
123
|
}
|
124
|
}
|
125
|
rank = findRank(rankUuid);
|
126
|
|
127
|
return service.loadRankSpecificRootNodes(tree, rank, NODE_INIT_STRATEGY());
|
128
|
}
|
129
|
|
130
|
private Rank findRank(UUID rankUuid) {
|
131
|
Rank rank = null;
|
132
|
if(rankUuid != null){
|
133
|
DefinedTermBase definedTermBase = termService.find(rankUuid);
|
134
|
if(definedTermBase instanceof Rank){
|
135
|
rank = (Rank) definedTermBase;
|
136
|
} else {
|
137
|
new IllegalArgumentException("DefinedTermBase is not a Rank");
|
138
|
}
|
139
|
}
|
140
|
return rank;
|
141
|
}
|
142
|
}
|