Search in sources :

Example 1 with ITaxonService

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;
}
Also used : HashMap(java.util.HashMap) Element(org.jdom.Element) ArrayList(java.util.ArrayList) ITaxonService(eu.etaxonomy.cdm.api.service.ITaxonService) TaxonBase(eu.etaxonomy.cdm.model.taxon.TaxonBase) CommonTaxonName(eu.etaxonomy.cdm.model.description.CommonTaxonName) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) CommonTaxonName(eu.etaxonomy.cdm.model.description.CommonTaxonName) Reference(eu.etaxonomy.cdm.model.reference.Reference) Rank(eu.etaxonomy.cdm.model.name.Rank) MapWrapper(eu.etaxonomy.cdm.io.common.MapWrapper) Namespace(org.jdom.Namespace)

Example 2 with ITaxonService

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);
}
Also used : ITaxonService(eu.etaxonomy.cdm.api.service.ITaxonService) TransactionStatus(org.springframework.transaction.TransactionStatus) Synonym(eu.etaxonomy.cdm.model.taxon.Synonym)

Example 3 with ITaxonService

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);
}
Also used : ITaxonService(eu.etaxonomy.cdm.api.service.ITaxonService) TaxonDeletionConfigurator(eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator) ITaxonNodeService(eu.etaxonomy.cdm.api.service.ITaxonNodeService) TaxonNode(eu.etaxonomy.cdm.model.taxon.TaxonNode) Taxon(eu.etaxonomy.cdm.model.taxon.Taxon) TransactionStatus(org.springframework.transaction.TransactionStatus) SQLException(java.sql.SQLException) TermNotFoundException(eu.etaxonomy.cdm.model.term.init.TermNotFoundException) IOException(java.io.IOException) DataSourceNotFoundException(eu.etaxonomy.cdm.database.DataSourceNotFoundException)

Aggregations

ITaxonService (eu.etaxonomy.cdm.api.service.ITaxonService)3 TransactionStatus (org.springframework.transaction.TransactionStatus)2 ITaxonNodeService (eu.etaxonomy.cdm.api.service.ITaxonNodeService)1 TaxonDeletionConfigurator (eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator)1 DataSourceNotFoundException (eu.etaxonomy.cdm.database.DataSourceNotFoundException)1 MapWrapper (eu.etaxonomy.cdm.io.common.MapWrapper)1 CommonTaxonName (eu.etaxonomy.cdm.model.description.CommonTaxonName)1 Rank (eu.etaxonomy.cdm.model.name.Rank)1 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)1 Reference (eu.etaxonomy.cdm.model.reference.Reference)1 Synonym (eu.etaxonomy.cdm.model.taxon.Synonym)1 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)1 TaxonBase (eu.etaxonomy.cdm.model.taxon.TaxonBase)1 TaxonNode (eu.etaxonomy.cdm.model.taxon.TaxonNode)1 TermNotFoundException (eu.etaxonomy.cdm.model.term.init.TermNotFoundException)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Element (org.jdom.Element)1