use of eu.etaxonomy.cdm.strategy.merge.MergeException in project cdmlib by cybertaxonomy.
the class AgentServiceImplTest method testConvertTeam2Person.
@Test
@DataSets({ @DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"), @DataSet(value = "/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml") })
public void testConvertTeam2Person() {
String fullAuthor = "Original author";
String nomTitle = "Abrev. aut.";
Team team = Team.NewTitledInstance(fullAuthor, nomTitle);
Annotation annotation = Annotation.NewDefaultLanguageInstance("Meine annotation");
team.addAnnotation(annotation);
team.setContact(getContact());
TaxonName name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
name.setCombinationAuthorship(team);
service.save(team);
nameSerivce.save(name);
UpdateResult result = null;
Person person = null;
try {
result = service.convertTeam2Person(team);
person = (Person) result.getCdmEntity();
} catch (IllegalArgumentException e) {
Assert.fail("No IllegalArgumentException should be thrown");
} catch (MergeException e) {
Assert.fail("No Merge exception should be thrown");
}
Assert.assertNotNull(person);
Assert.assertEquals("Title cache must be equal", fullAuthor, person.getTitleCache());
Assert.assertEquals("Nom. title must be equal", nomTitle, person.getNomenclaturalTitleCache());
Assert.assertEquals("Annotations should be moved", 1, person.getAnnotations().size());
Assert.assertNotNull("Contact must be copied too", person.getContact());
Assert.assertEquals("person must be combination author now", person, name.getCombinationAuthorship());
}
use of eu.etaxonomy.cdm.strategy.merge.MergeException in project cdmlib by cybertaxonomy.
the class AgentServiceImplTest method testConvertTeam2PersonWithMember.
@Test
@DataSets({ @DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"), @DataSet(value = "/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml") })
public void testConvertTeam2PersonWithMember() {
String fullAuthor = "Original author";
String nomTitle = "Abrev. aut.";
Team team = Team.NewTitledInstance(fullAuthor, nomTitle);
Annotation annotation = Annotation.NewDefaultLanguageInstance("Meine annotation");
team.addAnnotation(annotation);
Annotation annotation2 = Annotation.NewDefaultLanguageInstance("Meine annotation2");
team.addAnnotation(annotation2);
team.setContact(getContact());
TaxonName name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
name.setCombinationAuthorship(team);
Person member = Person.NewTitledInstance("Member person");
member.setNomenclaturalTitle("Memb. pers.");
Annotation annotation3 = Annotation.NewDefaultLanguageInstance("Meine annotation3");
member.addAnnotation(annotation3);
team.addTeamMember(member);
service.save(team);
nameSerivce.save(name);
Person person = null;
UpdateResult result = null;
try {
result = service.convertTeam2Person(team);
person = (Person) result.getCdmEntity();
} catch (IllegalArgumentException e) {
Assert.fail("No IllegalArgumentException should be thrown");
} catch (MergeException e) {
Assert.fail("No Merge exception should be thrown");
}
Assert.assertNotNull(person);
Assert.assertEquals("Convert result and 'member' must be equal'", member, person);
Assert.assertEquals("Title cache must be equal", "Member person", person.getTitleCache());
Assert.assertEquals("Nom. title must be equal", "Memb. pers.", person.getNomenclaturalTitleCache());
// FIXME should annotations be taken only from member ??
// Assert.assertEquals("Annotations should be moved", 1, person.getAnnotations().size());
String annotationText = person.getAnnotations().iterator().next().getText();
// Assert.assertEquals("The only annotation should be annotation 3", annotation3.getText(), annotationText);
// FIXME currently merge mode is still MERGE for user defined fields
// Assert.assertNull("Contact must not be copied", person.getContact());
Assert.assertEquals("person must be combination author now", person, name.getCombinationAuthorship());
}
use of eu.etaxonomy.cdm.strategy.merge.MergeException in project cdmlib by cybertaxonomy.
the class CdmGenericDaoImplTest method testReallocatePersonTeam.
@Test
public void testReallocatePersonTeam() throws MergeException {
TaxonName name1 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
name1.setTitleCache("BotanicalName1", true);
IBook book1 = ReferenceFactory.newBook();
Team team1 = Team.NewInstance();
Team team2 = Team.NewInstance();
team1.setTitleCache("team1", true);
team2.setTitleCache("team2", true);
Person person1 = Person.NewTitledInstance("person1");
Person person2 = Person.NewTitledInstance("person2");
team1.setNomenclaturalTitleCache("T.1", true);
String street1 = "Strasse1";
person1.setContact(Contact.NewInstance(street1, "12345", "Berlin", Country.ARGENTINAARGENTINEREPUBLIC(), "pobox", "Region", "a@b.de", "f12345", "+49-30-123456", URI.create("www.abc.de"), Point.NewInstance(2.4, 3.2, ReferenceSystem.WGS84(), 3)));
team2.setContact(Contact.NewInstance("Street2", null, "London", null, null, null, null, "874599873", null, null, null));
String street3 = "Street3";
team2.addAddress(street3, null, null, null, null, null, Point.NewInstance(1.1, 2.2, null, 4));
String emailAddress1 = "Email1";
team1.addEmailAddress(emailAddress1);
// FIXME
// team2.addTeamMember(person1);
team2.addTeamMember(person2);
String emailAddress2 = "Email2";
team2.addEmailAddress(emailAddress2);
Credit credit1 = Credit.NewInstance(team2, "credit1");
book1.addCredit(credit1);
agentDao.save(team1);
agentDao.save(team2);
agentDao.save(person1);
agentDao.save(person2);
cdmGenericDao.save((Reference) book1);
// starting condition
name1.setCombinationAuthorship(person1);
Assert.assertEquals("Name1 should have person1 as combination author", person1, name1.getCombinationAuthorship());
DefaultMergeStrategy strategy = DefaultMergeStrategy.NewInstance(TeamOrPersonBase.class);
// strategy.setOnlyReallocateLinks(true);
FieldUnit fieldUnit1 = FieldUnit.NewInstance();
fieldUnit1.setPrimaryCollector(person1);
cdmGenericDao.save(fieldUnit1);
try {
cdmGenericDao.merge(team2, person1, strategy);
Assert.fail("We expect exception because fieldunit.primaryCollector is of type person");
} catch (MergeException e) {
if (!e.getMessage().contains("Object can not be merged into new object as it is referenced in a way that does not allow merging")) {
Assert.fail("The exception should be the one thrown by DeduplicationHelper.reallocateByHolder(...)");
}
// clean up for next test
fieldUnit1.setPrimaryCollector(null);
} catch (Exception e) {
Assert.fail("Unhandled exception during merge");
}
Assert.assertEquals("Name1 should still have person1 as combination author", person1, name1.getCombinationAuthorship());
// test collections
team1.addTeamMember(person1);
try {
cdmGenericDao.merge(team2, person1, strategy);
Assert.fail("We expect exception because fieldunit.primaryCollector is of type person");
} catch (MergeException e) {
if (!e.getMessage().contains("Object can not be merged into new object as it is referenced in a way that does not allow merging")) {
Assert.fail("The exception should be the one thrown by DeduplicationHelper.reallocateByHolder(...)");
}
// clean up for next test
team1.removeTeamMember(person1);
} catch (Exception e) {
Assert.fail("Unhandled exception during merge");
}
Assert.assertEquals("Name1 should still have person1 as combination author", person1, name1.getCombinationAuthorship());
// test successful merge
cdmGenericDao.save(name1);
cdmGenericDao.merge(team2, person1, strategy);
Assert.assertEquals("Name1 should have team2 as combination author now", team2, name1.getCombinationAuthorship());
}
use of eu.etaxonomy.cdm.strategy.merge.MergeException in project cdmlib by cybertaxonomy.
the class CdmGenericDaoImplTest method testDelete.
// ***************** TESTS **************************************************
@Test
@DataSets({ @DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"), @DataSet("/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml") })
public void testDelete() {
Reference ref1 = ReferenceFactory.newBook();
Reference ref2 = ReferenceFactory.newBook();
Annotation annotation = Annotation.NewInstance("Anno1", null);
ref1.addAnnotation(annotation);
cdmGenericDao.saveOrUpdate(ref1);
cdmGenericDao.saveOrUpdate(ref2);
List<Reference> list = cdmGenericDao.list(Reference.class, 10, 0, null, null);
try {
cdmGenericDao.merge(ref2, ref1, null);
} catch (MergeException e) {
Assert.fail();
}
commitAndStartNewTransaction(null);
list = cdmGenericDao.list(Reference.class, 10, 0, null, null);
Assert.assertEquals(1, list.size());
}
use of eu.etaxonomy.cdm.strategy.merge.MergeException in project cdmlib by cybertaxonomy.
the class Contact method merge.
// ************************ MERGE /MATCH ***************************/
public void merge(Contact contact2) throws MergeException {
if (contact2 != null) {
mergeList(this.getEmailAddresses(), contact2.getEmailAddresses());
mergeList(this.getFaxNumbers(), contact2.getFaxNumbers());
mergeList(this.getPhoneNumbers(), contact2.getPhoneNumbers());
mergeList(this.getUrls(), contact2.getUrls());
for (Address address : contact2.getAddresses()) {
try {
if (this.addresses == null) {
this.addresses = new HashSet<>();
}
this.addresses.add(address.clone());
} catch (CloneNotSupportedException e) {
throw new MergeException("Address must implement Cloneable");
}
}
}
}
Aggregations