package de.dkfz.roddy.core;

import de.dkfz.roddy.config.Configuration;

import java.lang.reflect.Method;

/**
 * A worklow can be created and executed to process a set of data.
 *
 * @author michael
 */
public abstract class Workflow {

    private Configuration config;
    private DataSet dataSet;
    private String baseDir;

    public Workflow() {
    }

    /**
     * Workflow specific setups can be created here.
     * This includes i.e. the creation of paths.
     */
    public void setupExecution(ExecutionContext context) {
    }

    public void finalizeExecution(ExecutionContext context) {
    }

    /**
     * Override this method to enable initial checks for a workflow run.
     * I.e. check if input files can be found.
     * @param context
     * @return
     */
    public boolean checkExecutability(ExecutionContext context) {
        return true;
    }

    public abstract boolean execute(ExecutionContext context);

    public boolean canCreateTestdata() {
        for (Method m : this.getClass().getMethods()) {
            if (m.getName().equals("createTestdata") && m.getDeclaringClass() == this.getClass()) {
                return true;
            }
        }
        return false;
    }

    public boolean createTestdata(ExecutionContext context) {
        return false;
    }

    public boolean hasCleanupMethod() {
        for (Method m : this.getClass().getMethods()) {
            if (m.getName().equals("cleanup") && m.getDeclaringClass() == this.getClass()) {
                return true;
            }
        }
        return false;
    }

    public boolean cleanup(DataSet dataset) {
        return false;
    }
}

@@ -64,16 +64,166 @@
 uration;
+%0Aimport de.dkfz.roddy.knowledge.files.BaseFile;%0Aimport de.dkfz.roddy.knowledge.files.FileObject;%0Aimport de.dkfz.roddy.knowledge.methods.GenericMethod;
 %0A%0Aimport
@@ -1802,11 +1802,1032 @@
 e;%0A    %7D
+%0A%0A    /**%0A     * Convenience method to call GenericMethod.callGenericTool()%0A     * @param toolName%0A     * @param input%0A     * @param additionalInput%0A     * @return%0A     */%0A    protected FileObject call(String toolName, BaseFile input, Object... additionalInput) %7B%0A        return GenericMethod.callGenericTool(toolName, input, additionalInput);%0A    %7D%0A%0A    /**%0A     * Convenience method to get a boolean runflag from the context config, defaults to true%0A     * @param context%0A     * @param flagID%0A     * @return%0A     */%0A    protected boolean getflag(ExecutionContext context, String flagID) %7B%0A        return getflag(context, flagID, true);%0A    %7D%0A%0A    /**%0A     * Convenience method to get a boolean runflag from the context config, defaults to defaultValue%0A     * @param context%0A     * @param flagID%0A     * @return%0A     */%0A    protected boolean getflag(ExecutionContext context, String flagID, boolean defaultValue) %7B%0A        return context.getConfiguration().getConfigurationValues().getBoolean(flagID, defaultValue);%0A    %7D
 %0A%7D%0A

Add convenience methods to the Workflow class