Skip to content

Commit ea5dc8d

Browse files
Merge pull request #6965 from davidwatkins73/waltz-6963-attestation-bug
Attestation Run creation error message
2 parents de8dccc + 9ace8a0 commit ea5dc8d

1 file changed

Lines changed: 42 additions & 35 deletions

File tree

waltz-data/src/main/java/org/finos/waltz/data/attestation/AttestationRunDao.java

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.jooq.Select;
4444
import org.jooq.SelectHavingStep;
4545
import org.jooq.impl.DSL;
46+
import org.jooq.lambda.tuple.Tuple2;
4647
import org.springframework.beans.factory.annotation.Autowired;
4748
import org.springframework.stereotype.Repository;
4849

@@ -52,6 +53,7 @@
5253
import java.util.Map;
5354
import java.util.Optional;
5455
import java.util.Set;
56+
import java.util.stream.Collectors;
5557

5658
import static java.util.Collections.emptyList;
5759
import static org.finos.waltz.common.Checks.checkNotNull;
@@ -62,6 +64,7 @@
6264
import static org.finos.waltz.schema.tables.AttestationInstance.ATTESTATION_INSTANCE;
6365
import static org.finos.waltz.schema.tables.AttestationInstanceRecipient.ATTESTATION_INSTANCE_RECIPIENT;
6466
import static org.finos.waltz.schema.tables.AttestationRun.ATTESTATION_RUN;
67+
import static org.jooq.lambda.tuple.Tuple.tuple;
6568

6669
@Repository
6770
public class AttestationRunDao {
@@ -308,51 +311,55 @@ public int updateRecipientInvolvementGroupId(long attestationRunId, Long recipie
308311
public Set<AttestationRunRecipient> findRunRecipients(long runId) {
309312

310313
Field<Boolean> isPendingField = DSL
311-
.nvl2(
312-
ATTESTATION_INSTANCE.ATTESTED_AT,
313-
DSL.value(false),
314-
DSL.value(true))
315-
.as("isPending");
314+
.when(ATTESTATION_INSTANCE.ATTESTED_AT.isNull(), DSL.value(false))
315+
.otherwise(DSL.value(true));
316316

317-
SelectHavingStep<Record3<String, Boolean, Integer>> qry = dsl
317+
SelectHavingStep<Record3<String, Boolean, Long>> qry = dsl
318318
.select(ATTESTATION_INSTANCE_RECIPIENT.USER_ID,
319-
isPendingField,
320-
DSL.count())
319+
isPendingField.as("is_pending_field"),
320+
ATTESTATION_INSTANCE.ID)
321321
.from(ATTESTATION_RUN)
322322
.innerJoin(ATTESTATION_INSTANCE)
323323
.on(ATTESTATION_INSTANCE.ATTESTATION_RUN_ID.eq(ATTESTATION_RUN.ID))
324324
.innerJoin(ATTESTATION_INSTANCE_RECIPIENT)
325325
.on(ATTESTATION_INSTANCE_RECIPIENT.ATTESTATION_INSTANCE_ID.eq(ATTESTATION_INSTANCE.ID))
326-
.where(ATTESTATION_RUN.ID.eq(runId))
327-
.groupBy(ATTESTATION_INSTANCE_RECIPIENT.USER_ID, isPendingField);
326+
.where(ATTESTATION_RUN.ID.eq(runId));
328327

329328
Map<String, ImmutableAttestationRunRecipient> recipientsByUserId = new HashMap<>();
330329

331-
qry.fetch().forEach(r -> {
332-
String userId = r.get(ATTESTATION_INSTANCE_RECIPIENT.USER_ID);
333-
boolean isPending = r.get(isPendingField);
334-
int count = r.get(DSL.count());
335-
336-
ImmutableAttestationRunRecipient recipient = recipientsByUserId.getOrDefault(
337-
userId,
338-
ImmutableAttestationRunRecipient.builder()
339-
.userId(userId)
340-
.pendingCount(0)
341-
.completedCount(0)
342-
.build());
343-
344-
if (isPending) {
345-
recipient = ImmutableAttestationRunRecipient
346-
.copyOf(recipient)
347-
.withPendingCount(count);
348-
} else {
349-
recipient = ImmutableAttestationRunRecipient
350-
.copyOf(recipient)
351-
.withCompletedCount(count);
352-
}
353-
354-
recipientsByUserId.put(userId, recipient);
355-
});
330+
Map<Tuple2<String, Boolean>, Long> attestationInfo = qry
331+
.fetchSet(r -> r)
332+
.stream()
333+
.collect(Collectors.groupingBy(
334+
r -> tuple(r.get(ATTESTATION_INSTANCE_RECIPIENT.USER_ID), r.get("is_pending_field", Boolean.class)),
335+
Collectors.counting()));
336+
337+
attestationInfo
338+
.forEach((key, value) -> {
339+
String userId = key.v1;
340+
boolean isPending = key.v2;
341+
long count = value;
342+
343+
ImmutableAttestationRunRecipient recipient = recipientsByUserId.getOrDefault(
344+
userId,
345+
ImmutableAttestationRunRecipient.builder()
346+
.userId(userId)
347+
.pendingCount(0)
348+
.completedCount(0)
349+
.build());
350+
351+
if (isPending) {
352+
recipient = ImmutableAttestationRunRecipient
353+
.copyOf(recipient)
354+
.withPendingCount(count);
355+
} else {
356+
recipient = ImmutableAttestationRunRecipient
357+
.copyOf(recipient)
358+
.withCompletedCount(count);
359+
}
360+
361+
recipientsByUserId.put(userId, recipient);
362+
});
356363

357364
return SetUtilities.fromCollection(recipientsByUserId.values());
358365
}

0 commit comments

Comments
 (0)