Project

General

Profile

Revision 32c018db

ID32c018db3e006b0019e4ed7bfb245d442a299cd5
Parent 59734b3b
Child 5090574f

Added by Andreas Müller 11 months ago

ref #7392 remove cascade from relationships and adapt tests (up to service layer)

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/HybridRelationship.java
21 21
import javax.xml.bind.annotation.XmlType;
22 22

  
23 23
import org.apache.log4j.Logger;
24
import org.hibernate.annotations.Cascade;
25
import org.hibernate.annotations.CascadeType;
26 24
import org.hibernate.envers.Audited;
27 25

  
28 26
import eu.etaxonomy.cdm.model.common.RelationshipBase;
......
71 69
    @XmlIDREF
72 70
    @XmlSchemaType(name = "IDREF")
73 71
    @ManyToOne(fetch=FetchType.LAZY)
74
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
72
//    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
75 73
	private TaxonName relatedFrom;
76 74

  
77 75
	@XmlElement(name = "RelatedTo")
78 76
    @XmlIDREF
79 77
    @XmlSchemaType(name = "IDREF")
80 78
    @ManyToOne(fetch=FetchType.LAZY)
81
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
79
//    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
82 80
	private TaxonName relatedTo;
83 81

  
84 82
    @XmlElement(name = "Type")
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/NameRelationship.java
20 20
import javax.xml.bind.annotation.XmlType;
21 21

  
22 22
import org.apache.log4j.Logger;
23
import org.hibernate.annotations.Cascade;
24
import org.hibernate.annotations.CascadeType;
25 23
import org.hibernate.envers.Audited;
26 24

  
27 25
import eu.etaxonomy.cdm.model.common.RelationshipBase;
......
58 56
@NamesWithHomotypicRelationshipsMustBelongToSameGroup(groups = Level3.class)
59 57
@BasionymsMustShareEpithetsAndAuthors(groups = Level3.class)
60 58
public class NameRelationship
61
            extends RelationshipBase<TaxonName, TaxonName, NameRelationshipType>
