Search in sources :

Example 1 with JsonReader

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

the class PipelineOperationsControllerV1Delegate method getScheduleOptions.

private PipelineScheduleOptions getScheduleOptions(Request req) {
    if (StringUtils.isBlank(req.body())) {
        return new PipelineScheduleOptions();
    }
    GsonTransformer gsonTransformer = GsonTransformer.getInstance();
    JsonReader jsonReader = gsonTransformer.jsonReaderFrom(req.body());
    return PipelineScheduleOptionsRepresenter.fromJSON(jsonReader);
}
Also used : GsonTransformer(com.thoughtworks.go.api.util.GsonTransformer) PipelineScheduleOptions(com.thoughtworks.go.server.domain.PipelineScheduleOptions) JsonReader(com.thoughtworks.go.api.representers.JsonReader)

Example 2 with JsonReader

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

the class PipelineScheduleOptionsRepresenter method fromJSON.

public static PipelineScheduleOptions fromJSON(JsonReader jsonReader) {
    PipelineScheduleOptions model = new PipelineScheduleOptions();
    model.shouldPerformMDUBeforeScheduling(jsonReader.optBoolean("update_materials_before_scheduling").orElse(Boolean.TRUE));
    jsonReader.readArrayIfPresent("materials", materials -> {
        List<MaterialForScheduling> materialsForScheduling = new ArrayList<>();
        materials.forEach(material -> materialsForScheduling.add(MaterialRevisionRepresenter.fromJSON(new JsonReader(material.getAsJsonObject()))));
        model.setMaterials(materialsForScheduling);
    });
    jsonReader.readArrayIfPresent("environment_variables", environmentVariables -> {
        EnvironmentVariablesConfig variables = new EnvironmentVariablesConfig();
        environmentVariables.forEach(variable -> variables.add(EnvrionmentVariableRepresenter.fromJSON(new JsonReader(variable.getAsJsonObject()))));
        model.setEnvironmentVariables(variables);
    });
    return model;
}
Also used : MaterialForScheduling(com.thoughtworks.go.server.domain.MaterialForScheduling) PipelineScheduleOptions(com.thoughtworks.go.server.domain.PipelineScheduleOptions) ArrayList(java.util.ArrayList) EnvironmentVariablesConfig(com.thoughtworks.go.config.EnvironmentVariablesConfig) JsonReader(com.thoughtworks.go.api.representers.JsonReader)

Example 3 with JsonReader

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

the class PipelineSelectionControllerDelegate method update.

public String update(Request request, Response response) {
    String fromCookie = request.cookie("selected_pipelines");
    JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(request.body());
    PipelineSelectionResponse selectionResponse = PipelineSelectionsRepresenter.fromJSON(jsonReader);
    Long recordId = pipelineSelectionsService.persistSelectedPipelines(fromCookie, currentUserId(request), selectionResponse.getSelectedPipelines().pipelineList(), selectionResponse.getSelectedPipelines().isBlacklist());
    if (!apiAuthenticationHelper.securityEnabled()) {
        response.cookie("/go", "selected_pipelines", String.valueOf(recordId), ONE_YEAR, systemEnvironment.isSessionCookieSecure(), true);
    }
    response.status(204);
    return NOTHING;
}
Also used : JsonReader(com.thoughtworks.go.api.representers.JsonReader) PipelineSelectionResponse(com.thoughtworks.go.apiv1.pipelineselection.representers.PipelineSelectionResponse)

Example 4 with JsonReader

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

the class PluginRoleConfigRepresenter method fromJSON.

public static PluginRoleConfig fromJSON(JsonReader jsonReader) {
    PluginRoleConfig model = new PluginRoleConfig();
    if (jsonReader == null) {
        return model;
    }
    jsonReader.readStringIfPresent("auth_config_id", model::setAuthConfigId);
    jsonReader.readArrayIfPresent("properties", properties -> {
        List<ConfigurationProperty> configurationProperties = new ArrayList<>();
        properties.forEach(property -> {
            JsonReader configPropertyReader = new JsonReader(property.getAsJsonObject());
            ConfigurationProperty configurationProperty = ConfigurationPropertyRepresenter.fromJSON(configPropertyReader);
            configurationProperties.add(configurationProperty);
        });
        model.addConfigurations(configurationProperties);
    });
    return model;
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ArrayList(java.util.ArrayList) JsonReader(com.thoughtworks.go.api.representers.JsonReader) PluginRoleConfig(com.thoughtworks.go.config.PluginRoleConfig)

Example 5 with JsonReader

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

the class EncryptionControllerDelegate method encrypt.

public String encrypt(Request request, Response response) throws InvalidCipherTextException, IOException {
    JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(request.body());
    String value = jsonReader.getString("value");
    String encrypt = cipher.encrypt(value);
    return writerForTopLevelObject(request, response, writer -> EncryptedValueRepresenter.toJSON(writer, encrypt));
}
Also used : JsonReader(com.thoughtworks.go.api.representers.JsonReader)

Aggregations

JsonReader (com.thoughtworks.go.api.representers.JsonReader)6 PipelineScheduleOptions (com.thoughtworks.go.server.domain.PipelineScheduleOptions)2 ArrayList (java.util.ArrayList)2 GsonTransformer (com.thoughtworks.go.api.util.GsonTransformer)1 PipelineSelectionResponse (com.thoughtworks.go.apiv1.pipelineselection.representers.PipelineSelectionResponse)1 EnvironmentVariablesConfig (com.thoughtworks.go.config.EnvironmentVariablesConfig)1 PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)1 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)1 MaterialForScheduling (com.thoughtworks.go.server.domain.MaterialForScheduling)1 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)1