Search in sources :

Example 16 with MediaSpecimen

use of eu.etaxonomy.cdm.model.occurrence.MediaSpecimen in project cdmlib by cybertaxonomy.

the class OccurrenceServiceImpl method getMediaInHierarchy.

@Override
public Pager<Media> getMediaInHierarchy(SpecimenOrObservationBase<?> rootOccurence, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
    List<Media> media = new ArrayList<>();
    // media specimens
    if (rootOccurence.isInstanceOf(MediaSpecimen.class)) {
        MediaSpecimen mediaSpecimen = HibernateProxyHelper.deproxy(rootOccurence, MediaSpecimen.class);
        media.add(mediaSpecimen.getMediaSpecimen());
    }
    // pherograms & gelPhotos
    if (rootOccurence.isInstanceOf(DnaSample.class)) {
        DnaSample dnaSample = CdmBase.deproxy(rootOccurence, DnaSample.class);
        Set<Sequence> sequences = dnaSample.getSequences();
        // we do show only those gelPhotos which lead to a consensus sequence
        for (Sequence sequence : sequences) {
            Set<Media> dnaRelatedMedia = new HashSet<>();
            for (SingleRead singleRead : sequence.getSingleReads()) {
                AmplificationResult amplification = singleRead.getAmplificationResult();
                dnaRelatedMedia.add(amplification.getGelPhoto());
                dnaRelatedMedia.add(singleRead.getPherogram());
                dnaRelatedMedia.remove(null);
            }
            media.addAll(dnaRelatedMedia);
        }
    }
    if (rootOccurence.isInstanceOf(DerivedUnit.class)) {
        DerivedUnit derivedUnit = HibernateProxyHelper.deproxy(rootOccurence, DerivedUnit.class);
        for (DerivationEvent derivationEvent : derivedUnit.getDerivationEvents()) {
            for (DerivedUnit childDerivative : derivationEvent.getDerivatives()) {
                media.addAll(getMediaInHierarchy(childDerivative, pageSize, pageNumber, propertyPaths).getRecords());
            }
        }
    }
    return new DefaultPagerImpl<>(pageNumber, Long.valueOf(media.size()), pageSize, media);
}
Also used : DefaultPagerImpl(eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl) DerivationEvent(eu.etaxonomy.cdm.model.occurrence.DerivationEvent) Media(eu.etaxonomy.cdm.model.media.Media) ArrayList(java.util.ArrayList) Sequence(eu.etaxonomy.cdm.model.molecular.Sequence) DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) DnaSample(eu.etaxonomy.cdm.model.molecular.DnaSample) MediaSpecimen(eu.etaxonomy.cdm.model.occurrence.MediaSpecimen) AmplificationResult(eu.etaxonomy.cdm.model.molecular.AmplificationResult) SingleRead(eu.etaxonomy.cdm.model.molecular.SingleRead) HashSet(java.util.HashSet)

Example 17 with MediaSpecimen

use of eu.etaxonomy.cdm.model.occurrence.MediaSpecimen in project cdmlib by cybertaxonomy.

the class MediaSpecimenDefaultCacheStrategyTest method test.

