3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.remote
.controller
;
12 import java
.util
.Arrays
;
13 import java
.util
.List
;
15 import javax
.servlet
.http
.HttpServletRequest
;
17 import org
.apache
.log4j
.Logger
;
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
;
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.
28 * This class guarantees consistent use of init-strategies and harmonizes the logging of full
29 * request urls with query parameters.
31 * @author a.kohlbecker
37 public abstract class AbstractController
<T
extends CdmBase
, SERVICE
extends IService
<T
>> {
39 protected static final List
<String
> DEFAULT_INIT_STRATEGY
= Arrays
.asList(new String
[]{
43 public static final Logger logger
= Logger
.getLogger(AbstractController
.class);
45 protected SERVICE service
;
47 public abstract void setService(SERVICE service
);
49 protected static final Integer DEFAULT_PAGE_SIZE
= PagerParameters
.DEFAULT_PAGESIZE
;
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}
57 public static final int DEFAULT_BATCH_THREAD_PRIORITY
= 3;
59 protected List
<String
> initializationStrategy
= DEFAULT_INIT_STRATEGY
;
62 * Set the default initialization strategy for this controller.
64 * @param initializationStrategy
66 public final void setInitializationStrategy(List
<String
> initializationStrategy
) {
67 this.initializationStrategy
= initializationStrategy
;
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.
77 * @return the default initialization strategy
79 public final List
<String
> getInitializationStrategy() {
80 return this.initializationStrategy
;
84 * Returns the HTTP request path and query parameters as string
87 * @return request path and query parameters as string.
89 protected static String
requestPathAndQuery(HttpServletRequest request
) {
93 StringBuilder b
= new StringBuilder();
94 b
.append(request
.getMethod()).append(": ");
95 b
.append(request
.getRequestURI());
96 String query
= request
.getQueryString();
98 b
.append("?").append(query
);