Revision 224f7da1
Added by Andreas Kohlbecker over 15 years ago
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/TaxonPortalController.java | ||
---|---|---|
12 | 12 |
|
13 | 13 |
import java.io.IOException; |
14 | 14 |
import java.util.Arrays; |
15 |
import java.util.Hashtable; |
|
15 | 16 |
import java.util.List; |
17 |
import java.util.Map; |
|
16 | 18 |
import java.util.UUID; |
17 | 19 |
|
18 | 20 |
import javax.servlet.http.HttpServletRequest; |
... | ... | |
24 | 26 |
import org.springframework.util.Assert; |
25 | 27 |
import org.springframework.web.bind.annotation.RequestMapping; |
26 | 28 |
import org.springframework.web.bind.annotation.RequestMethod; |
29 |
import org.springframework.web.servlet.ModelAndView; |
|
27 | 30 |
|
28 | 31 |
import eu.etaxonomy.cdm.api.service.ITaxonService; |
32 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
29 | 33 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
30 | 34 |
|
31 | 35 |
/** |
... | ... | |
34 | 38 |
*/ |
35 | 39 |
|
36 | 40 |
@Controller |
37 |
@RequestMapping(value = {"/*/portal/taxon/*"}) |
|
41 |
@RequestMapping(value = {"/*/portal/taxon/*", "/*/portal/taxon/*/*"})
|
|
38 | 42 |
public class TaxonPortalController extends BaseController<TaxonBase, ITaxonService> |
39 | 43 |
{ |
40 | 44 |
public static final Logger logger = Logger.getLogger(TaxonPortalController.class); |
41 | 45 |
|
42 | 46 |
private static final List<String> TAXON_INIT_STRATEGY = Arrays.asList(new String []{ |
43 | 47 |
"*", |
44 |
"name.*", |
|
45 |
"name.nomenclaturalReference.authorTeam.*", |
|
46 |
"name.homotypicalGroup.typifiedNames.*", |
|
47 |
"name.status.type.representations", |
|
48 |
// taxon relations |
|
49 |
"relationsToThisName.fromTaxon.name.taggedName", |
|
50 |
// the name |
|
51 |
"name.$", |
|
52 |
"name.taggedName", |
|
48 | 53 |
"name.rank.representations", |
49 |
"synonymRelations.*"}); |
|
54 |
"name.status.type.representations", |
|
55 |
|
|
56 |
// descriptions |
|
57 |
"descriptions.elements.$", |
|
58 |
"descriptions.elements.area", |
|
59 |
"descriptions.elements.area.$", |
|
60 |
"descriptions.elements.multilanguageText", |
|
61 |
"descriptions.elements.media.representations.parts", |
|
62 |
|
|
63 |
// // typeDesignations |
|
64 |
// "name.typeDesignations.$", |
|
65 |
// "name.typeDesignations.citation.authorTeam", |
|
66 |
// "name.typeDesignations.typeName.$", |
|
67 |
// "name.typeDesignations.typeStatus.representations", |
|
68 |
// "name.typeDesignations.typeSpecimen.media.representations.parts" |
|
69 |
|
|
70 |
}); |
|
71 |
|
|
72 |
private static final List<String> SYNONYMY_INIT_STRATEGY = Arrays.asList(new String []{ |
|
73 |
// initialize homotypical and heterotypical groups; needs synonyms |
|
74 |
"synonymRelations.$", |
|
75 |
"synonymRelations.synonym.$", |
|
76 |
"synonymRelations.synonym.name.taggedName", |
|
77 |
"synonymRelations.synonym.name.homotypicalGroup.typifiedNames.$", |
|
78 |
"synonymRelations.synonym.name.homotypicalGroup.typifiedNames.name.taggedName", |
|
79 |
"synonymRelations.synonym.name.homotypicalGroup.typifiedNames.taxonBases.$", |
|
80 |
"synonymRelations.synonym.name.homotypicalGroup.typifiedNames.taxonBases.name.taggedName", |
|
81 |
|
|
82 |
"name.homotypicalGroup.$", |
|
83 |
"name.homotypicalGroup.typifiedNames.$", |
|
84 |
"name.homotypicalGroup.typifiedNames.name.taggedName", |
|
85 |
"name.homotypicalGroup.typifiedNames.taxonBases.$", |
|
86 |
"name.homotypicalGroup.typifiedNames.taxonBases.name.taggedName" |
|
87 |
}); |
|
50 | 88 |
|
51 | 89 |
public TaxonPortalController(){ |
52 | 90 |
super(); |
... | ... | |
65 | 103 |
@Override |
66 | 104 |
@RequestMapping(method = RequestMethod.GET) |
67 | 105 |
public TaxonBase doGet(HttpServletRequest request, HttpServletResponse response)throws IOException { |
68 |
|
|
69 |
TaxonBase tb; |
|
70 |
try { |
|
71 |
UUID uuid = readValueUuid(request); |
|
72 |
Assert.notNull(uuid, HttpStatusMessage.UUID_NOT_FOUND.toString()); |
|
73 |
|
|
74 |
tb = service.load(uuid, TAXON_INIT_STRATEGY); |
|
75 |
Assert.notNull(tb, HttpStatusMessage.UUID_NOT_FOUND.toString()); |
|
76 |
} catch (IllegalArgumentException iae) { |
|
77 |
HttpStatusMessage.fromString(iae.getMessage()).send(response); |
|
78 |
return null; |
|
79 |
} |
|
80 |
|
|
106 |
TaxonBase tb = getCdmBase(request, response, TAXON_INIT_STRATEGY, TaxonBase.class); |
|
81 | 107 |
return tb; |
82 | 108 |
} |
109 |
|
|
110 |
|
|
111 |
@RequestMapping( |
|
112 |
value = {"/*/portal/taxon/*/synonymy"}, |
|
113 |
method = RequestMethod.GET) |
|
114 |
public ModelAndView doGetSynonymy(HttpServletRequest request, HttpServletResponse response)throws IOException { |
|
115 |
ModelAndView mv = new ModelAndView(); |
|
116 |
TaxonBase tb = getCdmBase(request, response, null, Taxon.class); |
|
117 |
Taxon taxon = (Taxon)tb; |
|
118 |
Map<String, List<?>> synonymy = new Hashtable<String, List<?>>(); |
|
119 |
synonymy.put("homotypicSynonymsByHomotypicGroup", service.getHomotypicSynonymsByHomotypicGroup(taxon, SYNONYMY_INIT_STRATEGY)); |
|
120 |
synonymy.put("heterotypicSynonymyGroups", service.getHeterotypicSynonymyGroups(taxon, SYNONYMY_INIT_STRATEGY)); |
|
121 |
mv.addObject(synonymy); |
|
122 |
return mv; |
|
123 |
} |
|
124 |
|
|
125 |
// /** |
|
126 |
// * @param request |
|
127 |
// * @param response |
|
128 |
// * @return |
|
129 |
// * @throws IOException |
|
130 |
// */ |
|
131 |
// private <T> T getTaxon(HttpServletRequest request, HttpServletResponse response, List<String> initStrategy, Class<T> clazz) throws IOException { |
|
132 |
// TaxonBase tb = null; |
|
133 |
// try { |
|
134 |
// UUID uuid = readValueUuid(request); |
|
135 |
// Assert.notNull(uuid, HttpStatusMessage.UUID_NOT_FOUND.toString()); |
|
136 |
// tb = service.load(uuid, initStrategy); |
|
137 |
// Assert.notNull(tb, HttpStatusMessage.UUID_NOT_FOUND.toString()); |
|
138 |
// } catch (IllegalArgumentException iae) { |
|
139 |
// HttpStatusMessage.fromString(iae.getMessage()).send(response); |
|
140 |
// } |
|
141 |
// T t; |
|
142 |
// try { |
|
143 |
// t = (T)tb; |
|
144 |
// return t; |
|
145 |
// } catch (Exception e) { |
|
146 |
// HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response); |
|
147 |
// return null; |
|
148 |
// } |
|
149 |
// } |
|
83 | 150 |
} |
Also available in: Unified diff
new controllers & improved JSON serialization