2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.api
.service
;
12 import java
.util
.List
;
13 import java
.util
.UUID
;
15 import org
.hibernate
.criterion
.Criterion
;
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
.IdentifiableEntity
;
23 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
24 import eu
.etaxonomy
.cdm
.model
.common
.LSID
;
25 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
26 import eu
.etaxonomy
.cdm
.model
.media
.Rights
;
27 import eu
.etaxonomy
.cdm
.model
.reference
.ISourceable
;
28 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTerm
;
29 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.Restriction
;
30 import eu
.etaxonomy
.cdm
.persistence
.dao
.initializer
.IBeanInitializer
;
31 import eu
.etaxonomy
.cdm
.persistence
.dto
.UuidAndTitleCache
;
32 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
33 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
34 import eu
.etaxonomy
.cdm
.strategy
.cache
.common
.IIdentifiableEntityCacheStrategy
;
35 import eu
.etaxonomy
.cdm
.strategy
.match
.IMatchStrategyEqual
;
36 import eu
.etaxonomy
.cdm
.strategy
.match
.IMatchable
;
37 import eu
.etaxonomy
.cdm
.strategy
.merge
.IMergable
;
38 import eu
.etaxonomy
.cdm
.strategy
.merge
.IMergeStrategy
;
40 public interface IIdentifiableEntityService
<T
extends IdentifiableEntity
>
41 extends IAnnotatableService
<T
> {
44 * (Re-)generate the caches (e.g. title cache) for all objects of this concrete IdentifiableEntity class.
45 * Uses default values.
46 * @see #updateCaches(Class, Integer, IIdentifiableEntityCacheStrategy, IProgressMonitor)
48 public UpdateResult
updateCaches();
51 * (Re-)generate the caches for all objects of this concrete IdentifiableEntity class
53 * @param clazz class of objects to be updated
54 * @param stepSize number of objects loaded per step. If <code>null</code> use default.
55 * @param cacheStrategy cache strategy used for cache generation. If <code>null</code> use default.
56 * @param monitor progress monitor. If <code>null</code> use default.
58 public UpdateResult
updateCaches(Class
<?
extends T
> clazz
, Integer stepSize
, IIdentifiableEntityCacheStrategy
<T
> cacheStrategy
, IProgressMonitor monitor
);
61 * Finds an object with a given LSID. If the object does not currently exist in the current view, then
62 * the most recent prior version of the object will be returned, or null if an object with this identifier
66 * @return an object of type T or null of the object has never existed
68 public T
find(LSID lsid
);
71 * Replaces all *ToMany and *ToOne references to an object (x) with another object of the same type (y)
73 * Ignores ManyToAny and OneToAny relationships as these are typically involved with bidirectional
74 * parent-child relations
78 * @return the replacing object (y)
80 public T
replace(T x
, T y
);
83 * Return a Pager of sources belonging to this object
85 * @param t The identifiable entity
86 * @param pageSize The maximum number of sources returned (can be null for all sources)
87 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
88 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
89 * @return a Pager of OriginalSource entities
91 public Pager
<IdentifiableSource
> getSources(T t
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
);
94 * Return a Pager of rights belonging to this object
96 * @param t The identifiable entity
97 * @param pageSize The maximum number of rights returned (can be null for all rights)
98 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
99 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
100 * @return a Pager of Rights entities
102 public Pager
<Rights
> getRights(T t
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
);
106 * Returns the titleCache for a given object defined by uuid.
107 * @param uuid the uuid of the requested object.
108 * @param refresh if false the value as stored in the DB is returned,
109 * otherwise it is recomputed by loading the object and calling the formatter.
110 * @return the titleCache of the requested object
112 public String
getTitleCache(UUID uuid
, boolean refresh
);
115 * Return a Pager of objects matching the given query string, optionally filtered by class, optionally with a particular MatchMode
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)}
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
130 public <S
extends T
> Pager
<S
> findByTitle(Class
<S
> clazz
, String queryString
, MatchMode matchmode
, List
<Criterion
> criteria
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
134 * Return a Pager of objects matching the given query string, optionally filtered by class, optionally with a particular MatchMode
136 * @param clazz filter by class - can be null to include all instances of type T
137 * @param queryString the query string to filter by
138 * @param matchmode use a particular type of matching (can be null - defaults to exact matching)
139 * @param restrictions a <code>List</code> of additional {@link Restriction}s to filter by
140 * @param pageSize The maximum number of objects returned (can be null for all objects)
141 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
142 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
144 * Supports path like <code>orderHints.propertyNames</code> which
145 * include *-to-one properties like createdBy.username or
146 * authorTeam.persistentTitleCache
147 * @return a paged list of instances of type T matching the queryString
149 public <S
extends T
> Pager
<S
> findByTitleWithRestrictions(Class
<S
> clazz
, String queryString
,MatchMode matchmode
, List
<Restriction
<?
>> restrictions
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
153 * Return a Pager of objects matching the given query string, optionally filtered by class,
154 * optionally with a particular MatchMode
156 * @return a paged list of instances of type T matching the queryString
158 public <S
extends T
> Pager
<S
> findByTitle(IIdentifiableEntityServiceConfigurator
<S
> configurator
);
161 * Return an Integer of how many objects matching the given query string, optionally filtered by class, optionally with a particular MatchMode
163 * @param clazz filter by class - can be null to include all instances of type T
164 * @param queryString the query string to filter by
165 * @param matchmode use a particular type of matching (can be null - defaults to exact matching)
166 * @param criteria additional criteria to filter by
170 public long countByTitle(Class
<?
extends T
> clazz
, String queryString
,MatchMode matchmode
, List
<Criterion
> criteria
);
173 * Return an Integer of how many objects matching the given query string, optionally filtered by class, optionally with a particular MatchMode
175 * @param clazz filter by class - can be null to include all instances of type T
176 * @param queryString the query string to filter by
177 * @param matchmode use a particular type of matching (can be null - defaults to exact matching)
178 * @param restrictions a <code>List</code> of additional {@link Restriction}s to filter by
182 public long countByTitleWithRestrictions(Class
<?
extends T
> clazz
, String queryString
, MatchMode matchmode
, List
<Restriction
<?
>> restrictions
);
185 * Return an Integer of how many objects matching the given query string, optionally filtered by class, optionally with a particular MatchMode
187 * @param configurator an {@link IIdentifiableEntityServiceConfigurator} object
191 public long countByTitle(IIdentifiableEntityServiceConfigurator
<T
> configurator
);
194 * Return a List of objects matching the given query string, optionally filtered by class, optionally with a particular MatchMode
196 * @param clazz filter by class - can be null to include all instances of type T
197 * @param queryString the query string to filter by
198 * @param matchmode use a particular type of matching (can be null - defaults to exact matching)
199 * @param criteria additional criteria to filter by
200 * @param pageSize The maximum number of objects returned (can be null for all objects)
201 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
202 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
204 * Supports path like <code>orderHints.propertyNames</code> which
205 * include *-to-one properties like createdBy.username or
206 * authorTeam.persistentTitleCache
207 * @return a list of instances of type T matching the queryString
209 public <S
extends T
> List
<S
> listByTitle(Class
<S
> clazz
, String queryString
,MatchMode matchmode
, List
<Criterion
> criteria
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
212 * Return a List of objects matching the given query string, optionally filtered by class, optionally with a particular MatchMode
214 * @param clazz filter by class - can be null to include all instances of type T
215 * @param queryString the query string to filter by
216 * @param matchmode use a particular type of matching (can be null - defaults to exact matching)
217 * @param restrictions a <code>List</code> of additional {@link Restriction}s to filter by
218 * @param pageSize The maximum number of objects returned (can be null for all objects)
219 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
220 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
222 * Supports path like <code>orderHints.propertyNames</code> which
223 * include *-to-one properties like createdBy.username or
224 * authorTeam.persistentTitleCache
225 * @return a list of instances of type T matching the queryString
227 public <S
extends T
> List
<S
> listByTitleWithRestrictions(Class
<S
> clazz
, String queryString
,MatchMode matchmode
, List
<Restriction
<?
>> restrictions
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
230 * Return a List of objects matching the given query string, optionally filtered by class, optionally with a particular MatchMode
232 * @param clazz filter by class - can be null to include all instances of type T
233 * @param queryString the query string to filter by
234 * @param matchmode use a particular type of matching (can be null - defaults to exact matching)
235 * @param criteria additional criteria to filter by
236 * @param pageSize The maximum number of objects returned (can be null for all objects)
237 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
238 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
240 * Supports path like <code>orderHints.propertyNames</code> which
241 * include *-to-one properties like createdBy.username or
242 * authorTeam.persistentTitleCache
243 * @return a list of instances of type T matching the queryString
245 public <S
extends T
> List
<S
> listByReferenceTitle(Class
<S
> clazz
, String queryString
,MatchMode matchmode
, List
<Criterion
> criteria
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
248 * Return a List of objects matching the given query string, optionally filtered by class, optionally with a particular MatchMode
250 * @param clazz filter by class - can be null to include all instances of type T
251 * @param queryString the query string to filter by
252 * @param matchmode use a particular type of matching (can be null - defaults to exact matching)
253 * @param restrictions a <code>List</code> of additional {@link Restriction}s to filter by
254 * @param pageSize The maximum number of objects returned (can be null for all objects)
255 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
256 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
258 * Supports path like <code>orderHints.propertyNames</code> which
259 * include *-to-one properties like createdBy.username or
260 * authorTeam.persistentTitleCache
261 * @return a list of instances of type T matching the queryString
263 public <S
extends T
> List
<S
> listByReferenceTitleWithRestrictions(Class
<S
> clazz
, String queryString
,MatchMode matchmode
, List
<Restriction
<?
>> restrictions
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
266 * Returns a Paged List of IdentifiableEntity instances where the default field matches the String queryString (as interpreted by the Lucene QueryParser)
268 * @param clazz filter the results by class (or pass null to return all IdentifiableEntity instances)
270 * @param pageSize The maximum number of identifiable entities returned (can be null for all matching identifiable entities)
271 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
273 * Supports path like <code>orderHints.propertyNames</code> which
274 * include *-to-one properties like createdBy.username or
275 * authorTeam.persistentTitleCache
276 * @param propertyPaths properties to be initialized
277 * @return a Pager IdentifiableEntity instances
278 * @see <a href="http://lucene.apache.org/java/2_4_0/queryparsersyntax.html">Apache Lucene - Query Parser Syntax</a>
280 public Pager
<T
> search(Class
<?
extends T
> clazz
, String queryString
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
281 // public <S extends T> Pager<S> search(Class<S> clazz, String queryString, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
285 * This method tries to deduplicate all objects of a certain class by first trying to find matchabel objects and
286 * merging them in a second step. For performance reasons implementing classes must not guarantee that ALL
287 * matching object pairs are found but only a subset. But it must guarantee that only matching objects are merged.
288 *<BR> Matching is defined by the given matching strategy or if no matching strategy is given the default matching
290 *<BR>clazz must implement {@link IMatchable} and {@link IMergable} otherwise no deduplication is performed.
291 *<BR>The current implementation in IdentifiableServiceBase tries to match and merge all objects with an identical non
294 * @param matchStrategy
295 * @param mergeStrategy
296 * @return the number of merges performed during deduplication
298 public int deduplicate(Class
<?
extends T
> clazz
, IMatchStrategyEqual matchStrategy
, IMergeStrategy mergeStrategy
);
302 * Return a Pager of objects with distinct titleCache strings filtered by the given query string, optionally filtered by class, optionally with a particular MatchMode
311 public Pager
<String
> findTitleCache(Class
<?
extends T
> clazz
, String queryString
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, MatchMode matchMode
);
315 * Returns an Sourceable object according the
321 //TODO shouldn't we move this to CommonService or to a new SourceService ?
322 //TODO should this return a List ?
323 public ISourceable
getSourcedObjectByIdInSource(Class clazz
, String idInSource
, String idNamespace
);
326 * Returns a Pager for {@link IdentifiedEntityDTO DTOs} that hold the identifier including type, title and uuid
327 * and the according CDM Object information (uuid, title and the object itself (optional)).
329 * @param clazz the identifiable entity subclass, may be null
330 * @param identifier the identifier as {@link String}
331 * @param identifierType the identifier type, maybe null
333 * @param includeCdmEntity if true the CDM entity is also returned (this may slow down performance for large datasets)
336 * @param propertyPaths
337 * @return all {@link IdentifiableEntity identifiable entities} which have the according
338 * identifier attached
340 public <S
extends T
> Pager
<IdentifiedEntityDTO
<S
>> findByIdentifier(
341 Class
<S
> clazz
, String identifier
, DefinedTerm identifierType
,
342 MatchMode matchmode
, boolean includeCdmEntity
,
343 Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
);
346 * Returns a Pager for {@link MarkedEntityDTO DTOs} that hold the marker including type, title and uuid
347 * and the according CDM object information (uuid, title and the object itself (optional)).
352 * @param includeEntity
355 * @param propertyPaths
356 * @return all {@link IdentifiableEntity identifiable entities} which have the according
357 * marker with the given flag value attached
359 public <S
extends T
> Pager
<MarkedEntityDTO
<S
>> findByMarker(
360 Class
<S
> clazz
, MarkerType markerType
, Boolean markerValue
,
361 boolean includeEntity
, Integer pageSize
,
362 Integer pageNumber
, List
<String
> propertyPaths
);
368 * @param identifierType
370 * @param includeEntity
371 * @param propertyPaths
374 public <S
extends T
>List
<IdentifiedEntityDTO
<S
>> listByIdentifier(Class
<S
> clazz
, String identifier
, DefinedTerm identifierType
,
375 MatchMode matchmode
, boolean includeEntity
, List
<String
> propertyPaths
, Integer limit
);
378 * Like {@link #getUuidAndTitleCache(Integer, String)} but searching only on a subclass
379 * of the type handled by the DAO.
381 * @param clazz the (sub)class
382 * @param limit max number of results
383 * @param pattern search pattern
385 * @see #getUuidAndTitleCache(Integer, String)
387 public <S
extends T
> List
<UuidAndTitleCache
<S
>> getUuidAndTitleCache(Class
<S
> clazz
, Integer limit
, String pattern
);
390 * Return a list of all uuids mapped to titleCache in the convenient <code>UuidAndTitleCache</code> object.
391 * Retrieving this list is considered to be significantly faster than initializing the fully fledged business
392 * objects. To be used in cases where you want to present large amount of data and provide details after
393 * a selection has been made.
395 * @return a list of <code>UuidAndTitleCache</code> instances
397 * @see #getUuidAndTitleCache(Class, Integer, String)
399 public List
<UuidAndTitleCache
<T
>> getUuidAndTitleCache(Integer limit
, String pattern
);
408 public List
<UuidAndTitleCache
<T
>> findUuidAndTitleCacheByMarker(Integer limit
, String pattern
,
409 MarkerType markerType
);