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 io.swagger.annotations.Api;
|
13 |
|
|
14 |
|
import java.io.IOException;
|
15 |
|
import java.util.Arrays;
|
16 |
|
import java.util.List;
|
17 |
|
import java.util.UUID;
|
18 |
|
|
19 |
|
import javax.servlet.http.HttpServletRequest;
|
20 |
|
import javax.servlet.http.HttpServletResponse;
|
21 |
|
|
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;
|
29 |
|
import org.springframework.web.bind.annotation.RequestParam;
|
30 |
|
|
31 |
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
32 |
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
33 |
|
import eu.etaxonomy.cdm.api.service.dto.GroupedTaxonDTO;
|
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.TaxonNode;
|
38 |
|
import eu.etaxonomy.cdm.remote.editor.RankPropertyEditor;
|
39 |
|
import eu.etaxonomy.cdm.remote.editor.UUIDListPropertyEditor;
|
40 |
|
import eu.etaxonomy.cdm.remote.editor.UuidList;
|
41 |
|
|
42 |
|
/**
|
43 |
|
* @author a.kohlbecker
|
44 |
|
* @date 03.06.2010
|
45 |
|
*
|
46 |
|
*/
|
47 |
|
@Controller
|
48 |
|
@Api("classification")
|
49 |
|
@RequestMapping(value = {"/classification/{uuid}"})
|
50 |
|
public class ClassificationController extends BaseController<Classification,IClassificationService> {
|
51 |
|
|
52 |
|
|
53 |
|
private ITermService termService;
|
54 |
|
|
55 |
|
@Override
|
56 |
|
@Autowired
|
57 |
|
public void setService(IClassificationService service) {
|
58 |
|
this.service = service;
|
59 |
|
}
|
60 |
|
|
61 |
|
@Autowired
|
62 |
|
public void setTermService(ITermService termService) {
|
63 |
|
this.termService = termService;
|
64 |
|
}
|
65 |
|
|
66 |
|
|
67 |
|
@InitBinder
|
68 |
|
@Override
|
69 |
|
public void initBinder(WebDataBinder binder) {
|
70 |
|
super.initBinder(binder);
|
71 |
|
binder.registerCustomEditor(Rank.class, new RankPropertyEditor());
|
72 |
|
binder.registerCustomEditor(UuidList.class, new UUIDListPropertyEditor());
|
73 |
|
}
|
74 |
|
|
75 |
|
private List<String> NODE_INIT_STRATEGY(){
|
76 |
|
return Arrays.asList(new String[]{
|
77 |
|
"taxon.name"
|
78 |
|
});}
|
79 |
|
|
80 |
|
/**
|
81 |
|
* @param classificationUuid
|
82 |
|
* @param response
|
83 |
|
* @return
|
84 |
|
* @throws IOException
|
85 |
|
*
|
86 |
|
*/
|
87 |
|
@RequestMapping(
|
88 |
|
value = {"childNodes"},
|
89 |
|
method = RequestMethod.GET)
|
90 |
|
public List<TaxonNode> getChildNodes(
|
91 |
|
@PathVariable("uuid") UUID classificationUuid,
|
92 |
|
HttpServletRequest request,
|
93 |
|
HttpServletResponse response
|
94 |
|
) throws IOException {
|
95 |
|
|
96 |
|
return getChildNodesAtRank(classificationUuid, null, request, response);
|
97 |
|
}
|
98 |
|
|
99 |
|
@RequestMapping(
|
100 |
|
value = {"childNodesAt/{rankUuid}"},
|
101 |
|
method = RequestMethod.GET)
|
102 |
|
public List<TaxonNode> getChildNodesAtRank(
|
103 |
|
@PathVariable("uuid") UUID classificationUuid,
|
104 |
|
@PathVariable("rankUuid") UUID rankUuid,
|
105 |
|
HttpServletRequest request,
|
106 |
|
HttpServletResponse response
|
107 |
|
) throws IOException {
|
108 |
|
|
109 |
|
logger.info("getChildNodesAtRank() - " + request.getRequestURI());
|
110 |
|
|
111 |
|
Classification classification = service.find(classificationUuid);
|
112 |
|
|
113 |
|
if(classification == null) {
|
114 |
|
response.sendError(404 , "Classification not found using " + classificationUuid );
|
115 |
|
return null;
|
116 |
|
}
|
117 |
|
Rank rank = findRank(rankUuid);
|
118 |
|
|
119 |
|
// long start = System.currentTimeMillis();
|
120 |
|
List<TaxonNode> rootNodes = service.listRankSpecificRootNodes(classification, rank, null, null, NODE_INIT_STRATEGY());
|
121 |
|
// System.err.println("service.listRankSpecificRootNodes() " + (System.currentTimeMillis() - start));
|
122 |
|
|
123 |
|
return rootNodes;
|
124 |
|
}
|
125 |
|
|
126 |
|
private Rank findRank(UUID rankUuid) {
|
127 |
|
Rank rank = null;
|
128 |
|
if(rankUuid != null){
|
129 |
|
DefinedTermBase<?> definedTermBase = termService.find(rankUuid);
|
130 |
|
if(definedTermBase instanceof Rank){
|
131 |
|
rank = (Rank) definedTermBase;
|
132 |
|
} else {
|
133 |
|
throw new IllegalArgumentException("DefinedTermBase is not a Rank");
|
134 |
|
}
|
135 |
|
}
|
136 |
|
return rank;
|
137 |
|
}
|
138 |
|
|
139 |
|
/**
|
140 |
|
* @param classificationUuid
|
141 |
|
* @param response
|
142 |
|
* @return
|
143 |
|
* @throws IOException
|
144 |
|
*/
|
145 |
|
@RequestMapping(
|
146 |
|
value = {"groupedTaxa"},
|
147 |
|
method = RequestMethod.GET)
|
148 |
|
public List<GroupedTaxonDTO> getGroupedTaxaByHigherTaxon(
|
149 |
|
@PathVariable("uuid") UUID classificationUuid,
|
150 |
|
@RequestParam(value = "taxonUuids", required = true) UuidList taxonUuids,
|
151 |
|
@RequestParam(value = "minRankUuid", required = false) UUID minRankUuid,
|
152 |
|
@RequestParam(value = "maxRankUuid", required = false) UUID maxRankUuid,
|
153 |
|
HttpServletRequest request,
|
154 |
|
HttpServletResponse response
|
155 |
|
) throws IOException {
|
156 |
|
|
157 |
|
logger.info("getGroupedTaxaByHigherTaxon() - " + request.getRequestURI());
|
158 |
|
|
159 |
|
Classification classification = service.find(classificationUuid);
|
160 |
|
if(classification == null) {
|
161 |
|
response.sendError(404 , "Classification not found using " + classificationUuid );
|
162 |
|
return null;
|
163 |
|
}
|
164 |
|
|
165 |
|
|
166 |
|
Rank minRank = findRank(minRankUuid);
|
167 |
|
Rank maxRank = findRank(maxRankUuid);
|
168 |
|
|
169 |
|
// long start = System.currentTimeMillis();
|
170 |
|
List<GroupedTaxonDTO> result = service.groupTaxaByHigherTaxon(taxonUuids, classificationUuid, minRank, maxRank);
|
171 |
|
// System.err.println("service.listRankSpecificRootNodes() " + (System.currentTimeMillis() - start));
|
172 |
|
|
173 |
|
return result;
|
174 |
|
}
|
175 |
|
}
|
|
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 io.swagger.annotations.Api;
|
|
13 |
|
|
14 |
import java.io.IOException;
|
|
15 |
import java.util.Arrays;
|
|
16 |
import java.util.List;
|
|
17 |
import java.util.UUID;
|
|
18 |
|
|
19 |
import javax.servlet.http.HttpServletRequest;
|
|
20 |
import javax.servlet.http.HttpServletResponse;
|
|
21 |
|
|
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;
|
|
29 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
30 |
|
|
31 |
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
|
32 |
import eu.etaxonomy.cdm.api.service.ITermService;
|
|
33 |
import eu.etaxonomy.cdm.api.service.dto.GroupedTaxonDTO;
|
|
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.TaxonNode;
|
|
38 |
import eu.etaxonomy.cdm.remote.editor.RankPropertyEditor;
|
|
39 |
import eu.etaxonomy.cdm.remote.editor.UUIDListPropertyEditor;
|
|
40 |
import eu.etaxonomy.cdm.remote.editor.UuidList;
|
|
41 |
|
|
42 |
/**
|
|
43 |
* @author a.kohlbecker
|
|
44 |
* @date 03.06.2010
|
|
45 |
*
|
|
46 |
*/
|
|
47 |
@Controller
|
|
48 |
@Api("classification")
|
|
49 |
@RequestMapping(value = {"/classification/{uuid}"})
|
|
50 |
public class ClassificationController extends BaseController<Classification,IClassificationService> {
|
|
51 |
|
|
52 |
|
|
53 |
private ITermService termService;
|
|
54 |
|
|
55 |
@Override
|
|
56 |
@Autowired
|
|
57 |
public void setService(IClassificationService service) {
|
|
58 |
this.service = service;
|
|
59 |
}
|
|
60 |
|
|
61 |
@Autowired
|
|
62 |
public void setTermService(ITermService termService) {
|
|
63 |
this.termService = termService;
|
|
64 |
}
|
|
65 |
|
|
66 |
|
|
67 |
@InitBinder
|
|
68 |
@Override
|
|
69 |
public void initBinder(WebDataBinder binder) {
|
|
70 |
super.initBinder(binder);
|
|
71 |
binder.registerCustomEditor(Rank.class, new RankPropertyEditor());
|
|
72 |
binder.registerCustomEditor(UuidList.class, new UUIDListPropertyEditor());
|
|
73 |
}
|
|
74 |
|
|
75 |
private List<String> NODE_INIT_STRATEGY(){
|
|
76 |
return Arrays.asList(new String[]{
|
|
77 |
"taxon.name"
|
|
78 |
});}
|
|
79 |
|
|
80 |
/**
|
|
81 |
* @param classificationUuid
|
|
82 |
* @param response
|
|
83 |
* @return
|
|
84 |
* @throws IOException
|
|
85 |
*
|
|
86 |
*/
|
|
87 |
@RequestMapping(
|
|
88 |
value = {"childNodes"},
|
|
89 |
method = RequestMethod.GET)
|
|
90 |
public List<TaxonNode> getChildNodes(
|
|
91 |
@PathVariable("uuid") UUID classificationUuid,
|
|
92 |
HttpServletRequest request,
|
|
93 |
HttpServletResponse response
|
|
94 |
) throws IOException {
|
|
95 |
|
|
96 |
return getChildNodesAtRank(classificationUuid, null, request, response);
|
|
97 |
}
|
|
98 |
|
|
99 |
@RequestMapping(
|
|
100 |
value = {"childNodesAt/{rankUuid}"},
|
|
101 |
method = RequestMethod.GET)
|
|
102 |
public List<TaxonNode> getChildNodesAtRank(
|
|
103 |
@PathVariable("uuid") UUID classificationUuid,
|
|
104 |
@PathVariable("rankUuid") UUID rankUuid,
|
|
105 |
HttpServletRequest request,
|
|
106 |
HttpServletResponse response
|
|
107 |
) throws IOException {
|
|
108 |
|
|
109 |
logger.info("getChildNodesAtRank() - " + request.getRequestURI());
|
|
110 |
|
|
111 |
Classification classification = service.find(classificationUuid);
|
|
112 |
|
|
113 |
if(classification == null) {
|
|
114 |
response.sendError(404 , "Classification not found using " + classificationUuid );
|
|
115 |
return null;
|
|
116 |
}
|
|
117 |
Rank rank = findRank(rankUuid);
|
|
118 |
|
|
119 |
// long start = System.currentTimeMillis();
|
|
120 |
List<TaxonNode> rootNodes = service.listRankSpecificRootNodes(classification, rank, null, null, NODE_INIT_STRATEGY());
|
|
121 |
// System.err.println("service.listRankSpecificRootNodes() " + (System.currentTimeMillis() - start));
|
|
122 |
|
|
123 |
return rootNodes;
|
|
124 |
}
|
|
125 |
|
|
126 |
|
|
127 |
/**
|
|
128 |
* @param classificationUuid
|
|
129 |
* @param response
|
|
130 |
* @return
|
|
131 |
* @throws IOException
|
|
132 |
*/
|
|
133 |
@RequestMapping(
|
|
134 |
value = {"groupedTaxa"},
|
|
135 |
method = RequestMethod.GET)
|
|
136 |
public List<GroupedTaxonDTO> getGroupedTaxaByHigherTaxon(
|
|
137 |
@PathVariable("uuid") UUID classificationUuid,
|
|
138 |
@RequestParam(value = "taxonUuids", required = true) UuidList taxonUuids,
|
|
139 |
@RequestParam(value = "minRankUuid", required = false) UUID minRankUuid,
|
|
140 |
@RequestParam(value = "maxRankUuid", required = false) UUID maxRankUuid,
|
|
141 |
HttpServletRequest request,
|
|
142 |
HttpServletResponse response
|
|
143 |
) throws IOException {
|
|
144 |
|
|
145 |
logger.info("getGroupedTaxaByHigherTaxon() - " + request.getRequestURI());
|
|
146 |
|
|
147 |
Classification classification = service.find(classificationUuid);
|
|
148 |
if(classification == null) {
|
|
149 |
response.sendError(404 , "Classification not found using " + classificationUuid );
|
|
150 |
return null;
|
|
151 |
}
|
|
152 |
|
|
153 |
|
|
154 |
Rank minRank = findRank(minRankUuid);
|
|
155 |
Rank maxRank = findRank(maxRankUuid);
|
|
156 |
|
|
157 |
// long start = System.currentTimeMillis();
|
|
158 |
List<GroupedTaxonDTO> result = service.groupTaxaByHigherTaxon(taxonUuids, classificationUuid, minRank, maxRank);
|
|
159 |
// System.err.println("service.listRankSpecificRootNodes() " + (System.currentTimeMillis() - start));
|
|
160 |
|
|
161 |
return result;
|
|
162 |
}
|
|
163 |
|
|
164 |
|
|
165 |
private Rank findRank(UUID rankUuid) {
|
|
166 |
Rank rank = null;
|
|
167 |
if(rankUuid != null){
|
|
168 |
DefinedTermBase<?> definedTermBase = termService.find(rankUuid);
|
|
169 |
if(definedTermBase instanceof Rank){
|
|
170 |
rank = (Rank) definedTermBase;
|
|
171 |
} else {
|
|
172 |
throw new IllegalArgumentException("DefinedTermBase is not a Rank");
|
|
173 |
}
|
|
174 |
}
|
|
175 |
return rank;
|
|
176 |
}
|
|
177 |
}
|
Fix compile error in Print Publisher