For a rule, I need to increase the cardinality to 5. I am unsure how to add the .map
function and downstream the data. Also, after downstream how to extract the data.
Please see the following code what I am trying to develop. The commented section inside the code I am trying to fill out the .map
and .penalizeConfigurable
section I am trying to extract it.
return constraintFactory.forEach(RuleSetting.class)
.filter(ruleSetting -> ruleSetting.getRuleName().equals("E015")&& ruleSetting.getIsActive() == true)
.join(Shift.class)
.join(ForeignerType.class)
.filter((ruleSetting, shift, foreignerType) -> shift.getEmployee().getForeignerType() != null
&& foreignerType.getForeignerType().equals(shift.getEmployee().getForeignerType())
&& shift.getWeekNo() != null
)
.groupBy((ruleSetting, shift, foreignerType)->ruleSetting,
(ruleSetting, shift, foreignerType)->shift.getEmployee(),
(ruleSetting, shift, foreignerType)->shift.getWeekNo(),
ConstraintCollectors.sumLong((ruleSetting, shift, foreignerType)->shift.getWorkMinutes()))
.filter((ruleSetting, employee, weekNo, totalDuration) -> totalDuration > employee.getContracts().getMaxMinutesPerWeek())
.map(//How to fill the map function??
)
.join(ForeignerType.class)
.penalizeConfigurable((first, foreigner)->{
//How to extract the data here.
Double result = Math.abs(((double)totalDuration / (double) employee.getContracts().getMaxMinutesPerWeek()));
result = result * Math.abs(ruleSetting.getWeight());
return result.intValue();
})
.indictWith((ruleSetting, employee, weekNo, totalDuration) ->{
EmployeeScoreKeyItems res = new EmployeeScoreKeyItems(EmployeeScoreKeyItems.KeyType.BY_WEEK,
ruleSetting.getRuleName(),
employee.getEmployeeId(),
null, null, weekNo, null);
return List.of(res);
})
.asConstraint("E015")