@Test
public void test() {
    MediaSpecimen specimen = MediaSpecimen.NewInstance(SpecimenOrObservationType.Media);
    specimen.setUuid(UUID.fromString("b5fa679f-12a1-4f47-906a-28b41c90f019"));
    MediaSpecimenDefaultCacheStrategy strategy = new MediaSpecimenDefaultCacheStrategy();
    Assert.assertEquals("MediaSpecimen#0<b5fa679f-12a1-4f47-906a-28b41c90f019>", strategy.getTitleCache(specimen));
    Collection collection = Collection.NewInstance();
    collection.setCode("B");
    specimen.setCollection(collection);
    Assert.assertEquals("B", strategy.getTitleCache(specimen));
    specimen.setAccessionNumber("123");
    Assert.assertEquals("B 123", strategy.getTitleCache(specimen));
    Media media = Media.NewInstance();
    media.putTitle(Language.DEFAULT(), "Media title");
    media.setArtist(Person.NewTitledInstance("Artist"));
    specimen.setMediaSpecimen(media);
    Assert.assertEquals("B 123 (Media title)", strategy.getTitleCache(specimen));
    specimen.getMediaSpecimen().putTitle(Language.DEFAULT(), "Media Second Title");
    // #9632
    Assert.assertEquals("B 123 (Media Second Title)", strategy.getTitleCache(specimen));
    specimen.getMediaSpecimen().setArtist(Person.NewTitledInstance("Artist 2"));
    ;
    Assert.assertEquals("B 123 (Media Second Title)", strategy.getTitleCache(specimen));
    // remove collection and accession number
    specimen.setCollection(null);
    specimen.setAccessionNumber(null);
    Assert.assertEquals("Media Second Title", strategy.getTitleCache(specimen));
    // remove title
    media.putTitle(Language.DEFAULT(), null);
    Assert.assertEquals("Artist 2", strategy.getTitleCache(specimen));
    // remove artist
    media.setArtist(null);
    Assert.assertEquals("MediaSpecimen#0<b5fa679f-12a1-4f47-906a-28b41c90f019>", strategy.getTitleCache(specimen));
    MediaRepresentation mediaRep = MediaRepresentation.NewInstance("jpg", null, URI.create("https://www.abc.de/test.jpg"), 20, ImageFile.class);
    media.addRepresentation(mediaRep);
    Assert.assertEquals("test", strategy.getTitleCache(specimen));
    Assert.assertNull(strategy.getTitleCache(null));
}
Also used : MediaSpecimen(eu.etaxonomy.cdm.model.occurrence.MediaSpecimen) MediaRepresentation(eu.etaxonomy.cdm.model.media.MediaRepresentation) Media(eu.etaxonomy.cdm.model.media.Media) Collection(eu.etaxonomy.cdm.model.occurrence.Collection) Test(org.junit.Test)

Example 18 with MediaSpecimen

use of eu.etaxonomy.cdm.model.occurrence.MediaSpecimen in project cdmlib by cybertaxonomy.

the class DerivationTreeSummaryDTO method fromEntity.

/**
 * Factory method to create the summary information on media, DNA, molecular data and scans
 * found in the derivation tree including the passed {@link SpecimenOrObservationBase specimenOrObservation}
 *
 * @param specimenOrObservation
 *      The {@link SpecimenOrObservationBase} to create the summary for.
 * @param specimenIdentifier
 *      In case of a {@link DerivedUnit} being passed to this factory method, the <code>specimenIdentifier</code> should
 *      be set to the result of {@link DerivedUnitDTO#composeSpecimenShortTitle(DerivedUnit)}
 * @return
 *      The new instance.
 */
