use of eu.etaxonomy.cdm.ref.TypedEntityReference in project cdmlib by cybertaxonomy.
the class TypeDesignationSetManagerTest method test1.
@Test
public void test1() throws RegistrationValidationException {
@SuppressWarnings("rawtypes") List<TypeDesignationBase> tds = new ArrayList<>();
tds.add(ntd);
tds.add(std_IT);
tds.add(std_HT);
tds.add(std_IT_2);
tds.add(std_IT_3);
TaxonName typifiedName = TaxonNameFactory.NewBacterialInstance(Rank.GENUS());
typifiedName.setTitleCache("Prionus L.", true);
typifiedName.addTypeDesignation(ntd, false);
typifiedName.addTypeDesignation(std_HT, false);
typifiedName.addTypeDesignation(std_IT, false);
typifiedName.addTypeDesignation(std_IT_2, false);
typifiedName.addTypeDesignation(std_IT_3, false);
TypeDesignationSetManager typeDesignationManager = new TypeDesignationSetManager(tds);
String result = typeDesignationManager.print(WITH_CITATION, WITH_TYPE_LABEL, WITH_NAME);
// Logger.getLogger(this.getClass()).debug(result);
assertNotNull(result);
assertEquals("Prionus L.\u202F\u2013\u202FTypes: Dreamland, near Kissingen, A.Kohlbecker 66211, 2017 (isotype: M);" + " Testland, near Bughausen, A.Kohlbecker 81989, 2017 (holotype: OHA; isotypes: BER, KEW);" + " nametype: Prionus coriatius L.", result);
LinkedHashMap<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet> orderedTypeDesignations = typeDesignationManager.getOrderedTypeDesignationWorkingSets();
Iterator<TypeDesignationWorkingSet> byStatusMapIterator = orderedTypeDesignations.values().iterator();
Iterator<TypeDesignationStatusBase<?>> keyIt_1 = byStatusMapIterator.next().keySet().iterator();
Iterator<TypeDesignationStatusBase<?>> keyIt_2 = byStatusMapIterator.next().keySet().iterator();
assertEquals("isotype", keyIt_1.next().getLabel());
assertEquals("holotype", keyIt_2.next().getLabel());
assertEquals("isotype", keyIt_2.next().getLabel());
}
use of eu.etaxonomy.cdm.ref.TypedEntityReference in project cdmlib by cybertaxonomy.
the class MapJSONValueProcessor method processArrayValue.
@Override
public Object processArrayValue(Object value, JsonConfig jsonConfig) {
if (value instanceof TypeDesignationWorkingSet) {
TypeDesignationWorkingSet map = (TypeDesignationWorkingSet) value;
JSONObject json = new JSONObject();
for (TypeDesignationStatusBase<?> key : map.keySet()) {
TermRepresentation_L10n term_L10n = new TermRepresentation_L10n(key, false);
String label = Objects.toString(term_L10n.getLabel(), "NULL");
json.element(label, map.get(key), jsonConfig);
}
return json;
} else if (value instanceof Map) {
Map<?, ?> map = (Map<?, ?>) value;
if (!map.isEmpty()) {
JSONObject json = new JSONObject();
if (map.keySet().iterator().next() instanceof TypedEntityReference) {
for (Object key : map.keySet()) {
json.element(key.toString(), map.get(key), jsonConfig);
}
} else {
for (Object val : map.values()) {
if (val instanceof LanguageString) {
json.element(((LanguageString) val).getLanguageLabel(), val, jsonConfig);
} else {
return JSONObject.fromObject(value, jsonConfig);
}
}
}
return json;
}
}
return JSONObject.fromObject(value, jsonConfig);
}
use of eu.etaxonomy.cdm.ref.TypedEntityReference in project cdmlib by cybertaxonomy.
the class TaggedTextBuilder method add.
public void add(TagEnum type, String text, CdmBase entity) {
CdmBase deproxiedEntity = HibernateProxyHelper.deproxy(entity);
taggedText.add(new TaggedText(type, text, new TypedEntityReference<>(deproxiedEntity.getClass(), deproxiedEntity.getUuid())));
}
use of eu.etaxonomy.cdm.ref.TypedEntityReference in project cdmlib by cybertaxonomy.
the class TypeDesignationSetManager method orderByTypeByBaseEntity.
private LinkedHashMap<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet> orderByTypeByBaseEntity(Map<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet> stringsByTypeByBaseEntity) {
// order the FieldUnit TypeName keys
Set<Entry<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet>> entrySet = stringsByTypeByBaseEntity.entrySet();
LinkedList<Entry<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet>> baseEntityKeyList = new LinkedList<>(entrySet);
Collections.sort(baseEntityKeyList, entryComparator);
// new LinkedHashMap for the ordered FieldUnitOrTypeName keys
LinkedHashMap<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet> stringsOrderedbyBaseEntityOrderdByType = new LinkedHashMap<>(stringsByTypeByBaseEntity.size());
for (Entry<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet> entry : baseEntityKeyList) {
TypedEntityReference<? extends VersionableEntity> baseEntityRef = entry.getKey();
TypeDesignationWorkingSet typeDesignationWorkingSet = stringsByTypeByBaseEntity.get(baseEntityRef);
// order the TypeDesignationStatusBase keys
List<TypeDesignationStatusBase<?>> keyList = new LinkedList<>(typeDesignationWorkingSet.keySet());
Collections.sort(keyList, new TypeDesignationStatusComparator());
// new LinkedHashMap for the ordered TypeDesignationStatusBase keys
TypeDesignationWorkingSet orderedStringsByOrderedTypes = new TypeDesignationWorkingSet(typeDesignationWorkingSet.getBaseEntity());
keyList.forEach(key -> orderedStringsByOrderedTypes.put(key, typeDesignationWorkingSet.get(key)));
stringsOrderedbyBaseEntityOrderdByType.put(baseEntityRef, orderedStringsByOrderedTypes);
}
return stringsOrderedbyBaseEntityOrderdByType;
}
use of eu.etaxonomy.cdm.ref.TypedEntityReference in project cdmlib by cybertaxonomy.
the class TypeDesignationSetFormatter method buildTaggedText.
private List<TaggedText> buildTaggedText(TypeDesignationSetManager manager) {
// still unclear if this should become a parameter or should be always true
boolean withBrackets = true;
TaggedTextBuilder finalBuilder = new TaggedTextBuilder();
if (withNameIfAvailable && manager.getTypifiedNameCache() != null) {
finalBuilder.add(TagEnum.name, manager.getTypifiedNameCache(), TypedEntityReference.fromEntity(manager.getTypifiedName(), false));
finalBuilder.addPostSeparator(POST_NAME_SEPARTOR);
}
int typeSetCount = 0;
LinkedHashMap<TypedEntityReference<? extends VersionableEntity>, TypeDesignationWorkingSet> orderedByTypesByBaseEntity = manager.getOrderedTypeDesignationWorkingSets();
TypeDesignationWorkingSetType lastWsType = null;
if (orderedByTypesByBaseEntity != null) {
for (TypedEntityReference<?> baseEntityRef : orderedByTypesByBaseEntity.keySet()) {
buildTaggedTextForSingleTypeSet(manager, withBrackets, finalBuilder, typeSetCount, baseEntityRef, lastWsType);
lastWsType = orderedByTypesByBaseEntity.get(baseEntityRef).getWorkingsetType();
typeSetCount++;
}
}
return finalBuilder.getTaggedText();
}
Aggregations