Project

General

Profile

Revision 00da181d

ID00da181d3506de7e36636fb89741ed949a5e00bb
Parent db5f97f7
Child 62ae3f4e

Added by Andreas Kohlbecker about 3 years ago

ref #6964 base implementation of the RegistrationController

View differences:

cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/RegistrationController.java
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.UUID;
15

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

  
19
import org.springframework.beans.factory.annotation.Autowired;
20
import org.springframework.security.authentication.AnonymousAuthenticationToken;
21
import org.springframework.security.core.Authentication;
22
import org.springframework.security.core.context.SecurityContextHolder;
23
import org.springframework.stereotype.Controller;
24
import org.springframework.web.bind.annotation.PathVariable;
25
import org.springframework.web.bind.annotation.RequestMapping;
26

  
27
import eu.etaxonomy.cdm.api.service.IRegistrationService;
28
import eu.etaxonomy.cdm.model.name.Registration;
29
import eu.etaxonomy.cdm.model.name.RegistrationStatus;
30
import io.swagger.annotations.Api;
31

  
32
/**
33
 * TODO write controller documentation
34
 *
35
 * @author a.kohlbecker
36
 * @date 24.03.2009
37
 */
38

  
39
@Controller
40
@Api("registration")
41
@RequestMapping(value = {"/registration/{uuid}", "/registration/{localID}"})
42
public class RegistrationController extends BaseController<Registration, IRegistrationService>
43
{
44

  
45
    public RegistrationController(){
46
        setInitializationStrategy(Arrays.asList(new String[]{
47
                "$",
48
                "name.$",
49
                "typeDesignations.$"
50
             }));
51
    }
52

  
53
    /* (non-Javadoc)
54
     * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
55
     */
56
    @Autowired
57
    @Override
58
    public void setService(IRegistrationService service) {
59
        this.service = service;
60
    }
61

  
62
    @Override
63
    public Registration doGet(@PathVariable("uuid") UUID uuid,
64
            HttpServletRequest request,
65
            HttpServletResponse response) throws IOException {
66

  
67
        Registration reg = super.doGet(uuid, request, response);
68
        if(reg != null){
69
            if(userIsAutheticated() && userIsAnnonymous() && !reg.getStatus().equals(RegistrationStatus.PUBLISHED)) {
70
                // completely hide the fact that there is a registration
71
                HttpStatusMessage.create("No such Registration", HttpServletResponse.SC_NO_CONTENT).send(response);
72
            }
73
        }
74
        return reg;
75
    }
76

  
77
 /*
78
    @Override
79
    public Registration doGetbyLocalId(@PathVariable("localID") Integer localID,
80
            HttpServletRequest request,
81
            HttpServletResponse response) throws IOException {
82

  
83
        Registration reg = super.doGet(localID, request, response);
84
        if(reg != null){
85
            if(userIsAutheticated() && userIsAnnonymous() && !reg.getStatus().equals(RegistrationStatus.PUBLISHED)) {
86
                // completely hide the fact that there is a registration
87
                HttpStatusMessage.create("No such Registration", HttpServletResponse.SC_NO_CONTENT);
88
            }
89
        }
90
        return reg;
91
    }
92
*/
93

  
94
    // =============================================================
95
    // TODO move into userHelper Class? See Vaddin CdmUserHelper!
96
    /**
97
     * @return
98
     */
99
    private Authentication getAuthentication() {
100
        return SecurityContextHolder.getContext().getAuthentication();
101
    }
102

  
103

  
104
    public boolean userIsAutheticated() {
105
        Authentication authentication = getAuthentication();
106
        if(authentication != null){
107
            return authentication.isAuthenticated();
108
        }
109
        return false;
110
    }
111

  
112

  
113
    public boolean userIsAnnonymous() {
114
        Authentication authentication = getAuthentication();
115
        return authentication != null
116
                && authentication.isAuthenticated()
117
                && authentication instanceof AnonymousAuthenticationToken;
118
    }
119
    // =============================================================
120
}
cdmlib-remote/src/main/resources/eu/etaxonomy/cdm/remote/json/jsonConfigurations.xml
74 74
             <value>TaxonInteraction.feature</value>
75 75
             <value>TextData.feature</value>
76 76
             <value>IdentifiableSource.citation</value>
77
             
78
             <value>Registration.name</value>
79
             <value>Registration.typeDesignations</value>
80
             <value>Registration.institution</value>
77 81

  
78 82
             <value>SearchResult.entity</value>
79 83
             

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)