Search in sources :

Example 16 with NomenclaturalCode

use of eu.etaxonomy.cdm.model.name.NomenclaturalCode in project cdmlib by cybertaxonomy.

the class TcsXmlTaxonNameImport method handleTaxonNameElement.

public TaxonName handleTaxonNameElement(Element elTaxonName, ResultWrapper<Boolean> success, TcsXmlImportState state) {
    Namespace tcsNamespace = state.getConfig().getTcsXmlNamespace();
    MapWrapper<Person> authorMap = (MapWrapper<Person>) state.getStore(ICdmIO.TEAM_STORE);
    MapWrapper<TaxonName> taxonNameMap = (MapWrapper<TaxonName>) state.getStore(ICdmIO.TAXONNAME_STORE);
    MapWrapper<Reference> referenceMap = (MapWrapper<Reference>) state.getStore(ICdmIO.REFERENCE_STORE);
    List<String> elementList = new ArrayList<>();
    String idNamespace = "TaxonName";
    // create TaxonName element
    String strId = elTaxonName.getAttributeValue("id");
    String strNomenclaturalCode = elTaxonName.getAttributeValue("nomenclaturalCode");
    // Content elTaxName = elTaxonName.getChild(name, ns);
    String childName = "Rank";
    boolean obligatory = false;
    Element elRank = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
    Rank rank = null;
    if (elRank != null) {
        rank = TcsXmlTaxonNameImport.makeRank(elRank);
        if (rank == null) {
            logger.warn("Unknown rank for" + strId);
        }
    }
    elementList.add(childName.toString());
    try {
        TaxonName nameBase;
        NomenclaturalCode nomCode = TcsXmlTransformer.nomCodeString2NomCode(strNomenclaturalCode);
        if (nomCode != null) {
            nameBase = nomCode.getNewTaxonNameInstance(rank);
        } else {
            nameBase = TaxonNameFactory.NewNonViralInstance(rank);
        }
        childName = "Simple";
        obligatory = true;
        Element elSimple = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
        String simple = (elSimple == null) ? "" : elSimple.getTextNormalize();
        nameBase.setTitleCache(simple, false);
        elementList.add(childName.toString());
        childName = "CanonicalName";
        obligatory = false;
        Element elCanonicalName = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
        makeCanonicalName(nameBase, elCanonicalName, taxonNameMap, success);
        elementList.add(childName.toString());
        childName = "CanonicalAuthorship";
        obligatory = false;
        Element elCanonicalAuthorship = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
        makeCanonicalAuthorship(nameBase, elCanonicalAuthorship, authorMap, success);
        elementList.add(childName.toString());
        childName = "PublishedIn";
        obligatory = false;
        Element elPublishedIn = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
        makePublishedIn(nameBase, elPublishedIn, referenceMap, success);
        elementList.add(childName.toString());
        childName = "Year";
        obligatory = false;
        Element elYear = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
        makeYear(nameBase, elYear, success);
        elementList.add(childName.toString());
        childName = "MicroReference";
        obligatory = false;
        Element elMicroReference = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
        makeMicroReference(nameBase, elMicroReference, success);
        elementList.add(childName.toString());
        childName = "Typification";
        obligatory = false;
        Element elTypification = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
        makeTypification(nameBase, elTypification, success);
        elementList.add(childName.toString());
        childName = "PublicationStatus";
        obligatory = false;
        Element elPublicationStatus = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
        makePublicationStatus(nameBase, elPublicationStatus, success);
        elementList.add(childName.toString());
        childName = "ProviderLink";
        obligatory = false;
        Element elProviderLink = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
        makeProviderLink(nameBase, elProviderLink, success);
        elementList.add(childName.toString());
        childName = "ProviderSpecificData";
        obligatory = false;
        Element elProviderSpecificData = XmlHelp.getSingleChildElement(success, elTaxonName, childName, tcsNamespace, obligatory);
        makeProviderSpecificData(nameBase, elProviderSpecificData, success, state);
        elementList.add(childName.toString());
        return nameBase;
    } catch (UnknownCdmTypeException e) {
        logger.warn("Name with id " + strId + " has unknown nomenclatural code.");
        success.setValue(false);
    }
    return null;
}
Also used : NomenclaturalCode(eu.etaxonomy.cdm.model.name.NomenclaturalCode) Reference(eu.etaxonomy.cdm.model.reference.Reference) Element(org.jdom.Element) ArrayList(java.util.ArrayList) Rank(eu.etaxonomy.cdm.model.name.Rank) MapWrapper(eu.etaxonomy.cdm.io.common.MapWrapper) Namespace(org.jdom.Namespace) UnknownCdmTypeException(eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) Person(eu.etaxonomy.cdm.model.agent.Person)

Example 17 with NomenclaturalCode

use of eu.etaxonomy.cdm.model.name.NomenclaturalCode in project cdmlib by cybertaxonomy.

