Search in sources :

Example 1 with UnprocessableEntityException

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());
    }
}
Also used : UnprocessableEntityException(com.thoughtworks.go.config.exceptions.UnprocessableEntityException) ResourceConfigs(com.thoughtworks.go.config.ResourceConfigs)

Example 2 with UnprocessableEntityException

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));
    }
}
Also used : UnprocessableEntityException(com.thoughtworks.go.config.exceptions.UnprocessableEntityException) JsonReader(com.thoughtworks.go.api.representers.JsonReader)

Example 3 with UnprocessableEntityException

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)));
    }
}
Also used : UnprocessableEntityException(com.thoughtworks.go.config.exceptions.UnprocessableEntityException) JsonReader(com.thoughtworks.go.api.representers.JsonReader)

Example 4 with UnprocessableEntityException

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);
            }
        }
    });
}
Also used : UnprocessableEntityException(com.thoughtworks.go.config.exceptions.UnprocessableEntityException) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 5 with UnprocessableEntityException

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));
}
Also used : UnprocessableEntityException(com.thoughtworks.go.config.exceptions.UnprocessableEntityException) UncheckedValidationException(com.thoughtworks.go.domain.exception.UncheckedValidationException) NotificationFilter(com.thoughtworks.go.domain.NotificationFilter)

Aggregations

UnprocessableEntityException (com.thoughtworks.go.config.exceptions.UnprocessableEntityException)18 JsonReader (com.thoughtworks.go.api.representers.JsonReader)11 OutputListWriter (com.thoughtworks.go.api.base.OutputListWriter)3 OutputWriter (com.thoughtworks.go.api.base.OutputWriter)3 ErrorGetter (com.thoughtworks.go.api.representers.ErrorGetter)3 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)3 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)3 PluggableSCMMaterialConfig (com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig)3 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)3 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)3 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)3 P4MaterialConfig (com.thoughtworks.go.config.materials.perforce.P4MaterialConfig)3 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)3 TfsMaterialConfig (com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig)3 NotificationFilter (com.thoughtworks.go.domain.NotificationFilter)3 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)3 Arrays.stream (java.util.Arrays.stream)3 HashMap (java.util.HashMap)3 StringUtils.equalsIgnoreCase (org.apache.commons.lang3.StringUtils.equalsIgnoreCase)3 TransactionStatus (org.springframework.transaction.TransactionStatus)2