Project

General

Profile

Download (15 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 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.api.service;
12

    
13
import java.util.List;
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> extends IAnnotatableService<T> {
40

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

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

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

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

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

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

    
102
//    /**
103
//     * Return a list of all uuids mapped to titleCache in the convenient <code>UuidAndTitleCache</code> object.
104
//     * @see #getUuidAndTitleCache(Integer, String)
105
//     */
106
//    public List<UuidAndTitleCache<T>> getUuidAndTitleCache();
107

    
108
    /**
109
     * Return a list of all uuids mapped to titleCache in the convenient <code>UuidAndTitleCache</code> object.
110
     * Retrieving this list is considered to be significantly faster than initializing the fully fledged business
111
     * objects. To be used in cases where you want to present large amount of data and provide details after
112
     * a selection has been made.
113
     *
114
     * @return a list of <code>UuidAndTitleCache</code> instances
115
     */
116
    public List<UuidAndTitleCache<T>> getUuidAndTitleCache(Integer limit, String pattern);
117

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

    
136

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

    
145

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

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

    
167

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

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

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

    
221

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

    
238

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

    
251

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

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

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