62
            implements Cloneable{
59
            extends RelationshipBase<TaxonName, TaxonName, NameRelationshipType>{
63 60
	private static final long serialVersionUID = -615987333520172043L;
64 61
	private static final Logger logger = Logger.getLogger(NameRelationship.class);
65 62

  
......
72 69
    @XmlIDREF
73 70
    @XmlSchemaType(name = "IDREF")
74 71
    @ManyToOne(fetch=FetchType.LAZY)
75
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
72
//    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
76 73
	private TaxonName relatedFrom;
77 74

  
78 75
	@XmlElement(name = "RelatedTo")
79 76
    @XmlIDREF
80 77
    @XmlSchemaType(name = "IDREF")
81 78
    @ManyToOne(fetch=FetchType.LAZY)
82
    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
79
//    @Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
83 80
	private TaxonName relatedTo;
84 81

  
85 82
    @XmlElement(name = "Type")
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/TaxonRelationship.java
22 22
import javax.xml.bind.annotation.XmlType;
23 23

  
24 24
import org.apache.log4j.Logger;
25
import org.hibernate.annotations.Cascade;
26
import org.hibernate.annotations.CascadeType;
27 25
import org.hibernate.envers.Audited;
28 26
import org.hibernate.search.annotations.Indexed;
29 27
import org.hibernate.search.annotations.IndexedEmbedded;
......
63 61
    @XmlIDREF
64 62
    @XmlSchemaType(name = "IDREF")
65 63
    @ManyToOne(fetch=FetchType.EAGER)
66
    @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
64
//    @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
67 65
    @IndexedEmbedded(includeEmbeddedObjectId=true, depth=1)
68 66
    private Taxon relatedFrom;
69 67

  
......
71 69
    @XmlIDREF
72 70
    @XmlSchemaType(name = "IDREF")
73 71
    @ManyToOne(fetch=FetchType.EAGER)
74
    @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
72
//  @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
75 73
    @IndexedEmbedded(includeEmbeddedObjectId=true, depth=1)
76 74
    private Taxon relatedTo;
77 75

  
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonServiceImpl.java
328 328
*/
329 329
        // Create a taxon with synonym name
330 330
        Taxon fromTaxon = Taxon.NewInstance(synonymName, null);
331
        save(fromTaxon);
331 332
        fromTaxon.setAppendedPhrase(synonym.getAppendedPhrase());
332 333

  
333 334
        // Add taxon relation
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/NameServiceImplTest.java
112 112
        name1.addRelationshipToName(nameWithBasionym,nameRelType , null, null, null);
113 113
//		nameWithBasionym.addBasionym(name1);
114 114
        nameService.save(name1);
115
        nameService.save(nameWithBasionym);
115 116
        commitAndStartNewTransaction(tableNames);
116 117

  
117 118

  
......
155 156
        NameRelationshipType nameRelType = (NameRelationshipType)termService.find(NameRelationshipType.BASIONYM().getUuid());
156 157
        name1.addRelationshipToName(nameWithBasionym,nameRelType , null, null, null);
157 158
        nameService.save(name1);
159
        nameService.save(nameWithBasionym);
158 160
        commitAndStartNewTransaction(tableNames);
159 161
        NameDeletionConfigurator config = new NameDeletionConfigurator();
160 162

  
......
191 193
        NameRelationshipType nameRelType = (NameRelationshipType)termService.find(NameRelationshipType.BASIONYM().getUuid());
192 194
        name1.addRelationshipToName(nameWithBasionym,nameRelType , null, null, null);
193 195
        nameService.save(name1);
196
        nameService.save(nameWithBasionym);
194 197
        commitAndStartNewTransaction(tableNames);
195 198
        NameDeletionConfigurator config = new NameDeletionConfigurator();
196 199

  
......
227 230
        NameRelationshipType nameRelType = (NameRelationshipType)termService.find(NameRelationshipType.BASIONYM().getUuid());
228 231
        basionym.addRelationshipToName(name1,nameRelType , null, null, null);
229 232
        nameService.save(name1);
233
        nameService.save(basionym);
230 234
        commitAndStartNewTransaction(tableNames);
231 235
        NameDeletionConfigurator config = new NameDeletionConfigurator();
232 236
        config.setIgnoreHasBasionym(false);
......
270 274
        HybridRelationshipType relType = (HybridRelationshipType)termService.find(HybridRelationshipType.FIRST_PARENT().getUuid());
271 275
        name1.addHybridParent(parent, relType, null);
272 276
        nameService.save(name1);
277
        nameService.save(parent);
273 278
        commitAndStartNewTransaction(tableNames); //otherwise first save is rolled back with following failing delete
274 279
        Assert.assertEquals("'Parent' should be a parent in a hybrid relation.", 1,parent.getHybridParentRelations().size());
275
//		printDataSet(System.out, tableNames);
276 280

  
277 281
        //parent
278 282

  
279
         name1 = nameService.find(name1.getUuid());
280
         DeleteResult result = nameService.delete(name1);
281
         if (result.isError()){
283
        name1 = nameService.find(name1.getUuid());
284
        DeleteResult result = nameService.delete(name1);
285
        if (result.isError()){
282 286
            Assert.fail("Delete should throw NO exception when deleting a hybrid child: " + result.getExceptions().iterator().next().getMessage());
283 287
        }
284 288
        commitAndStartNewTransaction(tableNames);
......
291 295
        name1 = TaxonNameFactory.NewBotanicalInstance(getSpeciesRank());
292 296
        name1.addHybridChild(child, relType, null);
293 297
        nameService.save(name1);
298
        nameService.save(child);
294 299
        commitAndStartNewTransaction(tableNames);
295 300

  
296 301

  
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImplTest.java
146 146

  
147 147
		//nameRelations
148 148

  
149
		t1.getName().addRelationshipFromName(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), NameRelationshipType.ALTERNATIVE_NAME(), null );
149
		TaxonName relatedName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
150
		t1.getName().addRelationshipFromName(relatedName, NameRelationshipType.ALTERNATIVE_NAME(), null );
150 151

  
151 152
		//taxonRelations
152
		t1.addTaxonRelation(Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null), TaxonRelationshipType.CONGRUENT_OR_EXCLUDES(), null, null);
153
		Taxon relatedTaxon = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null);
