1515 */
1616package org .commonjava .indy .db .common ;
1717
18- import org .apache .commons .lang3 .StringUtils ;
1918import org .commonjava .indy .data .ArtifactStoreQuery ;
2019import org .commonjava .indy .data .IndyDataException ;
2120import org .commonjava .indy .data .StoreDataManager ;
6261 * Created by jdcasey on 5/10/17.
6362 */
6463// TODO: Eventually, it should probably be an error if packageType isn't set explicitly
64+ @ SuppressWarnings ( "unchecked" )
6565public class DefaultArtifactStoreQuery <T extends ArtifactStore >
6666 implements ArtifactStoreQuery <T >
6767{
6868
6969 private final Logger logger = LoggerFactory .getLogger ( getClass () );
7070
71- private StoreDataManager dataManager ;
71+ private final StoreDataManager dataManager ;
7272
7373 private String packageType = MavenPackageTypeDescriptor .MAVEN_PKG_KEY ;
7474
@@ -82,6 +82,7 @@ public DefaultArtifactStoreQuery( StoreDataManager dataManager )
8282 this .dataManager = dataManager ;
8383 }
8484
85+ @ SuppressWarnings ( "unused" )
8586 private DefaultArtifactStoreQuery ( final StoreDataManager dataManager , final String packageType ,
8687 final Boolean enabled , final Class <T > storeCls )
8788 {
@@ -245,31 +246,27 @@ public T getByName( String name )
245246 @ Override
246247 @ Measure
247248 public Set <Group > getGroupsContaining ( StoreKey storeKey )
248- throws IndyDataException
249249 {
250250 return getGroupsContaining ( storeKey , Boolean .TRUE );
251251 }
252252
253253 @ Override
254254 @ Measure
255255 public Set <Group > getGroupsContaining ( StoreKey storeKey , Boolean enabled )
256- throws IndyDataException
257256 {
258257 return getAllGroups ( storeKey .getPackageType (), enabled ).stream ().filter ( g -> g .getConstituents ().contains ( storeKey ) ).collect ( Collectors .toSet () );
259258 }
260259
261260 @ Override
262261 @ Measure
263262 public List <RemoteRepository > getRemoteRepositoryByUrl ( String packageType , String url )
264- throws IndyDataException
265263 {
266264 return getRemoteRepositoryByUrl ( packageType , url , Boolean .TRUE );
267265 }
268266
269267 @ Override
270268 @ Measure
271269 public List <RemoteRepository > getRemoteRepositoryByUrl ( String packageType , String url , Boolean enabled )
272- throws IndyDataException
273270 {
274271 /*
275272 This filter does these things:
@@ -307,15 +304,12 @@ public List<RemoteRepository> getRemoteRepositoryByUrl( String packageType, Stri
307304 return false ;
308305 }
309306
310- if ( targetUrlInfo != null )
307+ if ( urlInfo .getUrlWithNoSchemeAndLastSlash ().equals ( targetUrlInfo .getUrlWithNoSchemeAndLastSlash () )
308+ && urlInfo .getProtocol ().equals ( targetUrlInfo .getProtocol () ) )
311309 {
312- if ( urlInfo .getUrlWithNoSchemeAndLastSlash ().equals ( targetUrlInfo .getUrlWithNoSchemeAndLastSlash () )
313- && urlInfo .getProtocol ().equals ( targetUrlInfo .getProtocol () ) )
314- {
315- logger .debug ( "Repository found because of same host, url is {}, store key is {}" , url ,
316- store .getKey () );
317- return true ;
318- }
310+ logger .debug ( "Repository found because of same host, url is {}, store key is {}" , url ,
311+ store .getKey () );
312+ return true ;
319313 }
320314
321315 return false ;
@@ -339,32 +333,28 @@ public List<RemoteRepository> getRemoteRepositoryByUrl( String packageType, Stri
339333 return false ;
340334 }
341335
342- if ( targetUrlInfo != null )
336+ String ipForUrl = null ;
337+ String ipForTargetUrl = null ;
338+ try
343339 {
344- String ipForUrl = null ;
345- String ipForTargetUrl = null ;
346- try
340+ ipForUrl = urlInfo .getIpForUrl ();
341+ ipForTargetUrl = targetUrlInfo .getIpForUrl ();
342+ if ( ipForUrl != null && ipForUrl .equals ( ipForTargetUrl )
343+ && urlInfo .getPort () == targetUrlInfo .getPort ()
344+ && urlInfo .getFileWithNoLastSlash ().equals ( targetUrlInfo .getFileWithNoLastSlash () ) )
347345 {
348- ipForUrl = urlInfo .getIpForUrl ();
349- ipForTargetUrl = targetUrlInfo .getIpForUrl ();
350- if ( ipForUrl != null && ipForUrl .equals ( ipForTargetUrl )
351- && urlInfo .getPort () == targetUrlInfo .getPort ()
352- && urlInfo .getFileWithNoLastSlash ().equals ( targetUrlInfo .getFileWithNoLastSlash () ) )
353- {
354- logger .debug ( "Repository found because of same ip, url is {}, store key is {}" , url ,
355- store .getKey () );
356- return true ;
357- }
358- }
359- catch ( UnknownHostException ue )
360- {
361- logger .warn ( "Failed to filter remote: {}, ip fetch error: {}." , store .getKey (), ue .getMessage () );
346+ logger .debug ( "Repository found because of same ip, url is {}, store key is {}" , url ,
347+ store .getKey () );
348+ return true ;
362349 }
363-
364- logger .debug ( "ip not same: ip for url:{}-{}; ip for searching repo: {}-{}" , url , ipForUrl ,
365- store .getKey (), ipForTargetUrl );
350+ }
351+ catch ( UnknownHostException ue )
352+ {
353+ logger .warn ( "Failed to filter remote: {}, ip fetch error: {}." , store .getKey (), ue .getMessage () );
366354 }
367355
356+ logger .debug ( "ip not same: ip for url:{}-{}; ip for searching repo: {}-{}" , url , ipForUrl ,
357+ store .getKey (), ipForTargetUrl );
368358
369359 return false ;
370360 } ).collect (Collectors .toList ());
0 commit comments