# Mon, 22 Dec 2025 14:57:12 GMT
---
version: 23
data:


- type: ModificationMethod
  attributes:
    displayName: Pattern
    description: |
          Generates a sequence of letters and digits according to a pattern. The letter A is replaced by a letter between A and Z. The digit 9 is replaced by a digit between 0 and 9. The letter N is replaced by either a letter or a digit. The letter X is replaced by a hexadecimal digit (0 through F). All other characters are preserved as they are.
    inputType: COLUMN
    mappingTableContainers: []
    mappingTableAccessMode: READ
    code: |
        /*
         * *****************************************************************************
         * Pattern
         * *****************************************************************************
         *
         * The following variables are available in this script:
         * =====================================================
         * ctx             : A context object that offers a number of methods.
         *                   The method indexOf() can be used to get the index of a
         *                   specific column within the dataArray.
         * dataArray       : The data array. This array contains the contents of all
         *                   columns of the current row of the table that is being
         *                   masked by this method.
         *
         * Additionally for column based modification methods the following two
         * variables are available:
         * columnName      : The name of the column that matched the pattern.
         * columnIndex     : The position of the column that matched the pattern within
         *                   the data array. This value is zero-based.
         * *****************************************************************************
         */
        importClass(Packages.de.ubs.xdm3.batch.modification.HashUtils);
        importClass(Packages.de.ubs.xdm3.batch.modification.ModificationException);
        
        
        /*
         * This function is called once before the processing starts. The method
         * is called once per table.
         */
        function init() {
        
        }
        
        /*
         * This function should modify the row that is provided by the dataArray. The
         * method is called for each single row of the table.
         */
        function apply() {
            var seedValue = "";
        
            if (ctx.indexOf(seed) != -1) {
                seedValue = dataArray[ctx.indexOf(seed)];
            } else {
                if (seed == "RAND") {
                    seedValue = Math.floor(Math.random() * 1000000000);
                } else {
                    seedValue = seed;
                }
            }
        
            var ALNUM = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXZY";
            var ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXZY";
            var DIGITS = "0123456789";
            var HEX = "0123456789ABCDEF";
            var value = new java.lang.String(seedValue).trim();
            var h = HashUtils.hashStringLikeInt(value);
            h = HashUtils.hashInt(h);
            var r = "";
            for (var i = 0; i < pattern.length; i++) {
                var c = pattern.charAt(i);
                if (c == '9') {
                    r = r + DIGITS.charAt(h % DIGITS.length);
                } else if (c == 'A') {
                    r = r + ALPHABET.charAt(h % ALPHABET.length);
                } else if (c == 'X') {
                    r = r + HEX.charAt(h % HEX.length);
                } else if (c == 'N') {
                    r = r + ALNUM.charAt(h % ALNUM.length);
                } else {
                    r = r + c;
                }
                h = HashUtils.hashInt(h);
            }
            dataArray[columnIndex] = r;
        }
        
        /*
         * This function is executed once after the modification of a table is complete. The method
         * is called once per table.
         */
        function close() {
        }
    parameters:
    - displayName: Seed
      description: |
          Specifies the value that is used to calculate the hash.
      variableName: seed
      dataType: STRING
    - displayName: Pattern
      description: |
          The pattern string based upon which the resulting sequence of letters and digits will be calculated.
      variableName: pattern
      dataType: STRING
