Project

General

Profile

Download (16.1 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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

    
10
package eu.etaxonomy.cdm.api.service;
11

    
12
import java.util.List;
13
import java.util.UUID;
14

    
15
import org.hibernate.criterion.Criterion;
16

    
17
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
18
import eu.etaxonomy.cdm.api.service.dto.IdentifiedEntityDTO;
19
import eu.etaxonomy.cdm.api.service.dto.MarkedEntityDTO;
20
import eu.etaxonomy.cdm.api.service.pager.Pager;
21
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
22
import eu.etaxonomy.cdm.model.common.DefinedTerm;
23
import eu.etaxonomy.cdm.model.common.ISourceable;
24
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
25
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
26
import eu.etaxonomy.cdm.model.common.LSID;
27
import eu.etaxonomy.cdm.model.common.MarkerType;
28
import eu.etaxonomy.cdm.model.media.Rights;
29
import eu.etaxonomy.cdm.persistence.dao.initializer.IBeanInitializer;
30
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
31
import eu.etaxonomy.cdm.persistence.query.MatchMode;
32
import eu.etaxonomy.cdm.persistence.query.OrderHint;
33
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
34
import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
35
import eu.etaxonomy.cdm.strategy.match.IMatchable;
36
import eu.etaxonomy.cdm.strategy.merge.IMergable;
37
import eu.etaxonomy.cdm.strategy.merge.IMergeStrategy;
38

    
39
public interface IIdentifiableEntityService<T extends IdentifiableEntity>
40
            extends IAnnotatableService<T> {
41

    
42
    /**
43
     * (Re-)generate the title caches for all objects of this concrete IdentifiableEntity class.
44
     * Uses default values.
45
     * @see #updateTitleCache(Class, Integer, IIdentifiableEntityCacheStrategy, IProgressMonitor)
46
     */
47
    public void updateTitleCache();
48

    
49
    /**
50
     * (Re-)generate the title caches for all objects of this concrete IdentifiableEntity class
51
     *
52
     * @param clazz class of objects to be updated
53
     * @param stepSize number of objects loaded per step. If <code>null</code> use default.
54
     * @param cacheStrategy cachestrategy used for title cache. If <code>null</code> use default.
55
     * @param monitor progress monitor. If <code>null</code> use default.
56
     */
57
    public void updateTitleCache(Class<? extends T> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<T> cacheStrategy, IProgressMonitor monitor);
58

    
59
    /**
60
     * Finds an object with a given LSID. If the object does not currently exist in the current view, then
61
     * the most recent prior version of the object will be returned, or null if an object with this identifier
62
     * has never existed
63
     *
64
     * @param lsid
65
     * @return an object of type T or null of the object has never existed
66
     */
67
    public T find(LSID lsid);
68

    
69
    /**
70
     * Replaces all *ToMany and *ToOne references to an object (x) with another object of the same type (y)
71
     *
72
     * Ignores ManyToAny and OneToAny relationships as these are typically involved with bidirectional
73
     * parent-child relations
74
     *
75
     * @param x
76
     * @param y
77
     * @return the replacing object (y)
78
     */
79
    public T replace(T x, T y);
80

    
81
    /**
82
     * Return a Pager of sources belonging to this object
83
     *
84
     * @param t The identifiable entity
85
     * @param pageSize The maximum number of sources returned (can be null for all sources)
86
     * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
87
     * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
88
     * @return a Pager of OriginalSource entities
89
     */
90
    public Pager<IdentifiableSource> getSources(T t, Integer pageSize, Integer pageNumber, List<String> propertyPaths);
91

    
92
    /**
93
     * Return a Pager of rights belonging to this object
94
     *
95
     * @param t The identifiable entity
96
     * @param pageSize The maximum number of rights returned (can be null for all rights)
97
     * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
98
     * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
99
     * @return a Pager of Rights entities
100
     */
101
    public Pager<Rights> getRights(T t, Integer pageSize, Integer pageNumber, List<String> propertyPaths);
102

    
103

    
104
    /**
105
     * Returns the titleCache for a given object defined by uuid.
106
     * @param uuid the uuid of the requested object.
107
     * @param refresh if false the value as stored in the DB is returned,
108
     *      otherwise it is recomputed by loading the object and calling the formatter.
109
     * @return the titleCache of the requested object
110
     */
111
    public String getTitleCache(UUID uuid, boolean refresh);
112

    
113

    
114

    
115
    /**
116
     * Return a Pager of objects matching the given query string, optionally filtered by class, optionally with a particular MatchMode
117
     *
118
     * @param clazz filter by class - can be null to include all instances of type T
119
     * @param queryString the query string to filter by
120
     * @param matchmode use a particular type of matching (can be null - defaults to exact matching)
121
     * @param criteria additional criteria to filter by
122
     * @param pageSize The maximum number of objects returned (can be null for all objects)
123
     * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
124
     * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
125
     * @param orderHints
126
     *            Supports path like <code>orderHints.propertyNames</code> which
127
     *            include *-to-one properties like createdBy.username or
128
     *            authorTeam.persistentTitleCache
129
     * @return a paged list of instances of type T matching the queryString
130
     */
131
    public Pager<T> findByTitle(Class<? extends T> clazz, String queryString,MatchMode matchmode, List<Criterion> criteria, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
132

    
133

    
134
    /**
135
     * Return a Pager of objects matching the given query string, optionally filtered by class,
136
     * optionally with a particular MatchMode
137
     *
138
     * @return a paged list of instances of type T matching the queryString
139
     */
140
    public Pager<T> findByTitle(IIdentifiableEntityServiceConfigurator<T> configurator);
141

    
142

    
143
    /**
144
     * Return an Integer of how many objects matching the given query string, optionally filtered by class, optionally with a particular MatchMode
145
     *
146
     * @param clazz filter by class - can be null to include all instances of type T
147
     * @param queryString the query string to filter by
148
     * @param matchmode use a particular type of matching (can be null - defaults to exact matching)
149
     * @param criteria additional criteria to filter by
150
     *
151
     * @return
152
     */
153
    public Integer countByTitle(Class<? extends T> clazz, String queryString,MatchMode matchmode, List<Criterion> criteria);
154

    
155
    /**
156
     * Return an Integer of how many objects matching the given query string, optionally filtered by class, optionally with a particular MatchMode
157
     *
158
     * @param configurator an {@link IIdentifiableEntityServiceConfigurator} object
159
     *
160
     * @return
161
     */
162
    public Integer countByTitle(IIdentifiableEntityServiceConfigurator<T> configurator);
163

    
164

    
165
    /**
166
     * Return a List of objects matching the given query string, optionally filtered by class, optionally with a particular MatchMode
167
     *
168
     * @param clazz filter by class - can be null to include all instances of type T
169
     * @param queryString the query string to filter by
170
     * @param matchmode use a particular type of matching (can be null - defaults to exact matching)
171
     * @param criteria additional criteria to filter by
172
     * @param pageSize The maximum number of objects returned (can be null for all objects)
173
     * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
174
     * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
175
     * @param orderHints
176
     *            Supports path like <code>orderHints.propertyNames</code> which
177
     *            include *-to-one properties like createdBy.username or
178
     *            authorTeam.persistentTitleCache
179
     * @return a list of instances of type T matching the queryString
180
     */
181
    public List<T> listByTitle(Class<? extends T> clazz, String queryString,MatchMode matchmode, List<Criterion> criteria, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
182

    
183
    /**
184
     * Return a List of objects matching the given query string, optionally filtered by class, optionally with a particular MatchMode
185
     *
186
     * @param clazz filter by class - can be null to include all instances of type T
187
     * @param queryString the query string to filter by
188
     * @param matchmode use a particular type of matching (can be null - defaults to exact matching)
189
     * @param criteria additional criteria to filter by
190
     * @param pageSize The maximum number of objects returned (can be null for all objects)
191
     * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
192
     * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
193
     * @param orderHints
194
     *            Supports path like <code>orderHints.propertyNames</code> which
195
     *            include *-to-one properties like createdBy.username or
196
     *            authorTeam.persistentTitleCache
197
     * @return a list of instances of type T matching the queryString
198
     */
199
    public List<T> listByReferenceTitle(Class<? extends T> clazz, String queryString,MatchMode matchmode, List<Criterion> criteria, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
200

    
201
    /**
202
     * Returns a Paged List of IdentifiableEntity instances where the default field matches the String queryString (as interpreted by the Lucene QueryParser)
203
     *
204
     * @param clazz filter the results by class (or pass null to return all IdentifiableEntity instances)
205
     * @param queryString
206
     * @param pageSize The maximum number of identifiable entities returned (can be null for all matching identifiable entities)
207
     * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
208
     * @param orderHints
209
     *            Supports path like <code>orderHints.propertyNames</code> which
210
     *            include *-to-one properties like createdBy.username or
211
     *            authorTeam.persistentTitleCache
212
     * @param propertyPaths properties to be initialized
213
     * @return a Pager IdentifiableEntity instances
214
     * @see <a href="http://lucene.apache.org/java/2_4_0/queryparsersyntax.html">Apache Lucene - Query Parser Syntax</a>
215
     */
216
    public Pager<T> search(Class<? extends T> clazz, String queryString, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
217

    
218

    
219
    /**
220
     * This method tries to deduplicate all objects of a certain class by first trying to find matchabel objects and
221
     * merging them in a second step. For performance reasons implementing classes must not guarantee that ALL
222
     * matching object pairs are found but only a subset. But it must guarantee that only matching objects are merged.
223
     *<BR> Matching is defined by the given matching strategy or if no matching strategy is given the default matching
224
     *strategy is used.
225
     *<BR>clazz must implement {@link IMatchable} and {@link IMergable} otherwise no deduplication is performed.
226
     *<BR>The current implementation in IdentifiableServiceBase tries to match and merge all objects with an identical non
227
     *empty titleCache.
228
     * @param clazz
229
     * @param matchStrategy
230
     * @param mergeStrategy
231
     * @return the number of merges performed during deduplication
232
     */
233
    public int deduplicate(Class<? extends T> clazz, IMatchStrategy matchStrategy, IMergeStrategy mergeStrategy);
234

    
235

    
236
    /**
237
     * Return a Pager of objects with distinct titleCache strings filtered by the given query string, optionally filtered by class, optionally with a particular MatchMode
238
     * @param clazz
239
     * @param queryString
240
     * @param pageSize
241
     * @param pageNumber
242
     * @param orderHints
243
     * @param matchMode
244
     * @return
245
     */
246
    public Pager<T> findTitleCache(Class<? extends T> clazz, String queryString, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, MatchMode matchMode);
247

    
248

    
249
    /**
250
     * Returns an Sourceable object according the
251
     * @param clazz
252
     * @param idInSource
253
     * @param idNamespace
254
     * @return
255
     */
256
    //TODO shouldn't we move this to CommonService or to a new SourceService ?
257
    //TODO should this return a List ?
258
    public ISourceable getSourcedObjectByIdInSource(Class clazz, String idInSource, String idNamespace);
259

    
260
    /**
261
     * Returns a Pager for {@link IdentifiedEntityDTO DTOs} that hold the identifier including type, title and uuid
262
     * and the according CDM Object information (uuid, title and the object itself (optional)).
263
     *
264
     * @param clazz the identifiable entity subclass, may be null
265
     * @param identifier the identifier as {@link String}
266
     * @param identifierType the identifier type, maybe null
267
     * @param matchmode
268
     * @param includeCdmEntity if true the CDM entity is also returned (this may slow down performance for large datasets)
269
     * @param pageSize
270
     * @param pageNumber
271
     * @param propertyPaths
272
     * @return all {@link IdentifiableEntity identifiable entities} which have the according
273
     * identifier attached
274
     */
275
    public <S extends T> Pager<IdentifiedEntityDTO<S>> findByIdentifier(
276
            Class<S> clazz, String identifier, DefinedTerm identifierType,
277
            MatchMode matchmode, boolean includeCdmEntity,
278
            Integer pageSize, Integer pageNumber, List<String> propertyPaths);
279

    
280
    /**
281
     * Returns a Pager for {@link MarkedEntityDTO DTOs} that hold the marker including type, title and uuid
282
     * and the according CDM object information (uuid, title and the object itself (optional)).
283
     *
284
     * @param clazz
285
     * @param markerType
286
     * @param markerValue
287
     * @param includeEntity
288
     * @param pageSize
289
     * @param pageNumber
290
     * @param propertyPaths
291
     * @return all {@link IdentifiableEntity identifiable entities} which have the according
292
     * marker with the given flag value attached
293
     */
294
    public <S extends T> Pager<MarkedEntityDTO<S>> findByMarker(
295
            Class<S> clazz, MarkerType markerType, Boolean markerValue,
296
            boolean includeEntity, Integer pageSize,
297
            Integer pageNumber, List<String> propertyPaths);
298

    
299
    /**
300
     * @param <S>
301
     * @param clazz
302
     * @param identifier
303
     * @param identifierType
304
     * @param matchmode
305
     * @param includeEntity
306
     * @param propertyPaths
307
     * @return
308
     */
309
    public <S extends T>List<IdentifiedEntityDTO<S >> listByIdentifier(Class<S> clazz, String identifier, DefinedTerm identifierType,
310
            MatchMode matchmode, boolean includeEntity, List<String> propertyPaths, Integer limit);
311

    
312
    /**
313
     * Like {@link #getUuidAndTitleCache(Integer, String)} but searching only on a subclass
314
     * of the type handled by the DAO.
315
     *
316
     * @param clazz the (sub)class
317
     * @param limit max number of results
318
     * @param pattern search pattern
319

    
320
     * @see #getUuidAndTitleCache(Integer, String)
321
     */
322
    public <S extends T> List<UuidAndTitleCache<S>> getUuidAndTitleCache(Class<S> clazz, Integer limit, String pattern);
323

    
324
    /**
325
     * Return a list of all uuids mapped to titleCache in the convenient <code>UuidAndTitleCache</code> object.
326
     * Retrieving this list is considered to be significantly faster than initializing the fully fledged business
327
     * objects. To be used in cases where you want to present large amount of data and provide details after
328
     * a selection has been made.
329
     *
330
     * @return a list of <code>UuidAndTitleCache</code> instances
331
     *
332
     * @see #getUuidAndTitleCache(Class, Integer, String)
333
     */
334
    public List<UuidAndTitleCache<T>> getUuidAndTitleCache(Integer limit, String pattern);
335
}
(42-42/105)