use of eu.etaxonomy.cdm.model.occurrence.MediaSpecimen in project cdmlib by cybertaxonomy.
the class OccurrenceDaoHibernateImplTest method testGetMedia.
@Test
public void testGetMedia() {
MediaSpecimen unit = MediaSpecimen.NewInstance(SpecimenOrObservationType.Media);
SpecimenDescription desc = SpecimenDescription.NewInstance(unit);
desc.setImageGallery(true);
TextData textData = TextData.NewInstance(Feature.IMAGE());
desc.addElement(textData);
Media media1 = Media.NewInstance(URI.create("https://www.abc.de"), 5, "jpg", "jpg");
Media media2 = Media.NewInstance(URI.create("https://www.defg.de"), 5, "jpg", "jpg");
textData.addMedia(media1);
textData.addMedia(media2);
Media media3 = Media.NewInstance(URI.create("https://www.hij.de"), 5, "jpg", "jpg");
unit.setMediaSpecimen(media3);
dao.save(unit);
List<Media> media = dao.getMedia(unit, null, null, null);
Assert.assertEquals(3, media.size());
// test that paging works (note: the sorting is not a requirement for the method, but with current implementation it works; if implementation is changed the test may need to be adapted
List<Integer> ids = media.stream().map(m -> m.getId()).collect(Collectors.toList());
Collections.sort(ids);
Assert.assertEquals(ids.get(0), (Integer) media.get(0).getId());
Assert.assertEquals(ids.get(1), (Integer) media.get(1).getId());
Assert.assertEquals(ids.get(2), (Integer) media.get(2).getId());
media = dao.getMedia(unit, 2, 1, null);
Assert.assertEquals(1, media.size());
Assert.assertEquals(ids.get(2), (Integer) media.get(0).getId());
// test deduplication
unit.setMediaSpecimen(media2);
Assert.assertEquals(2, dao.countMedia(unit));
}
use of eu.etaxonomy.cdm.model.occurrence.MediaSpecimen in project cdmlib by cybertaxonomy.
the class OccurrenceDaoHibernateImplTest method testCountMedia.
@Test
public void testCountMedia() {
MediaSpecimen unit = MediaSpecimen.NewInstance(SpecimenOrObservationType.Media);
SpecimenDescription desc = SpecimenDescription.NewInstance(unit);
desc.setImageGallery(true);
TextData textData = TextData.NewInstance(Feature.IMAGE());
desc.addElement(textData);
Media media1 = Media.NewInstance(URI.create("https://www.abc.de"), 5, "jpg", "jpg");
Media media2 = Media.NewInstance(URI.create("https://www.abc.de"), 5, "jpg", "jpg");
textData.addMedia(media1);
textData.addMedia(media2);
Media media3 = Media.NewInstance(URI.create("https://www.abc.de"), 5, "jpg", "jpg");
unit.setMediaSpecimen(media3);
dao.save(unit);
Assert.assertEquals(3, dao.countMedia(unit));
unit.setMediaSpecimen(media2);
Assert.assertEquals(2, dao.countMedia(unit));
}
use of eu.etaxonomy.cdm.model.occurrence.MediaSpecimen in project cdmlib by cybertaxonomy.
the class TypeDesignationSetFormatterTest method setUp.
@Before
public void setUp() throws Exception {
Person person1 = Person.NewInstance("DC", "Decandolle", "A.", null);
Person person2 = Person.NewInstance("Hab.", "Haber", "M.", null);
Person person3 = Person.NewInstance("Moler", "Moler", "A.P.", null);
team = Team.NewInstance(person1, person2, person3);
book = ReferenceFactory.newBook();
book.setAuthorship(team);
book.setDatePublished(TimePeriodParser.parseStringVerbatim("11 Apr 1962"));
ntd = NameTypeDesignation.NewInstance();
ntd.setId(1);
TaxonName typeName = TaxonNameFactory.PARSED_BOTANICAL("Prionus coriatius L.");
ntd.setTypeName(typeName);
// Reference citation = ReferenceFactory.newGeneric();
// citation.setTitleCache("Species Plantarum", true);
// ntd.setCitation(citation);
// ntd.addPrimaryTaxonomicSource(citation, null);
ntd_LT = NameTypeDesignation.NewInstance();
ntd_LT.setTypeStatus(NameTypeDesignationStatus.LECTOTYPE());
TaxonName typeName2 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
typeName2.setTitleCache("Prionus arealus L.", true);
ntd_LT.setTypeName(typeName2);
ntd_LT.setCitation(book);
FieldUnit fu_1 = FieldUnit.NewInstance();
fu_1.setId(1);
fu_1.setTitleCache("Testland, near Bughausen, A.Kohlbecker 81989, 2017", true);
FieldUnit fu_2 = FieldUnit.NewInstance();
fu_2.setId(2);
fu_2.setTitleCache("Dreamland, near Kissingen, A.Kohlbecker 66211, 2017", true);
std_HT = SpecimenTypeDesignation.NewInstance();
std_HT.setId(1);
DerivedUnit specimen_HT = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
Collection collection_OHA = Collection.NewInstance("OHA", null);
specimen_HT.setCollection(collection_OHA);
specimen_HT.setAccessionNumber("OHA 1234");
createDerivationEvent(fu_1, specimen_HT);
specimen_HT.getOriginals().add(fu_1);
std_HT.setTypeSpecimen(specimen_HT);
std_HT.setTypeStatus(SpecimenTypeDesignationStatus.HOLOTYPE());
std_IT = SpecimenTypeDesignation.NewInstance();
std_IT.setId(2);
DerivedUnit specimen_IT = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
specimen_IT.setTitleCache("BER", true);
createDerivationEvent(fu_1, specimen_IT);
std_IT.setTypeSpecimen(specimen_IT);
std_IT.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
std_LT = SpecimenTypeDesignation.NewInstance();
DerivedUnit specimen_LT = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
specimen_LT.setTitleCache("LEC", true);
createDerivationEvent(fu_1, specimen_LT);
std_LT.setTypeSpecimen(specimen_LT);
std_LT.setTypeStatus(SpecimenTypeDesignationStatus.LECTOTYPE());
std_LT.setCitation(book);
std_IT_2 = SpecimenTypeDesignation.NewInstance();
std_IT_2.setId(3);
DerivedUnit specimen_IT_2 = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
specimen_IT_2.setTitleCache("KEW", true);
createDerivationEvent(fu_1, specimen_IT_2);
std_IT_2.setTypeSpecimen(specimen_IT_2);
std_IT_2.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
std_IT_3 = SpecimenTypeDesignation.NewInstance();
std_IT_3.setId(4);
DerivedUnit specimen_IT_3 = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
specimen_IT_3.setTitleCache("M", true);
createDerivationEvent(fu_2, specimen_IT_3);
std_IT_3.setTypeSpecimen(specimen_IT_3);
std_IT_3.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
mtd_HT_published = SpecimenTypeDesignation.NewInstance();
mtd_HT_published.setId(5);
MediaSpecimen mediaSpecimen_published = (MediaSpecimen) DerivedUnit.NewInstance(SpecimenOrObservationType.Media);
Media media = Media.NewInstance();
Reference ref = ReferenceFactory.newGeneric();
ref.setTitleCache("A.K. & W.K (2008) Algae of the BGBM", true);
media.addSource(IdentifiableSource.NewPrimaryMediaSourceInstance(ref, "p.33"));
mediaSpecimen_published.setMediaSpecimen(media);
createDerivationEvent(fu_1, mediaSpecimen_published);
mtd_HT_published.setTypeSpecimen(mediaSpecimen_published);
mtd_HT_published.setTypeStatus(SpecimenTypeDesignationStatus.HOLOTYPE());
mtd_IT_unpublished = SpecimenTypeDesignation.NewInstance();
mtd_IT_unpublished.setId(6);
MediaSpecimen mediaSpecimen_unpublished = (MediaSpecimen) DerivedUnit.NewInstance(SpecimenOrObservationType.Media);
eu.etaxonomy.cdm.model.occurrence.Collection collection = eu.etaxonomy.cdm.model.occurrence.Collection.NewInstance();
collection.setCode("B");
mediaSpecimen_unpublished.setCollection(collection);
mediaSpecimen_unpublished.setAccessionNumber("Slide A565656");
createDerivationEvent(fu_1, mediaSpecimen_unpublished);
mtd_IT_unpublished.setTypeSpecimen(mediaSpecimen_unpublished);
mtd_IT_unpublished.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
}
use of eu.etaxonomy.cdm.model.occurrence.MediaSpecimen in project cdmlib by cybertaxonomy.
the class TypeDesignationSetManagerTest method init.
@Before
public void init() {
Person person1 = Person.NewInstance("DC", "Decandolle", "A.", null);
Person person2 = Person.NewInstance("Hab.", "Haber", "M.", null);
Person person3 = Person.NewInstance("Moler", "Moler", "A.P.", null);
team = Team.NewInstance(person1, person2, person3);
book = ReferenceFactory.newBook();
book.setAuthorship(team);
book.setDatePublished(TimePeriodParser.parseStringVerbatim("11 Apr 1962"));
ntd = NameTypeDesignation.NewInstance();
ntd.setId(1);
TaxonName typeName = TaxonNameFactory.NewBacterialInstance(Rank.SPECIES());
typeName.setTitleCache("Prionus coriatius L.", true);
ntd.setTypeName(typeName);
// Reference citation = ReferenceFactory.newGeneric();
// citation.setTitleCache("Species Plantarum", true);
// ntd.setCitation(citation);
// ntd.addPrimaryTaxonomicSource(citation, null);
ntd_LT = NameTypeDesignation.NewInstance();
ntd_LT.setTypeStatus(NameTypeDesignationStatus.LECTOTYPE());
TaxonName typeName2 = TaxonNameFactory.NewBacterialInstance(Rank.SPECIES());
typeName2.setTitleCache("Prionus arealus L.", true);
ntd_LT.setTypeName(typeName2);
ntd_LT.setCitation(book);
FieldUnit fu_1 = FieldUnit.NewInstance();
fu_1.setId(1);
fu_1.setTitleCache("Testland, near Bughausen, A.Kohlbecker 81989, 2017", true);
FieldUnit fu_2 = FieldUnit.NewInstance();
fu_2.setId(2);
fu_2.setTitleCache("Dreamland, near Kissingen, A.Kohlbecker 66211, 2017", true);
std_HT = SpecimenTypeDesignation.NewInstance();
std_HT.setId(1);
DerivedUnit specimen_HT = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
specimen_HT.setTitleCache("OHA", true);
createDerivationEvent(fu_1, specimen_HT);
specimen_HT.getOriginals().add(fu_1);
std_HT.setTypeSpecimen(specimen_HT);
std_HT.setTypeStatus(SpecimenTypeDesignationStatus.HOLOTYPE());
std_IT = SpecimenTypeDesignation.NewInstance();
std_IT.setId(2);
DerivedUnit specimen_IT = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
specimen_IT.setTitleCache("BER", true);
createDerivationEvent(fu_1, specimen_IT);
std_IT.setTypeSpecimen(specimen_IT);
std_IT.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
std_LT = SpecimenTypeDesignation.NewInstance();
DerivedUnit specimen_LT = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
specimen_LT.setTitleCache("LEC", true);
createDerivationEvent(fu_1, specimen_LT);
std_LT.setTypeSpecimen(specimen_LT);
std_LT.setTypeStatus(SpecimenTypeDesignationStatus.LECTOTYPE());
std_LT.setCitation(book);
std_IT_2 = SpecimenTypeDesignation.NewInstance();
std_IT_2.setId(3);
DerivedUnit specimen_IT_2 = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
specimen_IT_2.setTitleCache("KEW", true);
createDerivationEvent(fu_1, specimen_IT_2);
std_IT_2.setTypeSpecimen(specimen_IT_2);
std_IT_2.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
std_IT_3 = SpecimenTypeDesignation.NewInstance();
std_IT_3.setId(4);
DerivedUnit specimen_IT_3 = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
specimen_IT_3.setTitleCache("M", true);
createDerivationEvent(fu_2, specimen_IT_3);
std_IT_3.setTypeSpecimen(specimen_IT_3);
std_IT_3.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
mtd_HT_published = SpecimenTypeDesignation.NewInstance();
mtd_HT_published.setId(5);
MediaSpecimen mediaSpecimen_published = (MediaSpecimen) DerivedUnit.NewInstance(SpecimenOrObservationType.Media);
Media media = Media.NewInstance();
Reference ref = ReferenceFactory.newBook();
ref.setTitle("Algae of the BGBM");
ref.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(2008));
ref.setAuthorship(Team.NewInstance(Person.NewInstance(null, "Kohlbecker", "A.", null), Person.NewInstance(null, "Kusber", "W.-H.", null)));
media.addSource(IdentifiableSource.NewPrimaryMediaSourceInstance(ref, "33"));
mediaSpecimen_published.setMediaSpecimen(media);
createDerivationEvent(fu_1, mediaSpecimen_published);
mtd_HT_published.setTypeSpecimen(mediaSpecimen_published);
mtd_HT_published.setTypeStatus(SpecimenTypeDesignationStatus.HOLOTYPE());
mtd_IT_unpublished = SpecimenTypeDesignation.NewInstance();
mtd_IT_unpublished.setId(6);
MediaSpecimen mediaSpecimen_unpublished = (MediaSpecimen) DerivedUnit.NewInstance(SpecimenOrObservationType.Media);
eu.etaxonomy.cdm.model.occurrence.Collection collection = eu.etaxonomy.cdm.model.occurrence.Collection.NewInstance();
collection.setCode("B");
mediaSpecimen_unpublished.setCollection(collection);
mediaSpecimen_unpublished.setAccessionNumber("Slide A565656");
createDerivationEvent(fu_1, mediaSpecimen_unpublished);
mtd_IT_unpublished.setTypeSpecimen(mediaSpecimen_unpublished);
mtd_IT_unpublished.setTypeStatus(SpecimenTypeDesignationStatus.ISOTYPE());
}
use of eu.etaxonomy.cdm.model.occurrence.MediaSpecimen in project cdmlib by cybertaxonomy.
the class TypeDesignationSetManagerTest method test_mediaType.
@Test
public void test_mediaType() {
for (int i = 0; i < 10; i++) {
init();
// repeat 10 times to assure the order of typedesignations is fix in the representations
TaxonName typifiedName = TaxonNameFactory.NewBacterialInstance(Rank.SPECIES());
typifiedName.setTitleCache("Prionus coriatius L.", true);
typifiedName.addTypeDesignation(mtd_HT_published, false);
typifiedName.addTypeDesignation(mtd_IT_unpublished, false);
TypeDesignationSetManager typeDesignationManager = new TypeDesignationSetManager(typifiedName);
typeDesignationManager.addTypeDesigations(mtd_HT_published);
typeDesignationManager.addTypeDesigations(mtd_IT_unpublished);
assertEquals("failed after repeating " + i + " times", "Prionus coriatius L.\u202F\u2013\u202FTypes: Testland, near Bughausen, A.Kohlbecker 81989, 2017 (holotype: [icon] in Kohlbecker & Kusber 2008: 33; isotype: [icon] B Slide A565656)", typeDesignationManager.print(WITH_CITATION, WITH_TYPE_LABEL, WITH_NAME));
Media media = ((MediaSpecimen) mtd_HT_published.getTypeSpecimen()).getMediaSpecimen();
Reference ref2 = ReferenceFactory.newBook();
ref2.setDatePublished(VerbatimTimePeriod.NewVerbatimInstance(2009));
ref2.setAuthorship(Person.NewInstance(null, "Mueller", "A.", null));
IdentifiableSource newSource = IdentifiableSource.NewPrimaryMediaSourceInstance(ref2, "tab. 4");
media.addSource(newSource);
String with2Sources = typeDesignationManager.print(WITH_CITATION, WITH_TYPE_LABEL, WITH_NAME);
Assert.assertTrue("failed after repeating " + i + " times", // the order of the sources is currently not yet defined (rare case), therefore 2 possibilities
with2Sources.equals("Prionus coriatius L.\u202F\u2013\u202FTypes: Testland, near Bughausen, A.Kohlbecker 81989, 2017 (holotype: [icon] in Mueller 2009: tab. 4, Kohlbecker & Kusber 2008: 33; isotype: [icon] B Slide A565656)") || with2Sources.equals("Prionus coriatius L.\u202F\u2013\u202FTypes: Testland, near Bughausen, A.Kohlbecker 81989, 2017 (holotype: [icon] in Kohlbecker & Kusber 2008: 33, Mueller 2009: tab. 4; isotype: [icon] B Slide A565656)"));
}
}
Aggregations