<?xml version="1.0" encoding="UTF-8"?>
<pipeline>
  <info>
    <name>citizen_appealing_violations_fz53_flow_delta</name>
    <name_sync_with_filename>Y</name_sync_with_filename>
    <description/>
    <extended_description/>
    <pipeline_version/>
    <pipeline_type>Normal</pipeline_type>
    <parameters>
    </parameters>
    <capture_transform_performance>N</capture_transform_performance>
    <transform_performance_capturing_delay>1000</transform_performance_capturing_delay>
    <transform_performance_capturing_size_limit>100</transform_performance_capturing_size_limit>
    <created_user>-</created_user>
    <created_date>2025/08/11 13:22:56.048</created_date>
    <modified_user>-</modified_user>
    <modified_date>2025/08/11 13:22:56.048</modified_date>
  </info>
  <notepads>
  </notepads>
  <order>
    <hop>
      <from>update_job_execution_record_CAV</from>
      <to>table_input_CAV</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>detect_empty_stream_CAV</from>
      <to>change_job_status_on_success_CAV</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>filter_last_row_CAV</from>
      <to>change_job_status_on_success_CAV</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>change_job_status_on_error_CAV</from>
      <to>abort_CAV</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>upsert_CAV</from>
      <to>change_job_status_on_error_CAV</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>update_CAV</from>
      <to>change_job_status_on_error_CAV</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>table_input_CAV</from>
      <to>identify_last_row_CAV</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>identify_last_row_CAV</from>
      <to>upsert_CAV</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>identify_last_row_CAV</from>
      <to>detect_empty_stream_CAV</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>upsert_CAV</from>
      <to>filter_last_row_CAV</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>filter_true_appeal_violations</from>
      <to>sort_rows_CAV</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>identify_last_row_CAV</from>
      <to>filter_true_appeal_violations</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>sort_rows_CAV</from>
      <to>update_CAV</to>
      <enabled>Y</enabled>
    </hop>
  </order>
  <transform>
    <name>abort_CAV</name>
    <type>Abort</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <abort_option>ABORT_WITH_ERROR</abort_option>
    <always_log_rows>Y</always_log_rows>
    <row_threshold>0</row_threshold>
    <attributes/>
    <GUI>
      <xloc>1472</xloc>
      <yloc>384</yloc>
    </GUI>
  </transform>
  <transform>
    <name>change_job_status_on_error_CAV</name>
    <type>ExecSql</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <arguments>
      <argument>
        <name>error_description</name>
      </argument>
    </arguments>
    <connection>ervu-dashboard</connection>
    <execute_each_row>Y</execute_each_row>
    <quoteString>N</quoteString>
    <replace_variables>Y</replace_variables>
    <set_params>Y</set_params>
    <single_statement>N</single_statement>
    <sql>UPDATE etl.job_execution
SET status = 'DELTA_ERROR',
    error_description = ?,
    execution_end_datetime = current_timestamp
WHERE job_name = '${JOB_NAME}' 
and recruitment_id = '${IDM_ID}';

</sql>
    <attributes/>
    <GUI>
      <xloc>1312</xloc>
      <yloc>384</yloc>
    </GUI>
  </transform>
  <transform>
    <name>change_job_status_on_success_CAV</name>
    <type>ExecSql</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <arguments>
</arguments>
    <connection>ervu-dashboard</connection>
    <execute_each_row>Y</execute_each_row>
    <quoteString>N</quoteString>
    <replace_variables>Y</replace_variables>
    <set_params>N</set_params>
    <single_statement>N</single_statement>
    <sql>UPDATE etl.job_execution
SET status = 'DELTA_SUCCESS',
    execution_end_datetime = current_timestamp
WHERE job_name = '${JOB_NAME}'
and recruitment_id = '${IDM_ID}';

</sql>
    <attributes/>
    <GUI>
      <xloc>1472</xloc>
      <yloc>80</yloc>
    </GUI>
  </transform>
  <transform>
    <name>detect_empty_stream_CAV</name>
    <type>DetectEmptyStream</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <attributes/>
    <GUI>
      <xloc>736</xloc>
      <yloc>80</yloc>
    </GUI>
  </transform>
  <transform>
    <name>filter_last_row_CAV</name>
    <type>FilterRows</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <compare>
      <condition>
        <conditions>
