Search in sources :

Example 11 with MediaSpecimen

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

the class DerivedUnitConverterIntegrationTest method toMediaSpecimen_issue7114.

@Test
public void toMediaSpecimen_issue7114() 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();
    assertEquals(0, service.list(null, null, null, null, null).size());
    DerivedUnit du = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
    du.setTitleCache("test derived unit", true);
    SpecimenTypeDesignation std = SpecimenTypeDesignation.NewInstance();
    std.setTypeSpecimen(du);
    // intermediate save is essential for this test
    du = service.save(du);
    DerivedUnitConverter<MediaSpecimen> converter = new DerivedUnitConverter<>(std);
    SpecimenTypeDesignation newDu = converter.convertTo(MediaSpecimen.class, SpecimenOrObservationType.StillImage);
    assertEquals(du, converter.oldDerivedUnit());
    // printDataSet(System.err, new String[]{"SpecimenOrObservationBase", "TypeDesignationBase"});
    service.saveOrUpdate(newDu.getTypeSpecimen());
    service.delete(du);
    // printDataSet(System.err, new String[]{"SpecimenOrObservationBase", "TypeDesignationBase"});
    assertEquals(1, service.list(null, null, null, null, null).size());
    assertEquals(1, service.list(MediaSpecimen.class, null, null, null, null).size());
}
Also used : DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) MediaSpecimen(eu.etaxonomy.cdm.model.occurrence.MediaSpecimen) SpecimenTypeDesignation(eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation) CdmTransactionalIntegrationTest(eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest) Test(org.junit.Test)

Example 12 with MediaSpecimen

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

the class DerivedUnitConverterTest method toMediaSpecimen.

@Test
public void toMediaSpecimen() throws DerivedUnitConversionException {
    DerivedUnit du = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
    du.setTitleCache("test derived unit", true);
    SpecimenTypeDesignation std = SpecimenTypeDesignation.NewInstance();
    std.setTypeSpecimen(du);
    DerivedUnitConverter<MediaSpecimen> duc = new DerivedUnitConverter<MediaSpecimen>(std);
    SpecimenTypeDesignation newStd = duc.convertTo(MediaSpecimen.class, SpecimenOrObservationType.StillImage);
    assertNotEquals(std.getUuid(), newStd.getUuid());
    MediaSpecimen target = (MediaSpecimen) newStd.getTypeSpecimen();
    assertNotNull(target);
    assertEquals(SpecimenOrObservationType.StillImage, target.getRecordBasis());
    assertEquals("test derived unit", target.getTitleCache());
}
Also used : DerivedUnit(eu.etaxonomy.cdm.model.occurrence.DerivedUnit) DerivedUnitConverter(eu.etaxonomy.cdm.api.util.DerivedUnitConverter) MediaSpecimen(eu.etaxonomy.cdm.model.occurrence.MediaSpecimen) SpecimenTypeDesignation(eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation) Test(org.junit.Test)

Example 13 with MediaSpecimen

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

the class MediaSpecimenFormatter method initFormatKeys.

@Override
protected void initFormatKeys(Object object) {
    super.initFormatKeys(object);
    MediaSpecimen mediaSpecimen = HibernateProxyHelper.deproxy(object, MediaSpecimen.class);
    Media media = mediaSpecimen.getMediaSpecimen();
    if (media != null) {
        if (media.getArtist() != null) {
            formatKeyMap.put(FormatKey.MEDIA_ARTIST, media.getArtist().toString());
        }
        if (media.getTitle() != null) {
            formatKeyMap.put(FormatKey.MEDIA_TITLE, media.getTitle().getText());
        }
        formatKeyMap.put(FormatKey.MEDIA_TITLE_CACHE, media.getTitleCache());
    }
}
Also used : MediaSpecimen(eu.etaxonomy.cdm.model.occurrence.MediaSpecimen) Media(eu.etaxonomy.cdm.model.media.Media)

Example 14 with MediaSpecimen

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

the class OccurrencePortalController method doGetMediaSpecimen.

@RequestMapping(value = { "mediaSpecimen" }, method = RequestMethod.GET)
public Media doGetMediaSpecimen(@PathVariable("uuid") UUID uuid, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) {
    logger.info("doGetMediaSpecimen() " + requestPathAndQuery(request));
    SpecimenOrObservationBase<?> sob = service.load(uuid, Arrays.asList("mediaSpecimen.sources.citation", "mediaSpecimen.representations.parts"));
    if (sob instanceof MediaSpecimen) {
        MediaSpecimen mediaSpecimen = (MediaSpecimen) sob;
        if (mediaSpecimen.isPublish()) {
            return mediaSpecimen.getMediaSpecimen();
        }
    }
    return null;
}
Also used : MediaSpecimen(eu.etaxonomy.cdm.model.occurrence.MediaSpecimen) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with MediaSpecimen

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

