Project

General

Profile

Download (5.33 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9
package eu.etaxonomy.cdm.remote.controller;
10

    
11
import java.util.Arrays;
12
import java.util.List;
13
import java.util.UUID;
14

    
15
import javax.servlet.http.HttpServletRequest;
16
import javax.servlet.http.HttpServletResponse;
17

    
18
import org.apache.logging.log4j.LogManager;
19
import org.apache.logging.log4j.Logger;
20
import org.springframework.beans.factory.annotation.Autowired;
21
import org.springframework.stereotype.Controller;
22
import org.springframework.web.bind.annotation.PathVariable;
23
import org.springframework.web.bind.annotation.RequestMapping;
24
import org.springframework.web.bind.annotation.RequestMethod;
25

    
26
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
27
import eu.etaxonomy.cdm.api.service.dto.SpecimenOrObservationBaseDTO;
28
import eu.etaxonomy.cdm.model.media.Media;
29
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
30
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
31
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
32
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
33
import io.swagger.annotations.Api;
34

    
35
/**
36
 * TODO write controller documentation
37
 *
38
 * @author a.kohlbecker
39
 * @since 24.03.2009
40
 */
41
@Controller
42
@Api("portal_occurrence")
43
@RequestMapping(value = {"/portal/occurrence/{uuid}"})
44
public class OccurrencePortalController extends OccurrenceController {
45

    
46
    private static Logger logger = LogManager.getLogger();
47

    
48
    private static final List<String> DEFAULT_INIT_STRATEGY =  Arrays.asList(new String []{
49
            "$",
50
            "determinations.*",
51
            "sources.$",
52
            "derivedFrom.type",
53
            "derivedFrom.originals.*",
54
            "derivedFrom.originals.determinations.taxon",
55
            "derivedFrom.originals.gatheringEvent.exactLocation.$",
56
            "derivedFrom.gatheringEvent.exactLocation.$",
57
            "derivationEvents.derivatives.$",
58
            "specimenTypeDesignations.*",
59
            "specimenTypeDesignations.citation.*",
60
            "specimenTypeDesignations.homotypicalGroup.*",
61
            "specimenTypeDesignations.typifiedNames",
62
            "sequences.$",
63
            "sequences.annotations",
64
            "markers.markerType",
65
            "gatheringEvent.$",
66
            "gatheringEvent.exactLocation.referenceSystem", // TODO implement auto initializer?
67
            "gatheringEvent.collectingAreas",
68
            "annotations",
69
            "descriptions",
70
            "collection.institute.$"
71
    });
72

    
73
    /**
74
     *
75
     */
76
    public OccurrencePortalController() {
77
        super();
78
        setInitializationStrategy(DEFAULT_INIT_STRATEGY);
79
    }
80

    
81
    @Autowired
82
    @Override
83
    public void setService(IOccurrenceService service) {
84
        this.service = service;
85
    }
86

    
87
    @RequestMapping(value = { "asDTO" }, method = RequestMethod.GET)
88
    public SpecimenOrObservationBaseDTO doGetAsDTO(
89
            @PathVariable("uuid") UUID uuid,
90
            HttpServletRequest request,
91
            HttpServletResponse response) {
92

    
93
        logger.info("doGetAsDTO() " + requestPathAndQuery(request));
94

    
95
        SpecimenOrObservationBase<?> sob = service.load(uuid);
96
        if(sob.isPublish()) {
97
            if(sob instanceof FieldUnit){
98
                return service.assembleFieldUnitDTO((FieldUnit)sob);
99
            } else {
100
                return service.assembleDerivedUnitDTO((DerivedUnit)sob);
101
            }
102
        }
103
        // FIXME proper http code
104
        return null;
105
    }
106

    
107
    @RequestMapping(value = { "mediaSpecimen" }, method = RequestMethod.GET)
108
    public Media doGetMediaSpecimen(
109
            @PathVariable("uuid") UUID uuid,
110
            HttpServletRequest request,
111
            @SuppressWarnings("unused") HttpServletResponse response) {
112

    
113
        logger.info("doGetMediaSpecimen() " + requestPathAndQuery(request));
114

    
115

    
116
        SpecimenOrObservationBase<?> sob = service.load(uuid, Arrays.asList("mediaSpecimen.sources.citation", "mediaSpecimen.representations.parts"));
117
        if(sob instanceof MediaSpecimen){
118
            MediaSpecimen mediaSpecimen = (MediaSpecimen) sob;
119
            if(mediaSpecimen.isPublish()){
120
                return mediaSpecimen.getMediaSpecimen();
121
            }
122
        }
123
        return null;
124
    }
125

    
126
//    @RequestMapping(value = { "specimenDerivatesAndOriginals" }, method = RequestMethod.GET)
127
//    public ModelAndView doGetSpecimenDerivatesAndOriginals(
128
//            @RequestParam(value = "relationships", required = false) UuidList relationshipUuids,
129
//            @RequestParam(value = "relationshipsInvers", required = false) UuidList relationshipInversUuids,
130
//            @PathVariable("uuid") UUID uuid,
131
//            HttpServletRequest request,
132
//            HttpServletResponse response) throws IOException {
133
//
134
//        logger.info("doGetSpecimenDerivates() " + request.getRequestURI());
135
//
136
//        ModelAndView mv = new ModelAndView();
137
//        Set<TaxonRelationshipEdge> includeRelationships = ControllerUtils.loadIncludeRelationships(relationshipUuids, relationshipInversUuids, termService);
138
//        List<FieldUnitDTO> fieldUnitDTOs = service.findFieldUnitDTOByAssociatedTaxon(includeRelationships, uuid);
139
//        if(fieldUnitDTOs!=null){
140
//                    mv.addObject(fieldUnitDTOs);
141
//        }
142
//
143
//        return mv;
144
//    }
145

    
146
}
(41-41/76)