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


- type: ModificationMethod
  attributes:
    displayName: UUID
    description: |
          Generates a version 4 universally unique identifier (UUID) based on the seed parameter. 'RAND' will generate a random value. All other values are used as they are for the seed.
    inputType: COLUMN
    mappingTableContainers: []
    mappingTableAccessMode: READ
    code: |
        /*
         * *****************************************************************************
         * UUID
         * *****************************************************************************
         *
         * 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 value = new java.lang.String(seedValue).trim();
            var h0 = HashUtils.hashStringLikeInt(value);
            var h1 = HashUtils.hashInt(h0);
            var h2 = HashUtils.hashInt(h1);
            var h3 = HashUtils.hashInt(h2);
            var h4 = HashUtils.hashInt(h3);
            var h3Left = ((h3 >> 16) & 0xBFFF) | 0x8000;
            var h3Right = h3 & 0xFFFF;
            var s1 = h4.toString(16);
            var s2 = h1.toString(16);
            var s3Left = h3Left.toString(16);
            var s3Right = h3Right.toString(16);
            var s4 = h2.toString(16);
            while (s1.length < 8) s1 = "0" + s1;
            while (s2.length < 8) s2 = "0" + s2;
            while (s3Left.length < 4) s3Left = "0" + s3Left;
            while (s3Right.length < 4) s3Right = "0" + s3Right;
            while (s4.length < 8) s4 = "0" + s4;
            r = s1 + "-" + s2.substring(0, 4) + "-4" + s2.substring(5, 8) + "-" + s3Left + "-" + s3Right + s4;
            dataArray[columnIndex] = r.toUpperCase();
        }
        
        /*
         * 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
