2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.remote
.controller
;
11 import java
.util
.Arrays
;
12 import java
.util
.List
;
14 import javax
.servlet
.http
.HttpServletRequest
;
16 import org
.apache
.log4j
.Logger
;
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
;
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.
27 * This class guarantees consistent use of init-strategies and harmonizes the logging of full
28 * request urls with query parameters.
30 * @author a.kohlbecker
36 public abstract class AbstractController
<T
extends CdmBase
, SERVICE
extends IService
<T
>> {
38 public static final Logger logger
= Logger
.getLogger(AbstractController
.class);
40 protected static final List
<String
> DEFAULT_INIT_STRATEGY
= Arrays
.asList(new String
[]{
43 protected static final Integer DEFAULT_PAGE_SIZE
= PagerParameters
.DEFAULT_PAGESIZE
;
46 * Default thread priority for long term processes which are running in
47 * separate threads. These batch processes are usually monitored with the
48 * {@link ProgressMonitorController}. This value must be lower than
49 * {@link Thread#NORM_PRIORITY}
51 public static final int DEFAULT_BATCH_THREAD_PRIORITY
= 3;
53 protected SERVICE service
;
55 public abstract void setService(SERVICE service
);
57 protected List
<String
> initializationStrategy
= DEFAULT_INIT_STRATEGY
;
60 * Set the default initialization strategy for this controller.
62 * @param initializationStrategy
64 public final void setInitializationStrategy(List
<String
> initializationStrategy
) {
65 this.initializationStrategy
= initializationStrategy
;
69 * Provides access to the default initialization strategy.
70 * The default initialization strategy is predefined for all controllers in
71 * {@link #DEFAULT_INIT_STRATEGY} but can be altered by
72 * concrete implementations by utilizing {@link #setInitializationStrategy(List)}
73 * in the constructor of the specific controller.
75 * @return the default initialization strategy
77 public final List
<String
> getInitializationStrategy() {
78 return this.initializationStrategy
;
82 * Returns the HTTP request path and query parameters as string
85 * @return request path and query parameters as string.
87 protected static String
requestPathAndQuery(HttpServletRequest request
) {
91 StringBuilder b
= new StringBuilder();
92 b
.append(request
.getMethod()).append(": ");
93 b
.append(request
.getRequestURI());
94 String query
= request
.getQueryString();
96 b
.append("?").append(query
);