From 63e80e105edfcd96366fe55c04aab6a61b2c37f6 Mon Sep 17 00:00:00 2001 From: Larry Diamond <1066589+larrydiamond@users.noreply.github.com> Date: Sat, 23 Sep 2023 22:12:17 -0400 Subject: [PATCH 1/3] Querying applications --- .../sqgraph/ApiProjectsSearchResults.java | 31 +++++++++++++++++++ .../java/com/ldiamond/sqgraph/Config.java | 3 ++ .../com/ldiamond/sqgraph/DashboardOutput.java | 4 +-- .../ldiamond/sqgraph/SqgraphApplication.java | 21 ++++++++++++- 4 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/ldiamond/sqgraph/ApiProjectsSearchResults.java diff --git a/src/main/java/com/ldiamond/sqgraph/ApiProjectsSearchResults.java b/src/main/java/com/ldiamond/sqgraph/ApiProjectsSearchResults.java new file mode 100644 index 0000000..e69c7f4 --- /dev/null +++ b/src/main/java/com/ldiamond/sqgraph/ApiProjectsSearchResults.java @@ -0,0 +1,31 @@ +/** + * Copyright (C) 2023-present Larry Diamond, All Rights Reserved. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * license linked below for more details. + * + * For license terms, see . + **/ +package com.ldiamond.sqgraph; + +import lombok.Data; + +@Data +public class ApiProjectsSearchResults { + ApiProjectsSearchResultsComponents [] components; +} + +@Data +class ApiProjectsSearchResultsComponents { + String key; + String name; + + public Application getApplication () { + Application application = new Application(); + application.setKey (key); + application.setTitle (name); + return application; + } +} \ No newline at end of file diff --git a/src/main/java/com/ldiamond/sqgraph/Config.java b/src/main/java/com/ldiamond/sqgraph/Config.java index ec5413b..f6650eb 100644 --- a/src/main/java/com/ldiamond/sqgraph/Config.java +++ b/src/main/java/com/ldiamond/sqgraph/Config.java @@ -11,6 +11,7 @@ package com.ldiamond.sqgraph; import java.io.Serializable; +import java.util.List; import lombok.Data; @@ -23,6 +24,7 @@ public class Config implements Serializable { int maxReportHistory; String pdf; String dashboard; + List expandedApplications; } @Data @@ -41,4 +43,5 @@ class Application implements Serializable { private static final long serialVersionUID = 2422222041950251807L; String key; String title; + String query; } diff --git a/src/main/java/com/ldiamond/sqgraph/DashboardOutput.java b/src/main/java/com/ldiamond/sqgraph/DashboardOutput.java index 0d0c4e8..042edfc 100644 --- a/src/main/java/com/ldiamond/sqgraph/DashboardOutput.java +++ b/src/main/java/com/ldiamond/sqgraph/DashboardOutput.java @@ -46,10 +46,10 @@ public static BufferedImage outputDashboard (HashBasedTable rowMap = dashboardData.column(app.getTitle()); String [] dRow = new String [1 + dashboardData.rowKeySet().size()]; dRow [0] = " " + app.getTitle(); diff --git a/src/main/java/com/ldiamond/sqgraph/SqgraphApplication.java b/src/main/java/com/ldiamond/sqgraph/SqgraphApplication.java index dd806ad..4ffc383 100644 --- a/src/main/java/com/ldiamond/sqgraph/SqgraphApplication.java +++ b/src/main/java/com/ldiamond/sqgraph/SqgraphApplication.java @@ -105,11 +105,30 @@ public CommandLineRunner commandLineRunner(ApplicationContext ctx) { return null; } + // Copy the config applications to the expanded applications and perform any searches + config.setExpandedApplications(new ArrayList<>()); + for (Application app : config.getApplications()) { + if (app.getKey() != null) { + config.getExpandedApplications().add(app); + } else { + if (app.getQuery() != null) { + final String uri = config.getUrl() + "/api/project/search?qualifiers=TRK&q=" + app.getQuery(); + ResponseEntity response = restTemplate.exchange(uri, HttpMethod.GET, new HttpEntity(headers), ApiProjectsSearchResults.class); + ApiProjectsSearchResults result = response.getBody(); + if ((result != null) && (result.getComponents() != null)) { + for (ApiProjectsSearchResultsComponents c : result.getComponents()) { + config.getExpandedApplications().add(c.getApplication()); + } + } + } + } + } + Map titleLookup = new HashMap<>(); final SimpleDateFormat sdfsq = new SimpleDateFormat("yyyy-MM-dd"); Map rawMetrics = new HashMap<>(); - for (Application app : config.getApplications()) { + for (Application app : config.getExpandedApplications()) { String key = app.getKey(); titleLookup.put(key, app.getTitle()); try { From d71d0132d2fed568b8ca13ddd1481509370f9e3d Mon Sep 17 00:00:00 2001 From: Larry Diamond <1066589+larrydiamond@users.noreply.github.com> Date: Thu, 28 Sep 2023 23:10:38 -0400 Subject: [PATCH 2/3] fixing defect of empty history results --- .../ldiamond/sqgraph/SqgraphApplication.java | 4 ++-- .../sqgraph/SqgraphApplicationTests.java | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ldiamond/sqgraph/SqgraphApplication.java b/src/main/java/com/ldiamond/sqgraph/SqgraphApplication.java index 4ffc383..682d177 100644 --- a/src/main/java/com/ldiamond/sqgraph/SqgraphApplication.java +++ b/src/main/java/com/ldiamond/sqgraph/SqgraphApplication.java @@ -112,7 +112,7 @@ public CommandLineRunner commandLineRunner(ApplicationContext ctx) { config.getExpandedApplications().add(app); } else { if (app.getQuery() != null) { - final String uri = config.getUrl() + "/api/project/search?qualifiers=TRK&q=" + app.getQuery(); + final String uri = config.getUrl() + "/api/projects/search?qualifiers=TRK&q=" + app.getQuery(); ResponseEntity response = restTemplate.exchange(uri, HttpMethod.GET, new HttpEntity(headers), ApiProjectsSearchResults.class); ApiProjectsSearchResults result = response.getBody(); if ((result != null) && (result.getComponents() != null)) { @@ -198,7 +198,7 @@ public static AssembledSearchHistory getHistory (final Config config, final Stri ResponseEntity response = restTemplate.exchange(uri, HttpMethod.GET, new HttpEntity(headers), SearchHistory.class); SearchHistory result = response.getBody(); if (result != null) { - if ((result.getPaging() != null) && (result.getPaging().total == page)) { + if ((result.getPaging() != null) && (result.getPaging().total <= page)) { notYetLastPage = false; try { Thread.sleep(1); // SonarCloud implemented rate limiting, https://docs.github.com/en/rest/rate-limit?apiVersion=2022-11-28, sorry for contributing to the problem. I guess we all got popular :) diff --git a/src/test/java/com/ldiamond/sqgraph/SqgraphApplicationTests.java b/src/test/java/com/ldiamond/sqgraph/SqgraphApplicationTests.java index 623cdd0..6f36815 100644 --- a/src/test/java/com/ldiamond/sqgraph/SqgraphApplicationTests.java +++ b/src/test/java/com/ldiamond/sqgraph/SqgraphApplicationTests.java @@ -301,4 +301,26 @@ void getHistory() { assertEquals(1, ash.getMeasures().get(2).history.length); assertEquals(1, ash.getMeasures().get(3).history.length); } + + @Test + void getHistoryEmpty() { + + final Config config = new Config(); + config.setUrl("prefix"); + + SearchHistory sh = new SearchHistory(); + Paging paging = new Paging(); + paging.setTotal(0); + sh.setPaging(paging); + Measures[] measuresArray = new Measures[0]; + sh.setMeasures(measuresArray); + + ResponseEntity rsh = new ResponseEntity<>(sh, null, HttpStatus.OK); + HttpHeaders httpHeaders = new HttpHeaders(); + HttpEntity hes = new HttpEntity<>(httpHeaders); + when (restTemplate.exchange("prefix/api/measures/search_history?from=blah&p=1&ps=999&component=blah&metrics=blah",HttpMethod.GET,hes,SearchHistory.class)).thenReturn(rsh); + AssembledSearchHistory ash = SqgraphApplication.getHistory(config, "blah", "blah", "blah", httpHeaders, restTemplate); + + assertEquals(0, ash.getMeasures().size()); + } } From a4f6b39e177dfbf109a7d79809f21b6017b97c83 Mon Sep 17 00:00:00 2001 From: Larry Diamond <1066589+larrydiamond@users.noreply.github.com> Date: Thu, 28 Sep 2023 23:28:32 -0400 Subject: [PATCH 3/3] adding archunit test for threadgroup --- src/test/java/com/ldiamond/sqgraph/ArchitectureUnitTests.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/com/ldiamond/sqgraph/ArchitectureUnitTests.java b/src/test/java/com/ldiamond/sqgraph/ArchitectureUnitTests.java index 3f37d1b..c0defaf 100644 --- a/src/test/java/com/ldiamond/sqgraph/ArchitectureUnitTests.java +++ b/src/test/java/com/ldiamond/sqgraph/ArchitectureUnitTests.java @@ -31,6 +31,9 @@ public class ArchitectureUnitTests { @ArchTest static final ArchRule no_treeset = noClasses().should().callConstructor(java.util.TreeSet.class).because("Use ConcurrentSkipListSet"); + @ArchTest + static final ArchRule no_threadgroup = noClasses().should().callConstructor(java.lang.ThreadGroup.class).because("Use ExecutorService"); + @ArchTest static final ArchRule no_treemap = noClasses().should().callConstructor(java.util.TreeMap.class).because("Use ConcurrentSkipListMap");