From d4626fad8e85593797ca5347228d80efd55bdb75 Mon Sep 17 00:00:00 2001 From: Ali Oezyetimoglu Date: Fri, 3 Nov 2023 16:58:14 +0100 Subject: [PATCH] RED-7679: Added code to detect count of rows matching type and adding component --- .../document/ComponentCreationService.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/service/document/ComponentCreationService.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/service/document/ComponentCreationService.java index c5a3a36e..49e01176 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/service/document/ComponentCreationService.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/service/document/ComponentCreationService.java @@ -299,6 +299,30 @@ public class ComponentCreationService { } + /** + * Computes the number of rows in table with values in the collection of entities and creates a component with the result. + * + * @param ruleIdentifier the identifier of the rule + * @param name the name of the record + * @param entities the collection of entities to count row values from + */ + public void rowValueCount(String ruleIdentifier, String name, Collection entities) { + + entities.stream().collect(Collectors.groupingBy(this::getFirstTable)).forEach((optionalTable, groupedEntities) -> { + + long count = groupedEntities.stream() + .filter(entity -> entity.getContainingNode() instanceof TableCell) + .collect(Collectors.groupingBy(entity -> ((TableCell) entity.getContainingNode()).getRow())) + .entrySet() + .stream() + .sorted(Comparator.comparingInt(Map.Entry::getKey)) + .map(Map.Entry::getValue) + .count(); + create(ruleIdentifier, name, String.valueOf(count), "Count rows with values in the entity references in same table", entities); + }); + } + + /** * Creates a component for each sentence in the collection of entities. *