</conditions>
        <function>=</function>
        <leftvalue>last_row</leftvalue>
        <negated>N</negated>
        <operator>-</operator>
        <value>
          <isnull>N</isnull>
          <length>-1</length>
          <name>constant</name>
          <precision>-1</precision>
          <text>Y</text>
          <type>Boolean</type>
        </value>
      </condition>
    </compare>
    <send_true_to>change_job_status_on_success_CAV</send_true_to>
    <attributes/>
    <GUI>
      <xloc>1472</xloc>
      <yloc>224</yloc>
    </GUI>
  </transform>
  <transform>
    <name>filter_true_appeal_violations</name>
    <type>FilterRows</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <compare>
      <condition>
        <conditions>
</conditions>
        <function>=</function>
        <leftvalue>has_appealing_violations_fz53</leftvalue>
        <negated>N</negated>
        <operator>-</operator>
        <value>
          <isnull>N</isnull>
          <length>-1</length>
          <name>constant</name>
          <precision>-1</precision>
          <text>Y</text>
          <type>Boolean</type>
        </value>
      </condition>
    </compare>
    <send_true_to>sort_rows_CAV</send_true_to>
    <attributes/>
    <GUI>
      <xloc>736</xloc>
      <yloc>384</yloc>
    </GUI>
  </transform>
  <transform>
    <name>identify_last_row_CAV</name>
    <type>DetectLastRow</type>
    <description/>
    <distribute>N</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <resultfieldname>last_row</resultfieldname>
    <attributes/>
    <GUI>
      <xloc>736</xloc>
      <yloc>224</yloc>
    </GUI>
  </transform>
  <transform>
    <name>sort_rows_CAV</name>
    <type>SortRows</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <directory>${java.io.tmpdir}</directory>
    <prefix>out</prefix>
    <sort_size>1000000</sort_size>
    <free_memory/>
    <compress>N</compress>
    <compress_variable/>
    <unique_rows>Y</unique_rows>
    <fields>
      <field>
        <name>recruit_id</name>
        <ascending>Y</ascending>
        <case_sensitive>N</case_sensitive>
        <collator_enabled>N</collator_enabled>
        <collator_strength>0</collator_strength>
        <presorted>N</presorted>
      </field>
    </fields>
    <attributes/>
    <GUI>
      <xloc>928</xloc>
      <yloc>384</yloc>
    </GUI>
  </transform>
  <transform>
    <name>table_input_CAV</name>
    <type>TableInput</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <connection>appeal_test</connection>
    <execute_each_row>N</execute_each_row>
    <sql>SELECT ad.recruit_id,
       ad.updated_at,                                                            -- дата создания обжалования
       ad.appeal_number                                      AS appeal_number, -- номер обжалуемого решения
       ad.appeal_date                                        AS appeal_date,   -- дата обжалуемого решения
       ad.extra_info ->> 'resultNumber'                      AS decision_number,     -- номер принятого решения
       to_date(ad.extra_info ->> 'resultDate', 'YYYY-MM-DD') AS decision_date,   -- дата принятия решения
       CASE ad.extra_info ->> 'result'
           WHEN '1' THEN 'Удовлетворена'
           WHEN '2' THEN 'Частично удовлетворена'
           WHEN '3' THEN 'Отказано в удовлетворении'
           END                                               AS decision_result,   -- код рассмотрения
       ad.extra_info ->> 'commissionName'                    AS commission_name, -- наименование комиссии, принявшей решение
       ad.extra_info ->> 'reasonForAddEntry'                 AS reason,         -- основание для внесения записи
       ad.hidden,
       NOT ad.hidden                                         AS has_appealing_violations_fz53
