use of com.thoughtworks.go.config.exceptions.UnprocessableEntityException in project gocd by gocd.
the class AgentsUpdateValidator method bombWhenResourceNamesToAddAreInvalid.
private void bombWhenResourceNamesToAddAreInvalid() {
ResourceConfigs resourceConfigs = new ResourceConfigs(commaSeparate(resourcesToAdd));
resourceConfigs.validate(null);
if (!resourceConfigs.errors().isEmpty()) {
throw new UnprocessableEntityException("Validations failed for bulk update of agents. Error(s): " + resourceConfigs.errors());
}
}
use of com.thoughtworks.go.config.exceptions.UnprocessableEntityException in project gocd by gocd.
the class MaterialRepresenter method fromJSON.
public static MaterialConfig fromJSON(JsonReader jsonReader, ConfigHelperOptions options) {
String type = jsonReader.getString("type");
JsonReader attributes = jsonReader.readJsonObject("attributes");
switch(type) {
case "git":
return GitMaterialRepresenter.fromJSON(attributes);
case "hg":
return HgMaterialRepresenter.fromJSON(attributes);
case "svn":
return SvnMaterialRepresenter.fromJSON(attributes, options);
case "p4":
return PerforceMaterialRepresenter.fromJSON(attributes, options);
case "tfs":
return TfsMaterialRepresenter.fromJSON(attributes, options);
case "dependency":
return DependencyMaterialRepresenter.fromJSON(attributes);
case "plugin":
return PluggableScmMaterialRepresenter.fromJSON(attributes, options);
case "package":
return PackageMaterialRepresenter.fromJSON(attributes, options);
default:
throw new UnprocessableEntityException(String.format("Invalid material type %s. It has to be one of 'git, svn, hg, p4, tfs, dependency, package, plugin'.", type));
}
}
use of com.thoughtworks.go.config.exceptions.UnprocessableEntityException in project gocd by gocd.
the class TaskRepresenter method fromJSON.
public static Task fromJSON(JsonReader jsonReader) {
JsonReader attributes = null;
String type = jsonReader.getString("type");
Optional<JsonReader> attributesObject = jsonReader.optJsonObject("attributes");
if (attributesObject.isPresent()) {
attributes = attributesObject.get();
}
switch(type) {
case AntTask.TYPE:
return AntTaskRepresenter.fromJSON(attributes);
case NantTask.TYPE:
return NantTaskRepresenter.fromJSON(attributes);
case RakeTask.TYPE:
return RakeTaskRepresenter.fromJSON(attributes);
case ExecTask.TYPE:
return ExecTaskRepresenter.fromJSON(attributes);
case FetchTask.TYPE:
return FetchTaskRepresenter.fromJSON(attributes);
case PluggableTask.TYPE:
return PluggableTaskRepresenter.fromJSON(attributes);
default:
throw new UnprocessableEntityException(String.format("Invalid task type %s. It has to be one of '%s'.", type, String.join(",", ExecTask.TYPE, AntTask.TYPE, NantTask.TYPE, RakeTask.TYPE, FetchTask.TYPE, PluggableTask.TYPE)));
}
}
use of com.thoughtworks.go.config.exceptions.UnprocessableEntityException in project gocd by gocd.
the class UserService method addNotificationFilter.
public void addNotificationFilter(final long userId, final NotificationFilter filter) {
filter.validate(validationContext);
if (!filter.errors().isEmpty()) {
throw new UnprocessableEntityException("Notification filter validation failed.");
}
User user = userDao.load(userId);
user.addNotificationFilter(filter);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
synchronized (enableUserMutex) {
userDao.saveOrUpdate(user);
}
}
});
}
use of com.thoughtworks.go.config.exceptions.UnprocessableEntityException in project gocd by gocd.
the class NotificationFilterControllerV2 method updateFilter.
public String updateFilter(Request request, Response response) throws IOException {
long id = parseIdToLong(request.params("id"));
NotificationFilter notificationFilter = buildEntityFromRequestBody(request);
notificationFilter.setId(id);
try {
userService.updateNotificationFilter(currentUserId(request), notificationFilter);
setEtagHeader(response, etagFor(notificationFilter));
} catch (UncheckedValidationException | UnprocessableEntityException e) {
response.status(HttpStatus.UNPROCESSABLE_ENTITY.value());
}
return writerForTopLevelObject(request, response, writer -> NotificationFilterRepresenter.toJSON(writer, notificationFilter));
}
Aggregations