<commit_before>package gov.hhs.onc.dcdt.ldap.impl;

import gov.hhs.onc.dcdt.convert.Converts;
import gov.hhs.onc.dcdt.convert.Converts.List;
import gov.hhs.onc.dcdt.convert.ConvertsJson;
import gov.hhs.onc.dcdt.convert.impl.AbstractToolConverter;
import gov.hhs.onc.dcdt.ldap.utils.ToolDnUtils;
import gov.hhs.onc.dcdt.utils.ToolCollectionUtils;
import javax.annotation.Nullable;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.api.ldap.model.name.Rdn;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.stereotype.Component;

@Component("dnConv")
@ConvertsJson(deserialize = { @Converts(from = String.class, to = Dn.class) }, serialize = { @Converts(from = Dn.class, to = String.class) })
@List({ @Converts(from = String.class, to = Dn.class), @Converts(from = String[].class, to = Dn.class), @Converts(from = Rdn[].class, to = Dn.class),
    @Converts(from = Dn.class, to = Rdn[].class), @Converts(from = Dn.class, to = String.class) })
public class DnConverter extends AbstractToolConverter {
    private final static TypeDescriptor TYPE_DESC_DN = TypeDescriptor.valueOf(Dn.class);
    private final static TypeDescriptor TYPE_DESC_RDN_ARR = TypeDescriptor.array(TypeDescriptor.valueOf(Rdn.class));

    @Nullable
    @Override
    protected Object convertInternal(Object source, TypeDescriptor sourceType, TypeDescriptor targetType, ConvertiblePair convertPair) throws Exception {
        if (sourceType.isAssignableTo(TYPE_DESC_DN)) {
            return ToolCollectionUtils.toArray(((Dn) source).getRdns(), Rdn.class);
        } else if (sourceType.isAssignableTo(TYPE_DESC_RDN_ARR)) {
            return ToolDnUtils.fromRdns(((Rdn[]) source));
        } else if (sourceType.isAssignableTo(TYPE_DESC_RDN_ARR)) {
            return ToolDnUtils.fromStrings(((String[]) source));
        } else {
            return ToolDnUtils.fromStrings(((String) source));
        }
    }
}
<commit_msg>- Further supports DCDT-118. - Fixed LDAP Distinguished Name Spring type conversion as per comments in review DCDT-58.<commit_after>package gov.hhs.onc.dcdt.ldap.impl;

import gov.hhs.onc.dcdt.convert.Converts;
import gov.hhs.onc.dcdt.convert.Converts.List;
import gov.hhs.onc.dcdt.convert.ConvertsJson;
import gov.hhs.onc.dcdt.convert.impl.AbstractToolConverter;
import gov.hhs.onc.dcdt.ldap.utils.ToolDnUtils;
import gov.hhs.onc.dcdt.utils.ToolCollectionUtils;
import javax.annotation.Nullable;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.api.ldap.model.name.Rdn;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.stereotype.Component;

@Component("dnConv")
@ConvertsJson(deserialize = { @Converts(from = String.class, to = Dn.class) }, serialize = { @Converts(from = Dn.class, to = String.class) })
@List({ @Converts(from = String.class, to = Dn.class), @Converts(from = String[].class, to = Dn.class), @Converts(from = Rdn[].class, to = Dn.class),
    @Converts(from = Dn.class, to = Rdn[].class), @Converts(from = Dn.class, to = String.class) })
public class DnConverter extends AbstractToolConverter {
    private final static TypeDescriptor TYPE_DESC_DN = TypeDescriptor.valueOf(Dn.class);
    private final static TypeDescriptor TYPE_DESC_RDN_ARR = TypeDescriptor.array(TypeDescriptor.valueOf(Rdn.class));

    @Nullable
    @Override
    protected Object convertInternal(Object source, TypeDescriptor sourceType, TypeDescriptor targetType, ConvertiblePair convertPair) throws Exception {
        if (sourceType.isAssignableTo(TYPE_DESC_DN)) {
            return (targetType.isAssignableTo(TYPE_DESC_RDN_ARR) ? ToolCollectionUtils.toArray(((Dn) source).getRdns(), Rdn.class) : source.toString());
        } else if (sourceType.isAssignableTo(TYPE_DESC_RDN_ARR)) {
            return ToolDnUtils.fromRdns(((Rdn[]) source));
        } else if (sourceType.isAssignableTo(TYPE_DESC_STR_ARR)) {
            return ToolDnUtils.fromStrings(((String[]) source));
        } else {
            return ToolDnUtils.fromStrings(((String) source));
        }
    }
}

{'fraction_non_alphanumeric': 0.12726382770435635, 'fraction_numerical': 0.0012236906510034262, 'mean_word_length': 4.568119891008174, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2769705', 'n_tokens_mistral': 1352, 'n_tokens_neox': 1338, 'n_words': 236}