package Specification;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import FileOps.Generator;
import FileOps.Parser;
import FileOps.GSON.GSONWrapper;
import FileOps.XStream.XStreamWrapper;
import Galaxy.Tree.Tool.Tool;
import Galaxy.Tree.Tool.UIHints;
import Galaxy.Tree.Tool.Action.Action;
import Galaxy.Tree.Tool.Action.UploadToolAction;
import Galaxy.Tree.Tool.Code.Code;
import Galaxy.Tree.Tool.Code.Hook;
import Galaxy.Tree.Tool.Command.Command;
import Galaxy.Tree.Tool.ConfigFiles.ConfigFile;
import Galaxy.Tree.Tool.ConfigFiles.ConfigFiles;
import Galaxy.Tree.Tool.Database.RequestParam;
import Galaxy.Tree.Tool.Database.RequestParamTranslation;
import Galaxy.Tree.Tool.Database.DBParam.AppendParam;
import Galaxy.Tree.Tool.Database.DBParam.ValueTranslation;
import Galaxy.Tree.Tool.Database.DBValue.AppendParamValue;
import Galaxy.Tree.Tool.Database.DBValue.BaseValue;
import Galaxy.Tree.Tool.Database.DBValue.ValueTranslationValue;
import Galaxy.Tree.Tool.Input.Input;
import Galaxy.Tree.Tool.Input.Inputs;
import Galaxy.Tree.Tool.Input.Control.Conditional;
import Galaxy.Tree.Tool.Input.Control.Page;
import Galaxy.Tree.Tool.Input.Control.Repeat;
import Galaxy.Tree.Tool.Input.Control.When;
import Galaxy.Tree.Tool.Input.Other.CompositeData;
import Galaxy.Tree.Tool.Input.Other.Display;
import Galaxy.Tree.Tool.Input.Other.UploadDataset;
import Galaxy.Tree.Tool.Input.Param.Option;
import Galaxy.Tree.Tool.Input.Param.Parameter;
import Galaxy.Tree.Tool.Input.Sanitize.Add;
import Galaxy.Tree.Tool.Input.Sanitize.Mapping;
import Galaxy.Tree.Tool.Input.Sanitize.Remove;
import Galaxy.Tree.Tool.Input.Sanitize.Sanitizer;
import Galaxy.Tree.Tool.Input.Sanitize.Valid;
import Galaxy.Tree.Tool.Option.Column;
import Galaxy.Tree.Tool.Option.Filter;
import Galaxy.Tree.Tool.Option.Options;
import Galaxy.Tree.Tool.Option.Validator;
import Galaxy.Tree.Tool.Output.ChangeFormat;
import Galaxy.Tree.Tool.Output.Data;
import Galaxy.Tree.Tool.Output.Outputs;
import Galaxy.Tree.Tool.Requirements.Requirement;
import Galaxy.Tree.Tool.Requirements.Requirements;
import Galaxy.Tree.Tool.Tests.ExtraFiles;
import Galaxy.Tree.Tool.Tests.Test;
import Galaxy.Tree.Tool.Tests.TestOutput;
import Galaxy.Tree.Tool.Tests.TestParameter;
import Galaxy.Tree.Tool.Tests.Tests;
import Galaxy.Tree.Workflow.ExternalInput;
import Galaxy.Tree.Workflow.ExternalOutput;
import Galaxy.Tree.Workflow.InputConnection;
import Galaxy.Tree.Workflow.Position;
import Galaxy.Tree.Workflow.Step;
import Galaxy.Tree.Workflow.ToolState;
import Galaxy.Tree.Workflow.Workflow;
import Galaxy.Toolbox.GalaxyToolDatabase;
import Specification.Galaxy.CommandHandler;
import Specification.Galaxy.DisplayHandler;
import Specification.Galaxy.OptionHandler;
import Specification.Galaxy.RequirementHandler;
import Specification.Galaxy.StateHandler;
import Specification.Galaxy.ValueHandler;
public class GalaxySpecification {
public final static GalaxyToolDatabase database= new GalaxyToolDatabase();
private static GSONWrapper<Workflow> gson = new GSONWrapper<Workflow>(Workflow.class);
private static XStreamWrapper<Tool> xstream = new XStreamWrapper<Tool>();
private static boolean initialized = false;
private static void init(){
initJSON();
initXML();
initialized = true;
}
private static void bindRequestDB(){
xstream.bindElementToClass(RequestParamTranslation.class, "request_param_translation");
xstream.bindGroupToList(RequestParamTranslation.class, "requestParams");
xstream.bindElementToClass(RequestParam.class, "request_param");
xstream.bindAttributeToClassField(RequestParam.class, "remoteName", "remote_name");
xstream.bindAttributeToClassField(RequestParam.class, "galaxyName", "galaxy_name");
xstream.bindAttributeToClassField(RequestParam.class, "missing", "missing");
xstream.bindGroupToList(RequestParam.class, "appendParams");
xstream.bindGroupToList(RequestParam.class, "valueTranslateParams");
xstream.bindElementToClass(ValueTranslation.class, "value_translation");
xstream.bindElementToClassField(ValueTranslation.class, "value", "value");
xstream.bindGroupToList(ValueTranslation.class, "value");
xstream.bindElementToClass(AppendParam.class, "append_param");
xstream.bindGroupToList(AppendParam.class, "value");
xstream.bindAttributeToClassField(AppendParam.class, "separator", "separator");
xstream.bindAttributeToClassField(AppendParam.class, "firstSeparator", "first_separator");
xstream.bindAttributeToClassField(AppendParam.class, "join", "join");
xstream.bindElementToClassField(AppendParam.class, "value", "value");
xstream.bindElementToClass(AppendParamValue.class, "value");
xstream.bindElementToClass(ValueTranslationValue.class, "value");
xstream.bindElementToClass(BaseValue.class, "value");
xstream.addAdvancedHandler(new ValueHandler());
/*
xstream.bindElementToClass(ValueTranslation.class, "value_translation");
xstream.bindAttributeToClassField(ValueTranslation.class, "values", "value");
xstream.bindGroupToList(ValueTranslation.class, "values");
xstream.bindElementToClass(AppendParam.class, "append_param");
xstream.bindAttributeToClassField(AppendParam.class, "seperator", "seperator");
xstream.bindAttributeToClassField(AppendParam.class, "firstSeperator", "first_seperator");
xstream.bindAttributeToClassField(AppendParam.class, "join", "join");
xstream.bindAttributeToClassField(AppendParam.class, "values", "value");
xstream.bindGroupToList(AppendParam.class, "values");
//xstream.bindElementToClass(AppendParamValue.class, "value");
xstream.bindElementToClass(BaseValue.class, "value");
xstream.addAdvancedHandler(new ValueHandler());
*/
}
public static void bindTool(){
xstream.bindElementToClass(Tool.class, "tool");
/*bind attributes*/
xstream.bindAttributeToClassField(Tool.class, "id", "id");
xstream.bindAttributeToClassField(Tool.class, "fullName", "name");
xstream.bindAttributeToClassField(Tool.class, "version", "version");
xstream.bindAttributeToClassField(Tool.class, "toolType", "tool_type");
xstream.bindAttributeToClassField(Tool.class, "URLMethod", "URL_method");
/* bind children*/
xstream.bindElementToClassField(Tool.class, "toolInputs", "inputs");
xstream.bindElementToClassField(Tool.class, "toolOutputs", "outputs");
//xstream.bindElementToClassField(Tool.class, "toolRequirements", "requirements");
xstream.bindElementToClassField(Tool.class, "UIHints", "uihints");
xstream.bindElementToClassField(Tool.class,"redirectUrlParams","redirect_url_params");
xstream.bindElementToClassField(Tool.class, "toolParallelism", "parallelism");
xstream.bindElementToClassField(Tool.class, "description", "description");
xstream.bindElementToClassField(Tool.class, "toolCommand", "command");
xstream.bindElementToClassField(Tool.class, "tests", "tests");
xstream.bindElementToClassField(Tool.class, "code", "code");
xstream.bindElementToClassField(Tool.class, "tracksterConf", "trackster_conf");
xstream.bindElementToClassField(Tool.class, "configFiles", "configfiles");
xstream.bindElementToClassField(Tool.class, "versionCommand", "version_command");
xstream.bindElementToClassField(Tool.class, "toolOptions", "options");
xstream.bindElementToClassField(Tool.class, "toolHelp", "help");
xstream.bindGroupToList(Tool.class, "toolRequirements", Requirements.class);
xstream.bindGroupToList(Tool.class, "actions", Action.class);
}
private static void initXML(){
bindTool();
xstream.bindElementToClass(Action.class, "action");
xstream.bindAttributeToClassField(Action.class, "actionModule", "module");
xstream.bindAttributeToClassField(Action.class, "actionClass", "class");
xstream.bindGroupToList(ConfigFiles.class, "configFiles");
xstream.bindElementToClass(ConfigFile.class, "configfile");
xstream.bindAttributeToClassField(ConfigFile.class, "name", "name");
xstream.bindElementToClass(Code.class, "code");
xstream.bindAttributeToClassField(Code.class, "file", "file");
xstream.bindAttributeToClassField(Code.class, "hook", "hook");
xstream.bindElementToClass(Hook.class, "hook");
xstream.bindAttributeToClassField(Hook.class, "execAfterProcess", "exec_after_process");
bindRequestDB();
xstream.bindElementToClass(Test.class, "test");
xstream.bindGroupToList(Tests.class, "tests");
xstream.bindGroupToList(Test.class, "params");
xstream.bindGroupToList(Test.class, "outputs");
xstream.bindElementToClass(TestParameter.class, "param");
xstream.bindAttributeToClassField(TestParameter.class, "name", "name");
xstream.bindAttributeToClassField(TestParameter.class, "value", "value");
xstream.bindElementToClass(TestOutput.class, "output");
xstream.bindAttributeToClassField(TestOutput.class, "name", "name");
xstream.bindAttributeToClassField(TestOutput.class, "file", "file");
xstream.bindGroupToList(TestOutput.class, "extraFiles");
xstream.bindElementToClass(ExtraFiles.class, "extra_files");
xstream.bindElementToClass(Options.class, "options");
xstream.bindAttributeToClassField(Options.class, "optFromFile", "from_file");
xstream.bindAttributeToClassField(Options.class, "sanitize", "sanitize");
xstream.bindAttributeToClassField(Options.class, "refresh", "refresh");
xstream.bindGroupToList(Options.class, "options");
xstream.bindElementToClass(Column.class, "column");
xstream.bindAttributeToClassField(Column.class, "name", "name");
xstream.bindAttributeToClassField(Column.class, "index", "index");
xstream.bindElementToClass(Filter.class, "filter");
xstream.bindAttributeToClassField(Filter.class, "type", "type");
xstream.bindAttributeToClassField(Filter.class, "reference", "ref");
xstream.bindAttributeToClassField(Filter.class, "key", "key");
xstream.bindAttributeToClassField(Filter.class, "column", "column");
xstream.bindAttributeToClassField(Filter.class, "value", "value");
xstream.bindAttributeToClassField(Filter.class, "name", "name");
xstream.bindAttributeToClassField(Filter.class, "separator", "separator");
xstream.bindElementToClass(Option.class, "option");
xstream.addAdvancedHandler(new OptionHandler());
xstream.bindElementToClass(Page.class, "page");
xstream.bindGroupToList(Page.class, "parameters");
xstream.bindElementToClass(Repeat.class, "repeat");
xstream.bindAttributeToClassField(Repeat.class, "name", "name");
xstream.bindAttributeToClassField(Repeat.class, "title", "title");
xstream.bindGroupToList(Repeat.class, "inputs");
xstream.bindElementToClass(Display.class, "display");
xstream.addAdvancedHandler(new DisplayHandler());
xstream.bindElementToClass(UploadDataset.class, "upload_dataset");
xstream.bindGroupToList(UploadDataset.class, "datasetInputs");
xstream.bindElementToClass(Conditional.class, "conditional");
xstream.bindElementToClassField(Conditional.class, "parameter", "param");
xstream.bindAttributeToClassField(Conditional.class, "name", "name");
xstream.bindGroupToList(Conditional.class, "conditions", When.class);
xstream.bindElementToClass(When.class, "when");
xstream.bindGroupToList(When.class, "parameter", Input.class);
xstream.bindAttributeToClassField(When.class, "value", "value");
xstream.bindAttributeToClassField(When.class, "input", "input");
xstream.bindAttributeToClassField(When.class, "format", "format");
xstream.bindAttributeToClassField(Command.class, "interpreter", "interpreter");
xstream.addAdvancedHandler(new CommandHandler());
xstream.bindElementToClass(Inputs.class, "inputs");
xstream.bindGroupToList(Inputs.class, "inputList");
xstream.bindAttributeToClassField(Inputs.class, "action", "action");
xstream.bindAttributeToClassField(Inputs.class, "target", "target");
xstream.bindElementToClass(Outputs.class, "outputs");
xstream.bindGroupToList(Outputs.class, "outputList");
xstream.bindElementToClass(Data.class, "data");
xstream.bindAttributeToClassField(Data.class, "name", "name");
xstream.bindAttributeToClassField(Data.class, "format", "format");
xstream.bindAttributeToClassField(Data.class, "label", "label");
xstream.bindAttributeToClassField(Data.class, "changeFormat", "change_format");
xstream.bindGroupToList(Data.class, "filters");
xstream.bindElementToClass(ChangeFormat.class, "change_format");
xstream.bindGroupToList(ChangeFormat.class, "condition");
xstream.bindElementToClass(Sanitizer.class, "sanitizer");
xstream.bindElementToClassField(Sanitizer.class, "validates", "valid");
xstream.bindElementToClassField(Sanitizer.class, "mappings", "mapping");
xstream.bindGroupToList(Sanitizer.class, "mappings");
xstream.bindGroupToList(Sanitizer.class, "validates");
xstream.bindElementToClass(Valid.class, "valid");
xstream.bindGroupToList(Valid.class, "adds");
xstream.bindGroupToList(Valid.class, "removes");
xstream.bindElementToClass(Mapping.class, "mapping");
xstream.bindGroupToList(Mapping.class, "adds");
xstream.bindGroupToList(Mapping.class, "removes");
xstream.bindElementToClass(Add.class, "add");
xstream.bindElementToClass(Remove.class, "remove");
xstream.bindAttributeToClassField(Data.class, "changeFormat", "change_format");
xstream.bindElementToClass(Parameter.class, "param");
xstream.bindAttributeToClassField(Parameter.class, "name", "name");
xstream.bindAttributeToClassField(Parameter.class, "type", "type");
xstream.bindAttributeToClassField(Parameter.class, "label", "label");
xstream.bindAttributeToClassField(Parameter.class, "size", "size");
xstream.bindAttributeToClassField(Parameter.class, "help", "help");
xstream.bindAttributeToClassField(Parameter.class, "format", "format");
xstream.bindAttributeToClassField(Parameter.class, "value", "value");
xstream.bindAttributeToClassField(Parameter.class, "ftype", "ftype");
xstream.bindAttributeToClassField(Parameter.class, "optionList", "option");
xstream.bindAttributeToClassField(Parameter.class, "options", "options");
xstream.bindAttributeToClassField(Parameter.class, "validators", "validator");
xstream.bindAttributeToClassField(Parameter.class, "multiple", "multiple");
xstream.bindAttributeToClassField(Parameter.class, "display", "display");
xstream.bindAttributeToClassField(Parameter.class, "fromFile", "fromFile");
xstream.bindAttributeToClassField(Parameter.class, "editAttributes", "edit_attributes");
xstream.bindGroupToList(Parameter.class, "optionList", Option.class);
xstream.bindGroupToList(Parameter.class, "validators", Validator.class);
xstream.bindGroupToList(Parameter.class, "compositeData", CompositeData.class);
xstream.bindElementToClass(CompositeData.class, "composite_data");
xstream.bindElementToClass(Validator.class, "validator");
xstream.bindAttributeToClassField(Validator.class, "type", "type");
xstream.bindAttributeToClassField(Validator.class, "minimum", "min");
xstream.bindAttributeToClassField(Validator.class, "message", "message");
xstream.bindAttributeToClassField(Validator.class, "filename", "filename");
xstream.bindAttributeToClassField(Validator.class, "metadataName", "metadata_name");
xstream.bindAttributeToClassField(Validator.class, "metadataColumn", "metadata_column");
xstream.bindElementToClass(UIHints.class, "uihints");
xstream.bindAttributeToClassField(UIHints.class, "minimumWidth", "minwidth");
xstream.bindElementToClass(Requirements.class, "requirements");
xstream.bindGroupToList(Requirements.class, "requirements", Requirement.class);
xstream.bindElementToClass(Requirement.class, "requirement");
xstream.addAdvancedHandler(new RequirementHandler());
}
private static void initJSON(){
gson.bindTag(Workflow.class, "name", "name");
gson.bindTag(Workflow.class, "formatVersion", "format-version");
gson.bindTag(Workflow.class, "annotation", "annotation");
gson.bindTag(Workflow.class, "isGalaxyWorkflow", "a_galaxy_workflow");
gson.bindTag(Workflow.class, "steps", "steps");
gson.bindTag(Step.class, "name", "name");
gson.bindTag(Step.class, "annotation", "annotation");
gson.bindTag(Step.class, "id", "id");
gson.bindTag(Step.class, "toolId", "tool_id");
gson.bindTag(Step.class, "connections", "input_connections");
gson.bindTag(Step.class, "externalInputs", "inputs");
gson.bindTag(Step.class, "externalOutputs", "outputs");
gson.bindTag(Step.class, "stepPosition", "position");
gson.bindTag(Step.class, "toolVersion", "tool_version");
gson.bindTag(Step.class, "toolState", "tool_state");
gson.bindTag(Step.class, "toolType", "type");
gson.bindTag(Step.class, "postJobActions", "post_job_actions");
gson.bindTag(ExternalInput.class, "name", "name");
gson.bindTag(ExternalInput.class, "description", "description");
gson.bindHandler(ToolState.class, new StateHandler());
gson.bindTag(Position.class, "unitsFromLeftMargin", "left");
gson.bindTag(Position.class, "unitsFromTopMargin", "top");
gson.bindTag(ExternalOutput.class, "name", "name");
gson.bindTag(ExternalOutput.class, "type", "type");
gson.bindTag(InputConnection.class, "sourceId", "id");
gson.bindTag(InputConnection.class, "outputName", "output_name");
gson.bindTag(Galaxy.Tree.Workflow.Action.class, "actionType", "action_type");
gson.bindTag(Galaxy.Tree.Workflow.Action.class, "outputName", "output_name");
gson.bindTag(Galaxy.Tree.Workflow.Action.class, "actionArguments", "action_arguments");
}
public static Parser<Workflow> getJSONParser(){
if(!initialized)
init();
return gson;
}
public static Generator<Workflow> getJSONGenerator(){
if(!initialized)
init();
return gson;
}
public static Generator getGenericJSONGenerator(){
if(!initialized)
init();
return gson.toGeneric();
}
public static Generator getGenericJSONParser(){
if(!initialized)
init();
return gson.toGeneric();
}
public static Parser<Tool> getXMLParser(){
if(!initialized)
init();
return xstream;
}
public static Generator<Tool> getXMLGenerator(){
if(!initialized)
init();
return xstream;
}
public static GalaxyToolDatabase getDatabase(){
return database;
}
}