Revision 47a15e28
Added by Andreas Kohlbecker over 12 years ago
.gitattributes | ||
---|---|---|
1525 | 1525 |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/oaipmh/ReferenceOaiPmhController.java -text |
1526 | 1526 |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/oaipmh/TaxonOaiPmhController.java -text |
1527 | 1527 |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/util/CdmAntPathMatcher.java -text |
1528 |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/util/PagerParameters.java -text |
|
1528 | 1529 |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/DozerBeanMapperFactoryBean.java -text |
1529 | 1530 |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/converter/DateTimeConverter.java -text |
1530 | 1531 |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/converter/DefaultRelatedPageConverter.java -text |
cdmlib-remote-webapp/src/main/webapp/WEB-INF/cdmlib-remote-servlet.xml | ||
---|---|---|
1 | 1 |
<?xml version="1.0" encoding="UTF-8"?> |
2 | 2 |
<beans xmlns="http://www.springframework.org/schema/beans" |
3 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
|
|
4 |
xmlns:tx="http://www.springframework.org/schema/tx"
|
|
5 |
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
|
3 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
|
|
4 |
xmlns:tx="http://www.springframework.org/schema/tx"
|
|
5 |
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
|
6 | 6 |
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd |
7 | 7 |
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd |
8 | 8 |
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd |
9 | 9 |
"> |
10 |
<context:component-scan base-package="eu/etaxonomy/cdm/remote" />
|
|
11 |
|
|
12 |
|
|
13 |
<!--
|
|
14 |
======= HandlerMappings =======
|
|
15 |
-->
|
|
16 |
<!--
|
|
17 |
first we try to find the controller using the simpleurlmapping, then
|
|
18 |
the classname this follows the principal of "convention over
|
|
19 |
configuration"
|
|
20 |
-->
|
|
21 |
<bean
|
|
22 |
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
|
|
23 |
<property name="order" value="1" />
|
|
24 |
<property name="interceptors">
|
|
25 |
<list>
|
|
26 |
<!--<ref bean="contentNegociationHandlerInterceptor" /> -->
|
|
27 |
<ref bean="localeContextHandlerInterceptor" />
|
|
28 |
</list>
|
|
29 |
</property>
|
|
30 |
<property name="pathMatcher">
|
|
31 |
<!-- must match the pathMatcher as set in AnnotationMethodHandlerAdapter -->
|
|
32 |
<bean class="eu.etaxonomy.cdm.remote.controller.util.CdmAntPathMatcher" />
|
|
33 |
</property>
|
|
34 |
</bean>
|
|
35 |
|
|
36 |
<!--
|
|
37 |
-->
|
|
38 |
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
|
|
39 |
<property name="order" value="0" />
|
|
40 |
<property name="mappings">
|
|
41 |
<props>
|
|
42 |
<prop key="/index.do">urlFilenameViewController</prop>
|
|
43 |
<prop key="/">welcomeFileViewController</prop>
|
|
44 |
</props>
|
|
45 |
</property>
|
|
46 |
</bean>
|
|
47 |
|
|
48 |
<!--
|
|
49 |
======= HandlerAdapters =======
|
|
50 |
-->
|
|
51 |
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
|
|
52 |
<property name="pathMatcher">
|
|
53 |
<!-- must match the pathMatcher as set in DefaultAnnotationHandlerMapping -->
|
|
10 |
<context:component-scan base-package="eu/etaxonomy/cdm/remote" />
|
|
11 |
|
|
12 |
|
|
13 |
<!--
|
|
14 |
======= HandlerMappings =======
|
|
15 |
-->
|
|
16 |
<!--
|
|
17 |
first we try to find the controller using the simpleurlmapping, then
|
|
18 |
the classname this follows the principal of "convention over
|
|
19 |
configuration"
|
|
20 |
-->
|
|
21 |
<bean
|
|
22 |
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
|
|
23 |
<property name="order" value="1" />
|
|
24 |
<property name="interceptors">
|
|
25 |
<list>
|
|
26 |
<!--<ref bean="contentNegociationHandlerInterceptor" /> -->
|
|
27 |
<ref bean="localeContextHandlerInterceptor" />
|
|
28 |
</list>
|
|
29 |
</property>
|
|
30 |
<property name="pathMatcher">
|
|
31 |
<!-- must match the pathMatcher as set in AnnotationMethodHandlerAdapter -->
|
|
32 |
<bean class="eu.etaxonomy.cdm.remote.controller.util.CdmAntPathMatcher" />
|
|
33 |
</property>
|
|
34 |
</bean>
|
|
35 |
|
|
36 |
<!-- |
|
37 |
-->
|
|
38 |
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
|
|
39 |
<property name="order" value="0" />
|
|
40 |
<property name="mappings">
|
|
41 |
<props>
|
|
42 |
<prop key="/index.do">urlFilenameViewController</prop>
|
|
43 |
<prop key="/">welcomeFileViewController</prop>
|
|
44 |
</props>
|
|
45 |
</property>
|
|
46 |
</bean>
|
|
47 |
|
|
48 |
<!--
|
|
49 |
======= HandlerAdapters =======
|
|
50 |
-->
|
|
51 |
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
|
|
52 |
<property name="pathMatcher">
|
|
53 |
<!-- must match the pathMatcher as set in DefaultAnnotationHandlerMapping -->
|
|
54 | 54 |
<bean class="eu.etaxonomy.cdm.remote.controller.util.CdmAntPathMatcher" /> |
55 | 55 |
</property> |
56 |
</bean>
|
|
57 |
|
|
58 |
<!-- needed when using SimpleUrlHandlerMapping -->
|
|
59 |
<bean
|
|
60 |
class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
|
|
61 |
|
|
62 |
|
|
63 |
<!--
|
|
64 |
======= HandlerInterceptors =======
|
|
65 |
-->
|
|
66 |
<!--
|
|
67 |
<bean id="datasourceContextHandlerInterceptor"
|
|
68 |
class="eu.etaxonomy.cdm.remote.controller.interceptor.DatasourceContextHandlerInterceptor" /> -->
|
|
69 |
<bean id="localeContextHandlerInterceptor"
|
|
70 |
class="eu.etaxonomy.cdm.remote.controller.interceptor.LocaleContextHandlerInterceptor" />
|
|
71 |
<!--
|
|
72 |
=== no longer needed, replaced by ContentNegotiatingViewResolver ==
|
|
73 |
<bean id="contentNegociationHandlerInterceptor"
|
|
74 |
class="eu.etaxonomy.cdm.remote.controller.interceptor.ContentNegociationHandlerInterceptor">
|
|
75 |
<property name="mapping">
|
|
76 |
<map>
|
|
77 |
<entry key="text/json" value="json" />
|
|
78 |
<entry key="application/json" value="json" />
|
|
79 |
<entry key="application/xml" value="xml" />
|
|
80 |
</map>
|
|
81 |
</property>
|
|
82 |
<property name="defaultExtension" value="xml" />
|
|
83 |
</bean>
|
|
84 |
-->
|
|
85 |
|
|
86 |
<!--
|
|
87 |
======= ViewControllers =======
|
|
88 |
-->
|
|
89 |
<bean id="urlFilenameViewController" class="org.springframework.web.servlet.mvc.UrlFilenameViewController">
|
|
90 |
</bean>
|
|
91 |
<!--
|
|
92 |
The welcome-file-list in the web.xml will is ignored since the
|
|
93 |
cdmserver servlet is mapped to the root path [/] So the welcome file
|
|
94 |
list is being replaced by a SimpleUrlHandlerMapping on the root path
|
|
95 |
[/] which is mapped via this ViewController to the [index] view
|
|
96 |
-->
|
|
97 |
<bean id="welcomeFileViewController"
|
|
98 |
class="org.springframework.web.servlet.mvc.UrlFilenameViewController">
|
|
99 |
<property name="suffix">
|
|
100 |
<value>index</value>
|
|
101 |
</property>
|
|
102 |
</bean>
|
|
103 |
|
|
104 |
|
|
105 |
<!--
|
|
56 |
</bean>
|
|
57 |
|
|
58 |
<!-- needed when using SimpleUrlHandlerMapping -->
|
|
59 |
<bean
|
|
60 |
class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
|
|
61 |
|
|
62 |
|
|
63 |
<!--
|
|
64 |
======= HandlerInterceptors =======
|
|
65 |
-->
|
|
66 |
<!--
|
|
67 |
<bean id="datasourceContextHandlerInterceptor"
|
|
68 |
class="eu.etaxonomy.cdm.remote.controller.interceptor.DatasourceContextHandlerInterceptor" /> -->
|
|
69 |
<bean id="localeContextHandlerInterceptor"
|
|
70 |
class="eu.etaxonomy.cdm.remote.controller.interceptor.LocaleContextHandlerInterceptor" />
|
|
71 |
<!--
|
|
72 |
=== no longer needed, replaced by ContentNegotiatingViewResolver ==
|
|
73 |
<bean id="contentNegociationHandlerInterceptor"
|
|
74 |
class="eu.etaxonomy.cdm.remote.controller.interceptor.ContentNegociationHandlerInterceptor">
|
|
75 |
<property name="mapping">
|
|
76 |
<map>
|
|
77 |
<entry key="text/json" value="json" />
|
|
78 |
<entry key="application/json" value="json" />
|
|
79 |
<entry key="application/xml" value="xml" />
|
|
80 |
</map>
|
|
81 |
</property>
|
|
82 |
<property name="defaultExtension" value="xml" />
|
|
83 |
</bean>
|
|
84 |
-->
|
|
85 |
|
|
86 |
<!--
|
|
87 |
======= ViewControllers =======
|
|
88 |
-->
|
|
89 |
<bean id="urlFilenameViewController" class="org.springframework.web.servlet.mvc.UrlFilenameViewController">
|
|
90 |
</bean>
|
|
91 |
<!--
|
|
92 |
The welcome-file-list in the web.xml will is ignored since the
|
|
93 |
cdmserver servlet is mapped to the root path [/] So the welcome file
|
|
94 |
list is being replaced by a SimpleUrlHandlerMapping on the root path
|
|
95 |
[/] which is mapped via this ViewController to the [index] view
|
|
96 |
-->
|
|
97 |
<bean id="welcomeFileViewController"
|
|
98 |
class="org.springframework.web.servlet.mvc.UrlFilenameViewController">
|
|
99 |
<property name="suffix">
|
|
100 |
<value>index</value>
|
|
101 |
</property>
|
|
102 |
</bean>
|
|
103 |
|
|
104 |
|
|
105 |
<!--
|
|
106 | 106 |
======= ViewResolver ======= |
107 | 107 |
--> |
108 |
|
|
108 |
|
|
109 | 109 |
<bean id="viewResolverJsp" |
110 | 110 |
class="org.springframework.web.servlet.view.InternalResourceViewResolver"> |
111 | 111 |
<property name="order" value="0" /> |
... | ... | |
121 | 121 |
</property> |
122 | 122 |
</bean> |
123 | 123 |
|
124 |
<bean id="oaiViewResolver" class="org.springframework.web.servlet.view.XmlViewResolver">
|
|
124 |
<bean id="oaiViewResolver" class="org.springframework.web.servlet.view.XmlViewResolver">
|
|
125 | 125 |
<property name="order" value="1"/> |
126 | 126 |
<property name="location" value="/WEB-INF/oai-views.xml"/> |
127 |
<!-- FOR DEBUGING ONLY !!!!
|
|
128 |
<property name="cache" value="false"/>
|
|
127 |
<!-- FOR DEBUGING ONLY !!!! |
|
128 |
<property name="cache" value="false"/> |
|
129 | 129 |
--> |
130 | 130 |
</bean> |
131 | 131 |
|
132 | 132 |
<bean id="contentNegotiatingViewResolver" class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> |
133 |
<property name="order" value="2" /> |
|
134 |
<property name="mediaTypes"> |
|
135 |
<map> |
|
136 |
<entry key="xml" value="application/xml" /> |
|
137 |
<entry key="dc" value="application/xml" /> |
|
138 |
<entry key="rdf" value="application/xml" /> |
|
139 |
<entry key="json" value="application/json" /> |
|
140 |
<entry key="json" value="application/json" /> |
|
141 |
</map> |
|
142 |
</property> |
|
143 |
<property name="viewResolvers"> |
|
144 |
<list> |
|
145 |
<bean id="xmlTypeViewResolver" class="eu.etaxonomy.cdm.remote.view.PatternViewResolver"> |
|
146 |
<property name="location" value="/WEB-INF/xml-views.xml"/> |
|
147 |
<!-- |
|
148 |
turn caching off FOR DEBUGING ONLY !!!! |
|
149 |
<property name="cache" value="false"/> |
|
150 |
--> |
|
151 |
</bean> |
|
152 |
<bean id="jsonTypeViewResolver" class="eu.etaxonomy.cdm.remote.view.PatternViewResolver"> |
|
153 |
<property name="location" value="/WEB-INF/json-views.xml"/> |
|
154 |
<!-- |
|
155 |
turn caching off FOR DEBUGING ONLY !!!! |
|
156 |
<property name="cache" value="false"/> |
|
157 |
--> |
|
158 |
</bean> |
|
159 |
</list> |
|
160 |
</property> |
|
161 |
</bean> |
|
162 |
|
|
163 |
<!-- |
|
164 |
======= Exception Handling ======= |
|
165 |
--> |
|
166 |
<bean id="exceptionResolver" class="eu.etaxonomy.cdm.remote.exception.CdmExceptionResolver"> |
|
167 |
</bean> |
|
168 |
|
|
169 |
<!-- |
|
170 |
======= Security ======= |
|
133 |
<property name="order" value="2" /> |
|
134 |
<property name="mediaTypes"> |
|
135 |
<map> |
|
136 |
<entry key="xml" value="application/xml" /> |
|
137 |
<entry key="dc" value="application/xml" /> |
|
138 |
<entry key="rdf" value="application/xml" /> |
|
139 |
<entry key="json" value="application/json" /> |
|
140 |
</map> |
|
141 |
</property> |
|
142 |
<property name="viewResolvers"> |
|
143 |
<list> |
|
144 |
<bean id="xmlTypeViewResolver" class="eu.etaxonomy.cdm.remote.view.PatternViewResolver"> |
|
145 |
<property name="location" value="/WEB-INF/xml-views.xml"/> |
|
146 |
<!-- |
|
147 |
turn caching off FOR DEBUGING ONLY !!!! |
|
148 |
<property name="cache" value="false"/> |
|
149 |
--> |
|
150 |
</bean> |
|
151 |
<bean id="jsonTypeViewResolver" class="eu.etaxonomy.cdm.remote.view.PatternViewResolver"> |
|
152 |
<property name="location" value="/WEB-INF/json-views.xml"/> |
|
153 |
<!-- |
|
154 |
turn caching off FOR DEBUGING ONLY !!!! |
|
155 |
<property name="cache" value="false"/> |
|
156 |
--> |
|
157 |
</bean> |
|
158 |
</list> |
|
159 |
</property> |
|
160 |
</bean> |
|
161 |
|
|
162 |
<!-- |
|
163 |
======= Exception Handling ======= |
|
164 |
--> |
|
165 |
<bean id="exceptionResolver" class="eu.etaxonomy.cdm.remote.exception.CdmExceptionResolver"> |
|
166 |
</bean> |
|
167 |
|
|
168 |
<!-- |
|
169 |
======= Security ======= |
|
171 | 170 |
--> |
172 | 171 |
<!-- <bean id="basicProcessingFilter" class="org.springframework.security.ui.basicauth.BasicProcessingFilter">--> |
173 | 172 |
<!-- <property name="authenticationManager"><ref bean="authenticationManager"/></property>--> |
... | ... | |
176 | 175 |
<!-- <bean id="authenticationEntryPoint" class="org.springframework.security.ui.basicauth.BasicProcessingFilterEntryPoint">--> |
177 | 176 |
<!-- <property name="realmName"><value>Name Of Your Realm</value></property>--> |
178 | 177 |
<!-- </bean>--> |
179 |
|
|
178 |
|
|
180 | 179 |
</beans> |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/BaseListController.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 2 |
/** |
3 | 3 |
* Copyright (C) 2007 EDIT |
4 |
* European Distributed Institute of Taxonomy
|
|
4 |
* European Distributed Institute of Taxonomy |
|
5 | 5 |
* http://www.e-taxonomy.eu |
6 |
*
|
|
6 |
* |
|
7 | 7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
8 | 8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
9 | 9 |
*/ |
... | ... | |
29 | 29 |
import eu.etaxonomy.cdm.api.service.IService; |
30 | 30 |
import eu.etaxonomy.cdm.api.service.pager.Pager; |
31 | 31 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
32 |
import eu.etaxonomy.cdm.remote.controller.util.PagerParameters; |
|
32 | 33 |
import eu.etaxonomy.cdm.remote.editor.CdmTypePropertyEditor; |
33 | 34 |
import eu.etaxonomy.cdm.remote.editor.UUIDPropertyEditor; |
34 | 35 |
|
... | ... | |
39 | 40 |
* |
40 | 41 |
* @param <T> |
41 | 42 |
* @param <SERVICE> |
42 |
*
|
|
43 |
* |
|
43 | 44 |
*/ |
44 | 45 |
public abstract class BaseListController <T extends CdmBase, SERVICE extends IService<T>> extends AbstractListController<T, SERVICE> { |
45 | 46 |
|
46 |
public static final Integer DEFAULT_PAGESIZE = 20;
|
|
47 |
public static final Integer DEFAULT_PAGE_NUMBER = 0;
|
|
48 |
|
|
49 |
@InitBinder
|
|
47 |
public static final Integer DEFAULT_PAGESIZE = 20;
|
|
48 |
public static final Integer DEFAULT_PAGE_NUMBER = 0;
|
|
49 |
|
|
50 |
@InitBinder
|
|
50 | 51 |
public void initBinder(WebDataBinder binder) { |
51 |
binder.registerCustomEditor(UUID.class, new UUIDPropertyEditor()); |
|
52 |
binder.registerCustomEditor(Class.class, new CdmTypePropertyEditor()); |
|
53 |
} |
|
54 |
|
|
55 |
|
|
56 |
/** |
|
57 |
* @param pageNumber |
|
58 |
* the number of the page to be returned, the first page has the |
|
59 |
* pageNumber = 1 - <i>optional parameter</i> |
|
60 |
* @param pageSize |
|
61 |
* the maximum number of entities returned per page (can be null |
|
62 |
* to return all entities in a single page) - <i>optional |
|
63 |
* parameter</i> |
|
64 |
* @param type |
|
65 |
* Further restricts the type of entities to be returned. |
|
66 |
* If null the base type <code><T></code> is being used. - <i>optional parameter</i> |
|
67 |
* @return |
|
68 |
* @throws IOException |
|
69 |
*/ |
|
70 |
@RequestMapping(method = RequestMethod.GET, params = "pageNumber") |
|
71 |
public Pager<T> doPage( |
|
72 |
@RequestParam(value = "pageNumber") Integer pageNumber, |
|
73 |
@RequestParam(value = "pageSize", required = false) Integer pageSize, |
|
74 |
@RequestParam(value = "class", required = false) Class<T> type, |
|
75 |
HttpServletRequest request, |
|
76 |
HttpServletResponse response) throws IOException |
|
77 |
{ |
|
78 |
|
|
79 |
normalizeAndValidatePagerParameters(pageNumber, pageSize, response); |
|
80 |
|
|
81 |
return service.page(type, pageSize, pageNumber, null, DEFAULT_INIT_STRATEGY); |
|
82 |
} |
|
83 |
|
|
84 |
/** |
|
85 |
* @param pageNumber |
|
86 |
* @param pageSize |
|
87 |
* @param response |
|
88 |
* @throws IOException |
|
89 |
*/ |
|
90 |
public static void normalizeAndValidatePagerParameters(Integer pageNumber, Integer pageSize, HttpServletResponse response) throws IOException{ |
|
91 |
|
|
92 |
if(pageNumber == null){ |
|
93 |
pageNumber = DEFAULT_PAGE_NUMBER; |
|
94 |
if(pageSize == null){ pageSize = DEFAULT_PAGESIZE;} |
|
95 |
} |
|
96 |
if(pageNumber < 0){ |
|
97 |
HttpStatusMessage.fromString("The query parameter 'pageNumber' must not be a negative number").setStatusCode(HTTP_BAD_REQUEST).send(response); |
|
98 |
} |
|
99 |
if(pageSize < 0){ |
|
100 |
HttpStatusMessage.fromString("The query parameter 'pageSize' must not be a negative number").setStatusCode(HTTP_BAD_REQUEST).send(response); |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
104 |
/** |
|
105 |
* Parameter less method to be used as default when request without parameter are made. Otherwise |
|
106 |
* the nameless methods {@link #doPage(Integer, Integer, Class)} and {@link #doList(Integer, Integer, Class)} |
|
107 |
* are ambigous. |
|
108 |
* @return |
|
109 |
* @throws IOException |
|
110 |
*/ |
|
111 |
@RequestMapping(method = RequestMethod.GET) |
|
112 |
public Pager<T> doPage(HttpServletRequest request, HttpServletResponse response) throws IOException{ |
|
113 |
return doPage(null, null, null, request, response); |
|
114 |
} |
|
115 |
|
|
116 |
/** |
|
117 |
* @param start |
|
118 |
* The offset index from the start of the list. The first entity |
|
119 |
* has the index = 0 - <i>required parameter</i> |
|
120 |
* @param limit |
|
121 |
* The maximum number of entities returned. - <i>optional parameter</i> |
|
122 |
* If limit is set to a value < 1 all entities will be returned |
|
123 |
* @param type |
|
124 |
* Further restricts the type of entities to be returned. |
|
125 |
* If null the base type <code><T></code> is being used. - <i>optional parameter</i> |
|
126 |
* @return a List of entities |
|
127 |
*/ |
|
128 |
@RequestMapping(method = RequestMethod.GET, params = "start") |
|
129 |
public List<T> doList( |
|
130 |
@RequestParam(value = "start", required = true) Integer start, |
|
131 |
@RequestParam(value = "limit", required = false) Integer limit, |
|
132 |
@RequestParam(value = "class", required = false) Class<T> type) { |
|
133 |
|
|
134 |
//if(start == null){ start = 0;} |
|
135 |
if(limit == null){ limit = DEFAULT_PAGESIZE;} |
|
136 |
if(limit < 1){ limit = null;} |
|
137 |
return service.list(type, limit, start, null, DEFAULT_INIT_STRATEGY); |
|
138 |
} |
|
139 |
|
|
140 |
/* TODO |
|
52 |
binder.registerCustomEditor(UUID.class, new UUIDPropertyEditor()); |
|
53 |
binder.registerCustomEditor(Class.class, new CdmTypePropertyEditor()); |
|
54 |
} |
|
55 |
|
|
56 |
|
|
57 |
/** |
|
58 |
* @param pageNumber |
|
59 |
* the number of the page to be returned, the first page has the |
|
60 |
* pageNumber = 1 - <i>optional parameter</i> |
|
61 |
* @param pageSize |
|
62 |
* the maximum number of entities returned per page (can be null |
|
63 |
* to return all entities in a single page) - <i>optional |
|
64 |
* parameter</i> |
|
65 |
* @param type |
|
66 |
* Further restricts the type of entities to be returned. |
|
67 |
* If null the base type <code><T></code> is being used. - <i>optional parameter</i> |
|
68 |
* @return |
|
69 |
* @throws IOException |
|
70 |
*/ |
|
71 |
@RequestMapping(method = RequestMethod.GET, params = "pageNumber") |
|
72 |
public Pager<T> doPage( |
|
73 |
@RequestParam(value = "pageNumber") Integer pageNumber, |
|
74 |
@RequestParam(value = "pageSize", required = false) Integer pageSize, |
|
75 |
@RequestParam(value = "class", required = false) Class<T> type, |
|
76 |
HttpServletRequest request, |
|
77 |
HttpServletResponse response) throws IOException |
|
78 |
{ |
|
79 |
|
|
80 |
PagerParameters pagerParameters = new PagerParameters(pageSize, pageNumber); |
|
81 |
pagerParameters.normalizeAndValidate(response); |
|
82 |
|
|
83 |
return service.page(type, pagerParameters.getPageSize(), pagerParameters.getPageNumber(), null, DEFAULT_INIT_STRATEGY); |
|
84 |
} |
|
85 |
|
|
86 |
/** |
|
87 |
* Parameter less method to be used as default when request without parameter are made. Otherwise |
|
88 |
* the nameless methods {@link #doPage(Integer, Integer, Class)} and {@link #doList(Integer, Integer, Class)} |
|
89 |
* are ambigous. |
|
90 |
* @return |
|
91 |
* @throws IOException |
|
92 |
*/ |
|
93 |
@RequestMapping(method = RequestMethod.GET) |
|
94 |
public Pager<T> doPage(HttpServletRequest request, HttpServletResponse response) throws IOException{ |
|
95 |
return doPage(null, null, null, request, response); |
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
99 |
* @param start |
|
100 |
* The offset index from the start of the list. The first entity |
|
101 |
* has the index = 0 - <i>required parameter</i> |
|
102 |
* @param limit |
|
103 |
* The maximum number of entities returned. - <i>optional parameter</i> |
|
104 |
* If limit is set to a value < 1 all entities will be returned |
|
105 |
* @param type |
|
106 |
* Further restricts the type of entities to be returned. |
|
107 |
* If null the base type <code><T></code> is being used. - <i>optional parameter</i> |
|
108 |
* @return a List of entities |
|
109 |
*/ |
|
110 |
@RequestMapping(method = RequestMethod.GET, params = "start") |
|
111 |
public List<T> doList( |
|
112 |
@RequestParam(value = "start", required = true) Integer start, |
|
113 |
@RequestParam(value = "limit", required = false) Integer limit, |
|
114 |
@RequestParam(value = "class", required = false) Class<T> type) { |
|
115 |
|
|
116 |
//if(start == null){ start = 0;} |
|
117 |
if(limit == null){ limit = DEFAULT_PAGESIZE;} |
|
118 |
if(limit < 1){ limit = null;} |
|
119 |
return service.list(type, limit, start, null, DEFAULT_INIT_STRATEGY); |
|
120 |
} |
|
121 |
|
|
122 |
/* TODO |
|
141 | 123 |
@RequestMapping(method = RequestMethod.POST) |
142 | 124 |
public T doPost(@ModelAttribute("object") T object, BindingResult result) { |
143 | 125 |
validator.validate(object, result); |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/PolytomousKeyListController.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 2 |
/** |
3 | 3 |
* Copyright (C) 2009 EDIT |
4 |
* European Distributed Institute of Taxonomy
|
|
4 |
* European Distributed Institute of Taxonomy |
|
5 | 5 |
* http://www.e-taxonomy.eu |
6 |
*
|
|
6 |
* |
|
7 | 7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
8 | 8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
9 | 9 |
*/ |
... | ... | |
30 | 30 |
import eu.etaxonomy.cdm.model.description.PolytomousKey; |
31 | 31 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
32 | 32 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
33 |
import eu.etaxonomy.cdm.remote.controller.util.PagerParameters; |
|
33 | 34 |
|
34 | 35 |
/** |
35 | 36 |
* @author a.kohlbecker |
... | ... | |
39 | 40 |
@Controller |
40 | 41 |
@RequestMapping(value = {"/polytomousKey"}) |
41 | 42 |
public class PolytomousKeyListController extends BaseListController<PolytomousKey, IPolytomousKeyService> { |
42 |
|
|
43 |
public static final Logger logger = Logger.getLogger(PolytomousKeyListController.class); |
|
44 |
|
|
45 |
private ITaxonService taxonService; |
|
46 |
|
|
47 |
@Autowired |
|
48 |
public void setService(IPolytomousKeyService service) { |
|
49 |
this.service = service; |
|
50 |
} |
|
51 |
|
|
52 |
@Autowired |
|
53 |
public void setService(ITaxonService taxonService) { |
|
54 |
this.taxonService = taxonService; |
|
55 |
} |
|
56 |
|
|
57 |
@RequestMapping( |
|
58 |
params = {"findByTaxonomicScope"}, |
|
59 |
method = RequestMethod.GET) |
|
60 |
public Pager<PolytomousKey> doFindByTaxonomicScope( |
|
61 |
@RequestParam(value = "findByTaxonomicScope") UUID taxonUuid, |
|
62 |
@RequestParam(value = "pageNumber", required = false) Integer pageNumber, |
|
63 |
@RequestParam(value = "pageSize", required = false) Integer pageSize, |
|
64 |
HttpServletRequest request, |
|
65 |
HttpServletResponse response)throws IOException { |
|
66 |
|
|
67 |
logger.info("doFindByTaxonomicScope: " + request.getRequestURI() + request.getQueryString()); |
|
68 |
|
|
69 |
normalizeAndValidatePagerParameters(pageNumber, pageSize, response); |
|
70 |
|
|
71 |
TaxonBase taxon = taxonService.find(taxonUuid); |
|
72 |
Pager<PolytomousKey> pager = service.findByTaxonomicScope(taxon, pageSize, pageNumber, null); |
|
73 |
return pager; |
|
74 |
} |
|
75 |
|
|
43 |
|
|
44 |
public static final Logger logger = Logger.getLogger(PolytomousKeyListController.class); |
|
45 |
|
|
46 |
private ITaxonService taxonService; |
|
47 |
|
|
48 |
@Autowired |
|
49 |
public void setService(IPolytomousKeyService service) { |
|
50 |
this.service = service; |
|
51 |
} |
|
52 |
|
|
53 |
@Autowired |
|
54 |
public void setService(ITaxonService taxonService) { |
|
55 |
this.taxonService = taxonService; |
|
56 |
} |
|
57 |
|
|
58 |
@RequestMapping( |
|
59 |
params = {"findByTaxonomicScope"}, |
|
60 |
method = RequestMethod.GET) |
|
61 |
public Pager<PolytomousKey> doFindByTaxonomicScope( |
|
62 |
@RequestParam(value = "findByTaxonomicScope") UUID taxonUuid, |
|
63 |
@RequestParam(value = "pageNumber", required = false) Integer pageNumber, |
|
64 |
@RequestParam(value = "pageSize", required = false) Integer pageSize, |
|
65 |
HttpServletRequest request, |
|
66 |
HttpServletResponse response)throws IOException { |
|
67 |
|
|
68 |
logger.info("doFindByTaxonomicScope: " + request.getRequestURI() + request.getQueryString()); |
|
69 |
|
|
70 |
PagerParameters pagerParameters = new PagerParameters(pageSize, pageNumber); |
|
71 |
pagerParameters.normalizeAndValidate(response); |
|
72 |
|
|
73 |
|
|
74 |
TaxonBase taxon = taxonService.find(taxonUuid); |
|
75 |
Pager<PolytomousKey> pager = service.findByTaxonomicScope(taxon, pagerParameters.getPageSize(), pagerParameters.getPageNumber(), null); |
|
76 |
return pager; |
|
77 |
} |
|
78 |
|
|
76 | 79 |
} |
77 |
|
|
80 |
|
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/TaxonPortalController.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
package eu.etaxonomy.cdm.remote.controller; |
12 | 12 |
|
13 |
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST; |
|
14 |
|
|
13 | 15 |
import java.io.IOException; |
14 | 16 |
import java.util.ArrayList; |
15 | 17 |
import java.util.Arrays; |
... | ... | |
65 | 67 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType; |
66 | 68 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
67 | 69 |
import eu.etaxonomy.cdm.persistence.query.MatchMode; |
70 |
import eu.etaxonomy.cdm.remote.controller.util.PagerParameters; |
|
68 | 71 |
import eu.etaxonomy.cdm.remote.editor.CdmTypePropertyEditor; |
69 | 72 |
import eu.etaxonomy.cdm.remote.editor.MatchModePropertyEditor; |
70 | 73 |
import eu.etaxonomy.cdm.remote.editor.NamedAreaPropertyEditor; |
... | ... | |
360 | 363 |
) |
361 | 364 |
throws IOException { |
362 | 365 |
|
363 |
logger.info("doFind : " + request.getRequestURI() + request.getQueryString() ); |
|
366 |
logger.info("doFind : " + request.getRequestURI() + "?" + request.getQueryString() );
|
|
364 | 367 |
|
365 |
BaseListController.normalizeAndValidatePagerParameters(pageNumber, pageSize, response); |
|
368 |
PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber); |
|
369 |
pagerParams.normalizeAndValidate(response); |
|
366 | 370 |
|
367 | 371 |
ITaxonServiceConfigurator config = new TaxonServiceConfiguratorImpl(); |
368 |
config.setPageNumber(pageNumber);
|
|
369 |
config.setPageSize(pageSize);
|
|
372 |
config.setPageNumber(pagerParams.getPageNumber());
|
|
373 |
config.setPageSize(pagerParams.getPageSize());
|
|
370 | 374 |
config.setTitleSearchString(query); |
371 | 375 |
config.setDoTaxa(doTaxa!= null ? doTaxa : Boolean.FALSE ); |
372 | 376 |
config.setDoSynonyms(doSynonyms != null ? doSynonyms : Boolean.FALSE ); |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/util/PagerParameters.java | ||
---|---|---|
1 |
// $Id: TaxonController.java 5473 2009-03-25 13:42:07Z a.kohlbecker $ |
|
2 |
/** |
|
3 |
* Copyright (C) 2011 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 |
|
|
11 |
package eu.etaxonomy.cdm.remote.controller.util; |
|
12 |
|
|
13 |
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST; |
|
14 |
|
|
15 |
import java.io.IOException; |
|
16 |
|
|
17 |
import javax.servlet.http.HttpServletResponse; |
|
18 |
|
|
19 |
import eu.etaxonomy.cdm.remote.controller.HttpStatusMessage; |
|
20 |
|
|
21 |
/** |
|
22 |
* @author a.kohlbecker |
|
23 |
* @date 22.08.2011 |
|
24 |
* |
|
25 |
*/ |
|
26 |
public class PagerParameters { |
|
27 |
|
|
28 |
private Integer pageSize; |
|
29 |
|
|
30 |
private Integer pageNumber; |
|
31 |
|
|
32 |
public void setPageSize(Integer pageSize) { |
|
33 |
this.pageSize = pageSize; |
|
34 |
} |
|
35 |
|
|
36 |
public Integer getPageSize() { |
|
37 |
return pageSize; |
|
38 |
} |
|
39 |
|
|
40 |
public void setPageNumber(Integer pageNumber) { |
|
41 |
this.pageNumber = pageNumber; |
|
42 |
} |
|
43 |
|
|
44 |
public Integer getPageNumber() { |
|
45 |
return pageNumber; |
|
46 |
} |
|
47 |
|
|
48 |
public PagerParameters(Integer pageSize, Integer pageNumber) { |
|
49 |
this.pageSize = pageSize; |
|
50 |
this.pageNumber = pageNumber; |
|
51 |
} |
|
52 |
|
|
53 |
public void normalizeAndValidate(HttpServletResponse response) throws IOException{ |
|
54 |
|
|
55 |
if(pageNumber == null){ |
|
56 |
pageNumber = 0; |
|
57 |
} |
|
58 |
if(pageSize == null){ |
|
59 |
pageSize = 0; |
|
60 |
} |
|
61 |
if(pageNumber < 0){ |
|
62 |
HttpStatusMessage.fromString("The query parameter 'pageNumber' must not be a negative number").setStatusCode(HTTP_BAD_REQUEST).send(response); |
|
63 |
} |
|
64 |
if(pageSize < 0){ |
|
65 |
HttpStatusMessage.fromString("The query parameter 'pageSize' must not be a negative number").setStatusCode(HTTP_BAD_REQUEST).send(response); |
|
66 |
} |
|
67 |
} |
|
68 |
|
|
69 |
|
|
70 |
} |
Also available in: Unified diff
fixing #2565 (DataPortal CacheBot is broken)