Search in sources :

Example 16 with PolytomousKey

use of eu.etaxonomy.cdm.model.description.PolytomousKey in project cdmlib by cybertaxonomy.

the class PolytomousKeyServiceImpl method updateAllNodeNumberings.

@Override
public UpdateResult updateAllNodeNumberings(UUID polytomousKeyUuid) {
    UpdateResult result = new UpdateResult();
    PolytomousKey polytomousKey = dao.load(polytomousKeyUuid);
    polytomousKey.getRoot().refreshNodeNumbering();
    return result;
}
Also used : PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey)

Example 17 with PolytomousKey

use of eu.etaxonomy.cdm.model.description.PolytomousKey in project cdmlib by cybertaxonomy.

the class PolytomousKeyServiceImpl method isDeletable.

@Override
public DeleteResult isDeletable(UUID keyUuid, DeleteConfiguratorBase config) {
    DeleteResult result = new DeleteResult();
    PolytomousKey key = this.load(keyUuid);
    Set<CdmBase> references = commonService.getReferencingObjectsForDeletion(key);
    if (references != null) {
        Iterator<CdmBase> iterator = references.iterator();
        CdmBase ref;
        while (iterator.hasNext()) {
            ref = iterator.next();
            if ((ref instanceof PolytomousKeyNode)) {
                PolytomousKeyNode node = HibernateProxyHelper.deproxy(ref, PolytomousKeyNode.class);
                if (!node.getKey().equals(key)) {
                    String message = "The key is a subkey of " + node.getKey() + ", referenced in node with id: " + node.getId() + ". Please remove the subkey reference first and then delete the key. ";
                    result.addException(new ReferencedObjectUndeletableException(message));
                    result.setAbort();
                    result.addRelatedObject(ref);
                }
            }
        }
    }
    return result;
}
Also used : ReferencedObjectUndeletableException(eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException) CdmBase(eu.etaxonomy.cdm.model.common.CdmBase) PolytomousKeyNode(eu.etaxonomy.cdm.model.description.PolytomousKeyNode) PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey)

Example 18 with PolytomousKey

use of eu.etaxonomy.cdm.model.description.PolytomousKey in project cdmlib by cybertaxonomy.

the class PolytomousKeyGenerator method invoke.

// *************************** METHODS ***************************************/
/**
 * Creates the key
 */
public PolytomousKey invoke(PolytomousKeyGeneratorConfigurator config) {
    if (config == null) {
        throw new NullPointerException("PolytomousKeyGeneratorConfigurator must not be null");
    }
    this.config = config;
    if (this.config.isUseDependencies()) {
        createDependencies(config.getDependenciesTree().getRoot());
    }
    PolytomousKey polytomousKey = PolytomousKey.NewInstance();
    PolytomousKeyNode root = polytomousKey.getRoot();
    @SuppressWarnings("unchecked") Set<KeyTaxon> taxaCovered = makeKeyTaxa((Set) config.getTaxonDescriptions());
    taxaCovered = replaceSingleRoot(taxaCovered);
    // filter if a feature is available only for certain states in this branche
    Map<Feature, Set<State>> featureStatesFilter = new HashMap<>();
    // TODO what if size(taxaCovered) <= 1, is this covered by algo? Write test to check
    buildBranches(root, config.getFeatures(), taxaCovered, featureStatesFilter);
    return polytomousKey;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) PolytomousKeyNode(eu.etaxonomy.cdm.model.description.PolytomousKeyNode) Feature(eu.etaxonomy.cdm.model.description.Feature) PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey)

Example 19 with PolytomousKey

use of eu.etaxonomy.cdm.model.description.PolytomousKey in project cdmlib by cybertaxonomy.

the class MarkupKeyImport method handleKeyTitle.

/**
 * @param state
 * @param reader
 * @param key
 * @param next
 * @throws XMLStreamException
 */
