- fully implemented deep delete (child derivates)
[cdmlib.git] / cdmlib-services / src / main / java / eu / etaxonomy / cdm / api / service / ICommonService.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.Collection;
14 import java.util.List;
15 import java.util.Map;
16 import java.util.Set;
17
18 import org.hibernate.Session;
19 import org.hibernate.collection.spi.PersistentCollection;
20
21 import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
22 import eu.etaxonomy.cdm.database.DatabaseSchemaMismatchException;
23 import eu.etaxonomy.cdm.model.common.CdmBase;
24 import eu.etaxonomy.cdm.model.common.ISourceable;
25 import eu.etaxonomy.cdm.model.common.OriginalSourceBase;
26 import eu.etaxonomy.cdm.model.metadata.CdmMetaData;
27 import eu.etaxonomy.cdm.model.metadata.CdmMetaData.MetaDataPropertyName;
28 import eu.etaxonomy.cdm.model.reference.IGeneric;
29 import eu.etaxonomy.cdm.persistence.dao.common.ICdmGenericDao;
30 import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
31 import eu.etaxonomy.cdm.strategy.match.IMatchable;
32 import eu.etaxonomy.cdm.strategy.match.MatchException;
33 import eu.etaxonomy.cdm.strategy.merge.IMergable;
34 import eu.etaxonomy.cdm.strategy.merge.IMergeStrategy;
35 import eu.etaxonomy.cdm.strategy.merge.MergeException;
36
37
38 public interface ICommonService extends IService<OriginalSourceBase>{
39 //
40 // /** find cdmBase by UUID**/
41 // public abstract CdmBase getCdmBaseByUuid(UUID uuid);
42 //
43 // /** save a reference and return its UUID**/
44 // public abstract UUID saveCdmBase(CdmBase cdmBase);
45
46 /**
47 * Saves all meta data
48 * @param metaData
49 */
50 public void saveAllMetaData(Collection<CdmMetaData> metaData);
51
52 /**
53 * Returns all meta data.
54 * @return
55 */
56 public Map<MetaDataPropertyName, CdmMetaData> getCdmMetaData();
57
58
59 /**
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.
63 * @param clazz
64 * @param idInSourceSet
65 * @param idNamespace
66 * @return
67 */
68 public Map<String, ? extends ISourceable> getSourcedObjectsByIdInSource(Class clazz, Set<String> idInSourceSet, String idNamespace);
69
70 /**
71 * Returns a list of identifiable entities according to their class, idInSource and idNamespace
72 * @param clazz
73 * @param idInSource
74 * @param idNamespace
75 * @return
76 */
77 public ISourceable getSourcedObjectByIdInSource(Class clazz, String idInSource, String idNamespace);
78
79
80 /**
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
86 * @return
87 */
88 public Set<CdmBase> getReferencingObjects(CdmBase referencedCdmBase);
89
90 /**
91 * Merges mergeSecond into mergeFirst. All references to mergeSecond will be replaced by references
92 * to merge first. If no merge strategy is defined (null), the DefaultMergeStrategy will be taken as default.
93 * @param <T>
94 * @param mergeFirst
95 * @param mergeSecond
96 * @param mergeStrategy
97 * @throws MergeException
98 */
99 public <T extends IMergable> void merge(T mergeFirst, T mergeSecond, IMergeStrategy mergeStrategy) throws MergeException;
100
101 /**
102 * Returns all objects that match the object to match according to the given match strategy.
103 * If no match strategy is defined the default match strategy is taken.
104 * @param <T>
105 * @param objectToMatch
106 * @param matchStrategy
107 * @return
108 * @throws MatchException
109 */
110 public <T extends IMatchable> List<T> findMatching(T objectToMatch, IMatchStrategy matchStrategy) throws MatchException;
111
112 /**
113 * A generic method to retrieve any CdmBase object by its id and class.<BR>
114 * @see ICdmGenericDao#find(Class, int)
115 * @see Session#get(Class, java.io.Serializable)
116 * @param clazz the CdmBase class
117 * @param id the cdmBase identifier
118 * @return the CdmBase object defined by clazz and id
119 */
120 public CdmBase find(Class<? extends CdmBase> clazz, int id);
121
122 public List getHqlResult(String hqlQuery);
123
124 /**
125 * Initializes a lazy loaded persistent collection.
126 *
127 * @param col the persistent collection to initialize
128 * @return the initialized persistent collection
129 */
130 public PersistentCollection initializeCollection(PersistentCollection col);
131
132 /**
133 * Checks if a lazy loaded persistent collection is empty.
134 *
135 * @param col the persistent collection
136 * @return the initialized persistent collection
137 */
138 public boolean isEmpty(PersistentCollection col);
139
140 /**
141 * Returns the size of a persistent collection.
142 *
143 * @param col the persistent collection to initialize
144 * @return the size of the persistent collection
145 */
146 public int size(PersistentCollection col);
147
148 /**
149 * Returns the object contained in a persistent collection at the given index.
150 *
151 * @param col the persistent collection
152 * @param index the index of the requested element
153 * @return the object at the requested index
154 */
155 public Object get(PersistentCollection col, int index);
156
157 /**
158 * checks whether an object is contained within a persistent collection.
159 *
160 * @param col the persistent collection
161 * @param element the element to check for
162 * @return true if the element exists in the collection, false o/w
163 */
164 public boolean contains(PersistentCollection col, Object element);
165
166 /**
167 * checks whether an index object exists within a persistent collection
168 * (usually a map)
169 *
170 * @param col the persistent collection
171 * @param key the index object to look for.
172 * @return true if the index object exists in the collection, false o/w
173 */
174 public boolean containsKey(PersistentCollection col, Object key);
175
176 /**
177 * checks whether an value object exists within a persistent collection
178 * (usually a map)
179 *
180 * @param col the persistent collection
181 * @param key the value object to look for.
182 * @return true if the value object exists in the collection, false o/w
183 */
184 public boolean containsValue(PersistentCollection col, Object element);
185
186 public Set<CdmBase> getReferencingObjectsForDeletion(CdmBase referencedCdmBase);
187
188 /**
189 * Preliminary, may be moved to test later
190 */
191 @Deprecated
192 public void createFullSampleData();
193
194
195 }