1
|
/**
|
2
|
* Copyright (C) 2017 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.service;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Arrays;
|
13
|
import java.util.List;
|
14
|
|
15
|
import org.hibernate.criterion.Criterion;
|
16
|
import org.vaadin.viritin.fields.LazyComboBox.FilterableCountProvider;
|
17
|
import org.vaadin.viritin.fields.LazyComboBox.FilterablePagingProvider;
|
18
|
|
19
|
import eu.etaxonomy.cdm.api.service.IIdentifiableEntityService;
|
20
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
21
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
22
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
23
|
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
24
|
|
25
|
/**
|
26
|
* @author a.kohlbecker
|
27
|
* @since Jun 7, 2017
|
28
|
*
|
29
|
*/
|
30
|
public class CdmFilterablePagingProvider<T extends IdentifiableEntity, V extends T> implements FilterablePagingProvider<V>, FilterableCountProvider {
|
31
|
|
32
|
/**
|
33
|
*
|
34
|
*/
|
35
|
private static final List<String> DEFAULT_INIT_STRATEGY = Arrays.asList("$");
|
36
|
|
37
|
private int pageSize = 20;
|
38
|
|
39
|
private IIdentifiableEntityService<T> service;
|
40
|
|
41
|
private Class<V> type = null;
|
42
|
|
43
|
private MatchMode matchMode = MatchMode.ANYWHERE;
|
44
|
|
45
|
private List<OrderHint> orderHints = OrderHint.ORDER_BY_TITLE_CACHE.asList();
|
46
|
|
47
|
List<String> initStrategy = DEFAULT_INIT_STRATEGY;
|
48
|
|
49
|
private List<Criterion> criteria = new ArrayList<>();
|
50
|
|
51
|
|
52
|
/**
|
53
|
* @return the matchMode
|
54
|
*/
|
55
|
protected MatchMode getMatchMode() {
|
56
|
return matchMode;
|
57
|
}
|
58
|
|
59
|
/**
|
60
|
* @param matchMode the matchMode to set
|
61
|
*/
|
62
|
protected void setMatchMode(MatchMode matchMode) {
|
63
|
this.matchMode = matchMode;
|
64
|
}
|
65
|
|
66
|
/**
|
67
|
* @return the orderHints
|
68
|
*/
|
69
|
protected List<OrderHint> getOrderHints() {
|
70
|
return orderHints;
|
71
|
}
|
72
|
|
73
|
/**
|
74
|
* @param orderHints the orderHints to set
|
75
|
*/
|
76
|
protected void setOrderHints(List<OrderHint> orderHints) {
|
77
|
this.orderHints = orderHints;
|
78
|
}
|
79
|
|
80
|
/**
|
81
|
* With defaults for matchMode = MatchMode.ANYWHERE and orderHints = OrderHint.ORDER_BY_TITLE_CACHE
|
82
|
*
|
83
|
*/
|
84
|
public CdmFilterablePagingProvider(IIdentifiableEntityService<T> service) {
|
85
|
this(service, null);
|
86
|
}
|
87
|
|
88
|
/**
|
89
|
* With defaults for matchMode = MatchMode.ANYWHERE and orderHints = OrderHint.ORDER_BY_TITLE_CACHE
|
90
|
*
|
91
|
*/
|
92
|
public CdmFilterablePagingProvider(IIdentifiableEntityService<T> service, Class<V> type) {
|
93
|
super();
|
94
|
this.type = type;
|
95
|
this.service = service;
|
96
|
}
|
97
|
|
98
|
|
99
|
public CdmFilterablePagingProvider(IIdentifiableEntityService<T> service, MatchMode matchMode, List<OrderHint> orderHints) {
|
100
|
this(service, null, matchMode, orderHints);
|
101
|
}
|
102
|
|
103
|
public <S extends T> CdmFilterablePagingProvider(IIdentifiableEntityService<T> service, Class<V> type, MatchMode matchMode, List<OrderHint> orderHints) {
|
104
|
super();
|
105
|
this.type = type;
|
106
|
this.service = service;
|
107
|
this.matchMode = matchMode;
|
108
|
this.orderHints = orderHints;
|
109
|
}
|
110
|
|
111
|
/**
|
112
|
* {@inheritDoc}
|
113
|
*/
|
114
|
@Override
|
115
|
public List<V> findEntities(int firstRow, String filter) {
|
116
|
|
117
|
Pager<V> page = (Pager<V>) service.findByTitle(
|
118
|
type,
|
119
|
filter,
|
120
|
matchMode,
|
121
|
criteria,
|
122
|
pageSize,
|
123
|
firstRow,
|
124
|
orderHints,
|
125
|
initStrategy
|
126
|
);
|
127
|
return page.getRecords();
|
128
|
}
|
129
|
|
130
|
/**
|
131
|
* {@inheritDoc}
|
132
|
*/
|
133
|
@Override
|
134
|
public int size(String filter) {
|
135
|
|
136
|
Pager<V> page = (Pager<V>) service.findByTitle(
|
137
|
type,
|
138
|
filter,
|
139
|
matchMode,
|
140
|
criteria,
|
141
|
1,
|
142
|
0,
|
143
|
null,
|
144
|
null
|
145
|
);
|
146
|
return page.getCount().intValue();
|
147
|
}
|
148
|
|
149
|
/**
|
150
|
* @return the pageSize
|
151
|
*/
|
152
|
public int getPageSize() {
|
153
|
return pageSize;
|
154
|
}
|
155
|
|
156
|
/**
|
157
|
* @param pageSize the pageSize to set
|
158
|
*/
|
159
|
public void setPageSize(int pageSize) {
|
160
|
this.pageSize = pageSize;
|
161
|
}
|
162
|
|
163
|
/**
|
164
|
* @return the initStrategy
|
165
|
*/
|
166
|
public List<String> getInitStrategy() {
|
167
|
return initStrategy;
|
168
|
}
|
169
|
|
170
|
/**
|
171
|
* @param initStrategy the initStrategy to set
|
172
|
*/
|
173
|
public void setInitStrategy(List<String> initStrategy) {
|
174
|
this.initStrategy = initStrategy;
|
175
|
}
|
176
|
|
177
|
/**
|
178
|
* The list of criteria is initially empty.
|
179
|
*
|
180
|
* @return the criteria
|
181
|
*/
|
182
|
public List<Criterion> getCriteria() {
|
183
|
return criteria;
|
184
|
}
|
185
|
}
|