use of com.thoughtworks.go.config.exceptions.BadRequestException in project gocd by gocd.
the class ApiController method getCursor.
protected long getCursor(Request request, String key) {
long cursor = 0;
try {
String value = request.queryParams(key);
if (isBlank(value)) {
return cursor;
}
cursor = Long.parseLong(value);
} catch (NumberFormatException nfe) {
throw new BadRequestException(String.format(BAD_CURSOR_MSG, key));
}
return cursor;
}
use of com.thoughtworks.go.config.exceptions.BadRequestException in project gocd by gocd.
the class BuildCauseController method index.
public String index(Request req, Response res) throws IOException {
HttpOperationResult httpOperationResult = new HttpOperationResult();
int result;
try {
result = Integer.parseInt(req.params(":pipeline_counter"));
} catch (NumberFormatException nfe) {
throw new BadRequestException("Parameter `pipeline_counter` must be an integer.");
}
String pipelineName = req.params("pipeline_name");
PipelineInstanceModel pipelineInstance = pipelineHistoryService.findPipelineInstance(pipelineName, result, currentUsername(), httpOperationResult);
if (httpOperationResult.isSuccess()) {
return writerForTopLevelObject(req, res, outputWriter -> BuildCauseRepresenter.toJSON(outputWriter, pipelineInstance.getBuildCause()));
} else {
return renderHTTPOperationResult(httpOperationResult, req, res);
}
}
use of com.thoughtworks.go.config.exceptions.BadRequestException in project gocd by gocd.
the class BackupsControllerV2 method show.
public String show(Request request, Response response) throws IOException {
String backupId = request.params("id");
Optional<ServerBackup> backup;
if (RUNNING.equals(backupId)) {
backup = backupService.runningBackup();
} else {
try {
backup = backupService.getServerBackup(Long.parseLong(backupId));
} catch (NumberFormatException e) {
throw new BadRequestException("The `id` parameter should be a number, or the keyword `running`");
}
}
if (!backup.isPresent()) {
throw new RecordNotFoundException(EntityType.Backup, backupId);
}
return writerForTopLevelObject(request, response, outputWriter -> BackupRepresenter.toJSON(outputWriter, backup.get()));
}
use of com.thoughtworks.go.config.exceptions.BadRequestException in project gocd by gocd.
the class JobInstanceControllerV1 method getValue.
private Integer getValue(Request request, String paramKey) {
Integer value;
String errorMsg = format("The params '%s' must be a number greater than 0.", paramKey);
try {
value = Integer.valueOf(request.params(paramKey));
if (value < 0) {
throw new BadRequestException(errorMsg);
}
} catch (NumberFormatException e) {
throw new BadRequestException(errorMsg);
}
return value;
}
use of com.thoughtworks.go.config.exceptions.BadRequestException in project gocd by gocd.
the class ExtractTemplateFromPipelineEntityConfigUpdateCommand method canContinue.
@Override
public boolean canContinue(CruiseConfig cruiseConfig) {
PipelineConfig pipelineConfig = cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString(pipelineName));
if (pipelineConfig == null) {
throw new RecordNotFoundException(EntityType.Pipeline, pipelineName);
}
if (pipelineConfig.hasTemplate()) {
throw new ConflictException(EntityType.Pipeline.alreadyUsesATemplate(pipelineName));
}
PipelineTemplateConfig templateByName = cruiseConfig.getTemplates().templateByName(this.newTemplate.name());
if (templateByName != null) {
throw new ConflictException(EntityType.Template.alreadyExists(this.newTemplate.name()));
}
if (new NameTypeValidator().isNameInvalid(this.newTemplate.name().toString())) {
throw new BadRequestException(NameTypeValidator.errorMessage("template", this.newTemplate.name()));
}
return true;
}
Aggregations