Project

General

Profile

« Previous | Next » 

Revision d0d4388c

Added by Patrick Plitzner almost 8 years ago

#5890 Add new controller method to get the root node for a given
classification

View differences:

cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/ClassificationPortalController.java
1
// $Id$
2
/**
3
 * Copyright (C) 2009 EDIT 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
7
 * 1.1 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 io.swagger.annotations.Api;
13

  
14
import java.util.Arrays;
15
import java.util.List;
16

  
17
import org.apache.log4j.Logger;
18
import org.springframework.beans.factory.annotation.Autowired;
19
import org.springframework.stereotype.Controller;
20
import org.springframework.web.bind.WebDataBinder;
21
import org.springframework.web.bind.annotation.InitBinder;
22
import org.springframework.web.bind.annotation.RequestMapping;
23

  
24
import eu.etaxonomy.cdm.api.service.IClassificationService;
25
import eu.etaxonomy.cdm.database.UpdatableRoutingDataSource;
26
import eu.etaxonomy.cdm.model.name.Rank;
27
import eu.etaxonomy.cdm.model.taxon.Classification;
28
import eu.etaxonomy.cdm.remote.editor.RankPropertyEditor;
29

  
30
/**
31
 * The ClassificationController class is a Spring MVC Controller.
32
 * <p>
33
 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
34
 * The available {datasource-name}s are defined in a configuration file which
35
 * is loaded by the {@link UpdatableRoutingDataSource}. If the
36
 * UpdatableRoutingDataSource is not being used in the actual application
37
 * context any arbitrary {datasource-name} may be used.
38
 * <p>
39
 * @author a.kohlbecker
40
 * @date 20.03.2009
41
 *
42
 * TODO this controller should be a portal controller!!
43
 */
44
@Controller
45
@Api("portal_classification")
46
@RequestMapping(value = {"/portal/classification/{uuid}"})
47
public class ClassificationPortalController extends BaseController<Classification,IClassificationService> {
48

  
49

  
50
    private static final List<String> CLASSIFICATION_INIT_STRATEGY = Arrays.asList(new String[]{
51
            "reference.authorship",
52
            "childNodes"
53
    });
54

  
55
    public static final Logger logger = Logger.getLogger(ClassificationPortalController.class);
56

  
57
    @Override
58
    @Autowired
59
    public void setService(IClassificationService service) {
60
        this.service = service;
61
    }
62

  
63

  
64

  
65
    @InitBinder
66
    @Override
67
    public void initBinder(WebDataBinder binder) {
68
        super.initBinder(binder);
69
        binder.registerCustomEditor(Rank.class, new RankPropertyEditor());
70
    }
71

  
72
    /**
73
     *
74
     */
75
    public ClassificationPortalController() {
76
        super();
77
        setInitializationStrategy(CLASSIFICATION_INIT_STRATEGY);
78
    }
79

  
80

  
1
// $Id$
2
/**
3
 * Copyright (C) 2009 EDIT 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
7
 * 1.1 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 io.swagger.annotations.Api;
13

  
14
import java.io.IOException;
15
import java.util.Arrays;
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.WebDataBinder;
26
import org.springframework.web.bind.annotation.InitBinder;
27
import org.springframework.web.bind.annotation.PathVariable;
28
import org.springframework.web.bind.annotation.RequestMapping;
29
import org.springframework.web.bind.annotation.RequestMethod;
30

  
31
import eu.etaxonomy.cdm.api.service.IClassificationService;
32
import eu.etaxonomy.cdm.database.UpdatableRoutingDataSource;
33
import eu.etaxonomy.cdm.model.name.Rank;
34
import eu.etaxonomy.cdm.model.taxon.Classification;
35
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
36
import eu.etaxonomy.cdm.remote.editor.RankPropertyEditor;
37

  
38
/**
39
 * The ClassificationController class is a Spring MVC Controller.
40
 * <p>
41
 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
42
 * The available {datasource-name}s are defined in a configuration file which
43
 * is loaded by the {@link UpdatableRoutingDataSource}. If the
44
 * UpdatableRoutingDataSource is not being used in the actual application
45
 * context any arbitrary {datasource-name} may be used.
46
 * <p>
47
 * @author a.kohlbecker
48
 * @date 20.03.2009
49
 *
50
 * TODO this controller should be a portal controller!!
51
 */
52
@Controller
53
@Api("portal_classification")
54
@RequestMapping(value = {"/portal/classification/{uuid}"})
55
public class ClassificationPortalController extends BaseController<Classification,IClassificationService> {
56

  
57

  
58
    private static final List<String> CLASSIFICATION_INIT_STRATEGY = Arrays.asList(new String[]{
59
            "reference.authorship",
60
            "childNodes"
61
    });
62

  
63
    public static final Logger logger = Logger.getLogger(ClassificationPortalController.class);
64

  
65
    @Override
66
    @Autowired
67
    public void setService(IClassificationService service) {
68
        this.service = service;
69
    }
70

  
71

  
72

  
73
    @InitBinder
74
    @Override
75
    public void initBinder(WebDataBinder binder) {
76
        super.initBinder(binder);
77
        binder.registerCustomEditor(Rank.class, new RankPropertyEditor());
78
    }
79

  
80
    /**
81
     *
82
     */
83
    public ClassificationPortalController() {
84
        super();
85
        setInitializationStrategy(CLASSIFICATION_INIT_STRATEGY);
86
    }
87

  
88
    @RequestMapping(value = { "classificationRootNode" }, method = RequestMethod.GET)
89
    public TaxonNode getClassificationRootNode(@PathVariable("uuid") UUID uuid, HttpServletRequest request,
90
            HttpServletResponse response) throws IOException {
91

  
92
        Classification classification = doGet(uuid, request, response);
93
        if(classification!=null){
94
            return classification.getRootNode();
95
        }
96
        return null;
97
    }
98

  
99

  
81 100
}

Also available in: Unified diff