controller method to find description elements by feature, a new property editor...
[cdmlib.git] / cdmlib-remote / src / main / java / eu / etaxonomy / cdm / remote / controller / DescriptionPortalController.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 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
11 package eu.etaxonomy.cdm.remote.controller;
12
13 import java.io.IOException;
14 import java.util.Arrays;
15 import java.util.HashSet;
16 import java.util.List;
17 import java.util.Set;
18 import java.util.UUID;
19
20 import javax.servlet.http.HttpServletRequest;
21 import javax.servlet.http.HttpServletResponse;
22
23 import org.apache.commons.lang.ObjectUtils;
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.stereotype.Controller;
26 import org.springframework.web.bind.WebDataBinder;
27 import org.springframework.web.bind.annotation.InitBinder;
28 import org.springframework.web.bind.annotation.PathVariable;
29 import org.springframework.web.bind.annotation.RequestMapping;
30 import org.springframework.web.bind.annotation.RequestMethod;
31 import org.springframework.web.bind.annotation.RequestParam;
32
33 import eu.etaxonomy.cdm.api.service.DistributionTree;
34 import eu.etaxonomy.cdm.api.service.IDescriptionService;
35 import eu.etaxonomy.cdm.api.service.pager.Pager;
36 import eu.etaxonomy.cdm.model.common.Annotation;
37 import eu.etaxonomy.cdm.model.description.DescriptionBase;
38 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
39 import eu.etaxonomy.cdm.model.description.TaxonDescription;
40 import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
41 import eu.etaxonomy.cdm.remote.editor.NamedAreaLevelPropertyEditor;
42 import eu.etaxonomy.cdm.remote.editor.UUIDListPropertyEditor;
43 import eu.etaxonomy.cdm.remote.editor.UuidList;
44
45 /**
46 * IMPORTANT:
47 *
48 * This controller is mostly a 1:1 copy of the DescriptionController
49 * and this provides identical end points which only differ in the depth of the
50 * object graphs returned.
51 *
52 * @author a.kohlbecker
53 * @date Jun 25, 2013
54 *
55 */
56 @Controller
57 @RequestMapping(value = {
58 "/portal/description/{uuid}",
59 "/portal/description/{uuid_list}",
60 "/portal/descriptionElement/{descriptionelement_uuid}"})
61 public class DescriptionPortalController extends BaseController<DescriptionBase, IDescriptionService>
62 {
63
64 protected static final List<String> DESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{
65 "$",
66 "elements.$",
67 "elements.sources.citation.authorTeam.$",
68 "elements.sources.nameUsedInSource.originalNameString",
69 "elements.area.level",
70 "elements.modifyingText",
71 "elements.states.*",
72 "elements.media",
73 });
74
75
76 public DescriptionPortalController() {
77 super();
78 setInitializationStrategy(DESCRIPTION_INIT_STRATEGY);
79 }
80
81 @InitBinder
82 @Override
83 public void initBinder(WebDataBinder binder) {
84 super.initBinder(binder);
85 binder.registerCustomEditor(UuidList.class, new UUIDListPropertyEditor());
86 binder.registerCustomEditor(NamedAreaLevel.class, new NamedAreaLevelPropertyEditor());
87 }
88
89 /* (non-Javadoc)
90 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
91 */
92 @Autowired
93 @Override
94 public void setService(IDescriptionService service) {
95 this.service = service;
96 }
97
98 @RequestMapping(value = "/portal/descriptionElement/{descriptionelement_uuid}/annotation", method = RequestMethod.GET)
99 public Pager<Annotation> getAnnotations(
100 @PathVariable("descriptionelement_uuid") UUID uuid,
101 HttpServletRequest request,
102 HttpServletResponse response) throws IOException {
103 logger.info("getAnnotations() - " + request.getRequestURI());
104 DescriptionElementBase annotatableEntity = service.getDescriptionElementByUuid(uuid);
105 Pager<Annotation> annotations = service.getDescriptionElementAnnotations(annotatableEntity, null, null, 0, null, getInitializationStrategy());
106 return annotations;
107 }
108
109 @RequestMapping(value = "/portal/description/{uuid_list}/DistributionTree", method = RequestMethod.GET)
110 public DistributionTree doGetOrderedDistributionsB(
111 @PathVariable("uuid_list") UuidList descriptionUuidList,
112 @RequestParam(value = "omitLevels", required = false) Set<NamedAreaLevel> levels,
113 HttpServletRequest request, HttpServletResponse response) {
114 logger.info("getOrderedDistributionsB(" + ObjectUtils.toString(levels) + ") - " + request.getRequestURI());
115 Set<TaxonDescription> taxonDescriptions = new HashSet<TaxonDescription>();
116 TaxonDescription description;
117 for (UUID descriptionUuid : descriptionUuidList) {
118 description = (TaxonDescription) service.load(descriptionUuid, DESCRIPTION_INIT_STRATEGY);
119 taxonDescriptions.add(description);
120 }
121 DistributionTree distTree = service.getOrderedDistributions(taxonDescriptions, levels, DESCRIPTION_INIT_STRATEGY);
122 return distTree;
123 }
124
125 }