Project

General

Profile

Download (3.94 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.Arrays;
14
import java.util.List;
15
import java.util.UUID;
16

    
17
import javax.servlet.http.HttpServletRequest;
18
import javax.servlet.http.HttpServletResponse;
19

    
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
import org.springframework.web.bind.annotation.RequestParam;
26

    
27
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
28
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
29
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
30
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
31
import io.swagger.annotations.Api;
32

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

    
44
    protected static final List<String> DEFAULT_INIT_STRATEGY = Arrays.asList(new String []{
45
            "$",
46
            "sequences.$",
47
    });
48

    
49
    private static final List<String> DERIVED_UNIT_INIT_STRATEGY =  Arrays.asList(new String []{
50
            "derivedFrom.derivatives",
51
            "derivedFrom.originals",
52
    });
53

    
54
    private static final List<String> EXTENSIONS_INIT_STRATEGY =  Arrays.asList(new String []{
55
            "extensions.type",
56
    });
57

    
58

    
59

    
60
    /* (non-Javadoc)
61
     * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
62
     */
63
    @Autowired
64
    @Override
65
    public void setService(IOccurrenceService service) {
66
        this.service = service;
67
    }
68

    
69
    @RequestMapping(value = { "derivedFrom" }, method = RequestMethod.GET)
70
    public DerivationEvent doGetDerivedFrom(
71
            @PathVariable("uuid") UUID uuid, HttpServletRequest request,
72
            HttpServletResponse response) throws IOException {
73

    
74
        logger.info("doGetDerivedFrom()" + requestPathAndQuery(request));
75

    
76
        SpecimenOrObservationBase<?> sob = getCdmBaseInstance(uuid, response, DERIVED_UNIT_INIT_STRATEGY);
77
        if(sob instanceof DerivedUnit){
78
            DerivationEvent derivationEvent = ((DerivedUnit)sob).getDerivedFrom();
79
            if (derivationEvent != null) {
80
                return derivationEvent;
81
            }
82
        }
83
        return null;
84
    }
85

    
86
    /**
87
     *
88
     * @param uuid
89
     * @param request
90
     * @param response
91
     * @return
92
     * @throws IOException
93
     */
94
    @RequestMapping(value = { "extensions" }, method = RequestMethod.GET)
95
    public Object doGetExtensions(
96
            @PathVariable("uuid") UUID uuid, HttpServletRequest request,
97
            // doPage request parametes
98
            @RequestParam(value = "pageNumber", required = false) Integer pageNumber,
99
            @RequestParam(value = "pageSize", required = false) Integer pageSize,
100
            // doList request parametes
101
            @RequestParam(value = "start", required = false) Integer start,
102
            @RequestParam(value = "limit", required = false) Integer limit,
103
            HttpServletResponse response) throws IOException {
104

    
105
        logger.info("doGetExtensions()" + requestPathAndQuery(request));
106
        SpecimenOrObservationBase<?> sob = getCdmBaseInstance(uuid, response, EXTENSIONS_INIT_STRATEGY);
107

    
108
        return pageFromCollection(sob.getExtensions(), pageNumber, pageSize, start, limit, response) ;
109
    }
110
}
(41-41/67)