public static org.kie.pmml.api.models.MiningField convertToKieMiningField(final MiningField toConvert,
                                                                              final Field<?> field) {
        final String name = toConvert.getName() != null ?toConvert.getName() : null;
        final FIELD_USAGE_TYPE fieldUsageType = toConvert.getUsageType() != null ?
                FIELD_USAGE_TYPE.byName(toConvert.getUsageType().value()) : null;
        final OP_TYPE opType = toConvert.getOpType() != null ? OP_TYPE.byName(toConvert.getOpType().value()) : null;
        final DATA_TYPE dataType = field.getDataType() != null ?
                DATA_TYPE.byName(field.getDataType().value()) : null;
        final MISSING_VALUE_TREATMENT_METHOD missingValueTreatmentMethod =
                toConvert.getMissingValueTreatment() != null ?
                        MISSING_VALUE_TREATMENT_METHOD.byName(toConvert.getMissingValueTreatment().value()) : null;
        final INVALID_VALUE_TREATMENT_METHOD invalidValueTreatmentMethod =
                toConvert.getInvalidValueTreatment() != null ?
                        INVALID_VALUE_TREATMENT_METHOD.byName(toConvert.getInvalidValueTreatment().value()) : null;
        final String missingValueReplacement = toConvert.getMissingValueReplacement() != null ?
                toConvert.getMissingValueReplacement().toString() : null;
        final String invalidValueReplacement = toConvert.getInvalidValueReplacement() != null ?
                toConvert.getInvalidValueReplacement().toString() : null;
        final List<String> allowedValues = field instanceof DataField ?
                convertDataFieldValues(((DataField) field).getValues()) : Collections.emptyList();
        final List<org.kie.pmml.api.models.Interval> intervals = field instanceof DataField ?
                convertDataFieldIntervals(((DataField) field).getIntervals()) : Collections.emptyList();

        return new org.kie.pmml.api.models.MiningField(name,
                                                       fieldUsageType,
                                                       opType,
                                                       dataType,
                                                       missingValueTreatmentMethod,
                                                       invalidValueTreatmentMethod,
                                                       missingValueReplacement,
                                                       invalidValueReplacement,
                                                       allowedValues,
                                                       intervals);
    }
@Test
    void convertToKieMiningField() {
        final String fieldName = "fieldName";
        final MiningField.UsageType usageType = MiningField.UsageType.ACTIVE;
        final MiningField toConvert = getMiningField(fieldName, usageType);
        toConvert.setOpType(null);
        final DataField dataField = getDataField(fieldName, OpType.CATEGORICAL, DataType.STRING);
        org.kie.pmml.api.models.MiningField retrieved =
                org.kie.pmml.compiler.api.utils.ModelUtils.convertToKieMiningField(toConvert, dataField);
        assertThat(retrieved).isNotNull();
        assertThat(retrieved.getName()).isEqualTo(fieldName);
        assertThat(retrieved.getUsageType()).isEqualTo(FIELD_USAGE_TYPE.ACTIVE);
        assertThat(retrieved.getDataType()).isEqualTo(DATA_TYPE.STRING);
        assertThat(retrieved.getOpType()).isNull();
        toConvert.setOpType(OpType.CATEGORICAL);
        retrieved = org.kie.pmml.compiler.api.utils.ModelUtils.convertToKieMiningField(toConvert, dataField);
        assertThat(retrieved.getOpType()).isEqualTo(OP_TYPE.CATEGORICAL);
    }