1 package org.apache.archiva.repository.validation;
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
20 import org.apache.archiva.repository.CheckedResult;
21 import org.apache.archiva.repository.Repository;
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.HashMap;
26 import java.util.List;
28 import java.util.function.Function;
31 * A validation response gives information about the validation status for certain attributes.
34 * @author Martin Stockhammer <martin_s@apache.org>
36 public class ValidationResponse<R extends Repository> implements CheckedResult<R, Map<String, List<ValidationError>>>
40 final Map<String, List<ValidationError>> validationErrors = new HashMap<>( );
43 public ValidationResponse( R repo, Map<String, List<ValidationError>> errors)
45 if( errors==null || errors.size()==0 ) {
49 validationErrors.putAll( errors );
51 this.repository = repo;
54 public static <S extends Repository> ValidationResponse<S> getValid( S repository )
56 return new ValidationResponse<>( repository, null );
60 public R getRepository( )
66 * Returns true, if the validation was successful and there are not validation errors.
67 * @return <code>true</code>, if the validation was successful, otherwise <code>false</code>
70 public boolean isValid( )
76 public Map<String, List<ValidationError>> getResult( )
78 return validationErrors;
83 * Add the given validation error to the list for the given attribute.
85 * @param attribute the name of the attribute
86 * @param error the error that is added to the list
88 public void addValidationError(String attribute, ValidationError error) {
89 if (!validationErrors.containsKey( attribute )) {
90 validationErrors.put( attribute, new ArrayList<>( ) );
92 validationErrors.get( attribute ).add( error );
96 * Returns a list of validation errors that are stored for the given attribute. If there are no
97 * errors stored for this attribute, a empty list is returned.
99 * @param attribute the name of the attribute
100 * @return the list of validation errors
102 public List<ValidationError> getValidationErrors(String attribute) {
103 if (validationErrors.containsKey( attribute )) {
104 return validationErrors.get( attribute );
106 return Collections.emptyList( );