Revision d1cf4a26
Added by Katja Luther over 8 years ago
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/OrderedTermVocabulary.java | ||
---|---|---|
5 | 5 |
* |
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 |
*/
|
|
8 |
*/ |
|
9 | 9 |
|
10 | 10 |
package eu.etaxonomy.cdm.model.common; |
11 | 11 |
|
... | ... | |
44 | 44 |
|
45 | 45 |
// ************************* FACTORY METHODS ***********************************************/ |
46 | 46 |
|
47 |
|
|
47 |
|
|
48 | 48 |
/** |
49 | 49 |
* @param type the {@link TermType term type}, must be the same as for all included terms |
50 | 50 |
* @return |
... | ... | |
53 | 53 |
public static OrderedTermVocabulary NewInstance(TermType type){ |
54 | 54 |
return new OrderedTermVocabulary(type); |
55 | 55 |
} |
56 |
|
|
57 |
|
|
56 |
|
|
57 |
|
|
58 | 58 |
/** |
59 | 59 |
* @param type the {@link TermType term type}, must be the same as for all included terms |
60 | 60 |
* @param description the description of this vocabulary |
61 |
* @param label
|
|
61 |
* @param label |
|
62 | 62 |
* @param labelAbbrev |
63 | 63 |
* @param termSourceUri |
64 | 64 |
* @return |
... | ... | |
67 | 67 |
public static OrderedTermVocabulary NewInstance(TermType type, String description, String label, String labelAbbrev, URI termSourceUri){ |
68 | 68 |
return new OrderedTermVocabulary(type, description, label, labelAbbrev, termSourceUri); |
69 | 69 |
} |
70 |
|
|
71 |
|
|
72 |
//************************ CONSTRUCTOR *****************************************************/
|
|
70 |
|
|
71 |
|
|
72 |
//************************ CONSTRUCTOR *****************************************************/ |
|
73 | 73 |
|
74 | 74 |
//for hibernate use only |
75 | 75 |
@Deprecated |
76 | 76 |
protected OrderedTermVocabulary() { |
77 | 77 |
super(); |
78 | 78 |
} |
79 |
|
|
79 |
|
|
80 | 80 |
/** |
81 | 81 |
* @param term |
82 | 82 |
* @param label |
... | ... | |
85 | 85 |
protected OrderedTermVocabulary(TermType type) { |
86 | 86 |
super(type); |
87 | 87 |
} |
88 |
|
|
88 |
|
|
89 | 89 |
/** |
90 | 90 |
* @param term |
91 | 91 |
* @param label |
... | ... | |
96 | 96 |
} |
97 | 97 |
|
98 | 98 |
|
99 |
//************************* METHODS **************************************/
|
|
100 |
|
|
99 |
//************************* METHODS **************************************/ |
|
100 |
|
|
101 | 101 |
@Transient |
102 | 102 |
@Override |
103 | 103 |
public Set<T> getNewTermSet() { |
104 | 104 |
return new TreeSet<T>(); |
105 | 105 |
} |
106 |
|
|
106 |
|
|
107 | 107 |
@Transient |
108 | 108 |
public SortedSet<T> getOrderedTerms() { |
109 | 109 |
SortedSet<T> result = getSortedSetOfTerms(); |
... | ... | |
129 | 129 |
|
130 | 130 |
public SortedSet<T> getLowerAndEqualTerms(T otb) { |
131 | 131 |
SortedSet<T> result = new TreeSet<T>(); |
132 |
SortedSet<T> sortedSet = getSortedSetOfTerms(); |
|
133 |
|
|
134 |
result.addAll( sortedSet.headSet(otb)); |
|
135 |
//headSet Returns a view of the portion of this set whose elements are STRICTLY less than toElement |
|
132 |
result = getLowerTerms(otb); |
|
133 |
/*SortedSet<T> sortedSet = getSortedSetOfTerms(); |
|
134 |
|
|
135 |
result.addAll( sortedSet.headSet(otb));*/ |
|
136 |
//getLowerTerms Returns a view of the portion of this set whose elements are STRICTLY less than toElement |
|
136 | 137 |
for (T setObject : terms){ |
137 | 138 |
if (setObject.compareTo(otb) == 0){ |
138 | 139 |
result.add(setObject); |
... | ... | |
140 | 141 |
} |
141 | 142 |
return result; |
142 | 143 |
} |
143 |
|
|
144 |
|
|
144 | 145 |
public SortedSet<T> getLowerTerms(T otb) { |
145 |
SortedSet<T> result = getLowerAndEqualTerms(otb); |
|
146 |
/*SortedSet<T> result = getLowerAndEqualTerms(otb);
|
|
146 | 147 |
for (T setObject : terms){ |
147 | 148 |
if (setObject.compareTo(otb) == 0){ |
148 | 149 |
result.remove(setObject); |
149 | 150 |
} |
150 |
} |
|
151 |
}*/ |
|
152 |
SortedSet<T> result = new TreeSet<T>(); |
|
153 |
SortedSet<T> sortedSet = getSortedSetOfTerms(); |
|
154 |
//headSet Returns a view of the portion of this set whose elements are STRICTLY less than toElement |
|
155 |
result.addAll( sortedSet.headSet(otb)); |
|
151 | 156 |
return result; |
152 | 157 |
} |
153 | 158 |
|
... | ... | |
160 | 165 |
} |
161 | 166 |
return result; |
162 | 167 |
} |
163 |
|
|
168 |
|
|
164 | 169 |
public T getNextHigherTerm(T otb) { |
165 | 170 |
try { |
166 | 171 |
return getHigherTerms(otb).first(); |
... | ... | |
168 | 173 |
return null; |
169 | 174 |
} |
170 | 175 |
} |
171 |
|
|
176 |
|
|
172 | 177 |
public T getNextLowerTerm(T otb) { |
173 | 178 |
try { |
174 | 179 |
return getLowerTerms(otb).last(); |
... | ... | |
187 | 192 |
return null; |
188 | 193 |
} |
189 | 194 |
} |
190 |
|
|
195 |
|
|
191 | 196 |
@Transient |
192 | 197 |
public T getHighestTerm() { |
193 | 198 |
try { |
... | ... | |
197 | 202 |
return null; |
198 | 203 |
} |
199 | 204 |
} |
200 |
|
|
205 |
|
|
201 | 206 |
/** |
202 | 207 |
* Adds a term to the the end / lowest |
203 | 208 |
* @see eu.etaxonomy.cdm.model.common.TermVocabulary#addTerm(eu.etaxonomy.cdm.model.common.DefinedTermBase) |
204 | 209 |
*/ |
205 |
public void addTerm(T term) { |
|
210 |
@Override |
|
211 |
public void addTerm(T term) { |
|
206 | 212 |
SortedSet<T> sortedTerms = getSortedSetOfTerms(); |
207 | 213 |
int lowestOrderIndex; |
208 | 214 |
if (sortedTerms.isEmpty()){ |
... | ... | |
212 | 218 |
lowestOrderIndex = first.orderIndex; |
213 | 219 |
} |
214 | 220 |
term.orderIndex = lowestOrderIndex + 1; |
215 |
super.addTerm(term);
|
|
221 |
super.addTerm(term); |
|
216 | 222 |
} |
217 | 223 |
|
218 | 224 |
public void addTermAbove(T termToBeAdded, T lowerTerm) { |
219 | 225 |
int orderInd = lowerTerm.orderIndex; |
220 | 226 |
termToBeAdded.orderIndex = orderInd; |
221 |
//increment all orderIndexes of terms below
|
|
227 |
//increment all orderIndexes of terms below |
|
222 | 228 |
Iterator<T> iterator = terms.iterator(); |
223 | 229 |
while(iterator.hasNext()){ |
224 | 230 |
T term = iterator.next(); |
... | ... | |
232 | 238 |
public void addTermBelow(T termToBeAdded, T higherTerm) { |
233 | 239 |
int orderInd = higherTerm.orderIndex; |
234 | 240 |
termToBeAdded.orderIndex = orderInd + 1; |
235 |
//increment all orderIndexes of terms below
|
|
241 |
//increment all orderIndexes of terms below |
|
236 | 242 |
Iterator<T> iterator = getLowerTerms(higherTerm).iterator(); |
237 | 243 |
while(iterator.hasNext()){ |
238 | 244 |
T term = iterator.next(); |
... | ... | |
242 | 248 |
} |
243 | 249 |
super.addTerm(termToBeAdded); |
244 | 250 |
} |
245 |
|
|
251 |
|
|
246 | 252 |
public void addTermEqualLevel(T termToBeAdded, T equalLevelTerm) throws WrongTermTypeException { |
247 | 253 |
int orderInd = equalLevelTerm.orderIndex; |
248 | 254 |
termToBeAdded.orderIndex = orderInd; |
249 | 255 |
super.addTerm(termToBeAdded); |
250 | 256 |
} |
251 |
|
|
257 |
|
|
252 | 258 |
@Override |
253 | 259 |
public void removeTerm(T term) { |
254 | 260 |
if (term == null){ |
... | ... | |
257 | 263 |
if (this.getEqualTerms(term).size() == 0){ |
258 | 264 |
Iterator<T> iterator = getLowerTerms(term).iterator(); |
259 | 265 |
while (iterator.hasNext()){ |
260 |
T otb = iterator.next();
|
|
266 |
T otb = iterator.next(); |
|
261 | 267 |
toBeChangedByObject = otb; |
262 | 268 |
otb.decreaseIndex(this); |
263 | 269 |
toBeChangedByObject = null; |
... | ... | |
265 | 271 |
} |
266 | 272 |
super.removeTerm(term); |
267 | 273 |
} |
268 |
|
|
274 |
|
|
269 | 275 |
@Transient |
270 | 276 |
private T toBeChangedByObject; |
271 |
|
|
277 |
|
|
272 | 278 |
public boolean indexChangeAllowed(OrderedTermBase<T> orderedTermBase){ |
273 | 279 |
return orderedTermBase == toBeChangedByObject ; |
274 | 280 |
} |
275 |
|
|
276 |
|
|
281 |
|
|
282 |
|
|
277 | 283 |
@Transient |
278 | 284 |
private SortedSet<T> getSortedSetOfTerms(){ |
279 | 285 |
SortedSet<T> sortedSet = new TreeSet<T>(); |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/CdmGenericDaoImpl.java | ||
---|---|---|
186 | 186 |
|
187 | 187 |
@Override |
188 | 188 |
public Set<CdmBase> getReferencingObjectsForDeletion(CdmBase referencedCdmBase){ |
189 |
if (referencedCdmBase == null){ |
|
190 |
return null; |
|
191 |
} |
|
189 | 192 |
Set<CdmBase> result = getReferencingObjects(referencedCdmBase); |
190 | 193 |
Set<ReferenceHolder> holderSet = referenceMap.get(IdentifiableEntity.class); |
191 | 194 |
try { |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/hibernate/CdmDeleteListener.java | ||
---|---|---|
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.persistence.hibernate; |
|
11 |
|
|
12 |
import java.util.Set; |
|
13 |
|
|
14 |
import org.apache.log4j.Logger; |
|
15 |
import org.hibernate.HibernateException; |
|
16 |
import org.hibernate.event.spi.DeleteEvent; |
|
17 |
import org.hibernate.event.spi.DeleteEventListener; |
|
18 |
|
|
19 |
import eu.etaxonomy.cdm.model.common.RelationshipBase; |
|
20 |
|
|
21 |
/** |
|
22 |
* @author a.mueller |
|
23 |
* @created 04.03.2009 |
|
24 |
* @version 1.0 |
|
25 |
*/ |
|
26 |
public class CdmDeleteListener implements DeleteEventListener { |
|
27 |
private static final long serialVersionUID = -5511287200489449838L; |
|
28 |
protected static final Logger logger = Logger.getLogger(CdmDeleteListener.class); |
|
29 |
|
|
30 |
@Override |
|
31 |
public void onDelete(DeleteEvent event) throws HibernateException { |
|
32 |
Object entity = event.getObject(); |
|
33 |
if(entity != null && RelationshipBase.class.isAssignableFrom(entity.getClass())) { |
|
34 |
logger.info("Deleting " + entity); |
|
35 |
deleteRelationship(event, entity); |
|
36 |
} |
|
37 |
} |
|
38 |
|
|
39 |
@Override |
|
40 |
public void onDelete(DeleteEvent event, Set transientEntities)throws HibernateException { |
|
41 |
Object entity = event.getObject(); |
|
42 |
if(entity != null && RelationshipBase.class.isAssignableFrom(entity.getClass())) { |
|
43 |
logger.info("Deleting " + entity); |
|
44 |
deleteRelationship(event, entity); |
|
45 |
} |
|
46 |
} |
|
47 |
|
|
48 |
/** |
|
49 |
* @param event |
|
50 |
* @param entity |
|
51 |
*/ |
|
52 |
private void deleteRelationship(DeleteEvent event, Object entity) { |
|
53 |
RelationshipBase relationshipEntity = (RelationshipBase)entity; |
|
54 |
/* if (relationshipEntity.isRemoved()){ |
|
55 |
Set<IRelated> deletedObjects = relationshipEntity.getDeletedObjects(); |
|
56 |
for (IRelated rel : deletedObjects){ |
|
57 |
if (rel != null){ |
|
58 |
logger.info("Updating related entity " + rel); |
|
59 |
Object o = CdmBase.deproxy(rel, CdmBase.class); |
|
60 |
EntityEntry entry = event.getSession().getPersistenceContext().getEntry(o); |
|
61 |
if (entry == null){ |
|
62 |
// System.out.println(); |
|
63 |
} |
|
64 |
if (!entry.getStatus().equals(Status.DELETED)){ |
|
65 |
event.getSession().update(rel); |
|
66 |
} |
|
67 |
} |
|
68 |
} |
|
69 |
}*/ |
|
70 |
} |
|
71 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/hibernate/CdmDeleteListener_.java | ||
---|---|---|
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.persistence.hibernate; |
|
11 |
|
|
12 |
import java.util.Set; |
|
13 |
|
|
14 |
import org.apache.log4j.Logger; |
|
15 |
import org.hibernate.HibernateException; |
|
16 |
import org.hibernate.event.spi.DeleteEvent; |
|
17 |
import org.hibernate.event.spi.DeleteEventListener; |
|
18 |
|
|
19 |
import eu.etaxonomy.cdm.model.common.RelationshipBase; |
|
20 |
|
|
21 |
/** |
|
22 |
* @author a.mueller |
|
23 |
* @created 04.03.2009 |
|
24 |
* @version 1.0 |
|
25 |
*/ |
|
26 |
public class CdmDeleteListener implements DeleteEventListener { |
|
27 |
private static final long serialVersionUID = -5511287200489449838L; |
|
28 |
protected static final Logger logger = Logger.getLogger(CdmDeleteListener.class); |
|
29 |
|
|
30 |
@Override |
|
31 |
public void onDelete(DeleteEvent event) throws HibernateException { |
|
32 |
Object entity = event.getObject(); |
|
33 |
if(entity != null && RelationshipBase.class.isAssignableFrom(entity.getClass())) { |
|
34 |
logger.info("Deleting " + entity); |
|
35 |
deleteRelationship(event, entity); |
|
36 |
} |
|
37 |
} |
|
38 |
|
|
39 |
@Override |
|
40 |
public void onDelete(DeleteEvent event, Set transientEntities)throws HibernateException { |
|
41 |
Object entity = event.getObject(); |
|
42 |
if(entity != null && RelationshipBase.class.isAssignableFrom(entity.getClass())) { |
|
43 |
logger.info("Deleting " + entity); |
|
44 |
deleteRelationship(event, entity); |
|
45 |
} |
|
46 |
} |
|
47 |
|
|
48 |
/** |
|
49 |
* @param event |
|
50 |
* @param entity |
|
51 |
*/ |
|
52 |
private void deleteRelationship(DeleteEvent event, Object entity) { |
|
53 |
RelationshipBase relationshipEntity = (RelationshipBase)entity; |
|
54 |
/* if (relationshipEntity.isRemoved()){ |
|
55 |
Set<IRelated> deletedObjects = relationshipEntity.getDeletedObjects(); |
|
56 |
for (IRelated rel : deletedObjects){ |
|
57 |
if (rel != null){ |
|
58 |
logger.info("Updating related entity " + rel); |
|
59 |
Object o = CdmBase.deproxy(rel, CdmBase.class); |
|
60 |
EntityEntry entry = event.getSession().getPersistenceContext().getEntry(o); |
|
61 |
if (entry == null){ |
|
62 |
// System.out.println(); |
|
63 |
} |
|
64 |
if (!entry.getStatus().equals(Status.DELETED)){ |
|
65 |
event.getSession().update(rel); |
|
66 |
} |
|
67 |
} |
|
68 |
} |
|
69 |
}*/ |
|
70 |
} |
|
71 |
} |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImpl.java | ||
---|---|---|
425 | 425 |
@Override |
426 | 426 |
@Transactional(readOnly = false) |
427 | 427 |
public DeleteResult deleteTaxonNode(UUID nodeUUID, TaxonDeletionConfigurator config) { |
428 |
|
|
428 | 429 |
TaxonNode node = HibernateProxyHelper.deproxy(dao.load(nodeUUID), TaxonNode.class); |
429 | 430 |
return deleteTaxonNode(node, config); |
430 | 431 |
} |
... | ... | |
432 | 433 |
@Override |
433 | 434 |
@Transactional(readOnly = false) |
434 | 435 |
public DeleteResult deleteTaxonNode(TaxonNode node, TaxonDeletionConfigurator config) { |
436 |
DeleteResult result = new DeleteResult(); |
|
437 |
if (node == null){ |
|
438 |
result.setAbort(); |
|
439 |
result.addException(new Exception("The TaxonNode is already deleted.")); |
|
440 |
return result; |
|
441 |
} |
|
442 |
Taxon taxon = null; |
|
443 |
try{ |
|
444 |
taxon = (Taxon)HibernateProxyHelper.deproxy(node.getTaxon()); |
|
445 |
}catch(NullPointerException e){ |
|
446 |
result.setAbort(); |
|
447 |
result.addException(new Exception("The Taxon is already deleted.")); |
|
435 | 448 |
|
436 |
Taxon taxon = (Taxon)HibernateProxyHelper.deproxy(node.getTaxon());
|
|
449 |
}
|
|
437 | 450 |
TaxonNode parent = HibernateProxyHelper.deproxy(node.getParent(), TaxonNode.class); |
438 | 451 |
if (config == null){ |
439 | 452 |
config = new TaxonDeletionConfigurator(); |
440 | 453 |
} |
441 |
DeleteResult result = new DeleteResult(); |
|
454 |
|
|
455 |
|
|
442 | 456 |
|
443 | 457 |
if (config.getTaxonNodeConfig().getChildHandling().equals(ChildHandling.MOVE_TO_PARENT)){ |
444 | 458 |
Object[] children = node.getChildNodes().toArray(); |
... | ... | |
451 | 465 |
deleteTaxonNodes(node.getChildNodes(), config); |
452 | 466 |
} |
453 | 467 |
|
454 |
if (config.getTaxonNodeConfig().isDeleteTaxon() && (config.isDeleteInAllClassifications() || taxon.getTaxonNodes().size() == 1)){ |
|
455 |
result = taxonService.deleteTaxon(taxon.getUuid(), config, node.getClassification().getUuid()); |
|
456 |
result.addUpdatedObject(parent); |
|
457 |
if (result.isOk()){ |
|
458 |
return result; |
|
459 |
} |
|
460 |
} else { |
|
461 |
result.addUpdatedObject(taxon); |
|
468 |
if (taxon != null){ |
|
469 |
if (config.getTaxonNodeConfig().isDeleteTaxon() && (config.isDeleteInAllClassifications() || taxon.getTaxonNodes().size() == 1)){ |
|
470 |
result = taxonService.deleteTaxon(taxon.getUuid(), config, node.getClassification().getUuid()); |
|
471 |
result.addUpdatedObject(parent); |
|
472 |
if (result.isOk()){ |
|
473 |
return result; |
|
474 |
} |
|
475 |
} else { |
|
476 |
result.addUpdatedObject(taxon); |
|
477 |
} |
|
462 | 478 |
} |
463 |
|
|
464 | 479 |
result.setCdmEntity(node); |
465 | 480 |
boolean success = taxon.removeTaxonNode(node); |
466 | 481 |
dao.save(parent); |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonServiceImpl.java | ||
---|---|---|
967 | 967 |
config = new TaxonDeletionConfigurator(); |
968 | 968 |
} |
969 | 969 |
Taxon taxon = (Taxon)dao.load(taxonUUID); |
970 |
DeleteResult result = new DeleteResult(); |
|
971 |
if (taxon == null){ |
|
972 |
result.setAbort(); |
|
973 |
result.addException(new Exception ("The taxon was already deleted.")); |
|
974 |
return result; |
|
975 |
} |
|
970 | 976 |
taxon = (Taxon) HibernateProxyHelper.deproxy(taxon); |
971 | 977 |
Classification classification = HibernateProxyHelper.deproxy(classificationDao.load(classificationUuid), Classification.class); |
972 |
DeleteResult result = isDeletable(taxon, config);
|
|
978 |
result = isDeletable(taxon, config); |
|
973 | 979 |
|
974 | 980 |
if (result.isOk()){ |
975 | 981 |
// --- DeleteSynonymRelations |
... | ... | |
1242 | 1248 |
DeleteResult result = new DeleteResult(); |
1243 | 1249 |
if (synonym == null){ |
1244 | 1250 |
result.setAbort(); |
1251 |
result.addException(new Exception("The synonym was already deleted.")); |
|
1245 | 1252 |
return result; |
1246 | 1253 |
} |
1247 | 1254 |
|
1248 | 1255 |
if (config == null){ |
1249 | 1256 |
config = new SynonymDeletionConfigurator(); |
1250 | 1257 |
} |
1258 |
|
|
1251 | 1259 |
result = isDeletable(synonym, config); |
1252 | 1260 |
|
1253 | 1261 |
|
Also available in: Unified diff
add null check for delete and minor