package org.ovirt.engine.core.bll.network.vm;

import java.util.List;

import org.ovirt.engine.core.bll.validator.VnicProfileValidator;
import org.ovirt.engine.core.common.AuditLogType;
import org.ovirt.engine.core.common.action.VnicProfileParameters;
import org.ovirt.engine.core.common.errors.VdcBllMessages;
import org.ovirt.engine.core.common.validation.group.UpdateEntity;

public class UpdateVnicProfileCommand<T extends VnicProfileParameters> extends VnicProfileCommandBase<T> {

    public UpdateVnicProfileCommand(T parameters) {
        super(parameters);
    }

    @Override
    protected boolean canDoAction() {
        VnicProfileValidator validator = new VnicProfileValidator(getVnicProfile());
        return validate(validator.vnicProfileIsSet())
                && validate(validator.vnicProfileExists())
                && validate(validator.vnicProfileNameNotUsed())
                && validate(validator.networkNotChanged())
                && validate(validator.portMirroringNotChangedIfUsedByVms());
    }

    @Override
    protected void executeCommand() {
        getVnicProfileDao().update(getVnicProfile());
        setSucceeded(true);
    }

    @Override
    protected List<Class<?>> getValidationGroups() {
        addValidationGroup(UpdateEntity.class);
        return super.getValidationGroups();
    }

    @Override
    protected void setActionMessageParameters() {
        super.setActionMessageParameters();
        addCanDoActionMessage(VdcBllMessages.VAR__ACTION__UPDATE);
    }

    @Override
    public AuditLogType getAuditLogTypeValue() {
        return getSucceeded() ? AuditLogType.UPDATE_VNIC_PROFILE
                : AuditLogType.UPDATE_VNIC_PROFILE_FAILED;
    }
}

@@ -64,16 +64,76 @@
 .List;%0A%0A
+import org.ovirt.engine.core.bll.RenamedEntityInfoProvider;%0A
 import o
@@ -239,16 +239,67 @@
 ogType;%0A
+import org.ovirt.engine.core.common.VdcObjectType;%0A
 import o
@@ -356,16 +356,90 @@
 meters;%0A
+import org.ovirt.engine.core.common.businessentities.network.VnicProfile;%0A
 import o
@@ -555,16 +555,93 @@
 eEntity;
+%0Aimport org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase;
 %0A%0Apublic
@@ -704,16 +704,24 @@
 ameters%3E
+%0A       
  extends
@@ -747,17 +747,95 @@
 Base%3CT%3E 
-%7B
+implements RenamedEntityInfoProvider %7B%0A%0A    private VnicProfile oldVnicProfile;
 %0A%0A    pu
@@ -1419,24 +1419,53 @@
 Command() %7B%0A
+        getOldVnicProfile();%0A
         getV
@@ -2081,11 +2081,649 @@
 D;%0A    %7D
+%0A%0A    @Override%0A    public String getEntityType() %7B%0A        return VdcObjectType.VnicProfile.getVdcObjectTranslation();%0A    %7D%0A%0A    @Override%0A    public String getEntityOldName() %7B%0A        return getOldVnicProfile().getName();%0A    %7D%0A%0A    @Override%0A    public String getEntityNewName() %7B%0A        return getVnicProfile().getName();%0A    %7D%0A%0A    @Override%0A    public void setEntityId(AuditLogableBase logable) %7B%0A    %7D%0A%0A    private VnicProfile getOldVnicProfile() %7B%0A        if (oldVnicProfile == null) %7B%0A            oldVnicProfile = getDbFacade().getVnicProfileDao().get(getVnicProfile().getId());%0A        %7D%0A%0A        return oldVnicProfile;%0A    %7D
 %0A%7D%0A

Add rename logging capability to UpdateVnic