Skip to content
This repository has been archived by the owner on Jan 20, 2025. It is now read-only.

Commit

Permalink
Merge branch 'Demo_branch_new' of https://github.com/catenax-ng/tx-de…
Browse files Browse the repository at this point in the history
…mand-capacity-mgmt into Demo_branch_new
  • Loading branch information
Ruskyy committed Jan 29, 2024
2 parents 70c2143 + d46f129 commit e887213
Showing 1 changed file with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ public MaterialDemandResponse updateDemand(
) {
MaterialDemandEntity demand = convertDtoToEntity(materialDemandRequest, demandId);
List<MaterialDemandEntity> oldMaterialDemands = new ArrayList<>(materialDemandRepository.findAll());
List<MaterialDemandEntity> newMaterialDemands = new ArrayList<>();
demand.setId(UUID.fromString(demandId));

for (MaterialDemandEntity materialDemandEntity : oldMaterialDemands) {
Expand All @@ -146,9 +145,6 @@ public MaterialDemandResponse updateDemand(
updateMaterial.setLinkStatus(materialDemandEntity.getLinkStatus());
demand.setLinkStatus(materialDemandEntity.getLinkStatus());
updateMaterial.setId(materialDemandEntity.getId());
newMaterialDemands.add(updateMaterial);
} else {
newMaterialDemands.add(materialDemandEntity);
}
}
linkedCapacityGroupMaterialDemandRepository
Expand Down Expand Up @@ -181,6 +177,8 @@ public MaterialDemandResponse updateDemand(
private void triggerDemandAlertsIfNeeded(String demandId, String userID, MaterialDemandEntity demand) {
List<Double> oldDemandValues = new ArrayList<>(List.of());
List<Double> newDemandValues = new ArrayList<>(List.of());
Map<UUID, List<Double>> oldDemandValuesMap = new HashMap<>();
Map<UUID, List<Double>> newDemandValuesMap = new HashMap<>();

demand
.getDemandSeries()
Expand All @@ -193,6 +191,8 @@ private void triggerDemandAlertsIfNeeded(String demandId, String userID, Materia
newDemandValues.add(demandSeriesValues.getDemand());
}
);
newDemandValuesMap.put(demandSeries.getDemandCategory().getId(), newDemandValues.stream().toList());
newDemandValues.clear();
}
);

Expand All @@ -209,21 +209,30 @@ private void triggerDemandAlertsIfNeeded(String demandId, String userID, Materia
oldDemandValues.add(demandSeriesValues.getDemand());
}
);
oldDemandValuesMap.put(
demandSeries1.getDemandCategory().getId(),
oldDemandValues.stream().toList()
);
oldDemandValues.clear();
}
);

int minSize = Math.min(oldDemandValues.size(), newDemandValues.size());
for (int i = 0; i < minSize; i++) {
if (!Objects.equals(oldDemandValues.get(i), newDemandValues.get(i))) {
alertService.triggerDemandAlertsIfNeeded(
userID,
true,
oldDemandValues.get(i),
newDemandValues.get(i),
demandId
);
newDemandValuesMap.forEach(
(newDemandKey, newValuesArray) -> {
int minSize = Math.min(newValuesArray.size(), oldDemandValuesMap.get(newDemandKey).size());
for (int i = 0; i < minSize; i++) {
if (!Objects.equals(oldDemandValuesMap.get(newDemandKey).get(i), newValuesArray.get(i))) {
alertService.triggerDemandAlertsIfNeeded(
userID,
true,
oldDemandValuesMap.get(newDemandKey).get(i),
newValuesArray.get(i),
demandId
);
}
}
}
}
);
}

private List<MaterialDemandEntity> getAllDemands() {
Expand Down Expand Up @@ -483,6 +492,7 @@ private MaterialDemandEntity convertDtoToEntity(MaterialDemandRequest materialDe
DemandCategoryEntity demandCategory = demandCategoryService.findById(
UUIDUtil.generateUUIDFromString(materialDemandSeries.getDemandCategoryId())
);
materialDemandSeries.setId(materialDemandSeries.getDemandCategoryId());
return enrichDemandSeries(materialDemandSeries, customerEntity, demandCategory);
}
)
Expand Down Expand Up @@ -513,6 +523,7 @@ private DemandSeries enrichDemandSeries(
return DemandSeries
.builder()
.expectedSupplierLocation(materialDemandSeries.getExpectedSupplierLocationId())
.id(UUID.fromString(materialDemandSeries.getId()))
.customerLocation(customerEntity)
.demandCategory(demandCategory)
.demandSeriesValues(demandSeriesValues)
Expand Down

0 comments on commit e887213

Please sign in to comment.