2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.remote
.controller
;
11 import java
.io
.IOException
;
12 import java
.util
.ArrayList
;
13 import java
.util
.Arrays
;
14 import java
.util
.Collection
;
15 import java
.util
.List
;
16 import java
.util
.UUID
;
17 import java
.util
.stream
.Collectors
;
19 import javax
.servlet
.http
.HttpServletRequest
;
20 import javax
.servlet
.http
.HttpServletResponse
;
22 import org
.apache
.logging
.log4j
.LogManager
;
23 import org
.apache
.logging
.log4j
.Logger
;
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
.servlet
.ModelAndView
;
33 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
34 import eu
.etaxonomy
.cdm
.api
.service
.dto
.MediaDTO
;
35 import eu
.etaxonomy
.cdm
.facade
.DerivedUnitFacade
;
36 import eu
.etaxonomy
.cdm
.facade
.DerivedUnitFacadeNotSupportedException
;
37 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
38 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldUnit
;
39 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
40 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDPropertyEditor
;
41 import io
.swagger
.annotations
.Api
;
44 * @author a.kohlbecker
48 @Api("derivedUnitFacade")
49 @RequestMapping(value
= {"/derivedUnitFacade/{uuid}"})
50 public class DerivedUnitFacadeController
extends AbstractController
<SpecimenOrObservationBase
, IOccurrenceService
>{
52 private static final Logger logger
= LogManager
.getLogger();
54 private IOccurrenceService service
;
56 private final List
<String
> derivedUnitFacadeInitStrategy
= Arrays
.asList(new String
[]{
62 public DerivedUnitFacadeController(){
63 setInitializationStrategy(derivedUnitFacadeInitStrategy
);
68 public void setService(IOccurrenceService service
) {
69 this.service
= service
;
73 public void initBinder(WebDataBinder binder
) {
74 binder
.registerCustomEditor(UUID
.class, new UUIDPropertyEditor());
77 @RequestMapping(method
= RequestMethod
.GET
)
78 public DerivedUnitFacade
doGet(
79 @PathVariable("uuid") UUID occurrenceUuid
,
80 HttpServletRequest request
,
81 HttpServletResponse response
) throws IOException
{
83 logger
.info("doGet() - " + request
.getRequestURI());
84 DerivedUnitFacade duf
= newFacadeFrom(occurrenceUuid
, response
, null);
88 @RequestMapping(value
= {"derivedUnitMedia"}, method
= RequestMethod
.GET
)
89 public ModelAndView
doGetDerivedUnitMedia(
90 @PathVariable("uuid") UUID occurrenceUuid
,
91 HttpServletRequest request
,
92 HttpServletResponse response
) throws IOException
{
94 logger
.info("doGetDerivedUnitMedia() - " + request
.getRequestURI());
95 ModelAndView mv
= new ModelAndView();
96 DerivedUnitFacade duf
= newFacadeFrom(occurrenceUuid
, response
, Arrays
.asList(new String
[]{
97 "derivedUnitMedia", "derivedUnitMedia.title"}));
99 mv
.addObject(duf
.getDerivedUnitMedia());
104 @RequestMapping(value
= {"fieldObjectMediaDTO"}, method
= RequestMethod
.GET
)
105 public List
<MediaDTO
> doGetFieldObjectMediaDTO(
106 @PathVariable("uuid") UUID occurrenceUuid
,
107 HttpServletRequest request
,
108 HttpServletResponse response
) {
110 logger
.info("doGetFieldObjectMediaDTO() - " + readPathParameter(request
, null));
112 Collection
<FieldUnit
> fus
= service
.findFieldUnits(occurrenceUuid
, null);
113 List
<MediaDTO
> mediaDTOs
= fus
.stream()
114 .map(fu
-> service
.getMediaDTOs(fu
, null, null))
115 .flatMap(p
-> p
.getRecords().stream())
116 .collect(Collectors
.toList());
120 @RequestMapping(value
= {"fieldObjectMedia"}, method
= RequestMethod
.GET
)
121 public ModelAndView
doGetFieldObjectMedia(
122 @PathVariable("uuid") UUID occurrenceUuid
,
123 HttpServletRequest request
,
124 HttpServletResponse response
) throws IOException
{
126 logger
.info("doGetFieldObjectMedia() - " + request
.getRequestURI());
127 ModelAndView mv
= new ModelAndView();
128 DerivedUnitFacade duf
= newFacadeFrom(occurrenceUuid
, response
,Arrays
.asList(new String
[]{
129 "fieldObjectMedia", "fieldObjectMedia.title"}));
131 mv
.addObject(duf
.getFieldObjectMedia());
138 //@RequestMapping(method = RequestMethod.GET, value = "{uuid}/collectingareas")
140 value
= {"collectingareas"},
141 method
= RequestMethod
.GET
)
142 public Object
doGetCollectingAreas(
143 @PathVariable("uuid") UUID occurrenceUuid
,
144 HttpServletRequest request
,
145 HttpServletResponse response
) throws IOException
{
147 logger
.info("doGetCollectingAreas() - " + request
.getRequestURI());
148 DerivedUnitFacade duf
= newFacadeFrom(occurrenceUuid
,
150 Arrays
.asList(new String
[]{"collectingAreas"}));
151 return duf
.getCollectingAreas();
154 @RequestMapping(method
= RequestMethod
.GET
, value
= "collection")
155 public Object
doGetCollection(
156 @PathVariable("uuid") UUID uuid
,
157 HttpServletRequest request
,
158 HttpServletResponse response
) throws IOException
{
160 logger
.info("doGetCollection() - " + request
.getRequestURI());
161 DerivedUnitFacade duf
= newFacadeFrom(uuid
,
163 Arrays
.asList(new String
[]{"collection"}));
164 return duf
.getCollection();
169 // public Point getExactLocation() => valueProcessor?
172 // public Collection getCollection() {
173 // public AgentBase getCollector() {
174 // public DerivedUnit getDerivedUnit() {
175 // public Map<Language, LanguageString> getDerivedUnitDefinitions(){
176 // public List<Media> getDerivedUnitMedia() {
177 // public Set<DeterminationEvent> getDeterminations() {
178 // public Set<Specimen> getDuplicates(){
179 // public Map<Language, LanguageString> getEcologyAll(){
180 // public Map<Language, LanguageString> getFieldObjectDefinition() {
181 // public List<Media> getFieldObjectMedia() {
182 // public FieldUnit getFieldUnit(){
183 // public GatheringEvent getGatheringEvent() {
184 // public String getGatheringEventDescription() {
185 // public Map<Language, LanguageString> getPlantDescriptionAll(){ ==> representation !!
186 // public PreservationMethod getPreservationMethod()
187 // public Set<IdentifiableSource> getSources(){
188 // public TaxonName getStoredUnder() {
192 * @param occurrenceUuid
194 * @param extendedInitStrategy
195 * @return the requested <code>DerivedUnitFacade</code> instance or <code>null</code>
196 * @throws IOException
198 private DerivedUnitFacade
newFacadeFrom(UUID occurrenceUuid
, HttpServletResponse response
, List
<String
> extendedInitStrategy
)
200 List
<String
> initStrategy
= new ArrayList
<String
>(getInitializationStrategy());
201 if(extendedInitStrategy
!= null && extendedInitStrategy
.size() > 0){
202 initStrategy
.addAll(extendedInitStrategy
);
204 SpecimenOrObservationBase
<?
> sob
= service
.load(occurrenceUuid
, null);
205 if(sob
instanceof DerivedUnit
){
207 return service
.getDerivedUnitFacade(((DerivedUnit
)sob
), initStrategy
);
208 } catch (DerivedUnitFacadeNotSupportedException e
) {
209 logger
.error(e
); //TODO ...
213 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);