3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.cdm
.api
.service
;
13 import java
.util
.Collection
;
14 import java
.util
.List
;
17 import java
.util
.UUID
;
19 import org
.hibernate
.Session
;
21 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
22 import eu
.etaxonomy
.cdm
.model
.common
.ISourceable
;
23 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmMetaData
;
24 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmMetaData
.MetaDataPropertyName
;
25 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.ICdmGenericDao
;
26 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
27 import eu
.etaxonomy
.cdm
.strategy
.match
.IMatchStrategy
;
28 import eu
.etaxonomy
.cdm
.strategy
.match
.IMatchable
;
29 import eu
.etaxonomy
.cdm
.strategy
.match
.MatchException
;
30 import eu
.etaxonomy
.cdm
.strategy
.match
.MatchStrategyConfigurator
;
31 import eu
.etaxonomy
.cdm
.strategy
.merge
.IMergable
;
32 import eu
.etaxonomy
.cdm
.strategy
.merge
.IMergeStrategy
;
33 import eu
.etaxonomy
.cdm
.strategy
.merge
.MergeException
;
37 public interface ICommonService
/*extends IService<OriginalSourceBase>*/{
40 // /** find cdmBase by UUID**/
41 // public abstract CdmBase getCdmBaseByUuid(UUID uuid);
43 // /** save a reference and return its UUID**/
44 // public abstract UUID saveCdmBase(CdmBase cdmBase);
50 public void saveAllMetaData(Collection
<CdmMetaData
> metaData
);
53 * Returns all meta data.
56 public Map
<MetaDataPropertyName
, CdmMetaData
> getCdmMetaData();
60 * Returns a map of identifiable entities of class <code>clazz</code> which have an original source of
61 * with namespace <code>idNamespace</code> and with an idInSource in <code>idInSourceSet</code> <BR>
62 * The key of the map is the idInSource. If there are multiple objects that have the same id an arbitrary one is chosen.
64 * @param idInSourceSet
68 public Map
<String
, ?
extends ISourceable
> getSourcedObjectsByIdInSource(Class clazz
, Set
<String
> idInSourceSet
, String idNamespace
);
71 * Returns a list of identifiable entities according to their class, idInSource and idNamespace
77 public ISourceable
getSourcedObjectByIdInSource(Class clazz
, String idInSource
, String idNamespace
);
81 * Returns all CdmBase objects that reference the referencedCdmBase.
82 * For example, if referencedCdmBase is an agent it may return all taxon names
83 * that have this person as an author but also all books, articles, etc. that have
84 * this person as an author
85 * @param referencedCdmBase
88 public Set
<CdmBase
> getReferencingObjects(CdmBase referencedCdmBase
);
93 * Tests if cdmBase2 can be merged into cdmBase1. This is usually the case when both
94 * objects are of the same class.
95 * If they are not they must have a common super class and all links to CdmBase2 must be
96 * re-referenceable to cdmBase1.
97 * This is not the case if cdmBase2 is linked by a property which does not support class of cdmBase1.
98 * E.g. User.person requires a person so if user u1 exists with u1.person = person1 and we want to
99 * merge person1 into team1 this is not possible because team1 is not a valid replacement for person1
100 * within the user1.person context.
102 * This method is not expensive if classes are equal but may become more expensive if not, because
103 * in this concrete references to cdmBases2 need to be evaluated.
106 * @param mergeStrategy
108 * @throws MergeException
110 public <T
extends CdmBase
> boolean isMergeable(T cdmBase1
, T cdmBase2
, IMergeStrategy mergeStrategy
) throws MergeException
;
114 * Merges mergeSecond into mergeFirst. All references to mergeSecond will be replaced by references
115 * to merge first. If no merge strategy is defined (null), the DefaultMergeStrategy will be taken as default.
119 * @param mergeStrategy
120 * @throws MergeException
122 public <T
extends IMergable
> void merge(T mergeFirst
, T mergeSecond
, IMergeStrategy mergeStrategy
) throws MergeException
;
125 * Merges mergeSecond into mergeFirst. All references to mergeSecond will be replaced by references
126 * to merge first, using a merge strategy defined by the given class.
131 * @throws MergeException
133 public <T
extends IMergable
> void merge(T mergeFirst
, T mergeSecond
, Class
<?
extends CdmBase
> clazz
) throws MergeException
;
137 * Merges mergeSecond into mergeFirst. All references to mergeSecond will be replaced by references
138 * to merge first, using a merge strategy defined by the mergeFirst type.
141 * @throws MergeException
143 public <T
extends IMergable
> void merge(T mergeFirst
, T mergeSecond
) throws MergeException
;
147 * Returns all objects that match the object to match according to the given match strategy.
148 * If no match strategy is defined the default match strategy is taken.
150 * @param objectToMatch
151 * @param matchStrategy
153 * @throws MatchException
155 public <T
extends IMatchable
> List
<T
> findMatching(T objectToMatch
, IMatchStrategy matchStrategy
) throws MatchException
;
158 public <T
extends IMatchable
> List
<T
> findMatching(T objectToMatch
, MatchStrategyConfigurator
.MatchStrategy strategy
) throws MatchException
;
166 public CdmBase
findWithUpdate(Class
<?
extends CdmBase
> clazz
, int id
);
169 * A generic method to retrieve any CdmBase object by its id and class.<BR>
170 * @see ICdmGenericDao#find(Class, int)
171 * @see Session#get(Class, java.io.Serializable)
172 * @param clazz the CdmBase class
173 * @param id the cdmBase identifier
174 * @return the CdmBase object defined by clazz and id
176 public CdmBase
find(Class
<?
extends CdmBase
> clazz
, int id
);
181 * @param propertyPaths
184 public CdmBase
find(Class
<?
extends CdmBase
> clazz
, int id
, List
<String
> propertyPaths
);
187 public List
getHqlResult(String hqlQuery
);
191 * Initializes a collection or map.
193 * @param ownerUuid uuid of owner cdm entity
194 * @param fieldName field name of collection or map
195 * @return initialised collection or map
197 public Object
initializeCollection(UUID ownerUuid
, String fieldName
);
202 * @param propertyPaths
205 public Object
initializeCollection(UUID ownerUuid
, String fieldName
, List
<String
> propertyPaths
);
208 * Checks if a collection or map is empty.
210 * @param ownerUuid uuid of owner cdm entity
211 * @param fieldName field name of collection or map
212 * @return true if the collection of map is empty, else false
214 public boolean isEmpty(UUID ownerUuid
, String fieldName
);
217 * Returns the size of requested collection or map.
219 * @param ownerUuid uuid of owner cdm entity
220 * @param fieldName field name of collection or map
221 * @return the size of the persistent collection
223 public int size(UUID ownerUuid
, String fieldName
);
226 * Returns the object contained in a collection or map at the given index.
228 * @param ownerUuid uuid of owner cdm entity
229 * @param fieldName field name of collection or map
230 * @param index the index of the requested element
231 * @return the object at the requested index
233 public Object
get(UUID ownerUuid
, String fieldName
, int index
);
236 * Checks whether an object is contained within a persistent collection.
238 * @param ownerUuid uuid of owner cdm entity
239 * @param fieldName field name of collection or map
240 * @param element the element to check for
241 * @return true if the element exists in the collection, false o/w
243 public boolean contains(UUID ownerUuid
, String fieldName
, Object element
);
246 * Checks whether an index object exists within a persistent collection
249 * @param ownerUuid uuid of owner cdm entity
250 * @param fieldName field name of map
251 * @param key the index object to look for.
252 * @return true if the index object exists in the collection, false o/w
254 public boolean containsKey(UUID ownerUuid
, String fieldName
, Object key
);
257 * checks whether an value object exists within a persistent collection
260 * @param ownerUuid uuid of owner cdm entity
261 * @param fieldName field name of map
262 * @param key the value object to look for.
263 * @return true if the value object exists in the collection, false o/w
265 public boolean containsValue(UUID ownerUuid
, String fieldName
, Object element
);
267 public Set
<CdmBase
> getReferencingObjectsForDeletion(CdmBase referencedCdmBase
);
270 * Preliminary, may be moved to test later
273 public void createFullSampleData();
277 * Returns the number of objects that belong to a certain class.
278 * @param type the CdmBase class
279 * @return the number of objects in the database
281 public <S
extends CdmBase
> int count(Class
<S
> type
);
285 * Generic method to retrieve a list of objects. Use only if no specific service class
291 * @param propertyPaths
292 * @see IService#list(Class, Integer, Integer, List, List)
295 public <S
extends CdmBase
> List
<S
> list(Class
<S
> type
, Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
298 * Save a new entity (persists the entity)
299 * @param newInstance the new entity to be persisted
300 * @return A generated UUID for the new persistent entity
302 public CdmBase
save(CdmBase newInstance
);
306 * Save a collection containing new entities (persists the entities)
307 * @param newInstances the new entities to be persisted
308 * @return A Map containing the new entities, keyed using the generated UUID's
311 public <T
extends CdmBase
> Map
<UUID
,T
> save(Collection
<T
> newInstances
);
314 * @param mergeFirstId
315 * @param mergeSecondId
317 * @throws MergeException
318 * @Deprecated the preferred method is to use uuids {@link #merge(UUID, UUID, Class)}
321 public <T
extends IMergable
> void merge(int mergeFirstId
, int mergeSecondId
, Class
<?
extends CdmBase
> clazz
) throws MergeException
;
324 * @param mergeFirstUuid uuid of the first object to merge
325 * @param mergeSecondUuid UUID of the second object to merge
327 * @throws MergeException
329 public <T
extends IMergable
> void merge(UUID mergeFirstUuid
, UUID mergeSecondUuid
, Class
<?
extends CdmBase
> clazz
) throws MergeException
;