1 package org.apache.archiva.rest.api.model.v2;
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
21 import io.swagger.v3.oas.annotations.media.Schema;
23 import javax.xml.bind.annotation.XmlRootElement;
24 import java.io.Serializable;
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.stream.Collectors;
30 * @author Martin Stockhammer <martin_s@apache.org>
32 @XmlRootElement(name = "validationError")
33 @Schema(name = "ValidationError", description = "A validation error.")
34 public class ValidationError implements Serializable
36 private static final long serialVersionUID = 2079020598090660171L;
42 List<String> parameter;
45 public ValidationError( )
49 public ValidationError( String key, String field, String category, String type, List<String> parameter) {
52 this.category = category;
54 if (parameter==null) {
55 this.parameter = new ArrayList<>( );
58 this.parameter = parameter;
63 * Creates a new instance based on the given error
64 * @param error the error instance
67 public static ValidationError of( org.apache.archiva.repository.validation.ValidationError error ) {
68 return error != null ? new ValidationError( error.getErrorKey( ), error.getAttribute( ), error.getCategory( ),
69 error.getType( ), error.getArguments( ).stream( ).map( Object::toString ).collect( Collectors.toList( ) ) )
70 : new ValidationError( );
74 * Creates a new instance based on the field name and the error instance
75 * @param fieldName the name of the field to which the error applies
76 * @param error the error definition
77 * @return a new validation error instance
79 public static ValidationError of( String fieldName, org.apache.archiva.repository.validation.ValidationError error ) {
80 return error != null ? new ValidationError( error.getErrorKey( ), fieldName, error.getCategory( ),
81 error.getType( ), error.getArguments( ).stream( ).map( Object::toString ).collect( Collectors.toList( ) ) )
82 : new ValidationError( );
85 @Schema(name="key", description = "The full key of the validation error")
86 public String getKey( )
91 public void setKey( String key )
96 @Schema(name="field", description = "The name of the field where the error was detected")
97 public String getField( )
102 public void setField( String field )
107 @Schema(name="category", description = "The name of the category this error is assigned to")
108 public String getCategory( )
113 public void setCategory( String category )
115 this.category = category;
118 @Schema(name="type", description = "The type of the error. This is a unique string that defines the type of error, e.g. empty, bad_number_range, ... .")
119 public String getType( )
124 public void setType( String type )
129 @Schema(name="parameter", description = "The list of parameters, that can be used to create a translated error message")
130 public List<String> getParameter( )
135 public void setParameter( List<String> parameter )
137 this.parameter = parameter;