fix #6268 initializing decriptions of media entities for portal webservices
[cdmlib.git] / cdmlib-remote / src / main / java / eu / etaxonomy / cdm / remote / controller / OccurrencePortalController.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.List;
16 import java.util.UUID;
17
18 import javax.servlet.http.HttpServletRequest;
19 import javax.servlet.http.HttpServletResponse;
20
21 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.stereotype.Controller;
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 import org.springframework.web.bind.annotation.RequestParam;
27 import org.springframework.web.servlet.ModelAndView;
28
29 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
30 import eu.etaxonomy.cdm.api.service.dto.DerivateDTO;
31 import eu.etaxonomy.cdm.api.service.dto.PreservedSpecimenDTO;
32 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
33 import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
34 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
35 import io.swagger.annotations.Api;
36
37 /**
38 * TODO write controller documentation
39 *
40 * @author a.kohlbecker
41 * @date 24.03.2009
42 */
43 @Controller
44 @Api("portal_occurrence")
45 @RequestMapping(value = {"/portal/occurrence/{uuid}"})
46 public class OccurrencePortalController extends OccurrenceController
47 {
48
49 private static final List<String> DEFAULT_INIT_STRATEGY = Arrays.asList(new String []{
50 "$",
51 "determinations.*",
52 "sources.$",
53 "derivedFrom.type",
54 "derivedFrom.originals.*",
55 "derivedFrom.originals.determinations.taxon",
56 "derivedFrom.originals.gatheringEvent.exactLocation.$",
57 "derivedFrom.gatheringEvent.exactLocation.$",
58 "specimenTypeDesignations.*",
59 "specimenTypeDesignations.citation.*",
60 "specimenTypeDesignations.homotypicalGroup.*",
61 "sequences.$",
62 "sequences.annotations",
63 "markers.markerType",
64 "gatheringEvent.$",
65 "gatheringEvent.exactLocation.referenceSystem", // TODO implement auto initializer?
66 "gatheringEvent.collectingAreas",
67 "descriptions"
68 });
69
70
71 /**
72 *
73 */
74 public OccurrencePortalController() {
75 super();
76 setInitializationStrategy(DEFAULT_INIT_STRATEGY);
77 }
78
79 /* (non-Javadoc)
80 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
81 */
82 @Autowired
83 @Override
84 public void setService(IOccurrenceService service) {
85 this.service = service;
86 }
87
88 @RequestMapping(value = { "derivateHierarchy" }, method = RequestMethod.GET)
89 public ModelAndView doGetDerivateHierarchy(
90 @PathVariable("uuid") UUID uuid,
91 @RequestParam(value = "taxonUuid", required = true) UUID taxonUuid,
92 HttpServletRequest request,
93 HttpServletResponse response) throws IOException {
94
95 logger.info("doGetDerivateHierarchy() " + request.getRequestURI());
96
97 ModelAndView mv = new ModelAndView();
98
99 SpecimenOrObservationBase sob = service.load(uuid);
100 if(sob instanceof FieldUnit){
101 FieldUnit fieldUnit = (FieldUnit)sob;
102 if(fieldUnit.isPublish()){
103 final DerivateDTO fieldUnitDTO = service.assembleFieldUnitDTO(fieldUnit, taxonUuid);
104 if(fieldUnitDTO!=null){
105 mv.addObject(fieldUnitDTO);
106 }
107 }
108 }
109 return mv;
110 }
111
112 @RequestMapping(value = { "specimenDerivates" }, method = RequestMethod.GET)
113 public ModelAndView doGetSpecimenDerivates(
114 @PathVariable("uuid") UUID uuid,
115 HttpServletRequest request,
116 HttpServletResponse response) throws IOException {
117
118 logger.info("doGetSpecimenDerivates() " + request.getRequestURI());
119
120 ModelAndView mv = new ModelAndView();
121
122 SpecimenOrObservationBase sob = service.load(uuid);
123 if(sob instanceof DerivedUnit){
124 DerivedUnit derivedUnit = (DerivedUnit) sob;
125 if(derivedUnit.isPublish()){
126 PreservedSpecimenDTO specimenDTO = service.assemblePreservedSpecimenDTO(derivedUnit);
127 if(specimenDTO!=null){
128 mv.addObject(specimenDTO);
129 }
130 }
131 }
132 return mv;
133 }
134
135
136
137 }