in services/src/main/java/org/apache/unomi/services/impl/segments/SegmentServiceImpl.java [924:977]
public void recalculatePastEventConditions() {
Set<String> segmentOrScoringIdsToReevaluate = new HashSet<>();
// reevaluate auto generated rules used to store the event occurrence count on the profile
for (Rule rule : rulesService.getAllRules()) {
if (rule.getActions() != null && !rule.getActions().isEmpty()) {
for (Action action : rule.getActions()) {
if (action.getActionTypeId().equals("setEventOccurenceCountAction")) {
Condition pastEventCondition = (Condition) action.getParameterValues().get("pastEventCondition");
if (pastEventCondition.containsParameter("numberOfDays")) {
recalculatePastEventOccurrencesOnProfiles(rule.getCondition(), pastEventCondition, true, true);
LOGGER.info("Event occurrence count on profiles updated for rule: {}", rule.getItemId());
if (rule.getLinkedItems() != null && rule.getLinkedItems().size() > 0) {
segmentOrScoringIdsToReevaluate.addAll(rule.getLinkedItems());
}
}
}
}
}
}
int pastEventSegmentsAndScoringsSize = segmentOrScoringIdsToReevaluate.size();
LOGGER.info("Found {} segments or scoring plans containing pastEventCondition conditions", pastEventSegmentsAndScoringsSize);
// get Segments and Scoring that contains relative date expressions
segmentOrScoringIdsToReevaluate.addAll(allSegments.stream()
.filter(segment -> segment.getCondition() != null && segment.getCondition().toString().contains("propertyValueDateExpr"))
.map(Item::getItemId)
.collect(Collectors.toList()));
segmentOrScoringIdsToReevaluate.addAll(allScoring.stream()
.filter(scoring -> scoring.getElements() != null && !scoring.getElements().isEmpty() && scoring.getElements().stream()
.anyMatch(scoringElement -> scoringElement != null && scoringElement.getCondition() != null && scoringElement.getCondition().toString().contains("propertyValueDateExpr")))
.map(Item::getItemId)
.collect(Collectors.toList()));
LOGGER.info("Found {} segments or scoring plans containing date relative expressions", segmentOrScoringIdsToReevaluate.size() - pastEventSegmentsAndScoringsSize);
// reevaluate segments and scoring.
if (!segmentOrScoringIdsToReevaluate.isEmpty()) {
persistenceService.refreshIndex(Profile.class, null);
for (String linkedItem : segmentOrScoringIdsToReevaluate) {
Segment linkedSegment = getSegmentDefinition(linkedItem);
if (linkedSegment != null) {
LOGGER.info("Start segment recalculation for segment: {} - {}", linkedSegment.getItemId(), linkedSegment.getMetadata().getName());
updateExistingProfilesForSegment(linkedSegment);
continue;
}
Scoring linkedScoring = getScoringDefinition(linkedItem);
if (linkedScoring != null) {
LOGGER.info("Start scoring plan recalculation for scoring plan: {} - {}", linkedScoring.getItemId(), linkedScoring.getMetadata().getName());
updateExistingProfilesForScoring(linkedScoring.getItemId(), linkedScoring.getElements(), linkedScoring.getMetadata().isEnabled());
}
}
}
}