---
version: 36
data:

  - type: "TaskStageHook"
    variation: null
    lastChangedDate: "2025-03-17T11:00:48"
    lastChangedBy: "andreas.kottmann"
    replacePermissions: true
    replaceObject: true
    attributes:
      code: "import org.apache.commons.codec.binary.Base64;\nimport de.ubs.xdm3.script.evaluator.ScriptValidationException;\n\
      \ndef query = \"SELECT \" + taskStageHook.blobColumn + \n            \" AS BLOBVALUE\
      \ FROM \" + taskStageHook.tableSchema + \n            \".\" + taskStageHook.tableName\
      \ + \n            \" WHERE \" + taskStageHook.condition;\n\nprint(\"Query for\
      \ BLOB is: \" + query);\n\ndef preparedStatement = taskStageHook.databaseConnection.jdbcConnection.prepareStatement(query);\n\
      def resultSet = preparedStatement.executeQuery();\n\nif (resultSet.next()) {\n\
      \    blob = resultSet.getBlob(\"BLOBVALUE\");\n    blobBytes = blob.getBinaryStream().readAllBytes();\n\
      \    base64String = Base64.encodeBase64(blobBytes);    \n    taskStageHook.outputFile.content=base64String;\n\
      } else {\n  throw new ScriptValidationException(\"No data found im query \"\
      \ + query);\n}\n\nresultSet.close();\npreparedStatement.close();\n\n\n"
      codeType: "GROOVY"
      description: null
      displayName: "BLOB example"
      libraries: []
      mappingTableAccessMode: "READ"
      mappingTableContainers: []
      parameters:
        - possibleValues: []
          displayName: "databaseConnection"
          defaultValue: null
          dataType: "CONNECTION"
          description: "Connection zur Datenbank, in der der BLOB gespeichert ist"
        - possibleValues: []
          displayName: "tableSchema"
          defaultValue: ""
          dataType: "STRING"
          description: "Schema der Tabelle, in der der BLOB gespeichert ist "
        - possibleValues: []
          displayName: "tableName"
          defaultValue: ""
          dataType: "STRING"
          description: "Name der Tabelle, in der der BLOB gespeichert ist "
        - possibleValues: []
          displayName: "blobColumn"
          defaultValue: ""
          dataType: "STRING"
          description: "Spalte, in der der BLOB liegt"
        - possibleValues: []
          displayName: "condition"
          defaultValue: ""
          dataType: "STRING"
          description: "Where Condition, um den BLOB zur ermitteln. Das WHERE ist nicht\
        \ Teil des Parameters"
        - possibleValues: []
          displayName: "outputFile"
          defaultValue: null
          dataType: "FILE"
          description: "File in XDM, in dem der BLOB gespeichert wird."
      tags: []