Project

General

Profile

Download (6.65 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

    
10
package eu.etaxonomy.cdm.remote.controller;
11

    
12
import java.io.IOException;
13
import java.util.ArrayList;
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.apache.log4j.Logger;
22
import org.springframework.beans.factory.annotation.Autowired;
23
import org.springframework.stereotype.Controller;
24
import org.springframework.web.bind.annotation.PathVariable;
25
import org.springframework.web.bind.annotation.RequestMapping;
26
import org.springframework.web.bind.annotation.RequestMethod;
27
import org.springframework.web.bind.annotation.RequestParam;
28

    
29
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
30
import eu.etaxonomy.cdm.api.service.dto.FieldUnitDTO;
31
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
32
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
33
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
34
import io.swagger.annotations.Api;
35

    
36
/**
37
 * TODO write controller documentation
38
 *
39
 * @author a.kohlbecker
40
 * @since 24.03.2009
41
 */
42
@Controller
43
@Api("occurrence")
44
@RequestMapping(value = {"/occurrence/{uuid}"})
45
public class OccurrenceController extends AbstractIdentifiableController<SpecimenOrObservationBase, IOccurrenceService>{
46

    
47
    private static final Logger logger = Logger.getLogger(OccurrenceController.class);
48

    
49

    
50
    protected static final List<String> DEFAULT_INIT_STRATEGY = Arrays.asList(new String []{
51
            "$",
52
            "sequences.$",
53
    });
54

    
55
    private static final List<String> DERIVED_UNIT_INIT_STRATEGY =  Arrays.asList(new String []{
56
            "derivedFrom.derivatives",
57
            "derivedFrom.originals",
58
            "specimenTypeDesignations.*",
59
            "specimenTypeDesignations.citation.*",
60
            "specimenTypeDesignations.homotypicalGroup.*",
61
            "specimenTypeDesignations.typifiedNames",
62
            "collection.$"
63
    });
64

    
65
    private static final List<String> EXTENSIONS_INIT_STRATEGY =  Arrays.asList(new String []{
66
            "extensions.type",
67
    });
68

    
69

    
70

    
71
    /* (non-Javadoc)
72
     * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
73
     */
74
    @Autowired
75
    @Override
76
    public void setService(IOccurrenceService service) {
77
        this.service = service;
78
    }
79

    
80
    @RequestMapping(value = { "derivedFrom" }, method = RequestMethod.GET)
81
    public DerivationEvent doGetDerivedFrom(
82
            @PathVariable("uuid") UUID uuid, HttpServletRequest request,
83
            HttpServletResponse response) throws IOException {
84

    
85
        logger.info("doGetDerivedFrom()" + requestPathAndQuery(request));
86

    
87
        SpecimenOrObservationBase<?> sob = getCdmBaseInstance(uuid, response, DERIVED_UNIT_INIT_STRATEGY);
88
        sob = checkExistsAndAccess(sob, NO_UNPUBLISHED, response);
89
        if(sob instanceof DerivedUnit){
90
            DerivationEvent derivationEvent = ((DerivedUnit)sob).getDerivedFrom();
91
            if (derivationEvent != null) {
92
                return derivationEvent;
93
            }
94
        }
95
        return null;
96
    }
97

    
98

    
99
    @RequestMapping(value = { "fieldUnitDTO" }, method = RequestMethod.GET)
100
    public  FieldUnitDTO doGetFieldUnitDTO(
101
            @PathVariable("uuid") UUID uuid,
102
            HttpServletRequest request,
103
            HttpServletResponse response) throws IOException {
104

    
105
        logger.info("doGetFieldUnitDTO()" + requestPathAndQuery(request));
106

    
107
        DerivedUnit sob = (DerivedUnit) getCdmBaseInstance(uuid, response, DERIVED_UNIT_INIT_STRATEGY);
108

    
109
        sob = checkExistsAndAccess(sob, NO_UNPUBLISHED, response);
110

    
111
        FieldUnitDTO fieldUnitDto = null;
112
        if(sob != null){
113
            fieldUnitDto = service.loadFieldUnitDTO(uuid);
114
        }
115

    
116
        return fieldUnitDto;
117
    }
118

    
119
    @RequestMapping(value = { "fieldUnitDTOs" }, method = RequestMethod.GET)
120
    public  List<FieldUnitDTO> doListFieldUnitDTO(
121
            @PathVariable("uuid") List<UUID> uuids,
122
            HttpServletRequest request,
123
            HttpServletResponse response) throws IOException {
124

    
125
        logger.info("doListFieldUnitDTO()" + requestPathAndQuery(request));
126
        List<FieldUnitDTO> dtos = new ArrayList<>(uuids.size());
127
        for(UUID uuid : uuids){
128
            dtos.add(service.loadFieldUnitDTO(uuid));
129
        }
130

    
131
        return dtos;
132
    }
133

    
134
//    @RequestMapping(value = { "specimenTypeDesignations" }, method = RequestMethod.GET)
135
//    public  List<SpecimenTypeDesignation> doGetTypeDesignations(
136
//            @PathVariable("uuid") UUID uuid,
137
//            HttpServletRequest request,
138
//            HttpServletResponse response) throws IOException {
139
//
140
//        logger.info("doGetSpecimenTypeDesignations()" + requestPathAndQuery(request));
141
//
142
//        DerivedUnit sob = (DerivedUnit) getCdmBaseInstance(uuid, response, DERIVED_UNIT_INIT_STRATEGY);
143
//
144
//        sob = checkExistsAndAccess(sob, NO_UNPUBLISHED, response);
145
//
146
//        FieldUnitDTO fieldUnitDto = null;
147
//        if(sob instanceof DerivedUnit){
148
//
149
//            fieldUnitDto = service.findFieldUnitDTO(new PreservedSpecimenDTO(sob) , new ArrayList<FieldUnitDTO>(), new HashMap<UUID, DerivateDTO>());
150
//
151
//        }
152
//
153
//        return fieldUnitDto;
154
//    }
155

    
156
    /**
157
     *
158
     * @param uuid
159
     * @param request
160
     * @param response
161
     * @return
162
     * @throws IOException
163
     */
164
    @RequestMapping(value = { "extensions" }, method = RequestMethod.GET)
165
    public Object doGetExtensions(
166
            @PathVariable("uuid") UUID uuid, HttpServletRequest request,
167
            // doPage request parameters
168
            @RequestParam(value = "pageNumber", required = false) Integer pageNumber,
169
            @RequestParam(value = "pageSize", required = false) Integer pageSize,
170
            // doList request parameters
171
            @RequestParam(value = "start", required = false) Integer start,
172
            @RequestParam(value = "limit", required = false) Integer limit,
173
            HttpServletResponse response) throws IOException {
174

    
175
        logger.info("doGetExtensions()" + requestPathAndQuery(request));
176
        SpecimenOrObservationBase<?> sob = getCdmBaseInstance(uuid, response, EXTENSIONS_INIT_STRATEGY);
177
        sob = checkExistsAndAccess(sob, NO_UNPUBLISHED, response);
178

    
179
        return pageFromCollection(sob.getExtensions(), pageNumber, pageSize, start, limit, response) ;
180
    }
181
}
(39-39/75)