use of eu.etaxonomy.cdm.model.name.NameRelationship in project cdmlib by cybertaxonomy.
the class CsvNameExport method createNewRecord.
private HashMap<String, String> createNewRecord(TaxonNode childNode, CsvNameExportState state) {
HashMap<String, String> nameRecord = new HashMap<>();
nameRecord.put("classification", childNode.getClassification().getTitleCache());
if (!childNode.getTaxon().getName().getRank().isLower(Rank.GENUS())) {
return null;
}
TaxonNode familyNode = getHigherNode(childNode, Rank.FAMILY());
Taxon taxon;
String nameString;
IBotanicalName name;
if (familyNode == null) {
nameRecord.put("familyTaxon", null);
nameRecord.put("familyName", null);
nameRecord.put("descriptionsFam", null);
} else {
familyNode = CdmBase.deproxy(familyNode);
familyNode.getTaxon().setProtectedTitleCache(true);
nameRecord.put("familyTaxon", familyNode.getTaxon().getTitleCache());
if (familyMap.get(familyNode.getTaxon().getUuid()) != null) {
nameRecord.putAll(familyMap.get(familyNode.getTaxon().getUuid()));
} else {
taxon = (Taxon) getTaxonService().load(familyNode.getTaxon().getUuid());
taxon = CdmBase.deproxy(taxon);
name = CdmBase.deproxy(taxon.getName());
nameRecord.put("familyName", name.getNameCache());
extractDescriptions(nameRecord, taxon, Feature.INTRODUCTION(), "descriptionsFam", state);
familyMap.put(familyNode.getTaxon().getUuid(), nameRecord);
}
}
TaxonNode genusNode = getHigherNode(childNode, Rank.GENUS());
if (genusNode != null) {
genusNode = CdmBase.deproxy(genusNode);
genusNode.getTaxon().setProtectedTitleCache(true);
nameRecord.put("genusTaxon", genusNode.getTaxon().getTitleCache());
if (genusMap.get(genusNode.getTaxon().getUuid()) != null) {
nameRecord.putAll(genusMap.get(genusNode.getTaxon().getUuid()));
} else {
taxon = (Taxon) getTaxonService().load(genusNode.getTaxon().getUuid());
taxon = CdmBase.deproxy(taxon);
name = CdmBase.deproxy(taxon.getName());
if (name.getNameCache() != null) {
nameRecord.put("genusName", name.getNameCache());
} else {
nameRecord.put("genusName", name.getGenusOrUninomial());
}
extractDescriptions(nameRecord, taxon, getNotesFeature(state), "descriptionsGen", state);
genusMap.put(genusNode.getTaxon().getUuid(), nameRecord);
}
} else {
nameRecord.put("genusTaxon", null);
nameRecord.put("genusName", null);
nameRecord.put("descriptionsGen", null);
}
// taxon = (Taxon) getTaxonService().load(childNode.getTaxon().getUuid());
taxon = CdmBase.deproxy(childNode.getTaxon());
// if (taxon.isPublish()){
INonViralName nonViralName = taxon.getName();
nameString = createTaggedNameString(nonViralName, false);
nameRecord.put("childTaxon", taxon.getTitleCache());
if (taxon.getSec() != null) {
nameRecord.put("secRef", taxon.getSec().getTitleCache());
} else {
nameRecord.put("secRef", null);
}
getTaxonRelations(nameRecord, taxon);
name = CdmBase.deproxy(taxon.getName());
nameRecord.put("childName", nameString);
nameRecord.put("nameId", String.valueOf(name.getId()));
nameRecord.put("nameCache", name.getNameCache());
nameRecord.put("titleName", name.getTitleCache());
if (name.getNomenclaturalReference() != null) {
nameRecord.put("NomRefTitleCache", name.getNomenclaturalReference().getTitleCache());
} else {
nameRecord.put("NomRefTitleCache", null);
}
nameRecord.put("fullName", name.getNameCache());
nameRecord.put("fullTitleCache", name.getFullTitleCache());
Set<TypeDesignationBase> typeDesSet = name.getTypeDesignations();
Iterator<TypeDesignationBase> it = typeDesSet.iterator();
String typeNameString = NOT_DESIGNATED;
String statusString = null;
if (it.hasNext()) {
TypeDesignationBase<?> typeDes = CdmBase.deproxy(it.next());
if (typeDes instanceof NameTypeDesignation) {
NameTypeDesignation nameTypeDes = CdmBase.deproxy(typeDes, NameTypeDesignation.class);
IBotanicalName typeName = CdmBase.deproxy(nameTypeDes.getTypeName());
if (typeName != null) {
typeNameString = "<i>" + typeName.getNameCache() + "</i> " + typeName.getAuthorshipCache();
if (nameTypeDes.getTypeStatus() != null) {
NameTypeDesignationStatus status = CdmBase.deproxy(nameTypeDes.getTypeStatus());
statusString = status.getTitleCache();
}
}
}
}
nameRecord.put("typeName", typeNameString);
StringBuffer homotypicalSynonyms = new StringBuffer();
TreeMap<HomotypicalGroup, List<Synonym>> heterotypicSynonymsList = new TreeMap<>(new HomotypicalGroupComparator());
List<Synonym> homotypicSynonymsList = new ArrayList<>();
StringBuffer heterotypicalSynonyms = new StringBuffer();
List<Synonym> homotypicSynonyms;
HomotypicalGroup group;
IBotanicalName synonymName;
String doubtfulTitleCache;
for (Synonym synonym : taxon.getSynonyms()) {
synonymName = CdmBase.deproxy(synonym.getName());
group = CdmBase.deproxy(synonymName.getHomotypicalGroup());
synonymName.generateFullTitle();
if (synonym.isDoubtful()) {
if (!synonymName.getFullTitleCache().startsWith("?")) {
doubtfulTitleCache = "?" + synonymName.getFullTitleCache();
synonymName = synonymName.clone();
synonymName.setFullTitleCache(doubtfulTitleCache, true);
}
}
if (!group.equals(name.getHomotypicalGroup())) {
if (heterotypicSynonymsList.containsKey(group)) {
heterotypicSynonymsList.get(group).add(synonym);
} else {
homotypicSynonyms = new ArrayList<>();
homotypicSynonyms.add(synonym);
heterotypicSynonymsList.put(group, homotypicSynonyms);
homotypicSynonyms = null;
}
} else {
synonymName.generateFullTitle();
homotypicSynonymsList.add(synonym);
}
}
String synonymString;
boolean first = true;
for (List<Synonym> list : heterotypicSynonymsList.values()) {
Collections.sort(list, new HomotypicGroupTaxonComparator(null));
first = true;
for (TaxonBase<?> synonym : list) {
NomenclaturalStatus status = null;
if (!synonym.getName().getStatus().isEmpty()) {
status = CdmBase.deproxy(synonym.getName().getStatus().iterator().next());
if (status.getType().isInvalid()) {
heterotypicalSynonyms.append(" <invalid> ");
synonymName = CdmBase.deproxy(synonym.getName());
synonymString = createSynonymNameString(synonymName, state.getConfig().isInvalidNamesQuoted());
heterotypicalSynonyms.append(synonymString);
continue;
}
}
if (first) {
heterotypicalSynonyms.append(" <heterotypic> ");
} else {
heterotypicalSynonyms.append(" <homonym> ");
}
first = false;
synonymName = CdmBase.deproxy(synonym.getName());
synonymString = createSynonymNameString(synonymName, false);
heterotypicalSynonyms.append(synonymString);
}
}
first = true;
Collections.sort(homotypicSynonymsList, new HomotypicGroupTaxonComparator(null));
NomenclaturalStatus status = null;
for (TaxonBase<?> synonym : homotypicSynonymsList) {
if (!synonym.getName().getStatus().isEmpty()) {
status = CdmBase.deproxy(synonym.getName().getStatus().iterator().next());
if (status.getType().isInvalid()) {
homotypicalSynonyms.append(" <invalid> ");
synonymName = CdmBase.deproxy(synonym.getName());
synonymString = createSynonymNameString(synonymName, true);
homotypicalSynonyms.append(synonymString);
continue;
} else if (!first) {
homotypicalSynonyms.append(" <homonym> ");
}
} else if (!first) {
homotypicalSynonyms.append(" <homonym> ");
}
first = false;
synonymName = CdmBase.deproxy(synonym.getName());
synonymString = createSynonymNameString(synonymName, false);
homotypicalSynonyms.append(synonymString);
}
nameRecord.put("synonyms_homotypic", homotypicalSynonyms.toString());
nameRecord.put("synonyms_heterotypic", heterotypicalSynonyms.toString());
nameRecord.put("status", statusString);
Set<NameRelationship> nameRelations = name.getNameRelations();
INonViralName relatedName = null;
String nameRelType = null;
String relNameString = null;
if (nameRelations.size() > 0) {
NameRelationship nameRel = nameRelations.iterator().next();
IBotanicalName fromName = CdmBase.deproxy(nameRel.getFromName());
if (fromName.equals(taxon.getName())) {
relatedName = nameRel.getToName();
} else {
relatedName = nameRel.getFromName();
}
nameRel = CdmBase.deproxy(nameRel);
nameRelType = nameRel.getType().getTitleCache();
relNameString = createTaggedNameString(relatedName, getStatus(relatedName));
}
nameRecord.put("relatedName", relNameString);
nameRecord.put("nameRelType", nameRelType);
extractDescriptions(nameRecord, taxon, Feature.DISTRIBUTION(), "descriptions", state);
return nameRecord;
}
use of eu.etaxonomy.cdm.model.name.NameRelationship in project cdmlib by cybertaxonomy.
the class TaxonNameDaoHibernateImplTest method testGetNameRelationships.
@Test
public void testGetNameRelationships() {
TaxonName acherontia = taxonNameDao.findByUuid(acherontiaUuid);
assert acherontia != null : "name must exist";
List<NameRelationship> result = taxonNameDao.getNameRelationships(acherontia, NameRelationship.Direction.relatedFrom, null, null, null, null, null);
assertNotNull("getRelatedNames should return a list", result);
assertFalse("the list should not be empty", result.isEmpty());
assertEquals("getRelatedNames should return 1 NameRelationship instance", 1, result.size());
// testing inverted direction
TaxonName atropos = taxonNameDao.findByUuid(atroposUuid);
assert atropos != null : "name must exist";
result = taxonNameDao.getNameRelationships(atropos, NameRelationship.Direction.relatedTo, null, null, null, null, null);
assertNotNull("getRelatedNames should return a list", result);
assertFalse("the list should not be empty", result.isEmpty());
assertEquals("getRelatedNames should return 2 NameRelationship instance", 2, result.size());
result = taxonNameDao.getNameRelationships(null, null, null, null, null, null, null);
assertNotNull("getRelatedNames should return a list", result);
assertFalse("the list should not be empty", result.isEmpty());
assertEquals("getRelatedNames should return all 2 NameRelationship instance", 2, result.size());
}
use of eu.etaxonomy.cdm.model.name.NameRelationship in project cdmlib by cybertaxonomy.
the class CdmImportBase method saveNameRelations.
/**
* Saves name relations. Needed if a name was parsed and has hybrid parents
* which will not be saved via cascade.
*/
protected void saveNameRelations(TaxonName name) {
for (HybridRelationship rel : name.getHybridChildRelations()) {
getNameService().saveOrUpdate(rel.getParentName());
}
for (NameRelationship rel : name.getNameRelations()) {
getNameService().saveOrUpdate(rel.getFromName());
getNameService().saveOrUpdate(rel.getToName());
}
}
use of eu.etaxonomy.cdm.model.name.NameRelationship in project cdmlib by cybertaxonomy.
the class CdmLightClassificationExport method handleNameRelationships.
private void handleNameRelationships(CdmLightExportState state, TaxonName name) {
Set<NameRelationship> rels = name.getRelationsFromThisName();
CdmLightExportTable table = CdmLightExportTable.NAME_RELATIONSHIP;
String[] csvLine = new String[table.getSize()];
for (NameRelationship rel : rels) {
NameRelationshipType type = rel.getType();
TaxonName name2 = rel.getToName();
name2 = HibernateProxyHelper.deproxy(name2, TaxonName.class);
if (!state.getNameStore().containsKey(name2.getId())) {
handleName(state, name2, null);
}
csvLine[table.getIndex(CdmLightExportTable.NAME_REL_TYPE)] = type.getLabel();
csvLine[table.getIndex(CdmLightExportTable.NAME1_FK)] = getId(state, name);
csvLine[table.getIndex(CdmLightExportTable.NAME2_FK)] = getId(state, name2);
state.getProcessor().put(table, name, csvLine);
}
rels = name.getRelationsToThisName();
csvLine = new String[table.getSize()];
for (NameRelationship rel : rels) {
NameRelationshipType type = rel.getType();
TaxonName name2 = rel.getFromName();
name2 = HibernateProxyHelper.deproxy(name2, TaxonName.class);
if (!state.getNameStore().containsKey(name2.getId())) {
handleName(state, name2, null);
}
}
}
use of eu.etaxonomy.cdm.model.name.NameRelationship in project cdmlib by cybertaxonomy.
the class FullCoverageDataGenerator method createTaxonName.
private void createTaxonName(List<CdmBase> cdmBases) {
TaxonName bacName = TaxonNameFactory.NewBacterialInstance(Rank.GENUS());
bacName.setSubGenusAuthorship("sub Genus author");
bacName.setNameApprobation("nameApprobation");
handleIdentifiableEntity(bacName);
TaxonName botName = TaxonNameFactory.NewCultivarInstance(Rank.SUBSPECIES());
botName.setAnamorphic(true);
botName.setCultivarEpithet("cultivarEpithet");
botName.setGenusOrUninomial("Genus");
botName.setInfraGenericEpithet("InfraGeneric");
botName.setSpecificEpithet("specificEpithet");
botName.setInfraSpecificEpithet("infraSpecificEpithet");
Person combinationAuthorship = Person.NewInstance();
botName.setCombinationAuthorship(combinationAuthorship);
Person exCombinationAuthorship = Person.NewInstance();
botName.setExCombinationAuthorship(exCombinationAuthorship);
Person basionymAuthorship = Person.NewInstance();
botName.setBasionymAuthorship(basionymAuthorship);
Person exBasionymAuthorship = Person.NewInstance();
botName.setExBasionymAuthorship(exBasionymAuthorship);
handleIdentifiableEntity(botName);
handleAnnotatableEntity(botName.getHomotypicalGroup());
TaxonName botName2 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
HybridRelationship hybridRel = botName2.addHybridChild(botName, HybridRelationshipType.FIRST_PARENT(), "Rule 1.2.3");
hybridRel.setCitation(ReferenceFactory.newBook());
hybridRel.setCitationMicroReference("p. 123");
handleAnnotatableEntity(hybridRel);
TaxonName zooName = TaxonNameFactory.NewZoologicalInstance(Rank.GENUS());
zooName.setBreed("breed");
zooName.setPublicationYear(1922);
zooName.setOriginalPublicationYear(1987);
zooName.setAppendedPhrase("appended phrase");
zooName.addDescription(TaxonNameDescription.NewInstance());
zooName.setNomenclaturalMicroReference("p. 123");
zooName.setNomenclaturalReference(getReference());
NameRelationship rel = zooName.addRelationshipFromName(botName, NameRelationshipType.LATER_HOMONYM(), "ruleConsidered", NomenclaturalCodeEdition.ICN_2017_SHENZHEN);
NomenclaturalStatus status = NomenclaturalStatus.NewInstance(NomenclaturalStatusType.CONSERVED(), getReference(), "p. 222");
zooName.addStatus(status);
handleAnnotatableEntity(rel);
handleAnnotatableEntity(status);
handleIdentifiableEntity(zooName);
// TypeDesignation
TaxonName speciesZooName = TaxonNameFactory.NewZoologicalInstance(Rank.SPECIES());
NameTypeDesignation nameDesig = zooName.addNameTypeDesignation(speciesZooName, getReference(), "111", "original name", NameTypeDesignationStatus.AUTOMATIC(), true, true, true, true);
handleAnnotatableEntity(nameDesig);
SpecimenTypeDesignation specimenDesig = speciesZooName.addSpecimenTypeDesignation(getSpecimen(), SpecimenTypeDesignationStatus.HOLOTYPE(), getReference(), "p,22", "original name", false, true);
handleAnnotatableEntity(specimenDesig);
speciesZooName.addTextualTypeDesignation("A textual type designation", Language.ENGLISH(), true, getReference(), "123", "Species orginalus", false);
TaxonName viralName = TaxonNameFactory.NewViralInstance(Rank.GENUS());
viralName.setAcronym("acronym");
handleIdentifiableEntity(viralName);
// Registration
Registration registration = Registration.NewInstance("registration identifier", "specificIdentifier", speciesZooName, null);
registration.addTypeDesignation(specimenDesig);
registration.setRegistrationDate(DateTime.now());
Registration blockingRegistration = Registration.NewInstance();
registration.addBlockedBy(blockingRegistration);
registration.setInstitution(Institution.NewInstance());
User submitter = User.NewInstance("submitter", "12345");
registration.setSubmitter(submitter);
handleAnnotatableEntity(registration);
;
cdmBases.add(submitter);
cdmBases.add(bacName);
cdmBases.add(botName);
cdmBases.add(viralName);
cdmBases.add(zooName);
cdmBases.add(botName2);
}
Aggregations