package org.ovirt.engine.core.bll;

import org.ovirt.engine.core.common.AuditLogType;
import org.ovirt.engine.core.common.action.VmPoolParametersBase;
import org.ovirt.engine.core.compat.NGuid;
import org.ovirt.engine.core.dal.VdcBllMessages;
import org.ovirt.engine.core.dal.dbbroker.DbFacade;

public class RemoveVmPoolCommand<T extends VmPoolParametersBase> extends VmPoolCommandBase<T> {
    public RemoveVmPoolCommand(T parameters) {
        super(parameters);
    }

    @Override
    protected boolean canDoAction() {
        return CanRemoveVmPool(getParameters().getVmPoolId(), getReturnValue().getCanDoActionMessages());
    }

    @Override
    protected void executeCommand() {
        if (getVmPoolId() != null && CanRemoveVmPoolWithoutReasons(getVmPoolId())) {
            DbFacade.getInstance().getVmPoolDAO().remove(getVmPoolId());
            setSucceeded(true);
        }
    }

    @Override
    public AuditLogType getAuditLogTypeValue() {
        return getSucceeded() ? AuditLogType.USER_REMOVE_VM_POOL : AuditLogType.USER_REMOVE_VM_POOL_FAILED;
    }

    public static boolean CanRemoveVmPoolWithoutReasons(NGuid vmPoolId) {
        java.util.ArrayList<String> reasons = new java.util.ArrayList<String>();
        return (CanRemoveVmPool(vmPoolId, reasons));
    }

    public static boolean CanRemoveVmPool(NGuid vmPoolId, java.util.ArrayList<String> reasons) {
        boolean returnValue = true;
        if (DbFacade.getInstance().getVmPoolDAO().getVmPoolsMapByVmPoolId(vmPoolId).size() != 0) {
            returnValue = false;
            reasons.add(VdcBllMessages.VM_POOL_CANNOT_REMOVE_VM_POOL_WITH_VMS.toString());
        }
        return returnValue;
    }
}

@@ -29,16 +29,39 @@
 e.bll;%0A%0A
+import java.util.Map;%0A%0A
 import o
@@ -102,16 +102,67 @@
 ogType;%0A
+import org.ovirt.engine.core.common.VdcObjectType;%0A
 import o
@@ -533,16 +533,163 @@
 eters);%0A
+        // set group id for logging and job%0A        if (getVmPool() != null) %7B%0A            setVdsGroupId(getVmPool().getvds_group_id());%0A        %7D%0A
     %7D%0A%0A 
@@ -1903,11 +1903,325 @@
 e;%0A    %7D
+%0A%0A    @Override%0A    public Map%3CString, String%3E getJobMessageProperties() %7B%0A        if (jobProperties == null) %7B%0A            jobProperties = super.getJobMessageProperties();%0A            jobProperties.put(VdcObjectType.VdsGroups.name().toLowerCase(), getVdsGroupName());%0A        %7D%0A        return jobProperties;%0A    %7D
 %0A%7D%0A

fix job properties in remove VmPool to show cluster name (#817366)