Skip to content

Commit

Permalink
Merge pull request #1952 from ruhan1/2.6.x-pathmapadmin
Browse files Browse the repository at this point in the history
Fix api/admin/pathmap/content NPE when target repo is gone
  • Loading branch information
ruhan1 authored Jul 13, 2021
2 parents 2baecef + 36262ab commit 640ab80
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/
package org.commonjava.indy.pathmapped.common;

import org.commonjava.indy.data.StoreDataManager;
import org.commonjava.indy.model.core.ArtifactStore;
import org.commonjava.indy.model.core.StoreKey;
import org.commonjava.indy.model.core.StoreType;
import org.commonjava.indy.model.galley.KeyedLocation;
import org.commonjava.indy.pathmapped.model.PathMappedDeleteResult;
import org.commonjava.indy.pathmapped.model.PathMappedListResult;
import org.commonjava.indy.util.LocationUtils;
import org.commonjava.maven.galley.cache.pathmapped.PathMappedCacheProvider;
import org.commonjava.maven.galley.model.ConcreteResource;
import org.commonjava.maven.galley.model.Location;
import org.commonjava.maven.galley.model.SimpleLocation;
import org.commonjava.maven.galley.spi.cache.CacheProvider;
import org.commonjava.storage.pathmapped.core.PathMappedFileManager;
import org.commonjava.storage.pathmapped.spi.PathDB;
Expand All @@ -41,9 +41,6 @@ public class PathMappedController
@Inject
private CacheProvider cacheProvider;

@Inject
private StoreDataManager storeDataManager;

private PathMappedCacheProvider pathMappedCacheProvider;

private PathMappedFileManager fileManager;
Expand Down Expand Up @@ -107,8 +104,27 @@ private ConcreteResource getConcreteResource( String packageType, String type, S
throws Exception
{
StoreKey storeKey = new StoreKey( packageType, StoreType.get( type ), name );
ArtifactStore store = storeDataManager.getArtifactStore( storeKey );
return new ConcreteResource( LocationUtils.toLocation( store ), path );
// we just need a simple keyed location which provides the name to underlying pathMappedCacheProvider
Location location = new SimpleKeyedLocation( storeKey );
return new ConcreteResource( location, path );
}

private static class SimpleKeyedLocation
extends SimpleLocation
implements KeyedLocation
{
private final StoreKey storeKey;

public SimpleKeyedLocation( StoreKey storeKey )
{
super( storeKey.toString() );
this.storeKey = storeKey;
}

@Override
public StoreKey getKey()
{
return storeKey;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ public Response get( final @PathParam( "packageType" ) String packageType,
}
catch ( Exception e )
{
logger.warn( e.getMessage(), e );
if ( e.getMessage().contains( "not exist" ) )
logger.warn( "Get pathmap content failed, message: " + e.getMessage(), e );
if ( e.getMessage() != null && e.getMessage().contains( "not exist" ) )
{
return Response.status( Response.Status.NOT_FOUND ).build();
}
Expand Down

0 comments on commit 640ab80

Please sign in to comment.