Project

General

Profile

Download (5.41 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.log4j.Logger;
19
import org.springframework.beans.factory.annotation.Autowired;
20
import org.springframework.stereotype.Controller;
21
import org.springframework.transaction.annotation.Transactional;
22
import org.springframework.web.bind.WebDataBinder;
23
import org.springframework.web.bind.annotation.InitBinder;
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

    
28
import eu.etaxonomy.cdm.api.service.IDescriptionElementService;
29
import eu.etaxonomy.cdm.api.service.IDescriptionService;
30
import eu.etaxonomy.cdm.api.service.ITermService;
31
import eu.etaxonomy.cdm.api.service.pager.Pager;
32
import eu.etaxonomy.cdm.model.common.Annotation;
33
import eu.etaxonomy.cdm.model.description.DescriptionBase;
34
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
35
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
36
import eu.etaxonomy.cdm.persistence.dao.initializer.EntityInitStrategy;
37
import eu.etaxonomy.cdm.remote.editor.DefinedTermBaseList;
38
import eu.etaxonomy.cdm.remote.editor.NamedAreaLevelPropertyEditor;
39
import eu.etaxonomy.cdm.remote.editor.TermBaseListPropertyEditor;
40
import eu.etaxonomy.cdm.remote.editor.UUIDListPropertyEditor;
41
import eu.etaxonomy.cdm.remote.editor.UuidList;
42
import io.swagger.annotations.Api;
43

    
44
/**
45
 * @author a.kohlbecker
46
 * @since Jun 25, 2013
47
 */
48
@Controller
49
@Api("portal_description")
50
@Transactional(readOnly=true)
51
@RequestMapping(value = {
52
            "/portal/description/{uuid}",
53
            "/portal/description/{uuid_list}"})
54
public class DescriptionPortalController extends BaseController<DescriptionBase, IDescriptionService> {
55

    
56
    private static final Logger logger = Logger.getLogger(DescriptionPortalController.class);
57

    
58
    public static final EntityInitStrategy DESCRIPTION_INIT_STRATEGY = new EntityInitStrategy(Arrays.asList(new String [] {
59
            "$",
60
            "descriptiveDataSets",
61
            "descriptiveDataSets.descriptiveSystem",
62
            "descriptiveDataSets.descriptiveSystem.root",
63
            "descriptiveDataSets.descriptiveSystem.root.childNodes",
64
            "descriptiveDataSets.descriptiveSystem.root.childNodes.term",
65
            "elements.$",
66
            "elements.annotations",
67
            "elements.multilanguageText.*",
68
            "elements.stateData.*",
69
            "elements.sources.citation.authorship.$",
70
            "elements.sources.nameUsedInSource",
71
            "elements.media",
72
            "elements.modifyingText",
73
            "elements.modifiers",
74
            "elements.area.level",
75
            "elements.statisticalValues.*",
76
            "elements.unit",
77
            "elements.kindOfUnit",
78
            "name.$",
79
            "name.rank.representations",
80
            "name.status.type.representations",
81
            "sources.$",
82
            "sources.cdmSource.target",
83
            "taxon.name"
84
    }));
85

    
86
    protected static final List<String> ORDERED_DISTRIBUTION_INIT_STRATEGY = Arrays.asList(new String []{
87
            "elements.$",
88
            "elements.annotations",
89
            "elements.markers",
90
            "elements.sources.citation.authorship.$",
91
            "elements.sources.nameUsedInSource",
92
            "elements.area.level",
93
    });
94

    
95
    protected static final List<String> DISTRIBUTION_INFO_INIT_STRATEGY = Arrays.asList(new String []{
96
            "sources.citation.authorship.$",
97
            "sources.nameUsedInSource",
98
            "annotations"
99
    });
100

    
101
    @Autowired
102
    private ITermService termService;
103

    
104
    @Autowired
105
    private IDescriptionElementService descriptionElementService;
106

    
107
    public DescriptionPortalController() {
108
        super();
109
        setInitializationStrategy(DESCRIPTION_INIT_STRATEGY.getPropertyPaths());
110
    }
111

    
112
    @InitBinder
113
    @Override
114
    public void initBinder(WebDataBinder binder) {
115
        super.initBinder(binder);
116
        binder.registerCustomEditor(UuidList.class, new UUIDListPropertyEditor());
117
        binder.registerCustomEditor(NamedAreaLevel.class, new NamedAreaLevelPropertyEditor());
118
        binder.registerCustomEditor(DefinedTermBaseList.class, new TermBaseListPropertyEditor<>(termService));
119
    }
120

    
121
    @Autowired
122
    @Override
123
    public void setService(IDescriptionService service) {
124
        this.service = service;
125
    }
126

    
127
    @RequestMapping(value = "//portal/descriptionElement/{descriptionelement_uuid}/annotation", method = RequestMethod.GET) // mapped as absolute path, see CdmAntPathMatcher
128
    public Pager<Annotation> getAnnotations(
129
            @PathVariable("descriptionelement_uuid") UUID uuid,
130
            HttpServletRequest request,
131
            HttpServletResponse response) {
132
        logger.info("getAnnotations() - " + requestPathAndQuery(request) );
133
        DescriptionElementBase annotatableEntity = descriptionElementService.find(uuid);
134
        Pager<Annotation> annotations = descriptionElementService.getDescriptionElementAnnotations(annotatableEntity, null, null, 0, null, getInitializationStrategy());
135
        return annotations;
136
    }
137
}
(25-25/76)