use of eu.etaxonomy.cdm.model.agent.TeamOrPersonBase in project cdmlib by cybertaxonomy.
the class MarkupNomenclatureImport method handleCitationSpecific.
/**
* Handles references used in the citation tag
* @param appendix
* @see #handleNonCitationSpecific(String, String, String, String, String, String, String, String)
*/
private Reference handleCitationSpecific(MarkupImportState state, String type, String authorStr, String titleStr, String titleCache, String volume, String issue, String edition, String editors, String pubName, String pages, String appendix, Map<String, String> refMap, XMLEvent parentEvent) {
if (titleStr != null) {
String message = "Currently it is not expected that a titleStr exists in a citation";
fireWarningEvent(message, parentEvent, 4);
}
if (isBlank(volume) && isNotBlank(issue)) {
String message = "Issue ('" + issue + "') exists but no volume";
fireWarningEvent(message, parentEvent, 4);
volume = issue;
} else if (isNotBlank(issue)) {
volume = volume + "(" + issue + ")";
}
RefType refType = defineRefTypeForCitation(type, volume, editors, authorStr, pubName, parentEvent);
Reference reference;
if (isNotBlank(appendix)) {
pubName = pubName == null ? appendix : (pubName + " " + appendix).replaceAll(" ", " ");
}
if (refType == RefType.Article) {
IArticle article = ReferenceFactory.newArticle();
if (pubName != null) {
IJournal journal = ReferenceFactory.newJournal();
journal.setTitle(pubName);
article.setInJournal(journal);
article.setVolume(volume);
if (isNotBlank(edition)) {
String message = "Article must not have an edition.";
fireWarningEvent(message, parentEvent, 4);
}
}
reference = (Reference) article;
} else if (refType == RefType.BookSection) {
// Book Section
reference = ReferenceFactory.newBookSection();
IBook book = ReferenceFactory.newBook();
reference.setInBook(book);
book.setTitle(pubName);
book.setVolume(volume);
book.setEdition(edition);
if (state.getConfig().isUseEditorAsInAuthorWhereNeeded()) {
TeamOrPersonBase<?> inAuthor = createAuthor(state, editors);
book.setAuthorship(inAuthor);
editors = null;
}
} else if (refType == RefType.Book) {
// Book
reference = ReferenceFactory.newBook();
reference.setTitle(pubName);
reference.setVolume(volume);
reference.setEdition(edition);
} else if (refType == RefType.Generic) {
// Generic - undefinable
// String message = "Can't define the type of the reference. Use generic instead";
// fireWarningEvent(message, parentEvent, 4);
reference = ReferenceFactory.newGeneric();
reference.setTitle(pubName);
reference.setEdition(edition);
// volume indicates an in-reference
if (isNotBlank(volume)) {
Reference partOf = ReferenceFactory.newGeneric();
partOf.setVolume(volume);
partOf.setInReference(reference);
reference = partOf;
}
} else if (refType == RefType.LatestUsed) {
Reference latestReference = state.getLatestReferenceInHomotype();
if (latestReference == null) {
String message = "No former reference available for incomplete citation";
fireWarningEvent(message, parentEvent, 6);
reference = ReferenceFactory.newGeneric();
} else {
if (latestReference.getInReference() != null) {
reference = latestReference.clone();
} else {
String message = "Latest reference is not an in-reference. This is not yet handled.";
fireWarningEvent(message, parentEvent, 6);
reference = ReferenceFactory.newGeneric();
}
}
reference.setVolume(volume);
if (isNotBlank(edition)) {
String message = "Edition not yet handled for incomplete citations";
fireWarningEvent(message, parentEvent, 4);
}
} else {
String message = "Unhandled reference type: %s";
fireWarningEvent(String.format(message, refType.toString()), parentEvent, 8);
reference = ReferenceFactory.newGeneric();
}
// author
TeamOrPersonBase<?> author;
if (isBlank(authorStr)) {
if (refType != RefType.LatestUsed) {
author = state.getLatestAuthorInHomotype();
reference.setAuthorship(author);
}
} else {
author = createAuthor(state, authorStr);
state.setLatestAuthorInHomotype(author);
reference.setAuthorship(author);
}
// title, titleCache
handleTitlesInCitation(titleStr, titleCache, parentEvent, reference);
// editors
handleEditorsInCitation(edition, editors, reference, parentEvent);
// pages
handlePages(state, refMap, parentEvent, reference, pages);
// state.getDeduplicationHelper(docImport).getExistingReference(state, reference);
// remember reference for following citation
state.setLatestReferenceInHomotype(reference);
return reference;
}
use of eu.etaxonomy.cdm.model.agent.TeamOrPersonBase in project cdmlib by cybertaxonomy.
the class MarkupSpecimenImport method handleGathering.
private void handleGathering(MarkupImportState state, XMLEventReader readerOrig, XMLEvent parentEvent, DerivedUnitFacade facade) throws XMLStreamException {
checkNoAttributes(parentEvent);
boolean hasCollector = false;
boolean hasFieldNum = false;
LookAheadEventReader reader = new LookAheadEventReader(parentEvent.asStartElement(), readerOrig);
// elements
while (reader.hasNext()) {
XMLEvent next = readNoWhitespace(reader);
if (isMyEndingElement(next, parentEvent)) {
if (!hasCollector) {
if (state.getCurrentCollector() == null) {
checkMandatoryElement(hasCollector, parentEvent.asStartElement(), COLLECTOR);
} else {
facade.setCollector(state.getCurrentCollector());
}
}
checkMandatoryElement(hasFieldNum, parentEvent.asStartElement(), FIELD_NUM);
return;
} else if (isStartingElement(next, COLLECTOR)) {
hasCollector = true;
String collectorStr = getCData(state, reader, next);
TeamOrPersonBase<?> collector = createCollector(state, collectorStr);
facade.setCollector(collector);
state.setCurrentCollector(collector);
} else if (isStartingElement(next, ALTERNATIVE_COLLECTOR)) {
handleNotYetImplementedElement(next);
} else if (isStartingElement(next, FIELD_NUM)) {
hasFieldNum = true;
String fieldNumStr = getCData(state, reader, next);
facade.setFieldNumber(fieldNumStr);
} else if (isStartingElement(next, ALTERNATIVE_FIELD_NUM)) {
handleAlternativeFieldNumber(state, reader, next, facade.innerFieldUnit());
} else if (isStartingElement(next, COLLECTION_TYPE_STATUS)) {
handleNotYetImplementedElement(next);
} else if (isStartingElement(next, COLLECTION_AND_TYPE)) {
handleGatheringCollectionAndType(state, reader, next, facade);
} else if (isStartingElement(next, ALTERNATIVE_COLLECTION_TYPE_STATUS)) {
handleNotYetImplementedElement(next);
} else if (isStartingElement(next, SUB_GATHERING)) {
handleNotYetImplementedElement(next);
} else if (isStartingElement(next, COLLECTION)) {
handleNotYetImplementedElement(next);
} else if (isStartingElement(next, LOCALITY)) {
handleLocality(state, reader, next, facade);
} else if (isStartingElement(next, FULL_NAME)) {
// can be any
Rank defaultRank = Rank.SPECIES();
INonViralName nvn = createNameByCode(state, defaultRank);
handleFullName(state, reader, nvn, next);
TaxonName name = TaxonName.castAndDeproxy(nvn);
DeterminationEvent.NewInstance(name, facade.innerDerivedUnit() != null ? facade.innerDerivedUnit() : facade.innerFieldUnit());
} else if (isStartingElement(next, DATES)) {
TimePeriod timePeriod = handleDates(state, reader, next);
facade.setGatheringPeriod(timePeriod);
} else if (isStartingElement(next, GATHERING_NOTES)) {
handleAmbigousManually(state, reader, next.asStartElement());
} else if (isStartingElement(next, NOTES)) {
handleNotYetImplementedElement(next);
} else if (next.isCharacters()) {
String text = next.asCharacters().getData().trim();
if (isPunctuation(text)) {
// do nothing
} else if (state.isSpecimenType() && charIsSimpleType(text)) {
// do nothing
} else if ((text.equals("=") || text.equals("(")) && reader.nextIsStart(ALTERNATIVE_FIELD_NUM)) {
// do nothing
} else if ((text.equals(").") || text.equals(")")) && reader.previousWasEnd(ALTERNATIVE_FIELD_NUM)) {
// do nothing
} else if (charIsOpeningOrClosingBracket(text)) {
// for now we don't do anything, however in future brackets may have semantics
} else {
// TODO
String message = "Unrecognized text: %s";
fireWarningEvent(String.format(message, text), next, 6);
}
} else {
handleUnexpectedElement(next);
}
}
throw new IllegalStateException("Collection has no closing tag.");
}
use of eu.etaxonomy.cdm.model.agent.TeamOrPersonBase in project cdmlib by cybertaxonomy.
the class CdmLightClassificationExport method handleIdentifier.
private void handleIdentifier(CdmLightExportState state, CdmBase cdmBase) {
CdmLightExportTable table = CdmLightExportTable.IDENTIFIER;
String[] csvLine;
try {
if (cdmBase instanceof TaxonName) {
TaxonName name = (TaxonName) cdmBase;
try {
List<Identifier> identifiers = name.getIdentifiers();
// first check which kind of identifiers are available and then sort and create table entries
Map<DefinedTerm, Set<Identifier>> identifierTypes = new HashMap<>();
for (Identifier identifier : identifiers) {
DefinedTerm type = identifier.getType();
if (identifierTypes.containsKey(type)) {
identifierTypes.get(type).add(identifier);
} else {
Set<Identifier> tempList = new HashSet<>();
tempList.add(identifier);
identifierTypes.put(type, tempList);
}
}
for (DefinedTerm type : identifierTypes.keySet()) {
Set<Identifier> identifiersByType = identifierTypes.get(type);
csvLine = new String[table.getSize()];
csvLine[table.getIndex(CdmLightExportTable.FK)] = getId(state, name);
csvLine[table.getIndex(CdmLightExportTable.REF_TABLE)] = "ScientificName";
csvLine[table.getIndex(CdmLightExportTable.IDENTIFIER_TYPE)] = type.getLabel();
csvLine[table.getIndex(CdmLightExportTable.EXTERNAL_NAME_IDENTIFIER)] = extractIdentifier(identifiersByType);
state.getProcessor().put(table, name.getUuid() + ", " + type.getLabel(), csvLine);
}
// Set<String> IPNIidentifiers = name.getIdentifiers(DefinedTerm.IDENTIFIER_NAME_IPNI());
// Set<String> tropicosIdentifiers = name.getIdentifiers(DefinedTerm.IDENTIFIER_NAME_TROPICOS());
// Set<String> WFOIdentifiers = name.getIdentifiers(DefinedTerm.uuidWfoNameIdentifier);
// if (!IPNIidentifiers.isEmpty()) {
// csvLine = new String[table.getSize()];
// csvLine[table.getIndex(CdmLightExportTable.FK)] = getId(state, name);
// csvLine[table.getIndex(CdmLightExportTable.REF_TABLE)] = "ScientificName";
// csvLine[table.getIndex(CdmLightExportTable.IDENTIFIER_TYPE)] = IPNI_NAME_IDENTIFIER;
// csvLine[table.getIndex(CdmLightExportTable.EXTERNAL_NAME_IDENTIFIER)] = extractIdentifier(
// IPNIidentifiers);
// state.getProcessor().put(table, name.getUuid() + ", " + IPNI_NAME_IDENTIFIER, csvLine);
// }
// if (!tropicosIdentifiers.isEmpty()) {
// csvLine = new String[table.getSize()];
// csvLine[table.getIndex(CdmLightExportTable.FK)] = getId(state, name);
// csvLine[table.getIndex(CdmLightExportTable.REF_TABLE)] = "ScientificName";
// csvLine[table.getIndex(CdmLightExportTable.IDENTIFIER_TYPE)] = TROPICOS_NAME_IDENTIFIER;
// csvLine[table.getIndex(CdmLightExportTable.EXTERNAL_NAME_IDENTIFIER)] = extractIdentifier(
// tropicosIdentifiers);
// state.getProcessor().put(table, name.getUuid() + ", " + IPNI_NAME_IDENTIFIER, csvLine);
// }
// if (!WFOIdentifiers.isEmpty()) {
// csvLine = new String[table.getSize()];
// csvLine[table.getIndex(CdmLightExportTable.FK)] = getId(state, name);
// csvLine[table.getIndex(CdmLightExportTable.REF_TABLE)] = "ScientificName";
// csvLine[table.getIndex(CdmLightExportTable.IDENTIFIER_TYPE)] = WFO_NAME_IDENTIFIER;
// csvLine[table.getIndex(CdmLightExportTable.EXTERNAL_NAME_IDENTIFIER)] = extractIdentifier(
// WFOIdentifiers);
// state.getProcessor().put(table, name.getUuid() + ", " + WFO_NAME_IDENTIFIER, csvLine);
// }
} catch (Exception e) {
state.getResult().addWarning("Please check the identifiers for " + cdmBaseStr(cdmBase) + " maybe there is an empty identifier");
}
} else {
if (cdmBase instanceof IdentifiableEntity) {
IdentifiableEntity<?> identifiableEntity = (IdentifiableEntity<?>) cdmBase;
List<Identifier> identifiers = identifiableEntity.getIdentifiers();
String tableName = null;
if (cdmBase instanceof Reference) {
tableName = "Reference";
} else if (cdmBase instanceof SpecimenOrObservationBase) {
tableName = "Specimen";
} else if (cdmBase instanceof Taxon) {
tableName = "Taxon";
} else if (cdmBase instanceof Synonym) {
tableName = "Synonym";
} else if (cdmBase instanceof TeamOrPersonBase) {
tableName = "PersonOrTeam";
}
for (Identifier identifier : identifiers) {
if (identifier.getType() == null && identifier.getIdentifier() == null) {
state.getResult().addWarning("Please check the identifiers for " + cdmBaseStr(cdmBase) + " there is an empty identifier");
continue;
}
csvLine = new String[table.getSize()];
csvLine[table.getIndex(CdmLightExportTable.FK)] = getId(state, cdmBase);
if (tableName != null) {
csvLine[table.getIndex(CdmLightExportTable.REF_TABLE)] = tableName;
csvLine[table.getIndex(CdmLightExportTable.IDENTIFIER_TYPE)] = identifier.getType() != null ? identifier.getType().getLabel() : null;
csvLine[table.getIndex(CdmLightExportTable.EXTERNAL_NAME_IDENTIFIER)] = identifier.getIdentifier();
state.getProcessor().put(table, cdmBase.getUuid() + (identifier.getType() != null ? identifier.getType().getLabel() : null), csvLine);
}
}
if (cdmBase instanceof Reference) {
Reference ref = (Reference) cdmBase;
if (ref.getDoi() != null) {
csvLine = new String[table.getSize()];
csvLine[table.getIndex(CdmLightExportTable.FK)] = getId(state, cdmBase);
csvLine[table.getIndex(CdmLightExportTable.REF_TABLE)] = tableName;
csvLine[table.getIndex(CdmLightExportTable.IDENTIFIER_TYPE)] = "DOI";
csvLine[table.getIndex(CdmLightExportTable.EXTERNAL_NAME_IDENTIFIER)] = ref.getDoiString();
state.getProcessor().put(table, cdmBase.getUuid() + "DOI", csvLine);
}
}
if (cdmBase instanceof TeamOrPersonBase) {
TeamOrPersonBase<?> person = HibernateProxyHelper.deproxy(cdmBase, TeamOrPersonBase.class);
if (person instanceof Person && ((Person) person).getOrcid() != null) {
csvLine = new String[table.getSize()];
csvLine[table.getIndex(CdmLightExportTable.FK)] = getId(state, cdmBase);
csvLine[table.getIndex(CdmLightExportTable.REF_TABLE)] = tableName;
csvLine[table.getIndex(CdmLightExportTable.IDENTIFIER_TYPE)] = "ORCID";
csvLine[table.getIndex(CdmLightExportTable.EXTERNAL_NAME_IDENTIFIER)] = ((Person) person).getOrcid().asURI();
state.getProcessor().put(table, cdmBase.getUuid() + "ORCID", csvLine);
}
}
}
}
} catch (Exception e) {
state.getResult().addException(e, "An unexpected error occurred when handling identifiers for " + cdmBaseStr(cdmBase) + ": " + e.getMessage());
e.printStackTrace();
}
}
use of eu.etaxonomy.cdm.model.agent.TeamOrPersonBase in project cdmlib by cybertaxonomy.
the class TcsRdfTaxonNameImport method doInvoke.
@Override
protected void doInvoke(TcsRdfImportState state) {
MapWrapper<TaxonName> taxonNameMap = (MapWrapper<TaxonName>) state.getStore(ICdmIO.TAXONNAME_STORE);
MapWrapper<Reference> referenceMap = (MapWrapper<Reference>) state.getStore(ICdmIO.REFERENCE_STORE);
MapWrapper<TeamOrPersonBase> authorMap = (MapWrapper<TeamOrPersonBase>) state.getStore(ICdmIO.TEAM_STORE);
String tcsElementName;
Namespace tcsNamespace;
String value;
logger.info("start makeTaxonNames ...");
TcsRdfImportConfigurator config = state.getConfig();
Model root = config.getSourceRoot();
String rdfNamespace = config.getRdfNamespaceURIString();
String taxonNameNamespace = config.getTnNamespaceURIString();
String idNamespace = "TaxonName";
Resource elTaxonName = root.getResource(taxonNameNamespace);
int i = 0;
TaxonName name;
Property property = root.getProperty(taxonNameNamespace + "authorship");
ResIterator iterator = root.listSubjectsWithProperty(property, (RDFNode) null);
String id;
while (iterator.hasNext()) {
Resource resource = iterator.next();
name = handleNameResource(resource, config);
id = resource.getNameSpace();
taxonNameMap.put(id, name);
}
logger.info(i + " names handled");
getNameService().save(taxonNameMap.objects());
// makeNameSpecificData(nameMap);
logger.info("end makeTaxonNames ...");
return;
}
use of eu.etaxonomy.cdm.model.agent.TeamOrPersonBase in project cdmlib by cybertaxonomy.
the class NonViralNameParserImpl method handleAuthors.
public void handleAuthors(INonViralName nameToBeFilled, String fullNameString, String authorString) {
TeamOrPersonBase<?>[] authors = new TeamOrPersonBase[4];
Integer[] years = new Integer[4];
try {
NomenclaturalCode code = nameToBeFilled.getNameType();
fullAuthors(authorString, authors, years, code);
} catch (StringNotParsableException e) {
nameToBeFilled.addParsingProblem(ParserProblem.UnparsableAuthorPart);
nameToBeFilled.setTitleCache(fullNameString, true);
// FIXME Quick fix, otherwise search would not deliver results for unparsable names
nameToBeFilled.setNameCache(fullNameString, true);
// END
logger.info("no applicable parsing rule could be found for \"" + fullNameString + "\"");
}
nameToBeFilled.setCombinationAuthorship(authors[0]);
nameToBeFilled.setExCombinationAuthorship(authors[1]);
nameToBeFilled.setBasionymAuthorship(authors[2]);
nameToBeFilled.setExBasionymAuthorship(authors[3]);
if (nameToBeFilled.isZoological()) {
IZoologicalName zooName = (IZoologicalName) nameToBeFilled;
zooName.setPublicationYear(years[0]);
zooName.setOriginalPublicationYear(years[2]);
}
}
Aggregations