public static DerivationTreeSummaryDTO fromEntity(SpecimenOrObservationBase<?> specimenOrObservation, String specimenIdentifier) {
    DerivationTreeSummaryDTO derivateDataDTO = new DerivationTreeSummaryDTO();
    Collection<DerivedUnit> childDerivates = specimenOrObservation.collectDerivedUnits(0);
    for (DerivedUnit childDerivate : childDerivates) {
        // pattern: DNAMarker [contig1, primer1_1, primer1_2, ...][contig2, primer2_1, ...]...
        if (childDerivate.isInstanceOf(DnaSample.class)) {
            if (childDerivate.getRecordBasis() == SpecimenOrObservationType.TissueSample) {
            // TODO implement TissueSample assembly for web service
            }
            if (childDerivate.getRecordBasis() == SpecimenOrObservationType.DnaSample) {
                DnaSample dna = HibernateProxyHelper.deproxy(childDerivate, DnaSample.class);
                for (Sequence sequence : dna.getSequences()) {
                    URI boldUri = null;
                    try {
                        boldUri = sequence.getBoldUri();
                    } catch (URISyntaxException e1) {
                        // TODO consider better reporting of this incident
                        logger.error("Could not create BOLD URI", e1);
                    }
                    final DefinedTerm dnaMarker = sequence.getDnaMarker();
                    Link providerLink = null;
                    if (boldUri != null && dnaMarker != null) {
                        providerLink = new DerivationTreeSummaryDTO.Link(boldUri, dnaMarker.getLabel());
                    }
                    MolecularData molecularData = derivateDataDTO.addProviderLink(providerLink);
                    // contig file
                    ContigFile contigFile = null;
                    if (sequence.getContigFile() != null) {
                        MediaRepresentationPart contigMediaRepresentationPart = MediaUtils.getFirstMediaRepresentationPart(sequence.getContigFile());
                        if (contigMediaRepresentationPart != null) {
                            contigFile = molecularData.addContigFile(new Link(contigMediaRepresentationPart.getUri(), "contig"));
                        }
                    } else {
                        contigFile = molecularData.addContigFile(null);
                    }
                    // primer files
                    if (sequence.getSingleReads() != null) {
                        int readCount = 1;
                        for (SingleRead singleRead : sequence.getSingleReads()) {
                            MediaRepresentationPart pherogramMediaRepresentationPart = MediaUtils.getFirstMediaRepresentationPart(singleRead.getPherogram());
                            if (pherogramMediaRepresentationPart != null && contigFile != null) {
                                contigFile.addPrimerLink(pherogramMediaRepresentationPart.getUri(), "read" + readCount++);
                            }
                        }
                    }
                }
            }
        } else // assemble media data
        if (childDerivate.isInstanceOf(MediaSpecimen.class)) {
            MediaSpecimen mediaSpecimen = HibernateProxyHelper.deproxy(childDerivate, MediaSpecimen.class);
            URI mediaUri = getMediaUri(mediaSpecimen);
            if (mediaSpecimen.getKindOfUnit() != null) {
                // specimen scan
                if (mediaSpecimen.getKindOfUnit().getUuid().equals(DefinedTerm.uuidSpecimenScan)) {
                    derivateDataDTO.addSpecimenScanUuid(mediaSpecimen.getMediaSpecimen().getUuid());
                    String imageLinkText = "scan of " + specimenIdentifier;
                    if (CdmUtils.isNotBlank(mediaSpecimen.getMostSignificantIdentifier())) {
                        imageLinkText = mediaSpecimen.getMostSignificantIdentifier();
                    }
                    if (CdmUtils.isNotBlank(mediaSpecimen.getMediaSpecimen().getTitleCache())) {
                        imageLinkText += " (" + mediaSpecimen.getMediaSpecimen().getTitleCache() + ")";
                    }
                    derivateDataDTO.addSpecimenScan(mediaUri, imageLinkText.trim());
                } else // detail image
                if (mediaSpecimen.getKindOfUnit().getUuid().equals(DefinedTerm.uuidDetailImage)) {
                    derivateDataDTO.addDetailImageUuid(mediaSpecimen.getMediaSpecimen().getUuid());
                    String motif = "detail image";
                    if (mediaSpecimen.getMediaSpecimen() != null) {
                        if (CdmUtils.isNotBlank(mediaSpecimen.getMediaSpecimen().getTitleCache())) {
                            motif = mediaSpecimen.getMediaSpecimen().getTitleCache();
                        }
                    }
                    derivateDataDTO.addDetailImage(mediaUri, motif);
                }
            }
        }
    }
    return derivateDataDTO;
}
Also used : MediaRepresentationPart(eu.etaxonomy.cdm.model.media.MediaRepresentationPart) Sequence(eu.etaxonomy.cdm.model.molecular.Sequence) URISyntaxException(java.net.URISyntaxException) URI(eu.etaxonomy.cdm.common.URI) DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) DnaSample(eu.etaxonomy.cdm.model.molecular.DnaSample) MediaSpecimen(eu.etaxonomy.cdm.model.occurrence.MediaSpecimen) SingleRead(eu.etaxonomy.cdm.model.molecular.SingleRead) DefinedTerm(eu.etaxonomy.cdm.model.term.DefinedTerm)

Example 19 with MediaSpecimen

use of eu.etaxonomy.cdm.model.occurrence.MediaSpecimen in project cdmlib by cybertaxonomy.

the class DerivedUnitDTO method composeSpecimenShortTitle.

