use of com.thoughtworks.go.api.representers.ErrorGetter in project gocd by gocd.
the class JobRepresenter method toJSON.
public static void toJSON(OutputWriter jsonWriter, JobConfig jobConfig) {
if (!jobConfig.errors().isEmpty() || !jobConfig.resourceConfigs().errors().isEmpty()) {
jsonWriter.addChild("errors", errorWriter -> {
HashMap<String, String> errorMapping = new HashMap<>();
errorMapping.put("runType", "run_instance_count");
new ErrorGetter(errorMapping).toJSON(errorWriter, jobConfig);
HashMap<String, String> resourcesErrorMapping = new HashMap<>();
resourcesErrorMapping.put("resources", "resources");
new ErrorGetter(resourcesErrorMapping).toJSON(errorWriter, jobConfig.resourceConfigs());
});
}
jsonWriter.addIfNotNull("name", jobConfig.name());
addRunInstanceCount(jsonWriter, jobConfig);
addTimeout(jsonWriter, jobConfig);
jsonWriter.addIfNotNull("elastic_profile_id", jobConfig.getElasticProfileId());
jsonWriter.addChildList("environment_variables", envVarsWriter -> EnvironmentVariableRepresenter.toJSON(envVarsWriter, jobConfig.getVariables()));
jsonWriter.addChildList("resources", getResourceNames(jobConfig));
jsonWriter.addChildList("tasks", tasksWriter -> TaskRepresenter.toJSONArray(tasksWriter, jobConfig.getTasks()));
jsonWriter.addChildList("tabs", tabsWriter -> TabConfigRepresenter.toJSONArray(tabsWriter, jobConfig.getTabs()));
jsonWriter.addChildList("artifacts", getArtifacts(jobConfig));
}
use of com.thoughtworks.go.api.representers.ErrorGetter in project gocd by gocd.
the class StageRepresenter method toJSON.
public static void toJSON(OutputWriter jsonWriter, StageConfig stageConfig) {
if (!stageConfig.errors().isEmpty()) {
jsonWriter.addChild("errors", errorWriter -> {
new ErrorGetter(new HashMap<>()).toJSON(errorWriter, stageConfig);
});
}
jsonWriter.addIfNotNull("name", stageConfig.name());
jsonWriter.add("fetch_materials", stageConfig.isFetchMaterials());
jsonWriter.add("clean_working_directory", stageConfig.isCleanWorkingDir());
jsonWriter.add("never_cleanup_artifacts", stageConfig.isArtifactCleanupProhibited());
jsonWriter.addChild("approval", approvalWriter -> ApprovalRepresenter.toJSON(approvalWriter, stageConfig.getApproval()));
jsonWriter.addChildList("environment_variables", envVarsWriter -> EnvironmentVariableRepresenter.toJSON(envVarsWriter, stageConfig.getVariables()));
jsonWriter.addChildList("jobs", getJobs(stageConfig));
}
use of com.thoughtworks.go.api.representers.ErrorGetter in project gocd by gocd.
the class ArtifactRepresenter method toJSON.
public static void toJSON(OutputWriter jsonWriter, ArtifactTypeConfig artifactConfig) {
if (!artifactConfig.errors().isEmpty()) {
jsonWriter.addChild("errors", errorWriter -> {
HashMap<String, String> errorMapping = new HashMap<>();
errorMapping.put("src", "source");
errorMapping.put("dest", "destination");
errorMapping.put("id", "artifact_id");
errorMapping.put("storeId", "store_id");
errorMapping.put("pluginId", "plugin_id");
new ErrorGetter(errorMapping).toJSON(errorWriter, artifactConfig);
});
}
jsonWriter.add("type", artifactConfig.getArtifactType().name());
switch(artifactConfig.getArtifactType()) {
case test:
case build:
BuiltinArtifactConfigRepresenter.toJSON(jsonWriter, (BuiltinArtifactConfig) artifactConfig);
break;
case external:
ExternalArtifactConfigRepresenter.toJSON(jsonWriter, (PluggableArtifactConfig) artifactConfig);
}
}
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) {
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());
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 ApprovalRepresenter method toJSON.
public static void toJSON(OutputWriter jsonWriter, Approval approval) {
if (!approval.errors().isEmpty()) {
jsonWriter.addChild("errors", errorWriter -> {
new ErrorGetter(new HashMap<>()).toJSON(errorWriter, approval);
});
}
jsonWriter.add("type", approval.getType());
jsonWriter.add(Approval.ALLOW_ONLY_ON_SUCCESS, approval.isAllowOnlyOnSuccess());
jsonWriter.addChild("authorization", authConfigWriter -> StageAuthorizationRepresenter.toJSON(authConfigWriter, approval.getAuthConfig()));
}
Aggregations