Search in sources :

Example 1 with ErrorGetter

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

the class PackageDefinitionRepresenter method toJSON.

public static void toJSON(OutputWriter outputWriter, PackageDefinition packageDefinition) {
    outputWriter.addLinks(linksWriter -> {
        linksWriter.addLink("self", Routes.Packages.self(packageDefinition.getId()));
        linksWriter.addAbsoluteLink("doc", Routes.Packages.DOC);
        linksWriter.addLink("find", Routes.Packages.FIND);
    });
    outputWriter.add("name", packageDefinition.getName());
    outputWriter.add("id", packageDefinition.getId());
    outputWriter.add("auto_update", packageDefinition.isAutoUpdate());
    outputWriter.addChild("package_repo", childWriter -> PackageRepositoryRepresenter.toJSON(childWriter, packageDefinition.getRepository()));
    outputWriter.addChildList("configuration", configWriter -> ConfigurationPropertyRepresenter.toJSON(configWriter, packageDefinition.getConfiguration()));
    if (!packageDefinition.errors().isEmpty()) {
        outputWriter.addChild("errors", errorWriter -> {
            HashMap<String, String> errorMapping = new HashMap<>();
            new ErrorGetter(errorMapping).toJSON(errorWriter, packageDefinition);
        });
    }
}
Also used : HashMap(java.util.HashMap) ErrorGetter(com.thoughtworks.go.api.representers.ErrorGetter)

Example 2 with ErrorGetter

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

Example 3 with ErrorGetter

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

Example 4 with ErrorGetter

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

Example 5 with ErrorGetter

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;
    }
}
Also used : PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) HashMap(java.util.HashMap) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) P4MaterialConfig(com.thoughtworks.go.config.materials.perforce.P4MaterialConfig) TfsMaterialConfig(com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) ErrorGetter(com.thoughtworks.go.api.representers.ErrorGetter) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) PluggableSCMMaterialConfig(com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig)

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