Project

General

Profile

Download (14.6 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.query.MatchMode;
31
import eu.etaxonomy.cdm.persistence.query.OrderHint;
32
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
33
import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
34
import eu.etaxonomy.cdm.strategy.match.IMatchable;
35
import eu.etaxonomy.cdm.strategy.merge.IMergable;
36
import eu.etaxonomy.cdm.strategy.merge.IMergeStrategy;
37

    
38
public interface IIdentifiableEntityService<T extends IdentifiableEntity>
39
            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
    /**
104
     * Returns the titleCache for a given object defined by uuid.
105
     * @param uuid the uuid of the requested object.
106
     * @param refresh if false the value as stored in the DB is returned,
107
     *      otherwise it is recomputed by loading the object and calling the formatter.
108
     * @return the titleCache of the requested object
109
     */
110
    public String getTitleCache(UUID uuid, boolean refresh);
111

    
112

    
113

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

    
132

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

    
141

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

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

    
163

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

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

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

    
217

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

    
234

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

    
247

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

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

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