private void handleKeyTitle(MarkupImportState state, XMLEventReader reader, XMLEvent parentEvent) throws XMLStreamException {
    PolytomousKey key = state.getCurrentKey();
    String keyTitle = getCData(state, reader, parentEvent);
    String standardTitlesEngl = "(?i)(Key\\sto\\sthe\\s(genera|species|varieties|forms))";
    String standardTitlesFrench = "(?i)(Cl\u00e9\\sdes\\s(genres|esp\u00e8ces))";
    String standardTitles = standardTitlesEngl;
    if (state.getDefaultLanguage() != null && state.getDefaultLanguage().equals(Language.FRENCH())) {
        standardTitles = standardTitlesFrench;
    }
    if (isNotBlank(keyTitle)) {
        if (!state.getConfig().isReplaceStandardKeyTitles() || !keyTitle.matches(standardTitles)) {
            key.setTitleCache(keyTitle, true);
        }
    }
}
Also used : PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey)

Example 20 with PolytomousKey

use of eu.etaxonomy.cdm.model.description.PolytomousKey in project cdmlib by cybertaxonomy.

the class MarkupDocumentImportNoComponent method handleTreatment.

private void handleTreatment(MarkupImportState state, XMLEventReader reader, XMLEvent parentEvent) throws XMLStreamException {
    checkNoAttributes(parentEvent);
    Taxon lastTaxon = null;
    while (reader.hasNext()) {
        XMLEvent next = readNoWhitespace(reader);
        if (isMyEndingElement(next, parentEvent)) {
            Set<PolytomousKeyNode> keyNodesToSave = state.getPolytomousKeyNodesToSave();
            // better save the key then the nodes
            Set<PolytomousKey> keySet = new HashSet<PolytomousKey>();
            for (PolytomousKeyNode node : keyNodesToSave) {
                PolytomousKey key = node.getKey();
                keySet.add(key);
            }
            save(keySet, state);
            // unmatched key leads
            UnmatchedLeads unmatched = state.getUnmatchedLeads();
            if (unmatched.size() > 0) {
                String message = "The following %d key leads are unmatched: %s";
                message = String.format(message, unmatched.size(), state.getUnmatchedLeads().toString());
                fireWarningEvent(message, next, 6);
            }
            return;
        } else if (isStartingElement(next, TAXON)) {
            state.setCurrentTaxonExcluded(false);
            Taxon thisTaxon = handleTaxon(state, reader, next.asStartElement());
            doTaxonRelation(state, thisTaxon, lastTaxon, parentEvent.getLocation());
            if (state.isTaxonInClassification() == true) {
                lastTaxon = thisTaxon;
                // TODO for imports spanning multiple documents ?? Still needed?
                state.getConfig().setLastTaxonUuid(lastTaxon.getUuid());
            }
        } else if (isStartingElement(next, ADDENDA)) {
            handleNotYetImplementedElement(next);
        } else {
            handleUnexpectedElement(next);
        }
    }
    return;
}
Also used : Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) XMLEvent(javax.xml.stream.events.XMLEvent) PolytomousKeyNode(eu.etaxonomy.cdm.model.description.PolytomousKeyNode) PolytomousKey(eu.etaxonomy.cdm.model.description.PolytomousKey) HashSet(java.util.HashSet)

Aggregations

PolytomousKey (eu.etaxonomy.cdm.model.description.PolytomousKey)33 PolytomousKeyNode (eu.etaxonomy.cdm.model.description.PolytomousKeyNode)23 Test (org.junit.Test)14 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)7 CdmTransactionalIntegrationTest (eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest)7 UUID (java.util.UUID)7 ArrayList (java.util.ArrayList)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)3 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)3 TaxonNode (eu.etaxonomy.cdm.model.taxon.TaxonNode)3 DataSet (org.unitils.dbunit.annotation.DataSet)3 CdmBase (eu.etaxonomy.cdm.model.common.CdmBase)2 DescriptiveDataSet (eu.etaxonomy.cdm.model.description.DescriptiveDataSet)2 Feature (eu.etaxonomy.cdm.model.description.Feature)2 TaxonDescription (eu.etaxonomy.cdm.model.description.TaxonDescription)2 LinkedPolytomousKeyNodeRowDto (eu.etaxonomy.cdm.remote.dto.polytomouskey.LinkedPolytomousKeyNodeRowDto)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 IdentifiableServiceConfiguratorImpl (eu.etaxonomy.cdm.api.service.config.IdentifiableServiceConfiguratorImpl)1 ReferencedObjectUndeletableException (eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException)1