private List extractSurrogatesAsCustomInfoTypes()

in src/main/java/com/google/cloud/solutions/bqremoteencryptionfn/fns/dlp/DlpReIdRequestMaker.java [79:120]


  private List<CustomInfoType> extractSurrogatesAsCustomInfoTypes() {

    Function<String, CustomInfoType> makeCustomInfoType =
        (name) ->
            CustomInfoType.newBuilder()
                .setInfoType(InfoType.newBuilder().setName(name))
                .setSurrogateType(SurrogateType.newBuilder())
                .build();

    Function<FieldTransformation, List<String>> extractSurrogateFromField =
        (fieldTransformation) ->
            switch (fieldTransformation.getTransformationCase()) {
              case PRIMITIVE_TRANSFORMATION -> List.of(
                  getSurrogateInfoType(fieldTransformation.getPrimitiveTransformation()).getName());
              case INFO_TYPE_TRANSFORMATIONS -> extractSurrogateName(
                  fieldTransformation.getInfoTypeTransformations());
              case TRANSFORMATION_NOT_SET -> throwUnknownTransformationException();
            };

    Stream<String> surrogateNamesStream =
        switch (deidentifyConfig.getTransformationCase()) {
          case INFO_TYPE_TRANSFORMATIONS -> extractSurrogateName(
              deidentifyConfig.getInfoTypeTransformations())
              .stream();

          case RECORD_TRANSFORMATIONS -> deidentifyConfig
              .getRecordTransformations()
              .getFieldTransformationsList()
              .stream()
              .map(extractSurrogateFromField)
              .flatMap(List::stream);

          case IMAGE_TRANSFORMATIONS,
              TRANSFORMATION_NOT_SET -> throwUnknownTransformationException();
        };

    return surrogateNamesStream
        .distinct()
        .filter(name -> (name != null && !name.isBlank()))
        .map(makeCustomInfoType)
        .collect(toList());
  }