Search in sources :

Example 36 with ErrorGetter

use of com.thoughtworks.go.api.representers.ErrorGetter in project gocd by gocd.

the class PackageRepositoryRepresenter method toJSON.

public static void toJSON(OutputWriter outputWriter, PackageRepository packageRepository) {
    outputWriter.addLinks(linkWriter -> {
        linkWriter.addLink("self", Routes.PackageRepository.self(packageRepository.getId()));
        linkWriter.addAbsoluteLink("doc", Routes.PackageRepository.DOC);
        linkWriter.addLink("find", Routes.PackageRepository.FIND);
    });
    outputWriter.add("repo_id", packageRepository.getId());
    outputWriter.add("name", packageRepository.getName());
    outputWriter.addChild("plugin_metadata", childWriter -> PluginConfigurationRepresenter.toJSON(childWriter, packageRepository.getPluginConfiguration()));
    outputWriter.addChildList("configuration", configWriter -> ConfigurationPropertyRepresenter.toJSON(configWriter, packageRepository.getConfiguration()));
    outputWriter.addChild("_embedded", embeddedWriter -> embeddedWriter.addChildList("packages", packageWriter -> PackagesRepresenter.toJSON(packageWriter, packageRepository.getPackages())));
    if (!packageRepository.errors().isEmpty()) {
        outputWriter.addChild("errors", errorWriter -> {
            HashMap<String, String> errorMapping = new HashMap<>();
            new ErrorGetter(errorMapping).toJSON(errorWriter, packageRepository);
        });
    }
}
Also used : OutputWriter(com.thoughtworks.go.api.base.OutputWriter) JsonReader(com.thoughtworks.go.api.representers.JsonReader) List(java.util.List) ConfigurationPropertyRepresenter(com.thoughtworks.go.api.representers.ConfigurationPropertyRepresenter) ErrorGetter(com.thoughtworks.go.api.representers.ErrorGetter) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) HashMap(java.util.HashMap) Routes(com.thoughtworks.go.spark.Routes) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) PluginConfigurationRepresenter(com.thoughtworks.go.api.representers.PluginConfigurationRepresenter) ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) HashMap(java.util.HashMap) ErrorGetter(com.thoughtworks.go.api.representers.ErrorGetter)

Example 37 with ErrorGetter

use of com.thoughtworks.go.api.representers.ErrorGetter in project gocd by gocd.

the class MaterialsRepresenter 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);
        });
    }
    stream(Materials.values()).filter(material -> material.type == materialConfig.getClass()).findFirst().ifPresent(material -> {
        jsonWriter.add("type", material.name().toLowerCase());
        jsonWriter.addChild("attributes", attributeWriter -> material.representer.toJSON(attributeWriter, materialConfig));
    });
}
Also used : HashMap(java.util.HashMap) ErrorGetter(com.thoughtworks.go.api.representers.ErrorGetter)

Example 38 with ErrorGetter

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());
}
Also used : HashMap(java.util.HashMap) ErrorGetter(com.thoughtworks.go.api.representers.ErrorGetter)

Example 39 with ErrorGetter

use of com.thoughtworks.go.api.representers.ErrorGetter in project gocd by gocd.

the class TabConfigRepresenter method toJSON.

public static void toJSON(OutputWriter jsonWriter, Tab tab) {
    if (!tab.errors().isEmpty()) {
        jsonWriter.addChild("errors", errorWriter -> {
            new ErrorGetter(new HashMap<>()).toJSON(errorWriter, tab);
        });
    }
    jsonWriter.add("name", tab.getName());
    jsonWriter.add("path", tab.getPath());
}
Also used : HashMap(java.util.HashMap) ErrorGetter(com.thoughtworks.go.api.representers.ErrorGetter)

Example 40 with ErrorGetter

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;
    }
}
Also used : HashMap(java.util.HashMap) ErrorGetter(com.thoughtworks.go.api.representers.ErrorGetter) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask)

Aggregations

ErrorGetter (com.thoughtworks.go.api.representers.ErrorGetter)43 HashMap (java.util.HashMap)43 TrackingTool (com.thoughtworks.go.config.TrackingTool)3 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)3 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)2 PluggableSCMMaterialConfig (com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig)2 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)2 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)2 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)2 P4MaterialConfig (com.thoughtworks.go.config.materials.perforce.P4MaterialConfig)2 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)2 TfsMaterialConfig (com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig)2 OutputWriter (com.thoughtworks.go.api.base.OutputWriter)1 ConfigurationPropertyRepresenter (com.thoughtworks.go.api.representers.ConfigurationPropertyRepresenter)1 JsonReader (com.thoughtworks.go.api.representers.JsonReader)1 PluginConfigurationRepresenter (com.thoughtworks.go.api.representers.PluginConfigurationRepresenter)1 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)1 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)1 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)1 Routes (com.thoughtworks.go.spark.Routes)1