package org.ovirt.engine.core.searchbackend;

import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.ovirt.engine.core.common.businessentities.ImageStatus;
import org.ovirt.engine.core.common.businessentities.VolumeFormat;
import org.ovirt.engine.core.compat.RefObject;
import org.ovirt.engine.core.compat.StringFormat;
import org.ovirt.engine.core.compat.StringHelper;

public class DiskImageConditionFieldAutoCompleter extends BaseConditionFieldAutoCompleter {
    public DiskImageConditionFieldAutoCompleter() {
        // Building the basic verbs dict.
        mVerbs.put("ALIAS", "ALIAS");
        mVerbs.put("DESCRIPTION", "DESCRIPTION");
        mVerbs.put("PROVISIONED_SIZE", "PROVISIONED_SIZE");
        mVerbs.put("SIZE", "SIZE");
        mVerbs.put("ACTUAL_SIZE", "ACTUAL_SIZE");
        mVerbs.put("CREATION_DATE", "CREATION_DATE");
        mVerbs.put("BOOTABLE", "BOOTABLE");
        mVerbs.put("FORMAT", "FORMAT");
        mVerbs.put("STATUS", "STATUS");

        // Building the autoCompletion dict.
        buildCompletions();

        // Building the types dict.
        getTypeDictionary().put("ALIAS", String.class);
        getTypeDictionary().put("DESCRIPTION", String.class);
        getTypeDictionary().put("PROVISIONED_SIZE", Long.class);
        getTypeDictionary().put("SIZE", Long.class);
        getTypeDictionary().put("ACTUAL_SIZE", Long.class);
        getTypeDictionary().put("CREATION_DATE", Date.class);
        getTypeDictionary().put("BOOTABLE", Boolean.class);
        getTypeDictionary().put("FORMAT", VolumeFormat.class);
        getTypeDictionary().put("STATUS", ImageStatus.class);

        // building the ColumnName dict.
        mColumnNameDict.put("ALIAS", "disk_alias");
        mColumnNameDict.put("DESCRIPTION", "disk_description");
        mColumnNameDict.put("PROVISIONED_SIZE", "size");
        mColumnNameDict.put("SIZE", "size");
        mColumnNameDict.put("ACTUAL_SIZE", "actual_size");
        mColumnNameDict.put("CREATION_DATE", "creation_date");
        mColumnNameDict.put("BOOTABLE", "boot");
        mColumnNameDict.put("FORMAT", "volume_format");
        mColumnNameDict.put("STATUS", "imageStatus");

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

    @Override
    public IAutoCompleter getFieldRelationshipAutoCompleter(String fieldName) {
        IAutoCompleter retval;
        if (StringHelper.EqOp(fieldName, "CREATIONDATE") || StringHelper.EqOp(fieldName, "SIZE") || StringHelper.EqOp(fieldName, "ACTUAL_SIZE")
                || StringHelper.EqOp(fieldName, "PROVISIONED_SIZE")) {
            retval = BiggerOrSmallerRelationAutoCompleter.INTSANCE;
        } else {
            retval = StringConditionRelationAutoCompleter.INSTANCE;
        }
        return retval;
    }

    @Override
    public IConditionValueAutoCompleter getFieldValueAutoCompleter(String fieldName) {
        IConditionValueAutoCompleter retval = null;
        if (StringHelper.EqOp(fieldName, "FORMAT")) {
            retval = new EnumValueAutoCompleter(VolumeFormat.class);
        } else if (StringHelper.EqOp(fieldName, "STATUS")) {
            retval = new EnumValueAutoCompleter(ImageStatus.class);
        }
        return retval;
    }

    @Override
    public void formatValue(String fieldName,
            RefObject<String> relations,
            RefObject<String> value,
            boolean caseSensitive) {
        if (StringHelper.EqOp(fieldName, "CREATIONDATE")) {
            Date tmp = new Date(Date.parse(StringHelper.trim(value.argvalue, '\'')));
            value.argvalue = StringFormat.format("'%1$s'", tmp);
        } else {
            super.formatValue(fieldName, relations, value, caseSensitive);
        }
    }

    private final Log log = LogFactory.getLog(getClass());
}

@@ -943,24 +943,126 @@
 BOOTABLE%22);%0A
+        mVerbs.put(%22SHAREABLE%22, %22SHAREABLE%22);%0A        mVerbs.put(%22ALLOW_SNAPSHOT%22, %22ALLOW_SNAPSHOT%22);%0A
         mVer
@@ -1085,24 +1085,24 @@
  %22FORMAT%22);%0A
-
         mVer
@@ -1650,32 +1650,159 @@
 Boolean.class);%0A
+        getTypeDictionary().put(%22SHAREABLE%22, Boolean.class);%0A        getTypeDictionary().put(%22ALLOW_SNAPSHOT%22, Boolean.class);%0A
         getTypeD
@@ -2288,24 +2288,24 @@
 ion_date%22);%0A
-
         mCol
@@ -2337,24 +2337,144 @@
 %22, %22boot%22);%0A
+        mColumnNameDict.put(%22SHAREABLE%22, %22shareable%22);%0A        mColumnNameDict.put(%22ALLOW_SNAPSHOT%22, %22allow_snapshot%22);%0A
         mCol

Add search for shared and snapshotable