the class MediaServiceImpl method isDeletable.

@Override
public DeleteResult isDeletable(UUID mediaUuid, DeleteConfiguratorBase config) {
    DeleteResult result = new DeleteResult();
    Media media = this.load(mediaUuid);
    Set<CdmBase> references = commonService.getReferencingObjectsForDeletion(media);
    MediaDeletionConfigurator mediaConfig = (MediaDeletionConfigurator) config;
    CdmBase deleteFrom = mediaConfig.getDeleteFrom();
    if (mediaConfig.isDeleteFromEveryWhere()) {
        return result;
    }
    for (CdmBase ref : references) {
        String message = null;
        if (ref instanceof MediaRepresentation) {
            continue;
        } else if (ref instanceof TextData) {
            TextData textData = HibernateProxyHelper.deproxy(ref, TextData.class);
            DescriptionBase<?> description = HibernateProxyHelper.deproxy(textData.getInDescription(), DescriptionBase.class);
            if (description instanceof TaxonDescription) {
                TaxonDescription desc = HibernateProxyHelper.deproxy(description, TaxonDescription.class);
                if (desc.getTaxon() == null || (mediaConfig.isDeleteFromDescription() && (deleteFrom instanceof Taxon && ((Taxon) deleteFrom).getId() == desc.getTaxon().getId()))) {
                    continue;
                } else {
                    message = "The media can't be deleted from the database because it is referenced by a taxon. (" + desc.getTaxon().getTitleCache() + ")";
                    result.setAbort();
                }
            } else if (description instanceof SpecimenDescription) {
                SpecimenDescription desc = HibernateProxyHelper.deproxy(description, SpecimenDescription.class);
                if (desc.getDescribedSpecimenOrObservation() == null || (mediaConfig.isDeleteFromDescription() && (deleteFrom instanceof SpecimenOrObservationBase && ((SpecimenOrObservationBase) deleteFrom).getId() == desc.getDescribedSpecimenOrObservation().getId()))) {
                    continue;
                } else {
                    message = "The media can't be deleted from the database because it is referenced by a specimen or observation. (" + desc.getDescribedSpecimenOrObservation().getTitleCache() + ")";
                    result.setAbort();
                }
            } else if (description instanceof TaxonNameDescription) {
                TaxonNameDescription desc = HibernateProxyHelper.deproxy(description, TaxonNameDescription.class);
                if (desc.getTaxonName() == null || (mediaConfig.isDeleteFromDescription() && (deleteFrom instanceof TaxonName && ((TaxonName) deleteFrom).getId() == desc.getTaxonName().getId()))) {
                    continue;
                } else {
                    message = "The media can't be deleted from the database because it is referenced by a scientific name. (" + desc.getTaxonName().getTitleCache() + ")";
                    result.setAbort();
                }
            }
        } else if (ref instanceof MediaSpecimen) {
            message = "The media can't be deleted from the database because it is referenced by a mediaspecimen. (" + ((MediaSpecimen) ref).getTitleCache() + ")";
            result.setAbort();
        } else {
            message = "The media can't be completely deleted because it is referenced by another " + ref.getUserFriendlyTypeName();
            result.setAbort();
        }
        if (message != null) {
            result.addException(new ReferencedObjectUndeletableException(message));
            result.addRelatedObject(ref);
        }
    }
    return result;
}
Also used : DescriptionBase(eu.etaxonomy.cdm.model.description.DescriptionBase) SpecimenDescription(eu.etaxonomy.cdm.model.description.SpecimenDescription) TaxonNameDescription(eu.etaxonomy.cdm.model.description.TaxonNameDescription) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) ReferencedObjectUndeletableException(eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException) Media(eu.etaxonomy.cdm.model.media.Media) TaxonDescription(eu.etaxonomy.cdm.model.description.TaxonDescription) MediaRepresentation(eu.etaxonomy.cdm.model.media.MediaRepresentation) TextData(eu.etaxonomy.cdm.model.description.TextData) MediaSpecimen(eu.etaxonomy.cdm.model.occurrence.MediaSpecimen) ICdmBase(eu.etaxonomy.cdm.model.common.ICdmBase) CdmBase(eu.etaxonomy.cdm.model.common.CdmBase) SpecimenOrObservationBase(eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) MediaDeletionConfigurator(eu.etaxonomy.cdm.api.service.config.MediaDeletionConfigurator)

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