use of com.thoughtworks.go.api.representers.ErrorGetter in project gocd by gocd.
the class PipelineConfigRepresenter method toJSON.
public static void toJSON(OutputWriter jsonWriter, PipelineConfig pipelineConfig, String groupName) {
jsonWriter.addLinks(linksWriter -> linksWriter.addLink("self", Routes.PipelineConfig.name(pipelineConfig.getName().toString())).addAbsoluteLink("doc", Routes.PipelineConfig.DOC).addLink("find", Routes.PipelineConfig.find()));
// This is needed for the case when there are no materials defined. Refer to pipeline_config_representer.rb#152
pipelineConfig.errors().addAll(pipelineConfig.materialConfigs().errors());
if (!pipelineConfig.errors().isEmpty()) {
jsonWriter.addChild("errors", errorWriter -> {
HashMap<String, String> errorMapping = new HashMap<>();
errorMapping.put("labelTemplate", "label_template");
errorMapping.put("params", "parameters");
errorMapping.put("variables", "environment_variables");
errorMapping.put("trackingTool", "tracking_tool");
new ErrorGetter(errorMapping).toJSON(errorWriter, pipelineConfig);
});
}
jsonWriter.add("label_template", pipelineConfig.getLabelTemplate());
jsonWriter.add("lock_behavior", pipelineConfig.getLockBehavior());
jsonWriter.add("name", pipelineConfig.name());
jsonWriter.add("template", pipelineConfig.getTemplateName());
jsonWriter.add("group", groupName);
writeOrigin(jsonWriter, pipelineConfig.getOrigin());
jsonWriter.addChildList("parameters", paramsWriter -> ParamRepresenter.toJSONArray(paramsWriter, pipelineConfig.getParams()));
jsonWriter.addChildList("environment_variables", envVarsWriter -> EnvironmentVariableRepresenter.toJSON(envVarsWriter, pipelineConfig.getVariables()));
jsonWriter.addChildList("materials", materialsWriter -> MaterialsRepresenter.toJSONArray(materialsWriter, pipelineConfig.materialConfigs()));
writeStages(jsonWriter, pipelineConfig);
writeTrackingTool(jsonWriter, pipelineConfig);
writeTimer(jsonWriter, pipelineConfig.getTimer());
}
use of com.thoughtworks.go.api.representers.ErrorGetter in project gocd by gocd.
the class RulesRepresenter method toJSON.
public static void toJSON(OutputListWriter listWriter, Rules rules) {
rules.forEach(directive -> {
listWriter.addChild(directiveWriter -> {
if (directive.hasErrors()) {
directiveWriter.addChild("errors", errorWriter -> {
new ErrorGetter(new HashMap<>()).toJSON(directiveWriter, directive);
});
}
if (directive instanceof Unknown) {
directiveWriter.add("directive", ((Unknown) directive).getDirective());
} else {
directiveWriter.add("directive", directive.getDirectiveType().type());
}
directiveWriter.add("action", directive.action());
directiveWriter.add("type", directive.type());
directiveWriter.add("resource", directive.resource());
});
});
}
use of com.thoughtworks.go.api.representers.ErrorGetter in project gocd by gocd.
the class MaterialRepresenter method toJSON.
public static void toJSON(OutputWriter jsonWriter, MaterialConfig materialConfig) {
if (!materialConfig.errors().isEmpty()) {
jsonWriter.addChild("errors", errorWriter -> {
HashMap<String, String> errorMapping = new HashMap<>();
errorMapping.put("materialName", "name");
errorMapping.put("folder", "destination");
errorMapping.put("autoUpdate", "auto_update");
errorMapping.put("filterAsString", "filter");
errorMapping.put("checkexternals", "check_externals");
errorMapping.put("serverAndPort", "port");
errorMapping.put("useTickets", "use_tickets");
errorMapping.put("pipelineName", "pipeline");
errorMapping.put("stageName", "stage");
errorMapping.put("pipelineStageName", "pipeline");
errorMapping.put("packageId", "ref");
errorMapping.put("scmId", "ref");
errorMapping.put("encryptedPassword", "encrypted_password");
new ErrorGetter(errorMapping).toJSON(errorWriter, materialConfig);
});
}
jsonWriter.add("type", classToTypeMap.get(materialConfig.getClass()));
switch(classToTypeMap.get(materialConfig.getClass())) {
case "git":
jsonWriter.addChild("attributes", attributeWriter -> GitMaterialRepresenter.toJSON(attributeWriter, (GitMaterialConfig) materialConfig));
break;
case "hg":
jsonWriter.addChild("attributes", attributeWriter -> HgMaterialRepresenter.toJSON(attributeWriter, (HgMaterialConfig) materialConfig));
break;
case "svn":
jsonWriter.addChild("attributes", attributeWriter -> SvnMaterialRepresenter.toJSON(attributeWriter, (SvnMaterialConfig) materialConfig));
break;
case "p4":
jsonWriter.addChild("attributes", attributeWriter -> PerforceMaterialRepresenter.toJSON(attributeWriter, (P4MaterialConfig) materialConfig));
break;
case "tfs":
jsonWriter.addChild("attributes", attributeWriter -> TfsMaterialRepresenter.toJSON(attributeWriter, (TfsMaterialConfig) materialConfig));
break;
case "dependency":
jsonWriter.addChild("attributes", attributeWriter -> DependencyMaterialRepresenter.toJSON(attributeWriter, (DependencyMaterialConfig) materialConfig));
break;
case "package":
jsonWriter.addChild("attributes", attributeWriter -> PackageMaterialRepresenter.toJSON(attributeWriter, (PackageMaterialConfig) materialConfig));
break;
case "plugin":
jsonWriter.addChild("attributes", attributeWriter -> PluggableScmMaterialRepresenter.toJSON(attributeWriter, (PluggableSCMMaterialConfig) materialConfig));
break;
}
}
use of com.thoughtworks.go.api.representers.ErrorGetter in project gocd by gocd.
the class RulesRepresenter method toJSON.
public static void toJSON(OutputListWriter listWriter, Rules rules) {
rules.forEach(directive -> {
listWriter.addChild(directiveWriter -> {
if (directive.hasErrors()) {
directiveWriter.addChild("errors", errorWriter -> {
new ErrorGetter(new HashMap<>()).toJSON(directiveWriter, directive);
});
}
if (directive instanceof Unknown) {
directiveWriter.add("directive", ((Unknown) directive).getDirective());
} else {
directiveWriter.add("directive", directive.getDirectiveType().type());
}
directiveWriter.add("action", directive.action());
directiveWriter.add("type", directive.type());
directiveWriter.add("resource", directive.resource());
});
});
}
use of com.thoughtworks.go.api.representers.ErrorGetter in project gocd by gocd.
the class TaskRepresenter method toJSON.
public static void toJSON(OutputWriter jsonWriter, Task task) {
if (!task.errors().isEmpty()) {
jsonWriter.addChild("errors", errorWriter -> {
HashMap<String, String> errorMapping = new HashMap<>();
errorMapping.put("buildFile", "build_file");
errorMapping.put("onCancelConfig", "on_cancel");
errorMapping.put("runIf", "run_if");
errorMapping.put("argListString", "arguments");
errorMapping.put("src", "source");
errorMapping.put("dest", "destination");
errorMapping.put("pipelineName", "pipeline");
new ErrorGetter(errorMapping).toJSON(errorWriter, task);
});
}
jsonWriter.add("type", task instanceof PluggableTask ? "pluggable_task" : task.getTaskType());
if (task instanceof PluggableTask) {
jsonWriter.addChild("attributes", attributeWriter -> PluggableTaskRepresenter.toJSON(attributeWriter, (PluggableTask) task));
return;
}
switch(task.getTaskType()) {
case AntTask.TYPE:
jsonWriter.addChild("attributes", attributeWriter -> AntTaskRepresenter.toJSON(attributeWriter, (AntTask) task));
break;
case NantTask.TYPE:
jsonWriter.addChild("attributes", attributeWriter -> NantTaskRepresenter.toJSON(attributeWriter, (NantTask) task));
break;
case RakeTask.TYPE:
jsonWriter.addChild("attributes", attributeWriter -> RakeTaskRepresenter.toJSON(attributeWriter, (RakeTask) task));
break;
case ExecTask.TYPE:
jsonWriter.addChild("attributes", attributeWriter -> ExecTaskRepresenter.toJSON(attributeWriter, (ExecTask) task));
break;
case FetchTask.TYPE:
jsonWriter.addChild("attributes", attributeWriter -> FetchTaskRepresenter.toJSON(attributeWriter, (AbstractFetchTask) task));
break;
}
}
Aggregations