# Thu, 20 Aug 2026 13:11:52 GMT
---
version: 23
data:


- type: ModificationMethod
  attributes:
    displayName: UUID
    description: |
          Generates a version 4 universally unique identifier (UUID) based on the specified seed value. 
    scriptLanguage: "GROOVY"
    legacyScript: false
    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 data.
         * data       : 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.
         * *****************************************************************************
         */
        
        import de.ubs.xdm3.batch.modification.HashUtils
        
        /*
         * This function is called once before the processing starts. The method
         * is called once per table.
         */
        def init() {
        
        }
        
        /*
         * This function should modify the row that is provided by the data. The
         * method is called for each single row of the table.
         */
        def apply() {
            def seedValue = seedValue = modificationMethod.seed
            def value = seedValue.toString().trim()
            def h0 = HashUtils.hashStringLikeInt(value)
            def h1 = HashUtils.hashInt(h0)
            def h2 = HashUtils.hashInt(h1)
            def h3 = HashUtils.hashInt(h2)
            def h4 = HashUtils.hashInt(h3)
        
            def h3Left = ((h3 >> 16) & 0xBFFF) | 0x8000
            def h3Right = h3 & 0xFFFF
        
            def s1 = Integer.toHexString(h4)
            def s2 = Integer.toHexString(h1)
            def s3Left = Integer.toHexString(h3Left)
            def s3Right = Integer.toHexString(h3Right)
            def s4 = Integer.toHexString(h2)
        
            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
        
            def r = s1 + "-" + s2.substring(0, 4) + "-4" + s2.substring(5, 8) + "-" + s3Left + "-" + s3Right + s4
            data[columnIndex] = r.toUpperCase()
            return true
        }
        
        /*
         * This function is executed once after the modification of a table is complete. The method
         * is called once per table.
         */
        def close() {
        }
    parameters:
    - displayName: Seed
      description: |
          Specifies the value that is used to calculate the hash.
      variableName: seed
      dataType: STRING
