package be.iminds.jfed.gts_highlevel.jobs.gts_parts;

import be.iminds.ilabt.jfed.experiment.tasks.ExperimentTaskStatus;
import be.iminds.ilabt.jfed.highlevel.jobs.ExperimentPartStateSlice;
import be.iminds.ilabt.jfed.highlevel.jobs.Job;
import be.iminds.ilabt.jfed.highlevel.jobs.SingleCallState;
import be.iminds.ilabt.jfed.lowlevel.JFedException;
import be.iminds.jfed.gts_highlevel.model.GtsXmlProject;
import be.iminds.jfed.gts_highlevel.tasks.GtsListResourcesTask;
import be.iminds.jfed.gts_highlevel.tasks.GtsTaskFactory;

/**
 * User: twalcari
 * Date: 1/14/2016
 * Time: 14:28
 */
public class UpdateGtsExperimentPartStateSlice extends ExperimentPartStateSlice<GtsExperimentPart> {

    private final GtsTaskFactory gtsTaskFactory;

    public UpdateGtsExperimentPartStateSlice(Job<?> job, GtsExperimentPart experimentPart, GtsTaskFactory gtsTaskFactory) {
        super(job, experimentPart);
        this.gtsTaskFactory = gtsTaskFactory;
    }

    @Override
    public ExperimentTaskStatus statefulRun() throws JFedException, InterruptedException {
        GtsXmlProject project = experimentPart.getContainer().getGtsProject();

        setAndRunState(new UpdateGtsExperimentPartState(project));


        return null;
    }


    private final class UpdateGtsExperimentPartState extends SingleCallState<GtsListResourcesTask> {
        protected UpdateGtsExperimentPartState(GtsXmlProject project) {
            super(gtsTaskFactory.createGtsListResourcesTask(project));
        }
    }
}
