Skip to content

Commit

Permalink
Merge branch 'central-hierarchy-id-changes' of https://github.com/Pub…
Browse files Browse the repository at this point in the history
…licisSapient/PSknowHOW into central-hierarchy-id-changes
  • Loading branch information
Rishabh Shukla committed Feb 7, 2025
2 parents 45ebc51 + f4f53ff commit 2312447
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ private void projectWiseLeafNodeValue(Map<String, Node> mapTmp, List<Node> proje
List<DataCount> dataCountAggList = new ArrayList<>();
String trendLineName = node.getProjectFilter().getName();
ObjectId basicProjectConfigId = node.getProjectFilter().getBasicProjectConfigId();
String projectNodeId = node.getProjectFilter().getId();
String projectName = projectNodeId.substring(0, projectNodeId.lastIndexOf(CommonConstant.UNDERSCORE));
String projectName = node.getProjectFilter().getName();
List<Deployment> deploymentListProjectWise = deploymentGroup.get(basicProjectConfigId);

if (CollectionUtils.isNotEmpty(deploymentListProjectWise)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void getSonarKpiData(List<Node> pList, Map<String, Node> tempMap, KpiElem
List<KPIExcelData> excelData = new ArrayList<>();

getSonarHistoryForAllProjects(pList, getScrumCurrentDateToFetchFromDb(CommonConstant.MONTH,
Long.valueOf(customApiConfig.getSonarMonthCount()))).forEach((projectNodeId, projectData) -> {
Long.valueOf(customApiConfig.getSonarMonthCount()))).forEach((projectNodePair, projectData) -> {
List<String> projectList = new ArrayList<>();
List<String> debtList = new ArrayList<>();
List<String> versionDate = new ArrayList<>();
Expand Down Expand Up @@ -145,15 +145,15 @@ public void getSonarKpiData(List<Node> pList, Map<String, Node> tempMap, KpiElem
history = prepareEmptyJobWiseHistoryMap(projectData, endms);
}

prepareSqualeList(history, date, projectNodeId, projectList, debtList, projectWiseDataMap,
prepareSqualeList(history, date, projectNodePair, projectList, debtList, projectWiseDataMap,
versionDate);

endDateTime = endDateTime.minusMonths(1);
}
tempMap.get(projectNodeId).setValue(projectWiseDataMap);
tempMap.get(projectNodePair.getKey()).setValue(projectWiseDataMap);
if (getRequestTrackerId().toLowerCase().contains(KPISource.EXCEL.name().toLowerCase())) {
KPIExcelUtility.populateSonarKpisExcelData(
tempMap.get(projectNodeId).getProjectFilter().getName(), projectList, debtList,
tempMap.get(projectNodePair.getKey()).getProjectFilter().getName(), projectList, debtList,
versionDate, excelData, KPICode.SONAR_CODE_QUALITY.getKpiId());
}
}
Expand Down Expand Up @@ -203,8 +203,8 @@ public Map<String, SonarHistory> prepareEmptyJobWiseHistoryMap(List<SonarHistory
* sonarhistory
* @param date
* node date
* @param projectName
* projectName
* @param projectNodePair
* projectNodePair
* @param projectList
* projectList
* @param debtList
Expand All @@ -214,9 +214,9 @@ public Map<String, SonarHistory> prepareEmptyJobWiseHistoryMap(List<SonarHistory
* @param versionDate
* versionDate
*/
private void prepareSqualeList(Map<String, SonarHistory> history, String date, String projectName,
List<String> projectList, List<String> debtList, Map<String, List<DataCount>> projectWiseDataMap,
List<String> versionDate) {
private void prepareSqualeList(Map<String, SonarHistory> history, String date, Pair<String, String> projectNodePair,
List<String> projectList, List<String> debtList, Map<String, List<DataCount>> projectWiseDataMap,
List<String> versionDate) {
List<Long> dateWiseDebtList = new ArrayList<>();
history.values().forEach(sonarDetails -> {

Expand All @@ -225,8 +225,8 @@ private void prepareSqualeList(Map<String, SonarHistory> history, String date, S
.collect(Collectors.toMap(SonarMetric::getMetricName, SonarMetric::getMetricValue));

final Long squaleRatingValue = getSqualeRatingValue(metricMap.get(SQALE_RATING));
String keyName = prepareSonarKeyName(projectName, sonarDetails.getName(), sonarDetails.getBranch());
DataCount dcObj = getDataCount(squaleRatingValue, projectName, date);
String keyName = prepareSonarKeyName(projectNodePair.getValue(), sonarDetails.getName(), sonarDetails.getBranch());
DataCount dcObj = getDataCount(squaleRatingValue, projectNodePair.getValue(), date);
projectWiseDataMap.computeIfAbsent(keyName, k -> new ArrayList<>()).add(dcObj);
projectList.add(keyName);
versionDate.add(date);
Expand All @@ -235,7 +235,7 @@ private void prepareSqualeList(Map<String, SonarHistory> history, String date, S

});
DataCount dcObj = getDataCount(calculateKpiValue(dateWiseDebtList, KPICode.SONAR_CODE_QUALITY.getKpiId()),
projectName, date);
projectNodePair.getValue(), date);
projectWiseDataMap.computeIfAbsent(CommonConstant.OVERALL, k -> new ArrayList<>()).add(dcObj);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,40 +71,24 @@
*/
@Component
public class CodeViolationsKanbanServiceImpl
extends SonarKPIService<Long, List<Object>, Map<String, List<SonarHistory>>> {
private static final Map<String, String> SEVERITY_MAP = Map.of(
Constant.CRITICAL_VIOLATIONS, "critical",
Constant.BLOCKER_VIOLATIONS, "blocker",
Constant.MAJOR_VIOLATIONS, "major",
Constant.MINOR_VIOLATIONS, "minor",
Constant.INFO_VIOLATIONS, "info"
);

private static final Map<String, String> TYPE_MAP = Map.of(
Constant.BUGS, "bugs",
Constant.VULNERABILITIES, "vulnerabilities",
Constant.CODE_SMELL, "code smells"
);
extends SonarKPIService<Long, List<Object>, Map<Pair<String, String>, List<SonarHistory>>> {
private static final Map<String, String> SEVERITY_MAP = Map.of(Constant.CRITICAL_VIOLATIONS, "critical",
Constant.BLOCKER_VIOLATIONS, "blocker", Constant.MAJOR_VIOLATIONS, "major", Constant.MINOR_VIOLATIONS,
"minor", Constant.INFO_VIOLATIONS, "info");

private static final Map<String, String> TYPE_MAP = Map.of(Constant.BUGS, "bugs", Constant.VULNERABILITIES,
"vulnerabilities", Constant.CODE_SMELL, "code smells");

private static final String VIOLATION_TYPES = "RadioBtn";
private static final String JOB_FILTER = "Select a filter";
private static final String SEVERITY = "Severity";
private static final String TYPE = "Type";


@Override
public String getQualifierType() {
return KPICode.CODE_VIOLATIONS_KANBAN.name();
}

/**
* @param sonarDetailsMap
*/
@Override
public Long calculateKPIMetrics(Map<String, List<SonarHistory>> sonarDetailsMap) {
return 0L;
}

/**
* Gets KPI Data
*
Expand Down Expand Up @@ -155,12 +139,24 @@ public KpiElement getKpiData(KpiRequest kpiRequest, KpiElement kpiElement,
return kpiElement;
}

/**
* Calculates KPI Metrics
*
* @param pairListMap
* type of db object
* @return KPI value
*/
@Override
public Long calculateKPIMetrics(Map<Pair<String, String>, List<SonarHistory>> pairListMap) {
return 0L;
}

/**
* fetch data from db.
*/
@Override
public Map<String, List<SonarHistory>> fetchKPIDataFromDb(List<Node> leafNodeList, String startDate, String endDate,
KpiRequest kpiRequest) {
public Map<Pair<String, String>, List<SonarHistory>> fetchKPIDataFromDb(List<Node> leafNodeList, String startDate,
String endDate, KpiRequest kpiRequest) {
return getSonarHistoryForAllProjects(leafNodeList, getKanbanCurrentDateToFetchFromDb(startDate));
}

Expand All @@ -186,8 +182,8 @@ private void dateWiseLeafNodeValue(Map<String, Node> mapTmp, List<Node> leafNode
String startDate = dateRange.getStartDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
String endDate = dateRange.getEndDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));

Map<String, List<SonarHistory>> sonarDetailsForAllProjects = fetchKPIDataFromDb(leafNodeList, startDate,
endDate, kpiRequest);
Map<Pair<String, String>, List<SonarHistory>> sonarDetailsForAllProjects = fetchKPIDataFromDb(leafNodeList,
startDate, endDate, kpiRequest);

kpiWithFilter(sonarDetailsForAllProjects, mapTmp, kpiElement, kpiRequest);

Expand All @@ -201,11 +197,11 @@ private void dateWiseLeafNodeValue(Map<String, Node> mapTmp, List<Node> leafNode
* @param kpiElement
* @param kpiRequest
*/
private void kpiWithFilter(Map<String, List<SonarHistory>> sonarDetailsForAllProjects, Map<String, Node> mapTmp,
KpiElement kpiElement, KpiRequest kpiRequest) {
private void kpiWithFilter(Map<Pair<String, String>, List<SonarHistory>> sonarDetailsForAllProjects,
Map<String, Node> mapTmp, KpiElement kpiElement, KpiRequest kpiRequest) {
List<KPIExcelData> excelData = new ArrayList<>();
Set<String> overAllJoblist = new HashSet<>();
sonarDetailsForAllProjects.forEach((projectName, projectData) -> {
sonarDetailsForAllProjects.forEach((projectNodePair, projectData) -> {
if (CollectionUtils.isNotEmpty(projectData)) {
List<String> projectList = new ArrayList<>();
List<List<String>> violations = new ArrayList<>();
Expand All @@ -221,18 +217,18 @@ private void kpiWithFilter(Map<String, List<SonarHistory>> sonarDetailsForAllPro
Long endms = dateRange.getEndDate().atTime(23, 59, 59).atZone(ZoneId.systemDefault()).toInstant()
.toEpochMilli();
Map<String, SonarHistory> history = prepareJobwiseHistoryMap(projectData, startms, endms,
projectName);
projectNodePair.getRight());
String date = getRange(dateRange, kpiRequest);
prepareViolationsList(history, date, projectName, projectList, violations,
prepareViolationsList(history, date, projectNodePair.getRight(), projectList, violations,
projectWiseDataMap, versionDate);

currentDate = getNextRangeDate(kpiRequest, currentDate);
}
overAllJoblist.addAll(projectList);
mapTmp.get(projectName).setValue(projectWiseDataMap);
mapTmp.get(projectNodePair.getLeft()).setValue(projectWiseDataMap);
if (getRequestTrackerIdKanban().toLowerCase().contains(KPISource.EXCEL.name().toLowerCase())) {
KPIExcelUtility.populateSonarViolationsExcelData(mapTmp.get(projectName).getName(), projectList,
violations, versionDate, excelData, KPICode.CODE_VIOLATIONS_KANBAN.getKpiId());
KPIExcelUtility.populateSonarViolationsExcelData(mapTmp.get(projectNodePair.getLeft()).getName(),
projectList, violations, versionDate, excelData, KPICode.CODE_VIOLATIONS_KANBAN.getKpiId());
}
}
});
Expand Down Expand Up @@ -279,8 +275,8 @@ private void prepareViolationsList(Map<String, SonarHistory> history, String dat
sonarViolations = sonarViolationsHoverMapByType.values().stream().map(Integer.class::cast)
.mapToLong(val -> val).sum();
kpiGroup = keyName + "#" + TYPE;
DataCount dcObjType = getDataCountObject(sonarViolations, sonarViolationsHoverMapByType,
projectName, date, kpiGroup);
DataCount dcObjType = getDataCountObject(sonarViolations, sonarViolationsHoverMapByType, projectName, date,
kpiGroup);
projectWiseDataMap.computeIfAbsent(kpiGroup, k -> new ArrayList<>()).add(dcObjType);
projectList.add(keyName);
versionDate.add(date);
Expand All @@ -290,51 +286,53 @@ private void prepareViolationsList(Map<String, SonarHistory> history, String dat
violations.add(Arrays.asList(mapToString.apply(sonarViolationsHoverMapBySeverity),
mapToString.apply(sonarViolationsHoverMapByType)));
});
DataCount dcObj= getDataCountObject(
DataCount dcObj = getDataCountObject(
calculateKpiValue(dateWiseViolationsList, KPICode.CODE_VIOLATIONS.getKpiId()),
calculateKpiValueForIntMap(globalSonarViolationsHoverMapBySeverity, KPICode.CODE_VIOLATIONS.getKpiId()),
projectName, date);
projectWiseDataMap.computeIfAbsent(CommonConstant.OVERALL + "#" + SEVERITY, k -> new ArrayList<>()).add(dcObj);

dcObj = getDataCountObject(
calculateKpiValue(dateWiseViolationsList, KPICode.CODE_VIOLATIONS.getKpiId()),
dcObj = getDataCountObject(calculateKpiValue(dateWiseViolationsList, KPICode.CODE_VIOLATIONS.getKpiId()),
calculateKpiValueForIntMap(globalSonarViolationsHoverMapByType, KPICode.CODE_VIOLATIONS.getKpiId()),
projectName, date);
projectWiseDataMap.computeIfAbsent(CommonConstant.OVERALL+"#"+TYPE, k -> new ArrayList<>()).add(dcObj);
projectWiseDataMap.computeIfAbsent(CommonConstant.OVERALL + "#" + TYPE, k -> new ArrayList<>()).add(dcObj);
}

/**
* Creates and sorts a map of violations based on the provided reference map and metric map.
* Creates and sorts a map of violations based on the provided reference map and
* metric map.
*
* @param referenceMap A map containing the reference values for sorting.
* @param metricMap A map containing the metric values to be evaluated and sorted.
* @return A sorted map of violations.
* @param referenceMap
* A map containing the reference values for sorting.
* @param metricMap
* A map containing the metric values to be evaluated and sorted.
* @return A sorted map of violations.
*/
private Map<String, Object> createAndSortViolationsMap(Map<String, String> referenceMap,
Map<String, Object> metricMap) {
Map<String, Object> metricMap) {
Map<String, Object> violationsMap = new LinkedHashMap<>();
referenceMap.forEach((key, value) -> evaluateViolations(metricMap.get(key), violationsMap, value));

return violationsMap.entrySet().stream()
.filter(entry -> entry.getValue() != null) // Exclude entries with null values
return violationsMap.entrySet().stream().filter(entry -> entry.getValue() != null) // Exclude entries with null
// values
.sorted((i1, i2) -> ((Integer) i2.getValue()).compareTo((Integer) i1.getValue()))
.collect(Collectors.toMap(
Map.Entry::getKey,
Map.Entry::getValue,
(e1, e2) -> e1,
LinkedHashMap::new
));
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
}

/**
* Creates a DataCount object with the provided values.
*
* @param value The value to be set in the DataCount object.
* @param hoverValues A map containing hover values to be set in the DataCount object.
* @param projectName The name of the project to be set in the DataCount object.
* @param date The date to be set in the DataCount object.
* @param kpiGroup The KPI group to be set in the DataCount object.
* @return A DataCount object populated with the provided values.
* @param value
* The value to be set in the DataCount object.
* @param hoverValues
* A map containing hover values to be set in the DataCount object.
* @param projectName
* The name of the project to be set in the DataCount object.
* @param date
* The date to be set in the DataCount object.
* @param kpiGroup
* The KPI group to be set in the DataCount object.
* @return A DataCount object populated with the provided values.
*/
public DataCount getDataCountObject(Long value, Map<String, Object> hoverValues, String projectName, String date,
String kpiGroup) {
Expand Down Expand Up @@ -451,8 +449,9 @@ public Long calculateKpiValue(List<Long> valueList, String kpiId) {
}

@Override
public Double calculateThresholdValue(FieldMapping fieldMapping){
return calculateThresholdValue(fieldMapping.getThresholdValueKPI64(),KPICode.CODE_VIOLATIONS_KANBAN.getKpiId());
public Double calculateThresholdValue(FieldMapping fieldMapping) {
return calculateThresholdValue(fieldMapping.getThresholdValueKPI64(),
KPICode.CODE_VIOLATIONS_KANBAN.getKpiId());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void getSonarKpiData(List<Node> pList, Map<String, Node> tempMap, KpiElem
Set<String> overAllJoblist = new HashSet<>();
getSonarHistoryForAllProjects(pList,
getScrumCurrentDateToFetchFromDb(CommonConstant.WEEK, (long) customApiConfig.getSonarWeekCount()))
.forEach((projectNodeId, projectData) -> {
.forEach((projectNodePair, projectData) -> {
List<String> projectList = new ArrayList<>();
List<List<String>> violations = new ArrayList<>();
List<String> versionDate = new ArrayList<>();
Expand All @@ -176,17 +176,17 @@ public void getSonarKpiData(List<Node> pList, Map<String, Node> tempMap, KpiElem
Long endms = sunday.atTime(23, 59, 59).atZone(ZoneId.systemDefault()).toInstant()
.toEpochMilli();
Map<String, SonarHistory> history = prepareJobwiseHistoryMap(projectData, startms, endms,
projectNodeId);
prepareViolationsList(history, date, projectNodeId, projectList, violations,
projectNodePair.getValue());
prepareViolationsList(history, date, projectNodePair.getValue(), projectList, violations,
projectWiseDataMap, versionDate);

endDateTime = endDateTime.minusWeeks(1);
}
overAllJoblist.addAll(projectList);
tempMap.get(projectNodeId).setValue(projectWiseDataMap);
tempMap.get(projectNodePair.getKey()).setValue(projectWiseDataMap);
if (getRequestTrackerId().toLowerCase().contains(KPISource.EXCEL.name().toLowerCase())) {
KPIExcelUtility.populateSonarViolationsExcelData(
tempMap.get(projectNodeId).getProjectFilter().getName(), projectList, violations,
tempMap.get(projectNodePair.getKey()).getProjectFilter().getName(), projectList, violations,
versionDate, excelData, KPICode.CODE_VIOLATIONS.getKpiId());
}
}
Expand Down Expand Up @@ -262,7 +262,7 @@ private Map<String, SonarHistory> prepareJobwiseHistoryMap(List<SonarHistory> so
*
* @param history A map containing the Sonar history data.
* @param date The date range for which the violations are being prepared.
* @param projectNodeId The ID of the project node.
* @param projectName The nodeDisplayName of the project node.
* @param projectList A list to store the project names.
* @param violations A list to store the violations.
* @param projectWiseDataMap A map to store the data counts for each project.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;

Expand Down Expand Up @@ -149,12 +150,12 @@ private List<SonarHistory> getSonarHistoryBasedOnProject(ObjectId projectId, Loc
* @param currentDate
* @return
*/
public Map<String, List<SonarHistory>> getSonarHistoryForAllProjects(List<Node> projectList,
public Map<Pair<String, String>, List<SonarHistory>> getSonarHistoryForAllProjects(List<Node> projectList,
LocalDate currentDate) {
Map<String, List<SonarHistory>> map = new HashMap<>();
Map<Pair<String, String>, List<SonarHistory>> map = new HashMap<>();
projectList.stream().filter(
node -> null != node.getProjectFilter() && null != node.getProjectFilter().getBasicProjectConfigId())
.forEach(node -> map.put(node.getId(),
.forEach(node -> map.put(Pair.of(node.getId(), node.getProjectFilter().getName()),
getSonarHistoryBasedOnProject(node.getProjectFilter().getBasicProjectConfigId(), currentDate)));
return map;
}
Expand Down
Loading

0 comments on commit 2312447

Please sign in to comment.