Skip to content

Commit

Permalink
Merge pull request #801 from catenax-ng/feature/TRACEFOSS-604-Dashboa…
Browse files Browse the repository at this point in the history
…rd-API

chore: TRACEFOSS-604 added received / sent investigation / alert count
  • Loading branch information
ds-mwesener authored Nov 28, 2023
2 parents a15a8da + 4d14730 commit 40e983c
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 47 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### Added
- Added new dashboard layout and additional widgets
- Refactored dashboard response
- Added new fields to dashboard response

## [9.0.0-rc3 - 27.11.2023]
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,9 @@ export const mockDashboardStats: DashboardStatsResponse = {
asBuiltSupplierParts: 163000,
asPlannedSupplierParts: 2563,
asBuiltOwnParts: 5300000,
asPlannedOwnParts: 11203
asPlannedOwnParts: 11203,
receivedActiveAlerts: 5000,
receivedActiveInvestigations: 2000,
sentActiveAlerts: 7000,
sentActiveInvestigations: 5
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,54 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

import { DashboardAssembler } from './dashboard.assembler';
import {DashboardAssembler} from './dashboard.assembler';

describe('DashboardAssembler', () => {
describe('assembleDashboard', () => {
it('should map response', () => {
expect(
DashboardAssembler.assembleDashboard({
asBuiltOwnParts: 200,
asBuiltCustomerParts: 0,
asBuiltSupplierParts: 10,
asPlannedCustomerParts: 0,
asPlannedOwnParts: 0,
asPlannedSupplierParts: 0,
customerPartsWithOpenAlerts: 0,
customerPartsWithOpenInvestigations: 0,
myPartsWithOpenAlerts: 0,
myPartsWithOpenInvestigations: 0,
supplierPartsWithOpenAlerts: 0,
supplierPartsWithOpenInvestigations: 0,
describe('assembleDashboard', () => {
it('should map response', () => {
expect(
DashboardAssembler.assembleDashboard({
asBuiltOwnParts: 200,
asBuiltCustomerParts: 0,
asBuiltSupplierParts: 10,
asPlannedCustomerParts: 0,
asPlannedOwnParts: 0,
asPlannedSupplierParts: 0,
customerPartsWithOpenAlerts: 0,
customerPartsWithOpenInvestigations: 0,
myPartsWithOpenAlerts: 0,
myPartsWithOpenInvestigations: 0,
supplierPartsWithOpenAlerts: 0,
supplierPartsWithOpenInvestigations: 0,
receivedActiveAlerts: 0,
receivedActiveInvestigations: 0,
sentActiveInvestigations: 0,
sentActiveAlerts: 0

}),
).toEqual({
asBuiltCustomerParts: 0,
asBuiltSupplierParts: 10,
asPlannedCustomerParts: 0,
asPlannedOwnParts: 0,
asPlannedSupplierParts: 0,
asBuiltOwnParts: 200,
}),
).toEqual({
asBuiltCustomerParts: 0,
asBuiltSupplierParts: 10,
asPlannedCustomerParts: 0,
asPlannedOwnParts: 0,
asPlannedSupplierParts: 0,
asBuiltOwnParts: 200,

totalOwnParts: 200,
totalOtherParts: 10,
totalOwnParts: 200,
totalOtherParts: 10,

ownOpenInvestigationsReceived: 0,
ownOpenInvestigationsCreated: 0,
ownOpenAlertsReceived: 0,
ownOpenAlertsCreated: 0,
ownOpenInvestigationsReceived: 0,
ownOpenInvestigationsCreated: 0,
ownOpenAlertsReceived: 0,
ownOpenAlertsCreated: 0,

myPartsWithOpenAlerts: 0,
myPartsWithOpenInvestigations: 0
});
myPartsWithOpenAlerts: 0,
myPartsWithOpenInvestigations: 0,
receivedActiveAlerts: 0,
receivedActiveInvestigations: 0,
sentActiveAlerts: 0,
sentActiveInvestigations: 0
});
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export class DashboardAssembler {
ownOpenInvestigationsCreated: dashboard.supplierPartsWithOpenInvestigations + dashboard.customerPartsWithOpenInvestigations,
ownOpenAlertsReceived: dashboard.supplierPartsWithOpenAlerts + dashboard.customerPartsWithOpenAlerts,
ownOpenAlertsCreated: dashboard.myPartsWithOpenAlerts,
receivedActiveAlerts: dashboard.receivedActiveAlerts,
sentActiveAlerts: dashboard.sentActiveAlerts,
receivedActiveInvestigations: dashboard.receivedActiveInvestigations,
sentActiveInvestigations: dashboard.sentActiveInvestigations

};
}
Expand Down
13 changes: 11 additions & 2 deletions frontend/src/app/modules/page/dashboard/model/dashboard.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ export interface DashboardStats {
ownOpenInvestigationsReceived: number,
ownOpenInvestigationsCreated: number,
ownOpenAlertsReceived: number,
ownOpenAlertsCreated: number
ownOpenAlertsCreated: number,
receivedActiveAlerts: number,
receivedActiveInvestigations: number,
sentActiveAlerts: number,
sentActiveInvestigations: number

}

Expand All @@ -57,5 +61,10 @@ export interface DashboardStatsResponse {
asBuiltSupplierParts: number,
asPlannedSupplierParts: number,
asBuiltOwnParts: number,
asPlannedOwnParts: number
asPlannedOwnParts: number,

receivedActiveAlerts: number,
receivedActiveInvestigations: number,
sentActiveAlerts: number,
sentActiveInvestigations: number
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ export class DashboardComponent implements OnInit, OnDestroy {
this.investigationsMetricData = [
{
metricName: 'amountReceived',
value: this.dashboardStats$.pipe(map(dashboardStats => dashboardStats.data.ownOpenInvestigationsReceived)),
value: this.dashboardStats$.pipe(map(dashboardStats => dashboardStats.data.receivedActiveInvestigations)),
metricUnit: 'investigations'
},
{
metricName: 'amountCreated',
value: this.dashboardStats$.pipe(map(dashboardStats => dashboardStats.data.ownOpenInvestigationsCreated)),
value: this.dashboardStats$.pipe(map(dashboardStats => dashboardStats.data.sentActiveInvestigations)),
metricUnit: 'investigations'
}
];
Expand All @@ -109,12 +109,12 @@ export class DashboardComponent implements OnInit, OnDestroy {
this.alertsMetricData = [
{
metricName: 'amountReceived',
value: this.dashboardStats$.pipe(map(dashboardStats => dashboardStats.data.ownOpenAlertsReceived)),
value: this.dashboardStats$.pipe(map(dashboardStats => dashboardStats.data.receivedActiveAlerts)),
metricUnit: 'alerts'
},
{
metricName: 'amountCreated',
value: this.dashboardStats$.pipe(map(dashboardStats => dashboardStats.data.ownOpenAlertsCreated)),
value: this.dashboardStats$.pipe(map(dashboardStats => dashboardStats.data.sentActiveAlerts)),
metricUnit: 'alerts'
}
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ public static DashboardResponse from(final Dashboard dashboard) {
dashboard.getSupplierPartsWithOpenAlerts(),
dashboard.getCustomerPartsWithOpenAlerts(),
dashboard.getSupplierPartsWithOpenInvestigations(),
dashboard.getCustomerPartsWithOpenInvestigations()
dashboard.getCustomerPartsWithOpenInvestigations(),
dashboard.getReceivedActiveAlerts(),
dashboard.getReceivedActiveInvestigations(),
dashboard.getSentActiveAlerts(),
dashboard.getSentActiveInvestigations()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ public class Dashboard {
long customerPartsWithOpenAlerts;
long supplierPartsWithOpenInvestigations;
long customerPartsWithOpenInvestigations;
long receivedActiveAlerts;
long receivedActiveInvestigations;
long sentActiveAlerts;
long sentActiveInvestigations;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.tractusx.traceability.assets.domain.dashboard.model.Dashboard;
import org.eclipse.tractusx.traceability.qualitynotification.domain.base.AlertRepository;
import org.eclipse.tractusx.traceability.qualitynotification.domain.base.InvestigationRepository;
import org.eclipse.tractusx.traceability.qualitynotification.domain.base.model.QualityNotificationSide;
import org.springframework.stereotype.Component;

import java.util.List;
Expand Down Expand Up @@ -62,6 +63,12 @@ public Dashboard getDashboard() {
long customerPartsWithOpenReceivedAlerts = alertRepository.countOpenNotificationsByOwnership(List.of(Owner.CUSTOMER));
long customerPartsWithOpenSentInvestigations = investigationsRepository.countOpenNotificationsByOwnership(List.of(Owner.CUSTOMER));

long receivedActiveInvestigations = investigationsRepository.countQualityNotificationEntitiesBySide(QualityNotificationSide.RECEIVER);
long sentActiveInvestigations = investigationsRepository.countQualityNotificationEntitiesBySide(QualityNotificationSide.SENDER);

long receivedActiveAlerts = alertRepository.countQualityNotificationEntitiesBySide(QualityNotificationSide.RECEIVER);
long sentActiveAlerts = alertRepository.countQualityNotificationEntitiesBySide(QualityNotificationSide.SENDER);

return Dashboard.builder()
.asBuiltCustomerParts(asBuiltCustomerParts)
.asPlannedCustomerParts(asPlannedCustomerParts)
Expand All @@ -75,6 +82,10 @@ public Dashboard getDashboard() {
.customerPartsWithOpenAlerts(customerPartsWithOpenReceivedAlerts)
.supplierPartsWithOpenInvestigations(supplierPartsWithOpenSentInvestigations)
.customerPartsWithOpenInvestigations(customerPartsWithOpenSentInvestigations)
.receivedActiveAlerts(receivedActiveAlerts)
.receivedActiveInvestigations(receivedActiveInvestigations)
.sentActiveAlerts(sentActiveAlerts)
.sentActiveInvestigations(sentActiveInvestigations)
.build();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ public interface QualityNotificationRepository {
PageResult<QualityNotification> getNotifications(Pageable pageable, SearchCriteria searchCriteria);

long countOpenNotificationsByOwnership(List<Owner> owners);

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ void dashboard() {
.customerPartsWithOpenAlerts(1111L)
.supplierPartsWithOpenInvestigations(1111L)
.customerPartsWithOpenInvestigations(1111L)
.sentActiveInvestigations(5000L)
.sentActiveAlerts(2000L)
.receivedActiveInvestigations(2500L)
.receivedActiveAlerts(3000L)
.build();
Mockito.when(dashboardService.getDashboard()).thenReturn(dashboard);
Dashboard testDashboard = dashboardService.getDashboard();
Expand All @@ -67,6 +71,11 @@ void dashboard() {
assertEquals(1111, testDashboard.getCustomerPartsWithOpenAlerts());
assertEquals(1111, testDashboard.getSupplierPartsWithOpenInvestigations());
assertEquals(1111, testDashboard.getCustomerPartsWithOpenInvestigations());
assertEquals(5000, testDashboard.getSentActiveInvestigations());
assertEquals(2000, testDashboard.getSentActiveAlerts());
assertEquals(3000, testDashboard.getReceivedActiveAlerts());
assertEquals(2500, testDashboard.getReceivedActiveInvestigations());

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ void givenRoles_whenGetDashboard_thenReturnResponse(final List<JwtRole> roles) t
.body("supplierPartsWithOpenAlerts", equalTo(0))
.body("customerPartsWithOpenAlerts", equalTo(0))
.body("supplierPartsWithOpenInvestigations", equalTo(0))
.body("customerPartsWithOpenInvestigations", equalTo(0));
.body("customerPartsWithOpenInvestigations", equalTo(0))
.body("receivedActiveAlerts", equalTo(0))
.body("receivedActiveInvestigations", equalTo(0))
.body("sentActiveAlerts", equalTo(0))
.body("sentActiveInvestigations", equalTo(0));
}

@Test
Expand Down Expand Up @@ -134,7 +138,11 @@ void givenAlertsWithAssets_whenGetDashboard_thenReturnResponse() throws JoseExce
.body("supplierPartsWithOpenAlerts", equalTo(12))
.body("customerPartsWithOpenAlerts", equalTo(0))
.body("supplierPartsWithOpenInvestigations", equalTo(0))
.body("customerPartsWithOpenInvestigations", equalTo(0));
.body("customerPartsWithOpenInvestigations", equalTo(0))
.body("receivedActiveAlerts", equalTo(2))
.body("receivedActiveInvestigations", equalTo(0))
.body("sentActiveAlerts", equalTo(0))
.body("sentActiveInvestigations", equalTo(0));
}

@Test
Expand Down Expand Up @@ -192,7 +200,11 @@ void givenPendingInvestigation_whenGetDashboard_thenReturnPendingInvestigation()
.body("supplierPartsWithOpenAlerts", equalTo(0))
.body("customerPartsWithOpenAlerts", equalTo(0))
.body("supplierPartsWithOpenInvestigations", equalTo(1))
.body("customerPartsWithOpenInvestigations", equalTo(0));
.body("customerPartsWithOpenInvestigations", equalTo(0))
.body("receivedActiveAlerts", equalTo(0))
.body("receivedActiveInvestigations", equalTo(1))
.body("sentActiveAlerts", equalTo(0))
.body("sentActiveInvestigations", equalTo(1));
}

private static Stream<Arguments> roles() {
Expand Down
15 changes: 14 additions & 1 deletion tx-models/src/main/java/assets/response/DashboardResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ public record DashboardResponse(
@ApiModelProperty(example = "2")
Long supplierPartsWithOpenInvestigations,
@ApiModelProperty(example = "2")
Long customerPartsWithOpenInvestigations) {
Long customerPartsWithOpenInvestigations,

@ApiModelProperty(example = "2")
Long receivedActiveAlerts,

@ApiModelProperty(example = "2")
Long receivedActiveInvestigations,

@ApiModelProperty(example = "2")
Long sentActiveAlerts,

@ApiModelProperty(example = "2")
Long sentActiveInvestigations) {


}

0 comments on commit 40e983c

Please sign in to comment.