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

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import javax.inject.Inject;
import javax.inject.Singleton;

import org.ovirt.engine.core.bll.CommandBase;
import org.ovirt.engine.core.bll.utils.PermissionSubject;
import org.ovirt.engine.core.common.VdcObjectType;
import org.ovirt.engine.core.common.action.VdcActionType;
import org.ovirt.engine.core.common.businessentities.network.NetworkCluster;
import org.ovirt.engine.core.compat.Guid;
import org.ovirt.engine.core.dao.network.NetworkClusterDao;

@Singleton
class AttachNetworkClusterPermissionsChecker {

    private final NetworkClusterDao networkClusterDao;

    @Inject
    AttachNetworkClusterPermissionsChecker(NetworkClusterDao networkClusterDao) {
        Objects.requireNonNull(networkClusterDao, "networkClusterDao cannot be null");

        this.networkClusterDao = networkClusterDao;
    }

    public boolean checkPermissions(CommandBase<?> command, List<PermissionSubject> permissionCheckSubjects) {
        final List<String> messages = new ArrayList<>();

        for (PermissionSubject permSubject : permissionCheckSubjects) {
            messages.clear();
            if (command.checkSinglePermission(permSubject, messages)) {
                return true;
            }
        }

        command.getReturnValue().getCanDoActionMessages().addAll(messages);
        return false;
    }

    public boolean checkPermissions(
            CommandBase<?> command,
            NetworkCluster attachment,
            VdcActionType actionType) {
        final List<PermissionSubject> permissionCheckSubjects = findPermissionCheckSubjects(attachment, actionType);

        return checkPermissions(command, permissionCheckSubjects);
    }

    public List<PermissionSubject> findPermissionCheckSubjects(
            NetworkCluster networkCluster,
            VdcActionType actionType) {

        final List<PermissionSubject> permissions = new ArrayList<>();

        final Guid networkId = networkCluster == null ? null : networkCluster.getNetworkId();
        // require permissions on network
        permissions.add(new PermissionSubject(networkId,
                VdcObjectType.Network,
                actionType.getActionGroup()));

        return permissions;
    }
}

@@ -100,62 +100,8 @@
 st;%0A
-import java.util.Objects;%0A%0Aimport javax.inject.Inject;
 %0Aimp
@@ -465,423 +465,66 @@
 id;%0A
-import org.ovirt.engine.core.dao.network.NetworkClusterDao;%0A%0A@Singleton%0Aclass AttachNetworkClusterPermissionsChecker %7B%0A%0A    private final NetworkClusterDao networkClusterDao;%0A%0A    @Inject%0A    AttachNetworkClusterPermissionsChecker(NetworkClusterDao networkClusterDao) %7B%0A        Objects.requireNonNull(networkClusterDao, %22networkClusterDao cannot be null%22);%0A%0A        this.networkClusterDao = networkClusterDao;%0A    %7D
+%0A@Singleton%0Aclass AttachNetworkClusterPermissionsChecker %7B
 %0A%0A  

Remove useless injected dao