Search in sources :

Example 1 with TypedEntityReference

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());
}
Also used : TypeDesignationBase(eu.etaxonomy.cdm.model.name.TypeDesignationBase) ArrayList(java.util.ArrayList) TypeDesignationStatusBase(eu.etaxonomy.cdm.model.name.TypeDesignationStatusBase) VersionableEntity(eu.etaxonomy.cdm.model.common.VersionableEntity) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName) TypedEntityReference(eu.etaxonomy.cdm.ref.TypedEntityReference) Test(org.junit.Test)

Example 2 with TypedEntityReference

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);
}
Also used : TermRepresentation_L10n(eu.etaxonomy.cdm.api.service.l10n.TermRepresentation_L10n) JSONObject(net.sf.json.JSONObject) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) TypeDesignationWorkingSet(eu.etaxonomy.cdm.api.service.name.TypeDesignationWorkingSet) JSONObject(net.sf.json.JSONObject) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) TypedEntityReference(eu.etaxonomy.cdm.ref.TypedEntityReference) Map(java.util.Map)

Example 3 with TypedEntityReference

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())));
}
Also used : CdmBase(eu.etaxonomy.cdm.model.common.CdmBase) TypedEntityReference(eu.etaxonomy.cdm.ref.TypedEntityReference)

Example 4 with TypedEntityReference

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;
}
Also used : TypeDesignationStatusComparator(eu.etaxonomy.cdm.compare.name.TypeDesignationStatusComparator) TypeDesignationStatusBase(eu.etaxonomy.cdm.model.name.TypeDesignationStatusBase) LinkedList(java.util.LinkedList) VersionableEntity(eu.etaxonomy.cdm.model.common.VersionableEntity) LinkedHashMap(java.util.LinkedHashMap) Entry(java.util.Map.Entry) TypedEntityReference(eu.etaxonomy.cdm.ref.TypedEntityReference)

Example 5 with TypedEntityReference

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();
}
Also used : TypeDesignationWorkingSetType(eu.etaxonomy.cdm.api.service.name.TypeDesignationWorkingSet.TypeDesignationWorkingSetType) TaggedTextBuilder(eu.etaxonomy.cdm.strategy.cache.TaggedTextBuilder) TypedEntityReference(eu.etaxonomy.cdm.ref.TypedEntityReference) VersionableEntity(eu.etaxonomy.cdm.model.common.VersionableEntity)

Aggregations

TypedEntityReference (eu.etaxonomy.cdm.ref.TypedEntityReference)7 VersionableEntity (eu.etaxonomy.cdm.model.common.VersionableEntity)4 TypeDesignationStatusBase (eu.etaxonomy.cdm.model.name.TypeDesignationStatusBase)2 TaggedTextBuilder (eu.etaxonomy.cdm.strategy.cache.TaggedTextBuilder)2 ArrayList (java.util.ArrayList)2 TermRepresentation_L10n (eu.etaxonomy.cdm.api.service.l10n.TermRepresentation_L10n)1 TypeDesignationWorkingSet (eu.etaxonomy.cdm.api.service.name.TypeDesignationWorkingSet)1 TypeDesignationWorkingSetType (eu.etaxonomy.cdm.api.service.name.TypeDesignationWorkingSet.TypeDesignationWorkingSetType)1 TypeDesignationStatusComparator (eu.etaxonomy.cdm.compare.name.TypeDesignationStatusComparator)1 CdmBase (eu.etaxonomy.cdm.model.common.CdmBase)1 Language (eu.etaxonomy.cdm.model.common.Language)1 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)1 NomenclaturalStatus (eu.etaxonomy.cdm.model.name.NomenclaturalStatus)1 NomenclaturalStatusType (eu.etaxonomy.cdm.model.name.NomenclaturalStatusType)1 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)1 TypeDesignationBase (eu.etaxonomy.cdm.model.name.TypeDesignationBase)1 Representation (eu.etaxonomy.cdm.model.term.Representation)1 TaggedText (eu.etaxonomy.cdm.strategy.cache.TaggedText)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1