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