Added public T replace(T x, T y) to ICdmEntityDao, implementation and tests
[cdmlib.git] / cdmlib-services / src / main / java / eu / etaxonomy / cdm / api / service / IIdentifiableEntityService.java
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.pager.Pager;
18 import eu.etaxonomy.cdm.model.common.ISourceable;
19 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
20 import eu.etaxonomy.cdm.model.common.IdentifiableSource;
21 import eu.etaxonomy.cdm.model.common.LSID;
22 import eu.etaxonomy.cdm.model.common.UuidAndTitleCache;
23 import eu.etaxonomy.cdm.model.media.Rights;
24 import eu.etaxonomy.cdm.persistence.dao.BeanInitializer;
25 import eu.etaxonomy.cdm.persistence.query.MatchMode;
26 import eu.etaxonomy.cdm.persistence.query.OrderHint;
27
28 public interface IIdentifiableEntityService<T extends IdentifiableEntity> extends IAnnotatableService<T> {
29
30 /**
31 * (Re-)generate the title caches for all objects of this concrete IdentifiableEntity class
32 */
33 public void generateTitleCache();
34
35 /**
36 * Finds an object with a given LSID. If the object does not currently exist in the current view, then
37 * the most recent prior version of the object will be returned, or null if an object with this identifier
38 * has never existed
39 *
40 * @param lsid
41 * @return an object of type T or null of the object has never existed
42 */
43 public T find(LSID lsid);
44
45 /**
46 * Replaces all *ToMany and *ToOne references to an object (x) with another object of the same type (y)
47 *
48 * Ignores ManyToAny and OneToAny relationships as these are typically involved with bidirectional
49 * parent-child relations
50 *
51 * @param x
52 * @param y
53 * @return the replacing object (y)
54 */
55 public T replace(T x, T y);
56
57 /**
58 * Return a Pager of sources belonging to this object
59 *
60 * @param t The identifiable entity
61 * @param pageSize The maximum number of sources returned (can be null for all sources)
62 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
63 * @param propertyPaths properties to initialize - see {@link BeanInitializer#initialize(Object, List)}
64 * @return a Pager of OriginalSource entities
65 */
66 public Pager<IdentifiableSource> getSources(T t, Integer pageSize, Integer pageNumber, List<String> propertyPaths);
67
68 /**
69 * Return a Pager of rights belonging to this object
70 *
71 * @param t The identifiable entity
72 * @param pageSize The maximum number of rights returned (can be null for all rights)
73 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
74 * @param propertyPaths properties to initialize - see {@link BeanInitializer#initialize(Object, List)}
75 * @return a Pager of Rights entities
76 */
77 public Pager<Rights> getRights(T t, Integer pageSize, Integer pageNumber, List<String> propertyPaths);
78
79 public ISourceable getSourcedObjectByIdInSource(Class clazz, String idInSource, String idNamespace);
80
81 /**
82 * Return a list of all uuids mapped to titleCache in the convenient <code>UuidAndTitleCache</code> object.
83 * Retrieving this list is considered to be significantly faster than initializing the fully fledged buiseness
84 * objects. To be used in cases where you want to present large amount of data and provide details after
85 * a selection has been made.
86 *
87 * @return a list of <code>UuidAndTitleCache</code> instances
88 */
89 public List<UuidAndTitleCache<T>> getUuidAndTitleCache();
90
91 /**
92 * Return a Pager of objects matching the given query string, optionally filtered by class, optionally with a particular MatchMode
93 *
94 * @param clazz filter by class - can be null to include all instances of type T
95 * @param queryString the query string to filter by
96 * @param matchmode use a particular type of matching (can be null - defaults to exact matching)
97 * @param criteria additional criteria to filter by
98 * @param pageSize The maximum number of objects returned (can be null for all objects)
99 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
100 * @param propertyPaths properties to initialize - see {@link BeanInitializer#initialize(Object, List)}
101 * @param orderHints
102 * Supports path like <code>orderHints.propertyNames</code> which
103 * include *-to-one properties like createdBy.username or
104 * authorTeam.persistentTitleCache
105 * @return a paged list of instances of type T matching the queryString
106 */
107 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);
108
109 /**
110 * Returns a Paged List of IdentifiableEntity instances where the default field matches the String queryString (as interpreted by the Lucene QueryParser)
111 *
112 * @param clazz filter the results by class (or pass null to return all IdentifiableEntity instances)
113 * @param queryString
114 * @param pageSize The maximum number of identifiable entities returned (can be null for all matching identifiable entities)
115 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
116 * @param orderHints
117 * Supports path like <code>orderHints.propertyNames</code> which
118 * include *-to-one properties like createdBy.username or
119 * authorTeam.persistentTitleCache
120 * @param propertyPaths properties to be initialized
121 * @return a Pager IdentifiableEntity instances
122 * @see <a href="http://lucene.apache.org/java/2_4_0/queryparsersyntax.html">Apache Lucene - Query Parser Syntax</a>
123 */
124 public Pager<T> search(Class<? extends T> clazz, String queryString, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
125 }