Search in sources :

Example 26 with ErrorGetter

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

the class TimerRepresenter method toJSON.

public static void toJSON(OutputWriter jsonWriter, TimerConfig timerConfig) {
    if (timerConfig == null) {
        return;
    }
    if (!timerConfig.errors().isEmpty()) {
        jsonWriter.addChild("errors", errorWriter -> {
            HashMap<String, String> mapping = new HashMap<>();
            mapping.put("timerSpec", "spec");
            new ErrorGetter(mapping).toJSON(errorWriter, timerConfig);
        });
    }
    jsonWriter.add("spec", timerConfig.getTimerSpec());
    jsonWriter.add("only_on_changes", timerConfig.getOnlyOnChanges());
}
Also used : HashMap(java.util.HashMap) ErrorGetter(com.thoughtworks.go.api.representers.ErrorGetter)

Example 27 with ErrorGetter

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

Example 28 with ErrorGetter

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

the class TrackingToolRepresenter method toJSON.

public static void toJSON(OutputWriter jsonWriter, PipelineConfig pipelineConfig) {
    HashMap<String, String> mapping = new HashMap<>();
    mapping.put("projectIdentifier", "project_identifier");
    mapping.put("baseUrl", "base_url");
    mapping.put("link", "url_pattern");
    if (pipelineConfig.getTrackingTool() != null) {
        TrackingTool trackingTool = pipelineConfig.getTrackingTool();
        if (!trackingTool.errors().isEmpty()) {
            jsonWriter.addChild("errors", errorWriter -> {
                new ErrorGetter(mapping).toJSON(errorWriter, trackingTool);
            });
        }
        jsonWriter.add("type", "generic");
        jsonWriter.addChild("attributes", attributeWriter -> ExternalTrackingToolRepresenter.toJSON(attributeWriter, trackingTool));
    }
}
Also used : HashMap(java.util.HashMap) ErrorGetter(com.thoughtworks.go.api.representers.ErrorGetter) TrackingTool(com.thoughtworks.go.config.TrackingTool)

Example 29 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 30 with ErrorGetter

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

the class StageAuthorizationRepresenter method toJSON.

public static void toJSON(OutputWriter jsonWriter, AuthConfig authConfig) {
    if (!authConfig.errors().isEmpty()) {
        jsonWriter.addChild("errors", errorWriter -> {
            new ErrorGetter(new HashMap<>()).toJSON(errorWriter, authConfig);
        });
    }
    jsonWriter.addChildList("roles", authConfig.getRoles().stream().map(eachItem -> eachItem.getName().toString()).collect(Collectors.toList()));
    jsonWriter.addChildList("users", authConfig.getUsers().stream().map(eachItem -> eachItem.getName().toString()).collect(Collectors.toList()));
}
Also used : HashMap(java.util.HashMap) ErrorGetter(com.thoughtworks.go.api.representers.ErrorGetter)

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