package org.ovirt.engine.core.bll.storage;

import org.ovirt.engine.core.bll.ImagesHandler;
import org.ovirt.engine.core.bll.tasks.CommandCoordinatorUtil;
import org.ovirt.engine.core.common.action.ImagesContainterParametersBase;
import org.ovirt.engine.core.common.businessentities.storage.CinderDisk;
import org.ovirt.engine.core.common.businessentities.storage.DiskImage;
import org.ovirt.engine.core.common.businessentities.storage.ImageStatus;
import org.ovirt.engine.core.compat.CommandStatus;
import org.ovirt.engine.core.compat.Guid;
import org.ovirt.engine.core.dal.dbbroker.DbFacade;
import org.ovirt.engine.core.dao.DiskDao;

import java.util.List;

public class CloneSingleCinderDiskCommandCallback extends AbstractCinderDiskCommandCallback<CloneSingleCinderDiskCommand<ImagesContainterParametersBase>> {

    @Override
    public void doPolling(Guid cmdId, List<Guid> childCmdIds) {
        super.doPolling(cmdId, childCmdIds);

        ImageStatus imageStatus = getCinderBroker().getDiskStatus(getDiskId());
        DiskImage disk = getDisk();
        if (imageStatus != null && imageStatus != disk.getImageStatus()) {
            switch (imageStatus) {
            case OK:
                getCommand().setCommandStatus(CommandStatus.SUCCEEDED);
                break;
            case ILLEGAL:
                getCommand().setCommandStatus(CommandStatus.FAILED);
                break;
            }
        }
    }

    @Override
    public void onFailed(Guid cmdId, List<Guid> childCmdIds) {
        super.onFailed(cmdId, childCmdIds);
        ImagesHandler.updateImageStatus(getDiskId(), ImageStatus.ILLEGAL);
        getCommand().getParameters().setTaskGroupSuccess(false);
        onFinish(cmdId);
    }

    @Override
    public void onSucceeded(Guid cmdId, List<Guid> childCmdIds) {
        super.onSucceeded(cmdId, childCmdIds);
        ImagesHandler.updateImageStatus(getDiskId(), ImageStatus.OK);
        onFinish(cmdId);
    }

    private void onFinish(Guid cmdId) {
        ImagesHandler.updateImageStatus(getCommand().getParameters().getImageId(), ImageStatus.OK);
        getCommand().endAction();
        CommandCoordinatorUtil.removeAllCommandsInHierarchy(cmdId);
    }

    @Override
    protected Guid getDiskId() {
        return getCommand().getParameters().getDestinationImageId();
    }

    @Override
    protected CinderDisk getDisk() {
        if (disk == null) {
            disk = (CinderDisk) getDiskDao().get(getCommand().getParameters().getDestinationImageId());
        }
        return disk;
    }

    protected DiskDao getDiskDao() {
        return DbFacade.getInstance().getDiskDao();
    }

    @Override
    protected CinderBroker getCinderBroker() {
        return getCommand().getCinderBroker();
    }
}

@@ -37,16 +37,92 @@
 orage;%0A%0A
+import java.util.List;%0A%0Aimport org.ovirt.engine.core.bll.BaseImagesCommand;%0A
 import o
@@ -710,32 +710,8 @@
 o;%0A%0A
-import java.util.List;%0A%0A
 publ
@@ -755,16 +755,18 @@
 Callback
+%3CT
  extends
@@ -770,102 +770,112 @@
 nds 
-AbstractCinderDiskCommandCallback%3CCloneSingleCinderDiskCommand%3CImagesContainterParametersBase%3E
+BaseImagesCommand%3C? extends ImagesContainterParametersBase%3E%3E extends AbstractCinderDiskCommandCallback%3CT
 %3E %7B%0A

Use generics in CloneSingleCinderDiskCommandCallback