1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2009 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.cdm.remote.controller;
|
11
|
|
12
|
import java.util.Arrays;
|
13
|
import java.util.List;
|
14
|
|
15
|
import javax.servlet.http.HttpServletRequest;
|
16
|
|
17
|
import org.apache.log4j.Logger;
|
18
|
|
19
|
import eu.etaxonomy.cdm.api.service.IService;
|
20
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
21
|
import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;
|
22
|
|
23
|
/**
|
24
|
* Abstract controller class for CDM Rest service controllers which return entities or DTOs
|
25
|
* from the underlying data base. Implementations of this class are primarily bound to a
|
26
|
* specific cdm service class and thus are operating primarily on a specific cdm base type.
|
27
|
*
|
28
|
* This class guarantees consistent use of init-strategies and harmonizes the logging of full
|
29
|
* request urls with query parameters.
|
30
|
*
|
31
|
* @author a.kohlbecker
|
32
|
* @date 23.06.2009
|
33
|
*
|
34
|
* @param <T>
|
35
|
* @param <SERVICE>
|
36
|
*/
|
37
|
public abstract class AbstractController<T extends CdmBase, SERVICE extends IService<T>> {
|
38
|
|
39
|
protected static final List<String> DEFAULT_INIT_STRATEGY = Arrays.asList(new String []{
|
40
|
"$"
|
41
|
});
|
42
|
|
43
|
public static final Logger logger = Logger.getLogger(AbstractController.class);
|
44
|
|
45
|
protected SERVICE service;
|
46
|
|
47
|
public abstract void setService(SERVICE service);
|
48
|
|
49
|
protected static final Integer DEFAULT_PAGE_SIZE = PagerParameters.DEFAULT_PAGESIZE;
|
50
|
|
51
|
/**
|
52
|
* Default thread priority for long term processes which are running in
|
53
|
* separate threads. These batch processes are usually monitored with the
|
54
|
* {@link ProgressMonitorController}. This value must be lower than
|
55
|
* {@link Thread#NORM_PRIORITY}
|
56
|
*/
|
57
|
public static final int DEFAULT_BATCH_THREAD_PRIORITY = 3;
|
58
|
|
59
|
protected List<String> initializationStrategy = DEFAULT_INIT_STRATEGY;
|
60
|
|
61
|
/**
|
62
|
* Set the default initialization strategy for this controller.
|
63
|
*
|
64
|
* @param initializationStrategy
|
65
|
*/
|
66
|
public final void setInitializationStrategy(List<String> initializationStrategy) {
|
67
|
this.initializationStrategy = initializationStrategy;
|
68
|
}
|
69
|
|
70
|
/**
|
71
|
* Provides access to the default initialization strategy.
|
72
|
* The default initialization strategy is predefined for all controllers in
|
73
|
* {@link #DEFAULT_INIT_STRATEGY} but can be altered by
|
74
|
* concrete implementations by utilizing {@link #setInitializationStrategy(List)}
|
75
|
* in the constructor of the specific controller.
|
76
|
*
|
77
|
* @return the default initialization strategy
|
78
|
*/
|
79
|
public final List<String> getInitializationStrategy() {
|
80
|
return this.initializationStrategy;
|
81
|
}
|
82
|
|
83
|
/**
|
84
|
* Returns the HTTP request path and query parameters as string
|
85
|
*
|
86
|
* @param request
|
87
|
* @return request path and query parameters as string.
|
88
|
*/
|
89
|
protected static String requestPathAndQuery(HttpServletRequest request) {
|
90
|
if(request == null) {
|
91
|
return "";
|
92
|
}
|
93
|
StringBuilder b = new StringBuilder();
|
94
|
b.append(request.getMethod()).append(": ");
|
95
|
b.append(request.getRequestURI());
|
96
|
String query = request.getQueryString();
|
97
|
if(query != null) {
|
98
|
b.append("?").append(query);
|
99
|
}
|
100
|
|
101
|
return b.toString();
|
102
|
}
|
103
|
|
104
|
}
|