public Set validate()

in src/main/java/com/epam/digital/data/platform/registry/regulation/validation/cli/validator/bpmn/BpAuthToBpmnRoleExistenceValidator.java [43:80]


  public Set<ValidationError> validate(RegulationFiles regulation, ValidationContext context) {
    Set<BpAuthConfiguration> processConfigs = new HashSet<>();
    Set<String> existingRoles = new HashSet<>();
    Set<ValidationError> errors = new HashSet<>();

    for (File file : regulation.getBpAuthFiles()) {
      try {
        processConfigs.add(getConfigsFromBpFile(file));
      } catch (IOException e) {
        errors.add(
            ValidationError.of(context.getRegulationFileType(), file,
                String.format("Exception during reading file %s", e.getMessage())));
      }
    }

    for (File file : regulation.getRolesFiles()) {

      try {
        existingRoles.addAll(getExistingRolesInBpFile(file));
      } catch (IOException e) {
        errors.add(
            ValidationError.of(context.getRegulationFileType(), file,
                String.format("Exception during reading file %s", e.getMessage())));
      }
    }
    if (!CollectionUtils.isEmpty(defaultRoles)) {
      existingRoles.addAll(defaultRoles);
    }
    processConfigs.forEach(config -> config.getAuthorization().getProcessDefinitions().stream()
        .flatMap(definition -> definition.getRoles().stream())
        .distinct()
        .filter(roleName -> !existingRoles.contains(roleName))
        .forEach(roleName -> errors.add(
            ValidationError.of(context.getRegulationFileType(), config.getRegulationFile(),
                String.format("Role with name : %s does not exists", roleName)))));

    return errors;
  }