the class NonViralNameParserImpl method parseAuthors.

/**
 * Author parser for external use
 * @param nonViralName
 * @param authorString
 * @throws StringNotParsableException
 */
@Override
public void parseAuthors(INonViralName nonViralNameOrig, String authorString) throws StringNotParsableException {
    INonViralName nonViralName = CdmBase.deproxy(nonViralNameOrig);
    TeamOrPersonBase<?>[] authors = new TeamOrPersonBase[4];
    Integer[] years = new Integer[4];
    NomenclaturalCode code = nonViralName.getNameType();
    fullAuthors(authorString, authors, years, code);
    nonViralName.setCombinationAuthorship(authors[0]);
    nonViralName.setExCombinationAuthorship(authors[1]);
    nonViralName.setBasionymAuthorship(authors[2]);
    nonViralName.setExBasionymAuthorship(authors[3]);
    if (nonViralName.isZoological()) {
        IZoologicalName zooName = (IZoologicalName) nonViralName;
        zooName.setPublicationYear(years[0]);
        zooName.setOriginalPublicationYear(years[2]);
    }
}
Also used : INonViralName(eu.etaxonomy.cdm.model.name.INonViralName) NomenclaturalCode(eu.etaxonomy.cdm.model.name.NomenclaturalCode) TeamOrPersonBase(eu.etaxonomy.cdm.model.agent.TeamOrPersonBase) IZoologicalName(eu.etaxonomy.cdm.model.name.IZoologicalName)

Example 18 with NomenclaturalCode

use of eu.etaxonomy.cdm.model.name.NomenclaturalCode in project cdmlib by cybertaxonomy.

the class NomenclaturalCodeUpdater method invoke.

@Override
public void invoke(ICdmDataSource datasource, IProgressMonitor monitor, CaseType caseType, SchemaUpdateResult result) throws SQLException {
    String existsSql = " SELECT count(*) FROM @@CdmPreference@@ " + " WHERE key_predicate = 'model.name.NC' AND key_subject = '/'";
    existsSql = caseType.replaceTableNames(existsSql);
    if (((Number) datasource.getSingleValue(existsSql)).intValue() > 0) {
        return;
    }
    String sql = "SELECT count(DTYPE) as n, DTYPE FROM @@TaxonNameBase@@ " + " GROUP BY DTYPE ORDER BY count(DTYPE) DESC ";
    sql = caseType.replaceTableNames(sql);
    ResultSet rs = datasource.executeQuery(sql);
    if (rs.next()) {
        String dtype = rs.getString(2);
        NomenclaturalCode code = NomenclaturalCode.fromDtype(dtype);
        if (code != null) {
            String insertSql = " INSERT INTO @@CdmPreference@@ (key_predicate, key_subject, value)" + " VALUES ('model.name.NC','/','eu.etaxonomy.cdm.model.name.NomenclaturalCode.%s')";
            insertSql = String.format(insertSql, code.getUuid());
            insertSql = caseType.replaceTableNames(insertSql);
            datasource.executeUpdate(insertSql);
            logger.warn("Nomenclatural code updated");
        }
    }
    return;
}
Also used : NomenclaturalCode(eu.etaxonomy.cdm.model.name.NomenclaturalCode) ResultSet(java.sql.ResultSet)

Aggregations

NomenclaturalCode (eu.etaxonomy.cdm.model.name.NomenclaturalCode)18 Rank (eu.etaxonomy.cdm.model.name.Rank)8 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)7 UnknownCdmTypeException (eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException)7 INonViralName (eu.etaxonomy.cdm.model.name.INonViralName)6 Reference (eu.etaxonomy.cdm.model.reference.Reference)4 ArrayList (java.util.ArrayList)3 Person (eu.etaxonomy.cdm.model.agent.Person)2 TeamOrPersonBase (eu.etaxonomy.cdm.model.agent.TeamOrPersonBase)2 CommonTaxonName (eu.etaxonomy.cdm.model.description.CommonTaxonName)2 IZoologicalName (eu.etaxonomy.cdm.model.name.IZoologicalName)2 TaxonBase (eu.etaxonomy.cdm.model.taxon.TaxonBase)2 StringNotParsableException (eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException)2 Property (com.hp.hpl.jena.rdf.model.Property)1 Statement (com.hp.hpl.jena.rdf.model.Statement)1 StmtIterator (com.hp.hpl.jena.rdf.model.StmtIterator)1 URI (eu.etaxonomy.cdm.common.URI)1 MapWrapper (eu.etaxonomy.cdm.io.common.MapWrapper)1 ExcelDistributionUpdateConfigurator (eu.etaxonomy.cdm.io.distribution.excelupdate.ExcelDistributionUpdateConfigurator)1 NormalExplicitImportConfigurator (eu.etaxonomy.cdm.io.excel.taxa.NormalExplicitImportConfigurator)1