Skip to content

Commit 3f32dfa

Browse files
Hackathon commit
1 parent 6292bb7 commit 3f32dfa

File tree

8 files changed

+81
-13
lines changed

8 files changed

+81
-13
lines changed

server/src/main/java/com/testsigma/controller/ReportsController.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.testsigma.mapper.ElementMapper;
1919
import com.testsigma.mapper.ReportsMapper;
2020
import com.testsigma.model.*;
21+
import com.testsigma.repository.ReportsRepository;
2122
import com.testsigma.service.*;
2223
import com.testsigma.specification.ElementSpecificationsBuilder;
2324
import com.testsigma.specification.ReportsSpecificationBuilder;
@@ -57,8 +58,17 @@ public class ReportsController {
5758

5859
private final ReportsMapper reportsMapper;
5960

60-
@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
61-
public ResponseEntity<Object> show(@PathVariable("id") Long id) throws TestsigmaException,Exception {
61+
private final ReportsRepository reportsRepository;
62+
63+
64+
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
65+
public ReportsDTO show(@PathVariable("id") Long id) throws TestsigmaException,Exception {
66+
Optional<Report> report = reportsRepository.findById(id);
67+
return reportsMapper.map(report.get());
68+
}
69+
70+
@RequestMapping(value = "/generate_report/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
71+
public ResponseEntity<Object> generateReport(@PathVariable("id") Long id) throws TestsigmaException,Exception {
6272
JSONArray responseObject = reportsService.getReport(id);
6373
List<Map<String,Object>> entities = new ArrayList<Map<String,Object>>();
6474
for (int i=0;i<responseObject.length();i++) {

server/src/main/java/com/testsigma/dto/ReportsDTO.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.testsigma.dto;
22

33

4+
import com.testsigma.model.ReportConfiguration;
45
import com.testsigma.model.ReportModule;
56
import com.testsigma.model.ReportType;
67
import com.testsigma.model.WorkspaceVersion;
@@ -14,5 +15,6 @@ public class ReportsDTO {
1415
private ReportType reportType;
1516
private ReportModule reportModule;
1617
private WorkspaceVersion workspaceVersion;
18+
private ReportConfiguration reportConfiguration;
1719
}
1820

server/src/main/java/com/testsigma/mapper/ReportsMapper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE,
3030
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
3131
public interface ReportsMapper {
32+
@Mapping(target = "reportConfiguration.reportCriteriaMappings", ignore = true)
3233
ReportsDTO map(Report report);
3334

35+
@Mapping(target = "reportConfiguration.reportCriteriaMappings", ignore = true)
3436
List<ReportsDTO> mapDTOs(List<Report> reports);
3537
}

ui/src/app/app.module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ import {LoginFormComponent} from './components/login-form.component';
210210
import {RecaptchaModule} from 'ng-recaptcha';
211211
import {CommonModule} from "@angular/common";
212212
import {ElementMetadataComponent} from "./components/webcomponents/element-metadata.component";
213+
import {ReportConfiguration} from "./models/report-configuration.model";
213214
import {MantisIssueFormComponent} from './components/webcomponents/mantis-issue-form.component';
214215
import {MantisIssueDetailsComponent} from './components/webcomponents/mantis-issue-details.component';
215216
import {BackLogIssueFormComponent} from './components/webcomponents/backlog-issue-form.component';

ui/src/app/components/reports.component.ts

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,10 @@ export class ReportsComponent implements OnInit {
504504
}
505505

506506
openReport(id){
507-
this.reportsService.show(id).subscribe((res)=>{
507+
this.reportsService.show(id).subscribe((report)=>{
508+
this.reportsService.generateReport(id).subscribe((res)=>{
508509
console.log(res);
510+
let seriesData = this.convertToSeriesForPie(res,report);
509511
let chartOptions = {
510512
chart: {
511513
backgroundColor: 'transparent',
@@ -540,18 +542,10 @@ export class ReportsComponent implements OnInit {
540542
}
541543
},
542544
series: [{
543-
name: 'Brands',
545+
name: report.reportConfiguration["chartGroupField"]?.fieldName,
544546
colorByPoint: true,
545547
type:'pie',
546-
data: [{
547-
name: 'Chrome',
548-
y: 70,
549-
color:'#1FB47E'
550-
},{
551-
name: 'Internet Explorer',
552-
y: 30,
553-
color:'#1FA87E'
554-
}]
548+
data: seriesData
555549
}]
556550
};
557551
const dialogRef = this.matModal.open<CustomReportsPopupComponent>(CustomReportsPopupComponent, {
@@ -564,5 +558,35 @@ export class ReportsComponent implements OnInit {
564558
this.router.navigate(['reports','custom_reports']);
565559
})
566560
});
561+
});
562+
}
563+
564+
convertToSeriesForPie(res,report){
565+
let series = [];
566+
let colorMap = {
567+
"DRAFT":'red',
568+
"READY":'green'
569+
}
570+
let seriesCount = {} as any;
571+
let i=0;
572+
res.forEach((data)=> {
573+
let key = report.reportConfiguration["chartGroupField"]?.fieldName;
574+
let obj = {} as any;
575+
obj.name = key;
576+
obj.color = colorMap[data[key]];
577+
if(seriesCount[key])
578+
seriesCount[key]++;
579+
else
580+
seriesCount[key] = 1;
581+
let flag=0;
582+
series.forEach((sData)=>{
583+
if(sData.name == key)
584+
flag = 1;
585+
});
586+
obj.y = seriesCount[key];
587+
if(flag==0)
588+
series.push(obj);
589+
});
590+
return series;
567591
}
568592
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {Base} from "../shared/models/base.model";
2+
import {PageObject} from "../shared/models/page-object";
3+
import {alias, custom, deserialize, object, optional, serializable, SKIP} from "serializr";
4+
import {ReportModule} from "./report-module.model";
5+
6+
7+
export class ReportConfiguration extends Base{
8+
9+
@serializable
10+
public id: number;
11+
@serializable
12+
public chartType: String;
13+
14+
deserialize(input: any): this {
15+
return Object.assign(this, deserialize(ReportConfiguration, input));
16+
}
17+
}

ui/src/app/models/report.model.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {Base} from "../shared/models/base.model";
22
import {PageObject} from "../shared/models/page-object";
33
import {alias, custom, deserialize, object, optional, serializable, SKIP} from "serializr";
44
import {ReportModule} from "./report-module.model";
5+
import {ReportConfiguration} from "./report-configuration.model";
56

67

78
export class Report extends Base implements PageObject {
@@ -16,6 +17,8 @@ export class Report extends Base implements PageObject {
1617
public reportType: String;
1718
@serializable(optional(object(ReportModule)))
1819
public reportModule:ReportModule;
20+
@serializable(optional(object(ReportConfiguration)))
21+
public reportConfiguration:ReportConfiguration;
1922

2023
deserialize(input: any): this {
2124
return Object.assign(this, deserialize(Report, input));

ui/src/app/services/reports.service.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ export class ReportsService{
3737
);
3838
}
3939

40+
41+
42+
public generateReport(id: number): Observable<any> {
43+
return this.http.get<any>(this.URLConstants.reportsURL + "/generate_report/" + id, {headers: this.httpHeaders.contentTypeApplication}).pipe(
44+
map(data => data),
45+
catchError(() => throwError('Problem while getting reports::' + id))
46+
);
47+
}
48+
4049
public getFlakyTests(versionId: number): Observable<any[]> {
4150
return this.http.get<any[]>(this.URLConstants.reportsURL + "/flaky_tests?versionId=" + versionId, {headers: this.httpHeaders.contentTypeApplication}).pipe(
4251
map(data => data),

0 commit comments

Comments
 (0)