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());
}
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());
}
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());
}
}
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;
}
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;
}
Aggregations