Project

General

Profile

Download (3.44 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 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

    
14
import javax.servlet.http.HttpServletRequest;
15

    
16
import org.apache.log4j.Logger;
17

    
18
import eu.etaxonomy.cdm.api.service.IService;
19
import eu.etaxonomy.cdm.model.common.CdmBase;
20
import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;
21

    
22
/**
23
 * Abstract controller class for CDM Rest service controllers which return entities or DTOs
24
 * from the underlying data base. Implementations of this class are primarily bound to a
25
 * specific cdm service class and thus are operating primarily on a specific cdm base type.
26
 *
27
 * This class guarantees consistent use of init-strategies and harmonizes the logging of full
28
 * request urls with query parameters.
29
 *
30
 * @author a.kohlbecker
31
 * @date 23.06.2009
32
 *
33
 * @param <T>
34
 * @param <SERVICE>
35
 */
36
public abstract class AbstractController<T extends CdmBase, SERVICE extends IService<T>> {
37

    
38
    protected static final List<String> DEFAULT_INIT_STRATEGY = Arrays.asList(new String []{
39
            "$"
40
    });
41

    
42
    public static final Logger logger = Logger.getLogger(AbstractController.class);
43

    
44
    protected SERVICE service;
45

    
46
    public abstract void setService(SERVICE service);
47

    
48
    protected static final Integer DEFAULT_PAGE_SIZE = PagerParameters.DEFAULT_PAGESIZE;
49

    
50
    /**
51
     * Default thread priority for long term processes which are running in
52
     * separate threads. These batch processes are usually monitored with the
53
     * {@link ProgressMonitorController}. This value must be lower than
54
     * {@link Thread#NORM_PRIORITY}
55
     */
56
    public static final int DEFAULT_BATCH_THREAD_PRIORITY = 3;
57

    
58
    protected List<String> initializationStrategy = DEFAULT_INIT_STRATEGY;
59

    
60
    /**
61
     * Set the default initialization strategy for this controller.
62
     *
63
     * @param initializationStrategy
64
     */
65
    public final void setInitializationStrategy(List<String> initializationStrategy) {
66
        this.initializationStrategy = initializationStrategy;
67
    }
68

    
69
    /**
70
     * Provides access to the default initialization strategy.
71
     * The default initialization strategy is predefined for all controllers in
72
     * {@link #DEFAULT_INIT_STRATEGY} but can be altered by
73
     * concrete implementations by utilizing {@link #setInitializationStrategy(List)}
74
     * in the constructor of the specific controller.
75
     *
76
     * @return the default initialization strategy
77
     */
78
    public final List<String> getInitializationStrategy() {
79
        return this.initializationStrategy;
80
    }
81

    
82
    /**
83
     * Returns the HTTP request path and query parameters as string
84
     *
85
     * @param request
86
     * @return request path and query parameters as string.
87
     */
88
    protected static String requestPathAndQuery(HttpServletRequest request) {
89
        if(request == null) {
90
            return "";
91
        }
92
        StringBuilder b = new StringBuilder();
93
        b.append(request.getMethod()).append(": ");
94
        b.append(request.getRequestURI());
95
        String query = request.getQueryString();
96
        if(query != null) {
97
            b.append("?").append(query);
98
        }
99

    
100
        return b.toString();
101
    }
102

    
103
}
(1-1/66)