package org.ovirt.engine.core.bll;

import java.util.List;

import org.ovirt.engine.core.bll.utils.PermissionSubject;
import org.ovirt.engine.core.common.AuditLogSeverity;
import org.ovirt.engine.core.common.action.RemoveExternalEventParameters;
import org.ovirt.engine.core.common.businessentities.AuditLog;
import org.ovirt.engine.core.dal.VdcBllMessages;
import org.ovirt.engine.core.dal.dbbroker.DbFacade;

public class RemoveExternalEventCommand <T extends RemoveExternalEventParameters> extends ExternalEventCommandBase<T> {

    private static final long serialVersionUID = 1L;
    private final String OVIRT="oVirt";

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

    @Override
    protected boolean canDoAction() {
        boolean result = true;
        // check if such event exists
        AuditLog event = DbFacade.getInstance().getAuditLogDao().get(getParameters().getId());
        if (event == null) {
            addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_EXTERNAL_EVENT_NOT_FOUND);
            result = false;
        }
        if (OVIRT.equalsIgnoreCase(event.getOrigin())) {
            addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_EXTERNAL_EVENT_ILLEGAL_ORIGIN);
            result = false;
        }
        if (!event.getseverity().equals(AuditLogSeverity.ALERT)) {
            addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_EXTERNAL_EVENT_ILLRGAL_OPERATION);
            result = false;
        }
        if (!result) {
            addCanDoActionMessage(VdcBllMessages.VAR__ACTION__REMOVE);
            addCanDoActionMessage(VdcBllMessages.VAR__TYPE__EXTERNAL_EVENT);
        }
        return result;
    }

    @Override
    protected void executeCommand() {
       DbFacade.getInstance().getAuditLogDao().remove(getParameters().getId());
       setSucceeded(true);
    }

    @Override
    public List<PermissionSubject> getPermissionCheckSubjects() {
        AuditLog event = DbFacade.getInstance().getAuditLogDao().get(getParameters().getId());
        return  getPermissionList(event);
    }
}

@@ -763,39 +763,8 @@
 ) %7B%0A
-        boolean result = true;%0A
     
@@ -925,35 +925,43 @@
 ) %7B%0A            
-add
+return fail
 CanDoActionMessa
@@ -947,39 +947,32 @@
  failCanDoAction
-Message
 (VdcBllMessages.
@@ -1021,36 +1021,8 @@
 D);%0A
-            result = false;%0A
     
@@ -1088,35 +1088,43 @@
 ) %7B%0A            
-add
+return fail
 CanDoActionMessa
@@ -1110,39 +1110,32 @@
  failCanDoAction
-Message
 (VdcBllMessages.
@@ -1189,36 +1189,8 @@
 N);%0A
-            result = false;%0A
     
@@ -1207,17 +1207,16 @@
     if (
-!
 event.ge
@@ -1230,16 +1230,12 @@
 ty()
-.equals(
+ == 
 Audi
@@ -1253,17 +1253,16 @@
 y.ALERT)
-)
  %7B%0A     
@@ -1260,35 +1260,43 @@
 ) %7B%0A            
-add
+return fail
 CanDoActionMessa
@@ -1282,39 +1282,32 @@
  failCanDoAction
-Message
 (VdcBllMessages.
@@ -1372,57 +1372,99 @@
     
-    result = fals
+%7D%0A%0A        return tru
 e;%0A    
+%7D%0A%0A
     
-%7D%0A        if (!result
+@Override%0A    protected void setActionMessageParameters(
 ) %7B%0A
@@ -1463,36 +1463,32 @@
 ers() %7B%0A        
-   
- 
 addCanDoActionMe
@@ -1530,20 +1530,16 @@
 EMOVE);%0A
-    
         
@@ -1607,41 +1607,8 @@
 T);%0A
-        %7D%0A        return result;%0A
     

Streamline RemoveExternalEvent canDoAction()