Project

General

Profile

Download (5.74 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.Collection;
16
import java.util.List;
17
import java.util.UUID;
18

    
19
import javax.servlet.http.HttpServletRequest;
20
import javax.servlet.http.HttpServletResponse;
21

    
22
import org.apache.log4j.Logger;
23
import org.springframework.beans.factory.annotation.Autowired;
24
import org.springframework.stereotype.Controller;
25
import org.springframework.web.bind.annotation.PathVariable;
26
import org.springframework.web.bind.annotation.RequestMapping;
27
import org.springframework.web.bind.annotation.RequestMethod;
28
import org.springframework.web.bind.annotation.RequestParam;
29

    
30
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
31
import eu.etaxonomy.cdm.api.service.dto.SpecimenOrObservationBaseDTO;
32
import eu.etaxonomy.cdm.model.common.CdmBase;
33
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
34
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
35
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
36
import io.swagger.annotations.Api;
37

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

    
49
    private static final Logger logger = Logger.getLogger(OccurrenceController.class);
50

    
51

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

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

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

    
71
    @Autowired
72
    @Override
73
    public void setService(IOccurrenceService service) {
74
        this.service = service;
75
    }
76

    
77
    @Override
78
    protected <CDM_BASE extends CdmBase> List<String> complementInitStrategy(Class<CDM_BASE> clazz,
79
            List<String> pathProperties) {
80

    
81
        if(pathProperties.stream().anyMatch(s -> s.startsWith("specimenTypeDesignations"))) {
82
            List<String> complemented = new ArrayList<>(pathProperties);
83
            complemented.add("specimenTypeDesignations.designationSource.citation.*");
84
            return complemented;
85
        }
86
        if(pathProperties.stream().anyMatch(s -> s.startsWith("sources"))) {
87
            List<String> complemented = new ArrayList<>(pathProperties);
88
            complemented.add("sources.citation.*");
89
            return complemented;
90
        }
91
        return pathProperties;
92
    }
93

    
94
    @RequestMapping(value = { "derivedFrom" }, method = RequestMethod.GET)
95
    public DerivationEvent doGetDerivedFrom(
96
            @PathVariable("uuid") UUID uuid, HttpServletRequest request,
97
            HttpServletResponse response) throws IOException {
98

    
99
        logger.info("doGetDerivedFrom()" + requestPathAndQuery(request));
100

    
101
        SpecimenOrObservationBase<?> sob = getCdmBaseInstance(uuid, response, DERIVED_UNIT_INIT_STRATEGY);
102
        sob = checkExistsAndAccess(sob, NO_UNPUBLISHED, response);
103
        if(sob instanceof DerivedUnit){
104
            DerivationEvent derivationEvent = ((DerivedUnit)sob).getDerivedFrom();
105
            if (derivationEvent != null) {
106
                return derivationEvent;
107
            }
108
        }
109
        return null;
110
    }
111

    
112

    
113
    @RequestMapping(value = { "rootUnitDTOs" }, method = RequestMethod.GET)
114
    public  Collection<SpecimenOrObservationBaseDTO> doGetRootUnitDTOs(
115
            @PathVariable("uuid") UUID uuid,
116
            HttpServletRequest request,
117
            HttpServletResponse response) throws IOException {
118

    
119
        logger.info("doGetRootUnitDTOs()" + requestPathAndQuery(request));
120

    
121
        SpecimenOrObservationBase<?> sob = getCdmBaseInstance(uuid, response, "$");
122
        sob = checkExistsAndAccess(sob, NO_UNPUBLISHED, response);
123

    
124
        Collection<SpecimenOrObservationBaseDTO> fieldUnitDtos = service.findRootUnitDTOs(uuid);
125

    
126

    
127
        return fieldUnitDtos;
128
    }
129

    
130

    
131
    @RequestMapping(value = { "extensions" }, method = RequestMethod.GET)
132
    public Object doGetExtensions(
133
            @PathVariable("uuid") UUID uuid, HttpServletRequest request,
134
            // doPage request parameters
135
            @RequestParam(value = "pageIndex", required = false) Integer pageIndex,
136
            @RequestParam(value = "pageSize", required = false) Integer pageSize,
137
            // doList request parameters
138
            @RequestParam(value = "start", required = false) Integer start,
139
            @RequestParam(value = "limit", required = false) Integer limit,
140
            HttpServletResponse response) throws IOException {
141

    
142
        logger.info("doGetExtensions()" + requestPathAndQuery(request));
143
        SpecimenOrObservationBase<?> sob = getCdmBaseInstance(uuid, response, EXTENSIONS_INIT_STRATEGY);
144
        sob = checkExistsAndAccess(sob, NO_UNPUBLISHED, response);
145

    
146
        return pageFromCollection(sob.getExtensions(), pageIndex, pageSize, start, limit, response) ;
147
    }
148
}
(39-39/76)