You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CombinedValidator.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package org.apache.archiva.repository.validation;
  2. /*
  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
  10. *
  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
  17. * under the License.
  18. */
  19. import org.apache.archiva.repository.Repository;
  20. import org.apache.archiva.repository.RepositoryRegistry;
  21. import java.util.List;
  22. import java.util.Map;
  23. /**
  24. * A combined validator cumulates the validation results of multiple validators
  25. *
  26. * @author Martin Stockhammer <martin_s@apache.org>
  27. */
  28. public class CombinedValidator<R extends Repository>
  29. implements RepositoryValidator<R> {
  30. private final List<RepositoryValidator<R>> validatorList;
  31. private final Class<R> flavourClazz;
  32. public CombinedValidator( Class<R> flavourClazz, List<RepositoryValidator<R>> validatorList )
  33. {
  34. if (flavourClazz==null) {
  35. throw new IllegalArgumentException( "The flavour class may not be null" );
  36. }
  37. this.flavourClazz = flavourClazz;
  38. if (validatorList==null) {
  39. throw new IllegalArgumentException( "The validator list may not be null" );
  40. }
  41. this.validatorList = validatorList;
  42. }
  43. @Override
  44. public CheckedResult<R, Map<String, List<ValidationError>>> apply( R r )
  45. {
  46. CombinedValidationResponse<R> response = new CombinedValidationResponse<>( r );
  47. validatorList.stream( ).forEach(
  48. v -> response.addResult( v.apply( r ) )
  49. );
  50. return response;
  51. }
  52. @Override
  53. public CheckedResult<R, Map<String, List<ValidationError>>> applyForUpdate( R repo )
  54. {
  55. CombinedValidationResponse<R> response = new CombinedValidationResponse<>( repo );
  56. validatorList.stream( ).forEach(
  57. v -> response.addResult( v.applyForUpdate( repo ) )
  58. );
  59. return response;
  60. }
  61. @Override
  62. public void setRepositoryRegistry( RepositoryRegistry repositoryRegistry )
  63. {
  64. // Not used
  65. }
  66. @Override
  67. public Class<R> getFlavour( )
  68. {
  69. return flavourClazz;
  70. }
  71. @Override
  72. public boolean isFlavour( Class<?> clazz )
  73. {
  74. return flavourClazz.isAssignableFrom( clazz );
  75. }
  76. }