Skip to content

Commit

Permalink
NCL6600 Code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
rnc committed Jun 17, 2021
1 parent 6a0fc31 commit 2369f57
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ public class DefaultTranslator
{
};

public enum ENDPOINT {
public enum Endpoint
{
LOOKUP_GAVS ("lookup/maven"),
LOOkUP_LATEST ("lookup/maven/latest");

@Getter
private final String endpoint;

ENDPOINT( String s )
Endpoint( String s )
{
this.endpoint = s;
}
Expand Down Expand Up @@ -165,7 +166,7 @@ public DefaultTranslator( String endpointUrl, int restMaxSize, int restMinSize,
@Override
public Map<ProjectVersionRef, String> lookupVersions( List<ProjectVersionRef> p ) throws RestException
{
return internalLookup( ENDPOINT.LOOKUP_GAVS, p );
return internalLookup( Endpoint.LOOKUP_GAVS, p );
}

/**
Expand All @@ -180,10 +181,10 @@ public Map<ProjectVersionRef, String> lookupVersions( List<ProjectVersionRef> p
@Override
public Map<ProjectVersionRef, String> lookupProjectVersions( List<ProjectVersionRef> p ) throws RestException
{
return internalLookup( ENDPOINT.LOOkUP_LATEST, p );
return internalLookup( Endpoint.LOOkUP_LATEST, p );
}

private void partition( ENDPOINT endpointType, List<ProjectVersionRef> projects, Queue<Task> queue ) {
private void partition( Endpoint endpointType, List<ProjectVersionRef> projects, Queue<Task> queue ) {
if ( initialRestMaxSize != 0 )
{
if (initialRestMaxSize == -1)
Expand All @@ -201,13 +202,13 @@ private void partition( ENDPOINT endpointType, List<ProjectVersionRef> projects,
}
}

private void noOpPartition( ENDPOINT endpointType, List<ProjectVersionRef> projects, Queue<Task> queue ) {
private void noOpPartition( Endpoint endpointType, List<ProjectVersionRef> projects, Queue<Task> queue ) {
logger.info("Using NO-OP partition strategy");

queue.add(new Task( projects, endpointUrl, endpointType ));
}

private void userDefinedPartition( ENDPOINT endpointType, List<ProjectVersionRef> projects, Queue<Task> queue ) {
private void userDefinedPartition( Endpoint endpointType, List<ProjectVersionRef> projects, Queue<Task> queue ) {
logger.info("Using user defined partition strategy");

// Presplit
Expand All @@ -221,7 +222,7 @@ private void userDefinedPartition( ENDPOINT endpointType, List<ProjectVersionRef
logger.debug( "For initial sizing of {} have split the queue into {} ", initialRestMaxSize , queue.size() );
}

private void autoPartition( ENDPOINT endpointType, List<ProjectVersionRef> projects, Queue<Task> queue ) {
private void autoPartition( Endpoint endpointType, List<ProjectVersionRef> projects, Queue<Task> queue ) {
List<List<ProjectVersionRef>> partition;

if (projects.size() < 600)
Expand All @@ -248,7 +249,7 @@ private void autoPartition( ENDPOINT endpointType, List<ProjectVersionRef> proje
}
}

private Map<ProjectVersionRef, String> internalLookup( ENDPOINT endpointType, List<ProjectVersionRef> p ) throws RestException
private Map<ProjectVersionRef, String> internalLookup( Endpoint endpointType, List<ProjectVersionRef> p ) throws RestException
{
final List<ProjectVersionRef> projects = p.stream().distinct().collect( Collectors.toList() );
if ( p.size() != projects.size() )
Expand Down Expand Up @@ -343,7 +344,7 @@ private class Task

private final String endpointUrl;

private final ENDPOINT endpointType;
private final Endpoint endpointType;

private Map<ProjectVersionRef, String> result = Collections.emptyMap();

Expand All @@ -355,7 +356,7 @@ private class Task



Task( List<ProjectVersionRef> chunk, String endpointUrl, ENDPOINT endpointType )
Task( List<ProjectVersionRef> chunk, String endpointUrl, Endpoint endpointType )
{
this.chunk = chunk;
this.endpointUrl = endpointUrl;
Expand All @@ -368,7 +369,7 @@ void executeTranslate()

try
{
final boolean lookup = (endpointType == ENDPOINT.LOOKUP_GAVS);
final boolean lookup = (endpointType == Endpoint.LOOKUP_GAVS);
Object request = lookup ?
( MavenLookupRequest
.builder()
Expand Down Expand Up @@ -455,7 +456,7 @@ else if (originalBody.startsWith( "javax.validation.ValidationException: " )) {
}
}

public List<Task> split( ENDPOINT endpointType )
public List<Task> split( Endpoint endpointType )
{
List<Task> res = new ArrayList<>( CHUNK_SPLIT_COUNT );
if ( chunk.size() >= CHUNK_SPLIT_COUNT )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface Translator
/**
* Executes HTTP request to a REST service that translates versions
*
* @param projects - List of projects (GAVs)
* @param projects List of projects (GAVs)
* @return Map of ProjectVersionRef objects as keys and translated versions as values
* @throws RestException if an error occurs.
*/
Expand All @@ -47,7 +47,7 @@ public interface Translator
* for this version, the DependencyAnalyser will ignore suffix priority and return the latest version for the
* configured suffix mode. This is typically used for project version lookups.
*
* @param projects - List of projects (GAVs)
* @param projects List of projects (GAVs)
* @return Map of ProjectVersionRef objects as keys and translated versions as values
* @throws RestException if an error occurs.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Setter;
import org.commonjava.maven.ext.common.util.JSONUtils;
import org.commonjava.maven.ext.io.rest.DefaultTranslator;
import org.commonjava.maven.ext.io.rest.DefaultTranslator.Endpoint;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
Expand Down Expand Up @@ -72,7 +72,7 @@ public class AddSuffixJettyHandler

public AddSuffixJettyHandler()
{
this( "/" + DefaultTranslator.ENDPOINT.LOOKUP_GAVS.getEndpoint(), DEFAULT_SUFFIX );
this( Endpoint.LOOKUP_GAVS.getEndpoint(), DEFAULT_SUFFIX );
}

public AddSuffixJettyHandler( String endpoint, String suffix )
Expand Down Expand Up @@ -226,7 +226,7 @@ else if ( gav.getVersion().equals("2.7.2_3-fuse") )
}
logger.info( "For GA {}, requesting version {} and got bestMatch {}", gav, version, bestMatchVersion);

if (request.getPathInfo().contains( DefaultTranslator.ENDPOINT.LOOkUP_LATEST.getEndpoint() ) )
if (request.getPathInfo().contains( Endpoint.LOOkUP_LATEST.getEndpoint() ) )
{
lr = new MavenLatestResult( gav, !returnNullBestMatch ? bestMatchVersion : null );
}
Expand Down

0 comments on commit 2369f57

Please sign in to comment.