protected String composeSpecimenShortTitle(DerivedUnit derivedUnit) {
    FormatKey collectionKey = FormatKey.COLLECTION_CODE;
    String specimenShortTitle = CdmFormatterFactory.format(derivedUnit, collectionKey);
    if (CdmUtils.isBlank(specimenShortTitle)) {
        collectionKey = FormatKey.COLLECTION_NAME;
    }
    if (CdmUtils.isNotBlank(derivedUnit.getMostSignificantIdentifier())) {
        specimenShortTitle = CdmFormatterFactory.format(derivedUnit, new FormatKey[] { collectionKey, FormatKey.SPACE, FormatKey.MOST_SIGNIFICANT_IDENTIFIER });
        if (!specimenShortTitle.isEmpty() && derivedUnit instanceof MediaSpecimen) {
            Media media = ((MediaSpecimen) derivedUnit).getMediaSpecimen();
            if (media != null && !CdmUtils.isBlank(media.getTitleCache())) {
                if (media.getTitle() != null && !media.getTitle().getText().isEmpty()) {
                    specimenShortTitle += " (" + media.getTitle().getText() + ")";
                }
            }
        }
    }
    if (CdmUtils.isBlank(specimenShortTitle)) {
        specimenShortTitle = derivedUnit.getTitleCache();
    }
    if (CdmUtils.isBlank(specimenShortTitle)) {
        // should not be necessary as titleCache should never be empty
        specimenShortTitle = derivedUnit.getUuid().toString();
    }
    return specimenShortTitle;
}
Also used : FormatKey(eu.etaxonomy.cdm.format.ICdmFormatter.FormatKey) MediaSpecimen(eu.etaxonomy.cdm.model.occurrence.MediaSpecimen) Media(eu.etaxonomy.cdm.model.media.Media)

Example 20 with MediaSpecimen

use of eu.etaxonomy.cdm.model.occurrence.MediaSpecimen in project cdmlib by cybertaxonomy.

the class DerivedUnitConverterIntegrationTest method cascadeDelete.

/**
 * Test with DerivedUnit which is used in a couple of associations to prevent from
 * org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade ...
 */
@Test
@DataSet(loadStrategy = CleanSweepInsertLoadStrategy.class, value = "DerivedUnitConverterIntegrationTest.cascadeDelete.xml")
public void cascadeDelete() throws DerivedUnitConversionException {
    // NOTE:
    // normally we would run this test as CdmIntegrationTest, but due to bug #7138
    // this is not possible, so we use CdmTransactionalIntegrationTest as super class
    // and stop the transaction at the beginning of the test
    commit();
    UUID uuid = UUID.fromString("10eceb2c-9b51-458e-8dcd-2cb92cc558a9");
    MediaSpecimen du = (MediaSpecimen) service.load(uuid, Arrays.asList(new String[] { "*", "derivedFrom.*", "derivedFrom.originals.*", "derivedFrom.originals.derivationEvents", "specimenTypeDesignations.typifiedNames.typeDesignations", "specimenTypeDesignations.typifiedNames.homotypicalGroup", "specimenTypeDesignations.annotations", "specimenTypeDesignations.markers", "specimenTypeDesignations.registrations", "specimenTypeDesignations.sources", // 
    "derivedFrom.originals.gatheringEvent.$", "derivedFrom.originals.gatheringEvent.country", "derivedFrom.originals.gatheringEvent.collectingAreas", "derivedFrom.originals.gatheringEvent.actor.teamMembers", "derivedFrom.originals.derivationEvents.derivatives" }));
    SpecimenTypeDesignation specimenTypeDesignation = du.getSpecimenTypeDesignations().iterator().next();
    DerivedUnitConverter<DerivedUnit> duc = new DerivedUnitConverter<>(specimenTypeDesignation);
    SpecimenTypeDesignation newSpecimenTypeDesignation = duc.convertTo(DerivedUnit.class, SpecimenOrObservationType.HumanObservation);
    DerivedUnit target = newSpecimenTypeDesignation.getTypeSpecimen();
    // service.save(target); // save is performed in convertTo()
    assertEquals(2, service.list(null, null, null, null, null).size());
    assertEquals(1, service.list(DerivedUnit.class, null, null, null, null).size());
    assertEquals(1, service.list(FieldUnit.class, null, null, null, null).size());
}
Also used : DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) MediaSpecimen(eu.etaxonomy.cdm.model.occurrence.MediaSpecimen) UUID(java.util.UUID) SpecimenTypeDesignation(eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test) DataSet(org.unitils.dbunit.annotation.DataSet)

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