use of eu.etaxonomy.cdm.strategy.generate.PolytomousKeyGeneratorConfigurator in project cdmlib by cybertaxonomy.
the class DescriptiveDataSetService method generatePolytomousKey.
@Override
@Transactional(readOnly = false)
public UpdateResult generatePolytomousKey(UUID descriptiveDataSetUuid, UUID taxonUuid) {
UpdateResult result = new UpdateResult();
PolytomousKeyGeneratorConfigurator keyConfig = new PolytomousKeyGeneratorConfigurator();
DescriptiveDataSet descriptiveDataSet = load(descriptiveDataSetUuid);
keyConfig.setDataSet(descriptiveDataSet);
PolytomousKey key = new PolytomousKeyGenerator().invoke(keyConfig);
IdentifiableServiceConfiguratorImpl<PolytomousKey> serviceConfig = new IdentifiableServiceConfiguratorImpl<>();
serviceConfig.setTitleSearchString(descriptiveDataSet.getTitleCache());
List<PolytomousKey> list = polytomousKeyService.findByTitle(serviceConfig).getRecords();
if (list != null) {
list.forEach(polytomousKey -> polytomousKeyService.delete(polytomousKey));
}
key.setTitleCache(descriptiveDataSet.getTitleCache(), true);
Taxon taxon = (Taxon) taxonService.load(taxonUuid);
key.addTaxonomicScope(taxon);
polytomousKeyService.saveOrUpdate(key);
result.setCdmEntity(key);
result.addUpdatedObject(taxon);
return result;
}
Aggregations