package org.ovirt.engine.core.searchbackend;

import org.ovirt.engine.core.common.businessentities.ProviderType;

public class ProviderConditionFieldAutoCompleter extends BaseConditionFieldAutoCompleter {

    public static final String NAME = "NAME";
    public static final String TYPE = "TYPE";
    public static final String DESCRIPTION = "DESCRIPTION";
    public static final String URL = "URL";

    public ProviderConditionFieldAutoCompleter() {
        // Building the basic verbs dict.
        mVerbs.add(NAME);
        mVerbs.add(TYPE);
        mVerbs.add(DESCRIPTION);
        mVerbs.add(URL);

        // Building the autoCompletion dict.
        buildCompletions();

        // Building the types dict.
        getTypeDictionary().put(NAME, String.class);
        getTypeDictionary().put(TYPE, ProviderType.class);
        getTypeDictionary().put(DESCRIPTION, String.class);
        getTypeDictionary().put(URL, String.class);

        // building the ColumnName dict.
        columnNameDict.put(NAME, "name");
        columnNameDict.put(TYPE, "provider_type");
        columnNameDict.put(DESCRIPTION, "description");
        columnNameDict.put(URL, "url");

        // Building the validation dict.
        buildBasicValidationTable();
    }

    @Override
    public IAutoCompleter getFieldRelationshipAutoCompleter(final String fieldName) {
        return StringConditionRelationAutoCompleter.INSTANCE;
    }

    @Override
    public IConditionValueAutoCompleter getFieldValueAutoCompleter(String fieldName) {
        if (TYPE.equals(fieldName)) {
            return new EnumValueAutoCompleter(ProviderType.class);
        }
        return null;
    }

}

package org.ovirt.engine.core.searchbackend;

import org.ovirt.engine.core.common.businessentities.ProviderType;

public class ProviderConditionFieldAutoCompleter extends BaseConditionFieldAutoCompleter {

    public static final String NAME = "NAME";
    public static final String TYPE = "TYPE";
    public static final String DESCRIPTION = "DESCRIPTION";
    public static final String URL = "URL";

    public ProviderConditionFieldAutoCompleter() {
        // Building the basic verbs dict.
        mVerbs.add(NAME);
        mVerbs.add(TYPE);
        mVerbs.add(DESCRIPTION);
        mVerbs.add(URL);

        // Building the autoCompletion dict.
        buildCompletions();

        // Building the types dict.
        getTypeDictionary().put(NAME, String.class);
        getTypeDictionary().put(TYPE, ProviderType.class);
        getTypeDictionary().put(DESCRIPTION, String.class);
        getTypeDictionary().put(URL, String.class);

        // building the ColumnName dict.
        columnNameDict.put(NAME, "name");
        columnNameDict.put(TYPE, "provider_type");
        columnNameDict.put(DESCRIPTION, "description");
        columnNameDict.put(URL, "url");

        // Building the validation dict.
        buildBasicValidationTable();
    }

    @Override
    public IAutoCompleter getFieldRelationshipAutoCompleter(final String fieldName) {
        return StringConditionRelationAutoCompleter.INSTANCE;
    }

    @Override
    public IConditionValueAutoCompleter getFieldValueAutoCompleter(String fieldName) {
        if (TYPE.equals(fieldName)) {
            return new EnumNameAutoCompleter(ProviderType.class);
        }
        return null;
    }

}

Use enum name to search providers
core: Use enum name to search providers

Currently we build search queries for providers using the numeric value
of the type, and comparing it to the "providers.provider_type" database
column. But this column stores the name of the enum, not the numeric
value. This patch changes the autocompleter so that it uses the name.

Change-Id: I4822be2cfd57c093d4fdf11f0410c055faea8be2
Bug-Url: https://bugzilla.redhat.com/1145247
Signed-off-by: Juan Hernandez <59e5b8140de97cc91c3fb6c5342dce948469af8c@redhat.com>
