Skip to content

Commit

Permalink
DEV UI: Added final code for Filters in the Scores Page
Browse files Browse the repository at this point in the history
DEV UI : Adding Filters in Score Page

added initial filter information

adding code

adding code- not final

DEV UI: adding filters

Committing Final Code for Filters
  • Loading branch information
saumya1singh committed Feb 25, 2021
1 parent 0c3d785 commit f7f03a3
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
<a href="{urlbase}/endpoints" class="badge badge-light">
<i class="fa fa-map fa-fw"></i>
List of endpoints</a>

Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{#include main}
{#title}Quarkus REST Score Console{/title}
{#style}
collapse-list{
cursor: pointer;
}
{/style}
{#body}
{#for endpoint in info:endpointScores.endpoints}
<div class="row">
Expand Down Expand Up @@ -52,6 +57,34 @@
</div>
{/for}
{/for}
<div class="row">
<div class="col-1"></div>
<div class="col-1">
Filters
</div>
</div>
<div class="row">
<div class="col-1"></div>
<div class="col-1"></div>
<div class="col">
<span class="badge badge-light" id="collapse-list" data-toggle="collapse" data-target="#filter">
<i class="fas fa-greater-than"></i>
</span>
</div>
</div>
{#for requestFilters in endpoint.requestFilterEntries}
<div class="row">
<div class="col-1"></div>
<div class="col-1"></div>
<div class="col">
<div id="filter" class="collapse">
<ul>
<li>{requestFilters.name}</li>
</ul>
</div>
</div>
</div>
{/for}
{/for}
{/body}
{/include}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ public ResourceRequestFilterHandler(ContainerRequestFilter filter, boolean preMa
this.preMatch = preMatch;
}

public ContainerRequestFilter getFilter() {
return filter;
}

public boolean isPreMatch() {
return preMatch;
}

@Override
public void handle(ResteasyReactiveRequestContext requestContext) throws Exception {
ContainerRequestContextImpl filterContext = requestContext.getContainerRequestContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.MessageBodyWriter;
import org.jboss.resteasy.reactive.common.util.ServerMediaType;
import org.jboss.resteasy.reactive.server.handlers.ResourceRequestFilterHandler;
import org.jboss.resteasy.reactive.server.mapping.RuntimeResource;
import org.jboss.resteasy.reactive.server.spi.ServerRestHandler;

public class ScoreSystem {

Expand All @@ -33,19 +35,31 @@ public static class EndpointScore {
public final List<MediaType> consumes;
public final Map<Category, List<Diagnostic>> diagnostics;
public final int score;
public final List<RequestFilterEntry> requestFilterEntries;

public EndpointScore(String httpMethod, String fullPath, List<MediaType> produces, List<MediaType> consumes,
Map<Category, List<Diagnostic>> diagnostics, int score) {
Map<Category, List<Diagnostic>> diagnostics, int score, List<RequestFilterEntry> requestFilterEntries) {
this.httpMethod = httpMethod;
this.fullPath = fullPath;
this.produces = produces;
this.consumes = consumes;
this.diagnostics = diagnostics;
this.score = score;
this.requestFilterEntries = requestFilterEntries;
}

}

public static class RequestFilterEntry {
public final String name;
public final boolean preMatch;

public RequestFilterEntry(String name, boolean preMatch) {
this.name = name;
this.preMatch = preMatch;
}
}

public static class Diagnostic {

public final String message;
Expand Down Expand Up @@ -107,6 +121,16 @@ public void visitRuntimeResource(String httpMethod, String fullPath, RuntimeReso
produces = Arrays.asList(serverMediaType.getSortedOriginalMediaTypes());
}
}

ServerRestHandler[] handlerChain = runtimeResource.getHandlerChain();
List<RequestFilterEntry> requestFilters = new ArrayList<>();
for (ServerRestHandler serverRestHandler : handlerChain) {
if (serverRestHandler instanceof ResourceRequestFilterHandler) {
ResourceRequestFilterHandler requestFilterHandler = (ResourceRequestFilterHandler) serverRestHandler;
requestFilters.add(new RequestFilterEntry(requestFilterHandler.getFilter().getClass().getName(),
requestFilterHandler.isPreMatch()));
}
}
List<MediaType> consumes = runtimeResource.getConsumes();
if (runtimeResource.getScore() == null) {
return;
Expand All @@ -123,7 +147,8 @@ public void visitRuntimeResource(String httpMethod, String fullPath, RuntimeReso
score = (int) Math.floor(((float) score / (float) total) * 100f);
overallScore += score;
overallTotal += 100;
endpoints.add(new EndpointScore(httpMethod, fullPath, produces, consumes, runtimeResource.getScore(), score));
endpoints.add(new EndpointScore(httpMethod, fullPath, produces, consumes, runtimeResource.getScore(), score,
requestFilters));
}

@Override
Expand Down

0 comments on commit f7f03a3

Please sign in to comment.