1package org.apache.archiva.policies;
23/*4 * Licensed to the Apache Software Foundation (ASF) under one5 * or more contributor license agreements. See the NOTICE file6 * distributed with this work for additional information7 * regarding copyright ownership. The ASF licenses this file8 * to you under the Apache License, Version 2.0 (the9 * "License"); you may not use this file except in compliance10 * with the License. You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 *14 * Unless required by applicable law or agreed to in writing,15 * software distributed under the License is distributed on an16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY17 * KIND, either express or implied. See the License for the18 * specific language governing permissions and limitations19 * under the License.20 */2122import org.apache.archiva.repository.storage.StorageAsset;
23import org.apache.commons.lang3.StringUtils;
24import org.slf4j.Logger;
25import org.slf4j.LoggerFactory;
26import org.springframework.stereotype.Service;
2728import java.util.ArrayList;
29import java.util.List;
30import java.util.Map;
31import java.util.Properties;
3233/**34 * PropagateErrorsPolicy - a policy applied on error to determine how to treat the error.35 */36 @Service( "downloadErrorPolicy#propagate-errors" )
37publicclassPropagateErrorsDownloadPolicy38extendsAbstractPolicyimplementsDownloadErrorPolicy39 {
40private Logger log = LoggerFactory.getLogger( PropagateErrorsDownloadPolicy.class );
41privatestaticfinal String ID = "propagate-errors";
424344/**45 * Signifies any error should stop searching for other proxies.46 */47publicstaticfinalDownloadErrorOption STOP = DownloadErrorOption.STOP;
4849/**50 * Propagate errors at the end after all are gathered, if there was no successful download from other proxies.51 */52publicstaticfinalDownloadErrorOption QUEUE = DownloadErrorOption.QUEUE;
5354/**55 * Ignore errors and treat as if it were not found.56 */57publicstaticfinalDownloadErrorOption IGNORE = DownloadErrorOption.IGNORE;
5859private List<PolicyOption> options = new ArrayList<>( 3 );
6061publicPropagateErrorsDownloadPolicy()
62 {
63 options.add( STOP );
64 options.add( QUEUE );
65 options.add( IGNORE );
66 }
6768 @Override
69publicboolean applyPolicy( PolicyOption policySetting, Properties request, StorageAsset localFile, Exception exception,
70 Map<String, Exception> previousExceptions )
71throwsPolicyConfigurationException72 {
73if ( !options.contains( policySetting ) )
74 {
75// Not a valid code.76thrownewPolicyConfigurationException( "Unknown error policy setting [" + policySetting +
77"], valid settings are [" + StringUtils.join(
78 options.iterator(), "," ) + "]" );
79 }
8081if ( IGNORE.equals( policySetting ) )
82 {
83// Ignore.84 log.debug( "Error policy set to IGNORE." );
85return false;
86 }
8788 String repositoryId = request.getProperty( "remoteRepositoryId" );
89if ( STOP.equals( policySetting ) )
90 {
91returntrue;
92 }
9394if ( QUEUE.equals( policySetting ) )
95 {
96 previousExceptions.put( repositoryId, exception );
97returntrue;
98 }
99100thrownewPolicyConfigurationException(
101"Unable to process checksum policy of [" + policySetting + "], please file a bug report." );
102 }
103104 @Override
105publicPolicyOption getDefaultOption()
106 {
107return QUEUE;
108 }
109110 @Override
111public String getId()
112 {
113return ID ;
114 }
115116 @Override
117public List<PolicyOption> getOptions()
118 {
119return options;
120 }
121 }