Skip to content

Commit

Permalink
spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan-Thurner committed Aug 16, 2024
1 parent f1a4000 commit ad4f2e4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static void analyzeEndpoints() {
if (matchingRestCalls.isEmpty() && endpointURI.endsWith("*")) {
for (String uri : restCallMap.keySet()) {
if (uri.startsWith(endpoint.buildComparableEndpointUri().substring(0, endpoint.buildComparableEndpointUri().length() - 1))
&& endpoint.getHttpMethod().toLowerCase().equals(restCallMap.get(uri).get(0).getMethod().toLowerCase())) {
&& endpoint.getHttpMethod().toLowerCase().equals(restCallMap.get(uri).get(0).getMethod().toLowerCase())) {
matchingRestCalls.addAll(restCallMap.get(uri));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -33,60 +32,62 @@ public static void main(String[] args) {
* the analysis result to a JSON file. REST calls without matching endpoints
* are also recorded.
*/
private static void analyzeRestCalls() {
ObjectMapper mapper = new ObjectMapper();

try {
List<EndpointClassInformation> endpointClasses = mapper.readValue(new File(EndpointParser.ENDPOINT_PARSING_RESULT_PATH),
new TypeReference<List<EndpointClassInformation>>() {
});
List<RestCallFileInformation> restCalls = mapper.readValue(new File(EndpointParser.REST_CALL_PARSING_RESULT_PATH), new TypeReference<List<RestCallFileInformation>>() {
});
private static void analyzeRestCalls() {
ObjectMapper mapper = new ObjectMapper();

try {
List<EndpointClassInformation> endpointClasses = mapper.readValue(new File(EndpointParser.ENDPOINT_PARSING_RESULT_PATH),
new TypeReference<List<EndpointClassInformation>>() {
});
List<RestCallFileInformation> restCalls = mapper.readValue(new File(EndpointParser.REST_CALL_PARSING_RESULT_PATH), new TypeReference<List<RestCallFileInformation>>() {
});

List<RestCallWithMatchingEndpoint> restCallsWithMatchingEndpoint = new ArrayList<>();
List<RestCallInformation> restCallsWithoutMatchingEndpoint = new ArrayList<>();
List<RestCallWithMatchingEndpoint> restCallsWithMatchingEndpoint = new ArrayList<>();
List<RestCallInformation> restCallsWithoutMatchingEndpoint = new ArrayList<>();

Map<String, List<EndpointInformation>> endpointMap = new HashMap<>();
Map<String, List<EndpointInformation>> endpointMap = new HashMap<>();

// Populate the map with endpoints
for (EndpointClassInformation endpointClass : endpointClasses) {
for (EndpointInformation endpoint : endpointClass.endpoints()) {
String endpointURI = endpoint.buildComparableEndpointUri();
endpointMap.computeIfAbsent(endpointURI, k -> new ArrayList<>()).add(endpoint);
// Populate the map with endpoints
for (EndpointClassInformation endpointClass : endpointClasses) {
for (EndpointInformation endpoint : endpointClass.endpoints()) {
String endpointURI = endpoint.buildComparableEndpointUri();
endpointMap.computeIfAbsent(endpointURI, k -> new ArrayList<>()).add(endpoint);
}
}
}

for (RestCallFileInformation restCallFile : restCalls) {
for (RestCallInformation restCall : restCallFile.restCalls()) {
String restCallURI = restCall.buildComparableRestCallUri();
List<EndpointInformation> matchingEndpoints = endpointMap.getOrDefault(restCallURI, new ArrayList<>());

// Check for wildcard matches if no exact match is found
if (matchingEndpoints.isEmpty() && restCallURI.endsWith("*")) {
for (String uri : endpointMap.keySet()) {
if (uri.startsWith(restCallURI.substring(0, restCallURI.length() - 1))
&& endpointMap.get(uri).get(0).getHttpMethod().toLowerCase().equals(restCall.getMethod().toLowerCase())) {
matchingEndpoints.addAll(endpointMap.get(uri));
for (RestCallFileInformation restCallFile : restCalls) {
for (RestCallInformation restCall : restCallFile.restCalls()) {
String restCallURI = restCall.buildComparableRestCallUri();
List<EndpointInformation> matchingEndpoints = endpointMap.getOrDefault(restCallURI, new ArrayList<>());

// Check for wildcard matches if no exact match is found
if (matchingEndpoints.isEmpty() && restCallURI.endsWith("*")) {
for (String uri : endpointMap.keySet()) {
if (uri.startsWith(restCallURI.substring(0, restCallURI.length() - 1))
&& endpointMap.get(uri).get(0).getHttpMethod().toLowerCase().equals(restCall.getMethod().toLowerCase())) {
matchingEndpoints.addAll(endpointMap.get(uri));
}
}
}
}

if (matchingEndpoints.isEmpty()) {
restCallsWithoutMatchingEndpoint.add(restCall);
} else {
for (EndpointInformation endpoint : matchingEndpoints) {
restCallsWithMatchingEndpoint.add(new RestCallWithMatchingEndpoint(endpoint, restCall, restCall.getFileName()));
if (matchingEndpoints.isEmpty()) {
restCallsWithoutMatchingEndpoint.add(restCall);
}
else {
for (EndpointInformation endpoint : matchingEndpoints) {
restCallsWithMatchingEndpoint.add(new RestCallWithMatchingEndpoint(endpoint, restCall, restCall.getFileName()));
}
}
}
}
}

RestCallAnalysis restCallAnalysis = new RestCallAnalysis(restCallsWithMatchingEndpoint, restCallsWithoutMatchingEndpoint);
mapper.writeValue(new File(REST_CALL_ANALYSIS_RESULT_PATH), restCallAnalysis);
} catch (IOException e) {
logger.error("Failed to analyze REST calls", e);
RestCallAnalysis restCallAnalysis = new RestCallAnalysis(restCallsWithMatchingEndpoint, restCallsWithoutMatchingEndpoint);
mapper.writeValue(new File(REST_CALL_ANALYSIS_RESULT_PATH), restCallAnalysis);
}
catch (IOException e) {
logger.error("Failed to analyze REST calls", e);
}
}
}

/**
* Prints the endpoint analysis result.
Expand Down

0 comments on commit ad4f2e4

Please sign in to comment.