use of eu.etaxonomy.cdm.compare.name.HomotypicalGroupComparator 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;
}
Aggregations