001package org.apache.archiva.repository.base; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022 023import org.apache.archiva.repository.EditableRemoteRepository; 024import org.apache.archiva.repository.RemoteRepositoryContent; 025import org.apache.archiva.repository.RepositoryCredentials; 026import org.apache.archiva.repository.RepositoryType; 027import org.apache.archiva.repository.storage.RepositoryStorage; 028import org.apache.archiva.repository.storage.StorageAsset; 029 030import java.net.URI; 031import java.time.Duration; 032import java.util.Collections; 033import java.util.HashMap; 034import java.util.Locale; 035import java.util.Map; 036 037/** 038 * Abstract implementation of a remote repository. Abstract classes must implement the 039 * features and capabilities by themselves. 040 */ 041public abstract class AbstractRemoteRepository extends AbstractRepository implements EditableRemoteRepository 042{ 043 044 private RepositoryCredentials credentials; 045 private String checkPath; 046 private Map<String,String> extraParameters = new HashMap<>( ); 047 private Map<String,String> uExtraParameters = Collections.unmodifiableMap( extraParameters ); 048 private Map<String,String> extraHeaders = new HashMap<>( ); 049 private Map<String,String> uExtraHeaders = Collections.unmodifiableMap( extraHeaders ); 050 private Duration timeout = Duration.ofSeconds( 60 ); 051 private String proxyId; 052 private RemoteRepositoryContent content; 053 054 public AbstractRemoteRepository( RepositoryType type, String id, String name , RepositoryStorage storage) 055 { 056 super( type, id, name, storage ); 057 } 058 059 public AbstractRemoteRepository( Locale primaryLocale, RepositoryType type, String id, String name, RepositoryStorage storage ) 060 { 061 super( primaryLocale, type, id, name, storage ); 062 } 063 064 @Override 065 public void setCredentials( RepositoryCredentials credentials ) 066 { 067 this.credentials = credentials; 068 } 069 070 @Override 071 public void setCheckPath( String path ) 072 { 073 this.checkPath = path; 074 } 075 076 @Override 077 public void setExtraParameters( Map<String, String> params ) 078 { 079 this.extraParameters.clear(); 080 this.extraParameters.putAll(params); 081 } 082 083 @Override 084 public void addExtraParameter( String key, String value ) 085 { 086 this.extraParameters.put(key, value); 087 } 088 089 @Override 090 public void setExtraHeaders( Map<String, String> headers ) 091 { 092 this.extraHeaders.clear(); 093 this.extraHeaders.putAll(headers); 094 } 095 096 @Override 097 public void addExtraHeader( String header, String value ) 098 { 099 this.extraHeaders.put(header, value); 100 } 101 102 @Override 103 public void setTimeout( Duration duration ) 104 { 105 this.timeout = duration; 106 } 107 108 @Override 109 public RemoteRepositoryContent getContent( ) 110 { 111 return content; 112 } 113 114 @Override 115 public void setContent(RemoteRepositoryContent content) { 116 this.content = content; 117 } 118 119 @Override 120 public RepositoryCredentials getLoginCredentials( ) 121 { 122 return credentials; 123 } 124 125 @Override 126 public String getCheckPath( ) 127 { 128 return checkPath; 129 } 130 131 @Override 132 public Map<String, String> getExtraParameters( ) 133 { 134 return uExtraParameters; 135 } 136 137 @Override 138 public Map<String, String> getExtraHeaders( ) 139 { 140 return uExtraHeaders; 141 } 142 143 @Override 144 public Duration getTimeout( ) 145 { 146 return timeout; 147 } 148 149 /** 150 * Remote repositories resolve always relative to the base directory. 151 * @return 152 */ 153 @Override 154 public StorageAsset getLocalPath() { 155 return getStorage().getAsset(""); 156 } 157 158 @Override 159 public String toString() { 160 StringBuilder str = new StringBuilder(); 161 return str.append("checkPath=").append(checkPath) 162 .append(",creds:").append(credentials).toString(); 163 } 164 165 @Override 166 public void setLocation(URI location) { 167 // Location of remote repositories is not for the local filestore 168 super.location = location; 169 } 170}