FROM public.appeal_document ad
where ad.vk_id = '${IDM_ID}'
and case when '${MAX_UPDATE_DATE}' &lt;&gt; ''
                                     then to_date(ri.info -> 'svedFL' -> 'svedDeputat' -> 'deputat' ->> 'dataSved', 'YYYY-MM-DD') >
                                          to_date('${MAX_UPDATE_DATE}', 'YYYY-MM-DD')
                                 else true end;</sql>
    <variables_active>Y</variables_active>
    <attributes/>
    <GUI>
      <xloc>544</xloc>
      <yloc>224</yloc>
    </GUI>
  </transform>
  <transform>
    <name>update_CAV</name>
    <type>Update</type>
    <description/>
    <distribute>N</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <commit>10000</commit>
    <connection>ervu-dashboard</connection>
    <error_ignored>Y</error_ignored>
    <lookup>
      <key>
        <condition>=</condition>
        <field>recruit_id</field>
        <name>recruit_id</name>
      </key>
      <schema>ervu_dashboard</schema>
      <table>citizen</table>
      <value>
        <name>has_appealing_violations_fz53</name>
        <rename>has_appealing_violations_fz53</rename>
      </value>
    </lookup>
    <skip_lookup>N</skip_lookup>
    <use_batch>Y</use_batch>
    <attributes/>
    <GUI>
      <xloc>1088</xloc>
      <yloc>384</yloc>
    </GUI>
  </transform>
  <transform>
    <name>update_job_execution_record_CAV</name>
    <type>ExecSql</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <arguments>
</arguments>
    <connection>ervu-dashboard</connection>
    <execute_each_row>N</execute_each_row>
    <quoteString>N</quoteString>
    <replace_variables>Y</replace_variables>
    <set_params>N</set_params>
    <single_statement>N</single_statement>
    <sql>UPDATE etl.job_execution  
SET
    status = 'DELTA_PROCESSING',
    execution_datetime = DEFAULT,
    error_description = NULL
where job_name = '${JOB_NAME}'
and recruitment_id = '${IDM_ID}';</sql>
    <attributes/>
    <GUI>
      <xloc>336</xloc>
      <yloc>224</yloc>
    </GUI>
  </transform>
  <transform>
    <name>upsert_CAV</name>
    <type>InsertUpdate</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <commit>10000</commit>
    <connection>ervu_dashboard_test</connection>
    <lookup>
      <key>
        <condition>=</condition>
        <field>recruit_id</field>
        <name>recruit_id</name>
      </key>
      <key>
        <condition>=</condition>
        <field>appeal_number</field>
        <name>appeal_number</name>
      </key>
      <schema>ervu_dashboard</schema>
      <table>citizen_appealing_violations_fz53</table>
      <value>
        <name>recruit_id</name>
        <rename>recruit_id</rename>
        <update>N</update>
      </value>
      <value>
        <name>updated_at</name>
        <rename>updated_at</rename>
        <update>Y</update>
      </value>
      <value>
        <name>appeal_number</name>
        <rename>appeal_number</rename>
        <update>N</update>
      </value>
      <value>
        <name>appeal_date</name>
        <rename>appeal_date</rename>
        <update>Y</update>
      </value>
      <value>
        <name>decision_number</name>
        <rename>decision_number</rename>
        <update>Y</update>
      </value>
      <value>
        <name>decision_date</name>
        <rename>decision_date</rename>
        <update>Y</update>
      </value>
      <value>
        <name>decision_result</name>
        <rename>decision_result</rename>
        <update>Y</update>
      </value>
      <value>
        <name>commission_name</name>
        <rename>commission_name</rename>
        <update>Y</update>
      </value>
      <value>
        <name>reason</name>
        <rename>reason</rename>
        <update>Y</update>
      </value>
      <value>
        <name>hidden</name>
        <rename>hidden</rename>
        <update>Y</update>
      </value>
    </lookup>
    <update_bypassed>N</update_bypassed>
    <attributes/>
    <GUI>
      <xloc>1088</xloc>
      <yloc>224</yloc>
    </GUI>
  </transform>
  <transform_error_handling>
    <error>
      <source_transform>update_CAV</source_transform>
      <target_transform>change_job_status_on_error_CAV</target_transform>
      <is_enabled>Y</is_enabled>
      <nr_valuename/>
      <descriptions_valuename>error_description</descriptions_valuename>
      <fields_valuename/>
      <codes_valuename/>
      <max_errors/>
      <max_pct_errors/>
      <min_pct_rows/>
    </error>
    <error>
      <source_transform>upsert_CAV</source_transform>
      <target_transform>change_job_status_on_error_CAV</target_transform>
      <is_enabled>Y</is_enabled>
      <nr_valuename/>
      <descriptions_valuename>error_description</descriptions_valuename>
      <fields_valuename/>
      <codes_valuename/>
      <max_errors/>
      <max_pct_errors/>
      <min_pct_rows/>
    </error>
  </transform_error_handling>
  <attributes/>
</pipeline>
