use of eu.etaxonomy.cdm.model.description.DescriptiveDataSet in project cdmlib by cybertaxonomy.
the class DescriptiveDataSetService method removeDescription.
@Override
@Transactional(readOnly = false)
public DeleteResult removeDescription(UUID descriptionUuid, UUID descriptiveDataSetUuid, RemoveDescriptionsFromDescriptiveDataSetConfigurator config) {
DeleteResult result = new DeleteResult();
DescriptiveDataSet dataSet = load(descriptiveDataSetUuid);
DescriptionBase<?> descriptionBase = descriptionService.load(descriptionUuid);
if (dataSet == null || descriptionBase == null) {
result.setError();
} else {
removeDescriptionFromDataSet(result, dataSet, descriptionBase, config);
}
return result;
}
use of eu.etaxonomy.cdm.model.description.DescriptiveDataSet in project cdmlib by cybertaxonomy.
the class DescriptiveDataSetService method createTaxonDescription.
@Override
@Transactional(readOnly = false)
public TaxonRowWrapperDTO createTaxonDescription(UUID dataSetUuid, UUID taxonNodeUuid, DescriptionType descriptionType) {
DescriptiveDataSet dataSet = load(dataSetUuid);
TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid, Arrays.asList("taxon"));
TaxonDescription newTaxonDescription = TaxonDescription.NewInstance(taxonNode.getTaxon());
// $NON-NLS-2$
newTaxonDescription.setTitleCache(dataSet.getLabel() + ": " + newTaxonDescription.generateTitle(), true);
newTaxonDescription.getTypes().add(descriptionType);
dataSet.addDescription(newTaxonDescription);
saveOrUpdate(dataSet);
return createTaxonRowWrapper(newTaxonDescription.getUuid(), dataSet.getUuid());
}
use of eu.etaxonomy.cdm.model.description.DescriptiveDataSet in project cdmlib by cybertaxonomy.
the class DescriptiveDataSetService method createTaxonRowWrapper.
@Override
public TaxonRowWrapperDTO createTaxonRowWrapper(DescriptionBaseDto description, UUID descriptiveDataSetUuid) {
Classification classification = null;
DescriptiveDataSet descriptiveDataSet = dao.load(descriptiveDataSetUuid, null);
Optional<TaxonNode> first = descriptiveDataSet.getTaxonSubtreeFilter().stream().filter(node -> node.getClassification() != null).findFirst();
Optional<Classification> classificationOptional = first.map(node -> node.getClassification());
Set<DescriptionBaseDto> descriptions = new HashSet<>();
TaxonNodeDto nodeDto = null;
if (classificationOptional.isPresent()) {
classification = classificationOptional.get();
nodeDto = taxonNodeService.dto(description.getTaxonDto().getUuid(), classification.getUuid());
}
return new TaxonRowWrapperDTO(description, nodeDto, descriptions);
}
use of eu.etaxonomy.cdm.model.description.DescriptiveDataSet in project cdmlib by cybertaxonomy.
the class DescriptionServiceImpl method deleteDescription.
@Override
@Transactional(readOnly = false)
public DeleteResult deleteDescription(DescriptionBase<?> description) {
DeleteResult deleteResult = new DeleteResult();
if (description == null) {
return deleteResult;
}
// avoid lazy init exception
description = load(description.getId(), Arrays.asList("descriptiveDataSets"));
deleteResult = isDeletable(description.getUuid());
if (deleteResult.getRelatedObjects() != null && deleteResult.getRelatedObjects().size() == 1) {
Iterator<CdmBase> relObjects = deleteResult.getRelatedObjects().iterator();
CdmBase next = relObjects.next();
if (next instanceof CdmLinkSource) {
CdmLinkSource source = (CdmLinkSource) next;
ICdmTarget target = source.getTarget();
}
}
if (deleteResult.isOk()) {
CdmBase.deproxy(description);
if (description instanceof TaxonDescription) {
TaxonDescription taxDescription = (TaxonDescription) description;
Taxon tax = taxDescription.getTaxon();
if (tax != null) {
tax.removeDescription(taxDescription, true);
deleteResult.addUpdatedObject(tax);
}
} else if (description instanceof SpecimenDescription) {
SpecimenDescription specimenDescription = (SpecimenDescription) description;
SpecimenOrObservationBase<?> specimen = specimenDescription.getDescribedSpecimenOrObservation();
if (specimen != null) {
specimen.removeDescription(specimenDescription);
deleteResult.addUpdatedObject(specimen);
}
}
for (DescriptiveDataSet dataset : description.getDescriptiveDataSets()) {
dataset.removeDescription(description);
}
dao.delete(description);
deleteResult.addDeletedObject(description);
deleteResult.setCdmEntity(description);
} else {
logger.info(deleteResult.getExceptions().toString());
}
return deleteResult;
}
use of eu.etaxonomy.cdm.model.description.DescriptiveDataSet in project cdmlib by cybertaxonomy.
the class PolytomousKeyGeneratorTest method createDataSet.
private DescriptiveDataSet createDataSet() {
DescriptiveDataSet dataset = DescriptiveDataSet.NewInstance();
dataset.setDescriptiveSystem(createFeatureTree());
for (TaxonDescription desc : taxa) {
dataset.addDescription(desc);
}
return dataset;
}
Aggregations