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);
}
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;
}
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;
}
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;
}
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));
}
Aggregations