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