public ElementViolationImpl build() { if (Objects.isNull(type)) { setType(ValidationUtils.getMaxSeverity(new LinkedHashSet<org.kie.workbench.common.stunner.core.validation.Violation>() {{ Optional.ofNullable(graphViolations).ifPresent(v -> addAll(v)); Optional.ofNullable(modelViolations).ifPresent(v -> addAll(v)); Optional.ofNullable(domainViolations).ifPresent(v -> addAll(v)); }})); } return new ElementViolationImpl(uuid, graphViolations, modelViolations, domainViolations, type); } }
public static ValidationFailedNotification build(final ClientTranslationService translationService, final NotificationContext context, final Collection<DiagramElementViolation<RuleViolation>> errors) { final Violation.Type type = ValidationUtils.getMaxSeverity(errors); return new ValidationFailedNotification(errors, context, CoreTranslationMessages.getDiagramValidationsErrorMessage( translationService, CoreTranslationMessages.VALIDATION_FAILED, errors ), getNotificationType(type)); }
@Test @SuppressWarnings("unchecked") public void testGetMaxSeverity() { when(violation1.getViolationType()).thenReturn(Violation.Type.INFO); when(violation2.getViolationType()).thenReturn(Violation.Type.WARNING); when(violation3.getViolationType()).thenReturn(Violation.Type.ERROR); assertEquals(Violation.Type.ERROR, ValidationUtils.getMaxSeverity(violations)); when(violation3.getViolationType()).thenReturn(Violation.Type.INFO); assertEquals(Violation.Type.WARNING, ValidationUtils.getMaxSeverity(violations)); when(violation1.getViolationType()).thenReturn(Violation.Type.ERROR); assertEquals(Violation.Type.ERROR, ValidationUtils.getMaxSeverity(violations)); } }