package fr.inria.spirals.repairnator.serializer;


import fr.inria.spirals.repairnator.states.LauncherMode;
import fr.inria.spirals.repairnator.states.ScannedBuildStatus;
import fr.inria.spirals.repairnator.config.RepairnatorConfig;
import fr.inria.spirals.repairnator.process.inspectors.JobStatus;
import fr.inria.spirals.repairnator.process.inspectors.ProjectInspector;
import fr.inria.spirals.repairnator.serializer.engines.SerializerEngine;

import java.util.List;


/**
 * Created by urli on 20/01/2017.
 */
public abstract class AbstractDataSerializer extends Serializer {



    public AbstractDataSerializer(List<SerializerEngine> engines, SerializerType type) {
        super(engines, type);
    }

    protected String getPrettyPrintState(ProjectInspector inspector) {

        JobStatus jobStatus = inspector.getJobStatus();
        if (jobStatus.isHasBeenPatched()) {
            return "PATCHED";
        }

        if (jobStatus.isReproducedAsFail()) {
            return "test failure";
        }

        if (jobStatus.isReproducedAsError()) {
            return "test errors";
        }

        switch (jobStatus.getPipelineState()) {
            case NONE:
            case INIT:
            case NOTCLONABLE:
                return "not clonable";

            case CLONABLE:
            case BUILDNOTCHECKEDOUT:
            case PREVIOUSBUILDCODENOTCHECKEDOUT:
                return "error in bug check out";

            case PATCHEDBUILDNOTCHECKEDOUT:
                if (RepairnatorConfig.getInstance().getLauncherMode() == LauncherMode.BEARS) {
                    return "error in patch check out";
                } else {
                    if (jobStatus.isHasBeenPatched()) {
                        return "PATCHED";
                    } else {
                        if (jobStatus.isReproducedAsFail()) {
                            return "test failure";
                        } else {
                            return "test errors";
                        }
                    }
                }


            case DEPENDENCY_UNRESOLVABLE:
            case DEPENDENCY_RESOLVED:
            case BUILDCHECKEDOUT:
            case PATCHEDBUILDCHECKEDOUT:
            case PREVIOUSBUILDCODECHECKEDOUT:
            case NOTBUILDABLE:
                return "not buildable";

            case BUILDABLE:
            case NOTTESTABLE:
                return "not testable";

            case TESTABLE:
                return "testable";

            case NOTFAILING:
                return "not failing";

            case HASTESTFAILURE:
                return "test failure";

            case HASTESTERRORS:
                return "test errors";

            case SOURCEDIRCOMPUTED:
            case SOURCEDIRNOTCOMPUTED:
            case NOPOL_NOTPATCHED:
            case NPEFIX_NOTPATCHED:
                if (jobStatus.isReproducedAsFail()) {
                    return "test failure";
                } else {
                    return "test errors";
                }

            case NPEFIX_PATCHED:
            case NOPOL_PATCHED:
                return "PATCHED";

            case FIXERBUILDCASE1:
                return "FIXERBUILD_CASE1";

            case FIXERBUILDCASE2:
                return "FIXERBUILD_CASE2";

            case CLASSPATHCOMPUTED:
            case CLASSPATHNOTCOMPUTED:
                if (RepairnatorConfig.getInstance().getLauncherMode() == LauncherMode.BEARS) {
                    if (inspector.getBuildToBeInspected().getStatus() == ScannedBuildStatus.FAILING_AND_PASSING) {
                        return "FIXERBUILD_CASE1";
                    } else {
                        return "FIXERBUILD_CASE2";
                    }
                } else {
                    if (jobStatus.isReproducedAsFail()) {
                        return "test failure";
                    } else {
                        return "test errors";
                    }
                }

            default:
                return "unknown";
        }
    }

    public abstract void serializeData(ProjectInspector inspector);
}

@@ -47,191 +47,8 @@
 r;%0A%0A
-%0Aimport fr.inria.spirals.repairnator.states.LauncherMode;%0Aimport fr.inria.spirals.repairnator.states.ScannedBuildStatus;%0Aimport fr.inria.spirals.repairnator.config.RepairnatorConfig;%0A
 impo
@@ -927,2916 +927,51 @@
     
-switch (jobStatus.getPipelineState()) %7B%0A            case NONE:%0A            case INIT:%0A            case NOTCLONABLE:%0A                return %22not clonable%22;%0A%0A            case CLONABLE:%0A            case BUILDNOTCHECKEDOUT:%0A            case PREVIOUSBUILDCODENOTCHECKEDOUT:%0A                return %22error in bug check out%22;%0A%0A            case PATCHEDBUILDNOTCHECKEDOUT:%0A                if (RepairnatorConfig.getInstance().getLauncherMode() == LauncherMode.BEARS) %7B%0A                    return %22error in patch check out%22;%0A                %7D else %7B%0A                    if (jobStatus.isHasBeenPatched()) %7B%0A                        return %22PATCHED%22;%0A                    %7D else %7B%0A                        if (jobStatus.isReproducedAsFail()) %7B%0A                            return %22test failure%22;%0A                        %7D else %7B%0A                            return %22test errors%22;%0A                        %7D%0A                    %7D%0A                %7D%0A%0A%0A            case DEPENDENCY_UNRESOLVABLE:%0A            case DEPENDENCY_RESOLVED:%0A            case BUILDCHECKEDOUT:%0A            case PATCHEDBUILDCHECKEDOUT:%0A            case PREVIOUSBUILDCODECHECKEDOUT:%0A            case NOTBUILDABLE:%0A                return %22not buildable%22;%0A%0A            case BUILDABLE:%0A            case NOTTESTABLE:%0A                return %22not testable%22;%0A%0A            case TESTABLE:%0A                return %22testable%22;%0A%0A            case NOTFAILING:%0A                return %22not failing%22;%0A%0A            case HASTESTFAILURE:%0A                return %22test failure%22;%0A%0A            case HASTESTERRORS:%0A                return %22test errors%22;%0A%0A            case SOURCEDIRCOMPUTED:%0A            case SOURCEDIRNOTCOMPUTED:%0A            case NOPOL_NOTPATCHED:%0A            case NPEFIX_NOTPATCHED:%0A                if (jobStatus.isReproducedAsFail()) %7B%0A                    return %22test failure%22;%0A                %7D else %7B%0A                    return %22test errors%22;%0A                %7D%0A%0A            case NPEFIX_PATCHED:%0A            case NOPOL_PATCHED:%0A                return %22PATCHED%22;%0A%0A            case FIXERBUILDCASE1:%0A                return %22FIXERBUILD_CASE1%22;%0A%0A            case FIXERBUILDCASE2:%0A                return %22FIXERBUILD_CASE2%22;%0A%0A            case CLASSPATHCOMPUTED:%0A            case CLASSPATHNOTCOMPUTED:%0A                if (RepairnatorConfig.getInstance().getLauncherMode() == LauncherMode.BEARS) %7B%0A                    if (inspector.getBuildToBeInspected().getStatus() == ScannedBuildStatus.FAILING_AND_PASSING) %7B%0A                        return %22FIXERBUILD_CASE1%22;%0A                    %7D else %7B%0A                        return %22FIXERBUILD_CASE2%22;%0A                    %7D%0A                %7D else %7B%0A                    if (jobStatus.isReproducedAsFail()) %7B%0A                        return %22test failure%22;%0A                    %7D else %7B%0A                        return %22test errors%22;%0A                    %7D%0A                %7D%0A%0A            default:%0A                return %22unknown%22;%0A        %7D
+return jobStatus.getPipelineState().name();
 %0A   

Change the way human status is computed and returned (#331)