Search in sources :

Example 1 with PolytomousKeyGeneratorConfigurator

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;
}
Also used : DescriptiveDataSet(eu.etaxonomy.cdm.model.description.DescriptiveDataSet) PolytomousKeyGenerator(eu.etaxonomy.cdm.strategy.generate.PolytomousKeyGenerator) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) PolytomousKeyGeneratorConfigurator(eu.etaxonomy.cdm.strategy.generate.PolytomousKeyGeneratorConfigurator) IdentifiableServiceConfiguratorImpl(eu.etaxonomy.cdm.api.service.config.IdentifiableServiceConfiguratorImpl) PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdentifiableServiceConfiguratorImpl (eu.etaxonomy.cdm.api.service.config.IdentifiableServiceConfiguratorImpl)1 DescriptiveDataSet (eu.etaxonomy.cdm.model.description.DescriptiveDataSet)1 PolytomousKey (eu.etaxonomy.cdm.model.description.PolytomousKey)1 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)1 PolytomousKeyGenerator (eu.etaxonomy.cdm.strategy.generate.PolytomousKeyGenerator)1 PolytomousKeyGeneratorConfigurator (eu.etaxonomy.cdm.strategy.generate.PolytomousKeyGeneratorConfigurator)1 Transactional (org.springframework.transaction.annotation.Transactional)1