use of eu.etaxonomy.cdm.api.service.ITaxonService in project cdmlib by cybertaxonomy.
the class TcsXmlTaxonImport method doInvoke.
@Override
public void doInvoke(TcsXmlImportState state) {
logger.info("start make TaxonConcepts ...");
MapWrapper<TaxonBase> taxonMap = (MapWrapper<TaxonBase>) state.getStore(ICdmIO.TAXON_STORE);
MapWrapper<TaxonName> taxonNameMap = (MapWrapper<TaxonName>) state.getStore(ICdmIO.TAXONNAME_STORE);
MapWrapper<Reference> referenceMap = (MapWrapper<Reference>) state.getStore(ICdmIO.REFERENCE_STORE);
Map<String, CommonTaxonName> commonNameMap = new HashMap<String, CommonTaxonName>();
ITaxonService taxonService = getTaxonService();
ResultWrapper<Boolean> success = ResultWrapper.NewInstance(true);
String childName;
boolean obligatory;
String idNamespace = "TaxonConcept";
TcsXmlImportConfigurator config = state.getConfig();
Element elDataSet = getDataSetElement(config);
Namespace tcsNamespace = config.getTcsXmlNamespace();
childName = "TaxonConcepts";
obligatory = false;
Element elTaxonConcepts = XmlHelp.getSingleChildElement(success, elDataSet, childName, tcsNamespace, obligatory);
String tcsElementName = "TaxonConcept";
List<Element> elTaxonConceptList = elTaxonConcepts.getChildren(tcsElementName, tcsNamespace);
Set<String> synonymIdSet = makeSynonymIds(elTaxonConceptList, success);
// TODO make the same for the Assertions
int i = 0;
// for each taxonConcept
for (Element elTaxonConcept : elTaxonConceptList) {
if ((i++ % modCount) == 0 && i > 1) {
logger.info("Taxa handled: " + (i - 1));
}
List<String> elementList = new ArrayList<>();
// create TaxonName element
String strId = elTaxonConcept.getAttributeValue("id");
// TODO
// original, revision, incomplete, aggregate, nominal
String strConceptType = elTaxonConcept.getAttributeValue("type");
// If primary='true' the concept is the first level response to a query. If 'false' the concept may be a secondary concept linked directly or indirectly to the definition of a primary concept.
String strPrimary = elTaxonConcept.getAttributeValue("primary");
// anamorph, teleomorph, hybrid
String strForm = elTaxonConcept.getAttributeValue("form");
childName = "Name";
obligatory = true;
Element elName = XmlHelp.getSingleChildElement(success, elTaxonConcept, childName, tcsNamespace, obligatory);
if (isVernacular(success, elName)) {
handleVernacularName(success, strId, elName, commonNameMap);
} else {
TaxonName taxonName = makeScientificName(elName, null, taxonNameMap, success);
elementList.add(childName.toString());
// TODO how to handle
childName = "Rank";
obligatory = false;
Element elRank = XmlHelp.getSingleChildElement(success, elTaxonConcept, childName, tcsNamespace, obligatory);
Rank rank = TcsXmlTaxonNameImport.makeRank(elRank);
if (rank != null) {
logger.warn("Rank in TaxonIO not yet implemented");
}
elementList.add(childName.toString());
childName = "AccordingTo";
obligatory = false;
Element elAccordingTo = XmlHelp.getSingleChildElement(success, elTaxonConcept, childName, tcsNamespace, obligatory);
Reference sec = makeAccordingTo(elAccordingTo, referenceMap, success);
elementList.add(childName.toString());
// TODO may sec be null?
if (sec == null) {
sec = unknownSec();
}
TaxonBase<?> taxonBase;
if (synonymIdSet.contains(strId)) {
taxonBase = Synonym.NewInstance(taxonName, sec);
} else {
taxonBase = Taxon.NewInstance(taxonName, sec);
}
childName = "TaxonRelationships";
obligatory = false;
Element elTaxonRelationships = XmlHelp.getSingleChildElement(success, elTaxonConcept, childName, tcsNamespace, obligatory);
makeTaxonRelationships(taxonBase, elTaxonRelationships, success);
elementList.add(childName.toString());
childName = "SpecimenCircumscription";
obligatory = false;
Element elSpecimenCircumscription = XmlHelp.getSingleChildElement(success, elTaxonConcept, childName, tcsNamespace, obligatory);
makeSpecimenCircumscription(taxonBase, elSpecimenCircumscription, success);
elementList.add(childName.toString());
childName = "CharacterCircumscription";
obligatory = false;
Element elCharacterCircumscription = XmlHelp.getSingleChildElement(success, elTaxonConcept, childName, tcsNamespace, obligatory);
makeCharacterCircumscription(taxonBase, elCharacterCircumscription, success);
elementList.add(childName.toString());
childName = "ProviderLink";
obligatory = false;
Element elProviderLink = XmlHelp.getSingleChildElement(success, elTaxonConcept, childName, tcsNamespace, obligatory);
makeProviderLink(taxonBase, elProviderLink, success);
elementList.add(childName.toString());
childName = "ProviderSpecificData";
obligatory = false;
Element elProviderSpecificData = XmlHelp.getSingleChildElement(success, elTaxonConcept, childName, tcsNamespace, obligatory);
makeProviderSpecificData(taxonBase, elProviderSpecificData, success);
elementList.add(childName.toString());
testAdditionalElements(elTaxonConcept, elementList);
ImportHelper.setOriginalSource(taxonBase, config.getSourceReference(), strId, idNamespace);
// delete the version information
taxonMap.put(removeVersionOfRef(strId), taxonBase);
}
}
state.setCommonNameMap(commonNameMap);
// invokeRelations(source, cdmApp, deleteAll, taxonMap, referenceMap);
logger.info(i + " taxa handled. Saving ...");
taxonService.save(taxonMap.objects());
logger.info("end makeTaxa ...");
if (!success.getValue()) {
state.setUnsuccessfull();
}
return;
}
use of eu.etaxonomy.cdm.api.service.ITaxonService in project cdmlib by cybertaxonomy.
the class TaxonXNomenclatureImport method unlazySynonym.
/**
* TODO Preliminary to avoid laizy loading errors
*/
private void unlazySynonym(IImportConfigurator config, Taxon taxon) {
TransactionStatus txStatus = startTransaction();
ITaxonService taxonService = getTaxonService();
taxonService.save(taxon);
Set<Synonym> synonyms = taxon.getSynonyms();
logger.debug(synonyms.size());
// taxonService.saveTaxon(taxon);
commitTransaction(txStatus);
}
use of eu.etaxonomy.cdm.api.service.ITaxonService in project cdmlib by cybertaxonomy.
the class TestScriptService method deleteHighLevelNode.
private void deleteHighLevelNode(CdmApplicationController appCtr) {
TransactionStatus tx = appCtr.startTransaction();
ITaxonNodeService service = appCtr.getTaxonNodeService();
TaxonNode node = service.find(60554);
// service.delete(node);
ITaxonService taxonService = appCtr.getTaxonService();
Taxon taxon = node.getTaxon();
// try {
taxonService.deleteTaxon(taxon.getUuid(), new TaxonDeletionConfigurator(), node.getClassification().getUuid());
/*} catch (DataChangeNoRollbackException e) {
e.printStackTrace();
}*/
try {
appCtr.commitTransaction(tx);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
TaxonNode node2 = service.find(60554);
}
Aggregations