From 4a1415c83a8f6f2700d085a7b643f1c3474acefe Mon Sep 17 00:00:00 2001 From: rvema Date: Fri, 15 Nov 2019 11:35:00 -0500 Subject: [PATCH 1/2] restclient uasge and fix for autoassociation --- .travis.yml | 7 +--- pom.xml | 2 +- .../webhook/github/GitHubCommitV3.java | 12 +++---- .../webhook/github/GitHubPullRequestV3.java | 2 +- .../sonarqube/SonarQubeHookServiceImpl.java | 36 +++---------------- 5 files changed, 11 insertions(+), 48 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3ac48383..fccf6d99 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,11 +28,6 @@ notifications: recipients: - tapabrata.pal@capitalone.com - ragha.vema@capitalone.com - - nireesh.thiruveedula@capitalone.com - - Stephen.Hughes@capitalone.com - - jiyang.xu@capitalone.com - - brian.shriver@capitalone.com - - kaitlyn.heinzmann@capitalone.com - - Justin.Hoelscher@capitalone.com + - hygieia2@capitalone.com on_success: always on_failure: always diff --git a/pom.xml b/pom.xml index 4bae946c..4b2e3cda 100644 --- a/pom.xml +++ b/pom.xml @@ -58,7 +58,7 @@ - 3.1.12 + 3.1.14 0.13 4.3.0 18.0 diff --git a/src/main/java/com/capitalone/dashboard/webhook/github/GitHubCommitV3.java b/src/main/java/com/capitalone/dashboard/webhook/github/GitHubCommitV3.java index 72a472ce..0b8715b8 100644 --- a/src/main/java/com/capitalone/dashboard/webhook/github/GitHubCommitV3.java +++ b/src/main/java/com/capitalone/dashboard/webhook/github/GitHubCommitV3.java @@ -247,16 +247,12 @@ && checkCommitsListForSettingPullNumber(commitsList)) { } private boolean checkCommitsWithPullNumber(List commitsWithPullNumber) { - if (!CollectionUtils.isEmpty(commitsWithPullNumber) - && (commitsWithPullNumber.size() == 1)) { return true; } - - return false; + return !CollectionUtils.isEmpty(commitsWithPullNumber) + && (commitsWithPullNumber.size() == 1); } private boolean checkCommitsListForSettingPullNumber(List commitsList) { - if (!CollectionUtils.isEmpty(commitsList) && (commitsList.size() > 1)) { return true; } - - return false; + return !CollectionUtils.isEmpty(commitsList) && (commitsList.size() > 1); } protected void setCommitPullNumber (Commit commit) { @@ -294,7 +290,7 @@ protected Object getCommitNode(GitHubParsed gitHubParsed, String branch, String ResponseEntity response = null; try { - response = restClient.makeRestCallPostGraphQL(gitHubParsed.getGraphQLUrl(), "token", token, postBody); + response = restClient.makeRestCallPost(gitHubParsed.getGraphQLUrl(), "token", token, postBody); } catch (Exception e) { throw new HygieiaException(e); } diff --git a/src/main/java/com/capitalone/dashboard/webhook/github/GitHubPullRequestV3.java b/src/main/java/com/capitalone/dashboard/webhook/github/GitHubPullRequestV3.java index ac8fa4bc..3ca0a1b3 100644 --- a/src/main/java/com/capitalone/dashboard/webhook/github/GitHubPullRequestV3.java +++ b/src/main/java/com/capitalone/dashboard/webhook/github/GitHubPullRequestV3.java @@ -110,7 +110,7 @@ public String process(JSONObject prJsonObject) throws MalformedURLException, Hyg ResponseEntity response = null; try { - response = restClient.makeRestCallPostGraphQL(gitHubParsed.getGraphQLUrl(), "token", token, postBody); + response = restClient.makeRestCallPost(gitHubParsed.getGraphQLUrl(), "token", token, postBody); } catch (Exception e) { throw new HygieiaException(e); } diff --git a/src/main/java/com/capitalone/dashboard/webhook/sonarqube/SonarQubeHookServiceImpl.java b/src/main/java/com/capitalone/dashboard/webhook/sonarqube/SonarQubeHookServiceImpl.java index 93eb8505..55b03852 100644 --- a/src/main/java/com/capitalone/dashboard/webhook/sonarqube/SonarQubeHookServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/webhook/sonarqube/SonarQubeHookServiceImpl.java @@ -67,7 +67,7 @@ public class SonarQubeHookServiceImpl implements SonarQubeHookService { } @Override - public String createFromSonarQubeV1(JSONObject request) throws ParseException, HygieiaException, MalformedURLException { + public String createFromSonarQubeV1(JSONObject request) throws ParseException { JSONParser jsonParser = new JSONParser(); JSONObject jsonObject = (JSONObject) jsonParser.parse(request.toJSONString()); @@ -130,7 +130,7 @@ private void refreshData(SonarProject sonarProject, JSONObject request) { } } - public CodeQuality currentCodeQuality(SonarProject project, JSONObject request) { + private CodeQuality currentCodeQuality(SonarProject project, JSONObject request) { try { JsonParser jsonParser = new JsonParser(); @@ -205,37 +205,13 @@ private String strSafe(JsonObject json, String key) { return obj == null ? "" : obj.toString(); } - private String strSafe(JSONObject json, String key) { - Object obj = json.get(key); - return obj == null ? "" : obj.toString(); - } - private Integer integer(JsonObject json, String key) { Object obj = json.get(key); return obj == null ? null : Integer.valueOf(obj.toString().replaceAll("\"","")); } - @SuppressWarnings("unused") - private Integer integer(JSONObject json, String key) { - Object obj = json.get(key); - return obj == null ? null : Integer.valueOf(obj.toString().replaceAll("\"","")); - } - - @SuppressWarnings("unused") - private BigDecimal decimal(JSONObject json, String key) { - Object obj = json.get(key); - return obj == null ? null : new BigDecimal(obj.toString().replaceAll("\"","")); - } - - @SuppressWarnings("unused") - private Boolean bool(JSONObject json, String key) { - Object obj = json.get(key); - return obj == null ? null : Boolean.valueOf(obj.toString().replaceAll("\"","")); - } - - @SuppressWarnings("unused") private String format(String duration) { - Long durationInMinutes = Long.valueOf(duration); + long durationInMinutes = Long.parseLong(duration); if (durationInMinutes == 0) { return "0"; } @@ -243,7 +219,7 @@ private String format(String duration) { Long absDuration = Math.abs(durationInMinutes); int days = ((Double) ((double) absDuration / HOURS_IN_DAY / 60)).intValue(); - Long remainingDuration = absDuration - (days * HOURS_IN_DAY * 60); + Long remainingDuration = absDuration - (days * HOURS_IN_DAY * 60); int hours = ((Double) (remainingDuration.doubleValue() / 60)).intValue(); remainingDuration = remainingDuration - (hours * 60); int minutes = remainingDuration.intValue(); @@ -274,10 +250,6 @@ private static void addSpaceIfNeeded(StringBuilder message) { } } - private JSONArray parseAsArray(JSONObject jsonObject, String key) throws ParseException { - return (JSONArray) jsonObject.get(key); - } - private static boolean displayHours(int days, int hours) { return hours > 0 && days < 10; } From 16ee2c425d39fba05761dcc00dd3b11b6d1a504e Mon Sep 17 00:00:00 2001 From: rvema Date: Fri, 15 Nov 2019 12:16:45 -0500 Subject: [PATCH 2/2] lgtm fixes --- .../dashboard/logging/LoggingFilter.java | 6 ++- .../dashboard/rest/FeatureController.java | 21 +++++----- .../dashboard/rest/ScopeController.java | 14 ++++--- .../service/DashboardServiceImpl.java | 15 ++++--- .../service/RallyFeatureServiceImpl.java | 39 +++++++------------ .../resources/static/swagger/lib/marked.js | 2 +- 6 files changed, 47 insertions(+), 50 deletions(-) diff --git a/src/main/java/com/capitalone/dashboard/logging/LoggingFilter.java b/src/main/java/com/capitalone/dashboard/logging/LoggingFilter.java index 253296cd..bb9e187c 100644 --- a/src/main/java/com/capitalone/dashboard/logging/LoggingFilter.java +++ b/src/main/java/com/capitalone/dashboard/logging/LoggingFilter.java @@ -390,8 +390,10 @@ public Locale getLocale() { @Override public void addCookie(Cookie cookie) { - if(cookie != null) {cookie.setSecure(Boolean.TRUE);} - original.addCookie(cookie); + if(cookie != null) { + cookie.setSecure(Boolean.TRUE); + original.addCookie(cookie); + } } @Override diff --git a/src/main/java/com/capitalone/dashboard/rest/FeatureController.java b/src/main/java/com/capitalone/dashboard/rest/FeatureController.java index 30f99a7b..7a9a12b7 100644 --- a/src/main/java/com/capitalone/dashboard/rest/FeatureController.java +++ b/src/main/java/com/capitalone/dashboard/rest/FeatureController.java @@ -1,11 +1,9 @@ package com.capitalone.dashboard.rest; -import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; -import static org.springframework.web.bind.annotation.RequestMethod.GET; - -import java.util.List; -import java.util.Optional; - +import com.capitalone.dashboard.model.DataResponse; +import com.capitalone.dashboard.model.Feature; +import com.capitalone.dashboard.model.SprintEstimate; +import com.capitalone.dashboard.service.FeatureService; import org.bson.types.ObjectId; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; @@ -13,10 +11,11 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.capitalone.dashboard.model.DataResponse; -import com.capitalone.dashboard.model.Feature; -import com.capitalone.dashboard.model.SprintEstimate; -import com.capitalone.dashboard.service.FeatureService; +import java.util.List; +import java.util.Optional; + +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; +import static org.springframework.web.bind.annotation.RequestMethod.GET; /** * REST service managing all requests to the feature repository. @@ -56,8 +55,6 @@ public DataResponse> relevantStories( * REST endpoint for retrieving all features for a given sprint and team * (the sprint is derived) * - * @param teamId - * A given scope-owner's source-system ID * @return A data response list of type Feature containing all features for * the given team and current sprint */ diff --git a/src/main/java/com/capitalone/dashboard/rest/ScopeController.java b/src/main/java/com/capitalone/dashboard/rest/ScopeController.java index ba1f0f16..c70daa01 100644 --- a/src/main/java/com/capitalone/dashboard/rest/ScopeController.java +++ b/src/main/java/com/capitalone/dashboard/rest/ScopeController.java @@ -33,17 +33,17 @@ public class ScopeController { private PaginationHeaderUtility paginationHeaderUtility; @Autowired - public ScopeController(ScopeService featureService,PaginationHeaderUtility paginationHeaderUtility) { - this.scopeService = featureService; + public ScopeController(ScopeService scopeService,PaginationHeaderUtility paginationHeaderUtility) { + this.scopeService = scopeService; this.paginationHeaderUtility = paginationHeaderUtility; } /** * REST endpoint for retrieving all features for a given sprint and team - * (the sprint is derived) + * (the sprint is derived) A given scope-owner's source-system ID * + * @param cId * @param scopeId - * A given scope-owner's source-system ID * @return A data response list of type Feature containing all features for * the given team and current sprint */ @@ -56,6 +56,7 @@ public DataResponse> scope( } /** + * Return list of Teams * * @param collectorId * @@ -80,8 +81,11 @@ public List allScopes() { } /** + * Return list of teams with pagination * - * @param collectorId, search criteria, pageable + * @param collectorId + * @param descriptionFilter + * @param pageable * * @return List of scope */ diff --git a/src/main/java/com/capitalone/dashboard/service/DashboardServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/DashboardServiceImpl.java index 91e31157..70805745 100644 --- a/src/main/java/com/capitalone/dashboard/service/DashboardServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/DashboardServiceImpl.java @@ -778,8 +778,10 @@ private void duplicateDashboardErrorCheck(Dashboard dashboard) throws HygieiaExc /** * Get all dashboards filtered by title and Pageable ( default page size = 10) * - * @param title, pageable - * @return Page + * @param title Title of Dashboard + * @param type Type of Dashboard + * @param pageable Pagination Object + * @return Page Page of Dashboards */ @Override public Page getDashboardByTitleWithFilter(String title, String type, Pageable pageable) { @@ -796,8 +798,9 @@ public Page getDashboardByTitleWithFilter(String title, String type, /** * Get count of all dashboards filtered by title * - * @param title - * @return Integer + * @param title Title of Dashboard + * @param type Type of Dashboard + * @return Integer Count of Dashboards */ @Override public Integer getAllDashboardsByTitleCount(String title, String type) { @@ -813,7 +816,7 @@ public Integer getAllDashboardsByTitleCount(String title, String type) { /** * Get count of all dashboards, use dashboard type if supplied * - * @param + * @param type Type of the Dashboard * @return long */ @Override @@ -828,6 +831,7 @@ public long count(String type) { /** * Get all dashboards with page size (default = 10) * + * @param type Type of Dashboard * @param page size * @return List of dashboards */ @@ -842,7 +846,6 @@ public Page findDashboardsByPage(String type, Pageable page) { /** * Get page size * - * @param * @return Integer */ @Override diff --git a/src/main/java/com/capitalone/dashboard/service/RallyFeatureServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/RallyFeatureServiceImpl.java index 2bf4a69d..6ce65846 100644 --- a/src/main/java/com/capitalone/dashboard/service/RallyFeatureServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/RallyFeatureServiceImpl.java @@ -1,21 +1,5 @@ package com.capitalone.dashboard.service; -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Function; -import java.util.function.Predicate; - -import org.bson.types.ObjectId; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - import com.capitalone.dashboard.model.Collector; import com.capitalone.dashboard.model.CollectorItem; import com.capitalone.dashboard.model.CollectorType; @@ -28,6 +12,18 @@ import com.capitalone.dashboard.repository.RallyFeatureRepository; import com.capitalone.dashboard.request.RallyFeatureRequest; import com.capitalone.dashboard.response.RallyBurnDownResponse; +import org.bson.types.ObjectId; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; @Service public class RallyFeatureServiceImpl implements RallyFeatureService { @@ -100,7 +96,7 @@ public RallyBurnDownResponse rallyBurnDownData(RallyFeature request) { List taskEstimateArray = new ArrayList<>(); RallyBurnDownData burnDownData = rallyBurnDownRepository.findByIterationIdAndProjectId(request.getIterationId(), - request.getProjectId().toString()); + request.getProjectId()); if(burnDownData!=null) { for (Map burnDownDetail : burnDownData.getBurnDownData()) { iterationDates.add(burnDownDetail.get(RallyBurnDownData.ITERATION_DATE).substring(5, 10)); @@ -108,8 +104,8 @@ public RallyBurnDownResponse rallyBurnDownData(RallyFeature request) { acceptedPoints.add(Double.parseDouble(burnDownDetail.get(RallyBurnDownData.ACCEPTED_POINTS))); } - Double maximumTotalEstimate = burnDownData.getTotalEstimate(); - Double estimateDiff = maximumTotalEstimate / (burnDownData.getBurnDownData().size() - 1); + double maximumTotalEstimate = burnDownData.getTotalEstimate(); + double estimateDiff = maximumTotalEstimate / (burnDownData.getBurnDownData().size() - 1); for (int j = 0; j < burnDownData.getBurnDownData().size(); j++) { if (burnDownData.getBurnDownData().size() - j == 1) { @@ -130,9 +126,4 @@ public RallyBurnDownResponse rallyBurnDownData(RallyFeature request) { } - public static Predicate distinctByKey(Function keyExtractor) { - Set seen = ConcurrentHashMap.newKeySet(); - return t -> seen.add(keyExtractor.apply(t)); - } - } diff --git a/src/main/resources/static/swagger/lib/marked.js b/src/main/resources/static/swagger/lib/marked.js index 8d04e417..752bee8f 100644 --- a/src/main/resources/static/swagger/lib/marked.js +++ b/src/main/resources/static/swagger/lib/marked.js @@ -454,7 +454,7 @@ reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/, nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/, strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/, - em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/, + em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/, //lgtm [js/redos] code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/, br: /^ {2,}\n(?!\s*$)/, del: noop,