154
		t1.addTaxonRelation(relatedTaxon, TaxonRelationshipType.CONGRUENT_OR_EXCLUDES(), null, null);
153 155
		Synonym synonym = Synonym.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null);
154
		UUID uuidSynonym = taxonService.save(synonym).getUuid();
156
		taxonService.save(t1);
157
		taxonService.save(relatedTaxon);
158
		nameService.save(relatedName);
155 159

  
156 160
		t1.addHomotypicSynonym(synonym);
157 161
		taxonService.saveOrUpdate(t1);
......
234 238
		polKeyService.save(polKey);
235 239

  
236 240
		//nameRelations
237
		t1.getName().addRelationshipFromName(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), NameRelationshipType.ALTERNATIVE_NAME(), null );
241
		TaxonName relatedName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
242
		t1.getName().addRelationshipFromName(relatedName, NameRelationshipType.ALTERNATIVE_NAME(), null );
238 243
		TaxonName name1 = t1.getName();
239 244
		UUID name1UUID = name1.getUuid();
240 245
		//taxonRelations
241
		t1.addTaxonRelation(Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null), TaxonRelationshipType.CONGRUENT_OR_EXCLUDES(), null, null);
246
		Taxon relatedTaxon = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null);
247
		t1.addTaxonRelation(relatedTaxon, TaxonRelationshipType.CONGRUENT_OR_EXCLUDES(), null, null);
242 248
		Synonym t1HomotypSynonym = Synonym.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null);
243 249

  
244 250
		t1.addHomotypicSynonym(t1HomotypSynonym);
......
250 256
		Assert.assertTrue("taxon 2 must have no descriptions", t2.getDescriptions().size() == 0);
251 257

  
252 258
		//save
253
		UUID uuidSynonym = taxonService.save(t1HomotypSynonym).getUuid();
259
		taxonService.save(t1HomotypSynonym);
260
		taxonService.save(relatedTaxon);
261
		nameService.save(relatedName);
254 262

  
255 263
		//do it
256 264
		DeleteResult result = taxonNodeService.makeTaxonNodeASynonymOfAnotherTaxonNode
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/TaxonServiceImplTest.java
1409 1409
        assertNotNull(taxonName);
1410 1410
        TaxonName fromName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
1411 1411
        taxonName.addRelationshipFromName(fromName, NameRelationshipType.VALIDATED_BY_NAME(), null);
1412
        nameService.save(fromName);
1412 1413

  
1413 1414
        TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
1414 1415
        config.setDeleteNameIfPossible(true);
......
1775 1776

  
1776 1777
    	service.saveOrUpdate(c1Species);
1777 1778
       	service.saveOrUpdate(c2Species);
1779
       	service.save(c4Species);
1778 1780

  
1779 1781
    	//Tests
1780 1782
       	//default starting at species 1
......
1988 1990
            missName.setSpecificEpithet("lupium");
1989 1991
            missName.setCombinationAuthorship(deCandolle);
1990 1992
            missName.setUuid(SPECIES5_NAME_UUID);
1991
            Taxon misappliedName = Taxon.NewInstance(missName, sec);
1992
            childTaxon2.addMisappliedName(misappliedName, citationRef, "125");
1993
            Taxon misappliedNameTaxon = Taxon.NewInstance(missName, sec);
1994
            childTaxon2.addMisappliedName(misappliedNameTaxon, citationRef, "125");
1993 1995
            taxDesc = getTestDescription(descrIndex++);
1994 1996
           // taxDesc.setUuid(DESCRIPTION2_UUID);
1995 1997
            genusTaxon.addDescription(taxDesc);
1996 1998
            service.saveOrUpdate(genusTaxon);
1999
            service.save(misappliedNameTaxon);
1997 2000

  
1998 2001
            return genusTaxon;
1999 2002
        }

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)