Project

General

Profile

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

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

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

    
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
    public DescriptionPortalController() {
105
        super();
106
        setInitializationStrategy(DESCRIPTION_INIT_STRATEGY.getPropertyPaths());
107
    }
108

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

    
118
    @Autowired
119
    @Override
120
    public void setService(IDescriptionService service) {
121
        this.service = service;
122
    }
123

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

    
135
}
(25-25/76)