Search in sources :

Example 1 with MediaSpecimen

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));
}
Also used : SpringBeanByType(org.unitils.spring.annotation.SpringBeanByType) MediaSpecimen(eu.etaxonomy.cdm.model.occurrence.MediaSpecimen) BeforeClass(org.junit.BeforeClass) CdmIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmIntegrationTest) TextData(eu.etaxonomy.cdm.model.description.TextData) Test(org.junit.Test) DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) Media(eu.etaxonomy.cdm.model.media.Media) StringUtils(org.h2.util.StringUtils) List(java.util.List) SpecimenOrObservationType(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType) IOccurrenceDao(eu.etaxonomy.cdm.persistence.dao.occurrence.IOccurrenceDao) Feature(eu.etaxonomy.cdm.model.description.Feature) Assert(org.junit.Assert) Collections(java.util.Collections) Before(org.junit.Before) URI(eu.etaxonomy.cdm.common.URI) SpecimenDescription(eu.etaxonomy.cdm.model.description.SpecimenDescription) SpecimenDescription(eu.etaxonomy.cdm.model.description.SpecimenDescription) MediaSpecimen(eu.etaxonomy.cdm.model.occurrence.MediaSpecimen) TextData(eu.etaxonomy.cdm.model.description.TextData) Media(eu.etaxonomy.cdm.model.media.Media) CdmIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmIntegrationTest) Test(org.junit.Test)

Example 2 with MediaSpecimen

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));
}
Also used : SpecimenDescription(eu.etaxonomy.cdm.model.description.SpecimenDescription) MediaSpecimen(eu.etaxonomy.cdm.model.occurrence.MediaSpecimen) TextData(eu.etaxonomy.cdm.model.description.TextData) Media(eu.etaxonomy.cdm.model.media.Media) CdmIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmIntegrationTest) Test(org.junit.Test)

Example 3 with MediaSpecimen

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());
}
Also used : DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) FieldUnit(eu.etaxonomy.cdm.model.occurrence.FieldUnit) Reference(eu.etaxonomy.cdm.model.reference.Reference) TypedEntityReference(eu.etaxonomy.cdm.ref.TypedEntityReference) MediaSpecimen(eu.etaxonomy.cdm.model.occurrence.MediaSpecimen) Media(eu.etaxonomy.cdm.model.media.Media) Collection(eu.etaxonomy.cdm.model.occurrence.Collection) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) Collection(eu.etaxonomy.cdm.model.occurrence.Collection) Person(eu.etaxonomy.cdm.model.agent.Person) Before(org.junit.Before)

Example 4 with MediaSpecimen

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());
}
Also used : DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) FieldUnit(eu.etaxonomy.cdm.model.occurrence.FieldUnit) Reference(eu.etaxonomy.cdm.model.reference.Reference) TypedEntityReference(eu.etaxonomy.cdm.ref.TypedEntityReference) MediaSpecimen(eu.etaxonomy.cdm.model.occurrence.MediaSpecimen) Media(eu.etaxonomy.cdm.model.media.Media) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) Collection(eu.etaxonomy.cdm.model.occurrence.Collection) Person(eu.etaxonomy.cdm.model.agent.Person) Before(org.junit.Before)

Example 5 with MediaSpecimen

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)"));
    }
}
Also used : Reference(eu.etaxonomy.cdm.model.reference.Reference) TypedEntityReference(eu.etaxonomy.cdm.ref.TypedEntityReference) MediaSpecimen(eu.etaxonomy.cdm.model.occurrence.MediaSpecimen) Media(eu.etaxonomy.cdm.model.media.Media) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) IdentifiableSource(eu.etaxonomy.cdm.model.common.IdentifiableSource) Test(org.junit.Test)

Aggregations

MediaSpecimen (eu.etaxonomy.cdm.model.occurrence.MediaSpecimen)23 DerivedUnit (eu.etaxonomy.cdm.model.occurrence.DerivedUnit)14 Media (eu.etaxonomy.cdm.model.media.Media)13 Test (org.junit.Test)9 SpecimenTypeDesignation (eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation)6 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)5 FieldUnit (eu.etaxonomy.cdm.model.occurrence.FieldUnit)5 MediaRepresentation (eu.etaxonomy.cdm.model.media.MediaRepresentation)4 Collection (eu.etaxonomy.cdm.model.occurrence.Collection)4 Person (eu.etaxonomy.cdm.model.agent.Person)3 IdentifiableSource (eu.etaxonomy.cdm.model.common.IdentifiableSource)3 SpecimenDescription (eu.etaxonomy.cdm.model.description.SpecimenDescription)3 TextData (eu.etaxonomy.cdm.model.description.TextData)3 DnaSample (eu.etaxonomy.cdm.model.molecular.DnaSample)3 DerivationEvent (eu.etaxonomy.cdm.model.occurrence.DerivationEvent)3 GatheringEvent (eu.etaxonomy.cdm.model.occurrence.GatheringEvent)3 Reference (eu.etaxonomy.cdm.model.reference.Reference)3 DefinedTerm (eu.etaxonomy.cdm.model.term.DefinedTerm)3 TypedEntityReference (eu.etaxonomy.cdm.ref.TypedEntityReference)3 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)3