CREATE TABLE ohrm_external_integration_process (
  id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(255) NOT NULL,
  configuration MEDIUMTEXT,
  parameters MEDIUMTEXT,
  isConsumer tinyint DEFAULT '0' NOT NULL,
  enabled tinyint DEFAULT '0' NOT NULL
) ENGINE = INNODB DEFAULT CHARSET=utf8;

CREATE TABLE ohrm_external_integration_schema_rule (
  id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(255) NOT NULL,
  configuration MEDIUMTEXT,
  enabled tinyint DEFAULT '0' NOT NULL
) ENGINE = INNODB DEFAULT CHARSET=utf8;

CREATE TABLE `ohrm_external_integration_process_execution_history` (
    `id` INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `integration_id` INT NOT NULL,
    `start_time_stamp` datetime,
    `success` TINYINT(1)
) ENGINE = INNODB DEFAULT CHARSET=utf8;

INSERT INTO `ohrm_data_group` (`name`, `description`, `can_read`, `can_create`, `can_update`, `can_delete`) VALUES
('integration_data_export', 'Integration - Data Export', 1, 0, 0, 0);

SET @integration_data_export := (SELECT id FROM ohrm_data_group WHERE name = 'integration_data_export');

INSERT INTO `ohrm_user_role_data_group` (`user_role_id`, `data_group_id`, `can_read`, `can_create`, `can_update`, `can_delete`, `self`)  (SELECT id, @integration_data_export , 1 ,0 , 0, 0, 0 FROM ohrm_user_role WHERE name = 'Admin');

INSERT INTO `ohrm_data_group` (`name`, `description`, `can_read`, `can_create`, `can_update`, `can_delete`) VALUES
('integration_data_import', 'Integration - Data Import', 0, 1, 0, 0);

SET @integration_data_import := (SELECT id FROM ohrm_data_group WHERE name = 'integration_data_import');

INSERT INTO `ohrm_user_role_data_group` (`user_role_id`, `data_group_id`, `can_read`, `can_create`, `can_update`, `can_delete`, `self`)  (SELECT id, @integration_data_import , 0 ,1 , 0, 0, 0 FROM ohrm_user_role WHERE name = 'Admin');

INSERT INTO `ohrm_external_integration_schema_rule` (`name`, `configuration`, `enabled`) VALUES ('Core_integration_mediator_rules','{
  "IntegrationProcessCoordinators": [
    "BasicIntegrationProcessCoordinator"
  ],
  "DataFormatters": {
    "ProductConfigExtractionMediator":{
      "properties": {
        "type": "array",
        "name": "properties",
        "fields": [
          "extractData",
          "updateLastExecutedTime",
          "client_id",
          "client_secret"
        ]
       },
      "extractData": {
        "type": "field",
        "name": "extractData"
      },
      "updateLastExecutedTime":{
        "type": "field",
        "name": "updateLastExecutedTime"
      }
    },
    "NavigationDataExtractionMediator":{
      "properties": {
        "type": "array",
        "name": "properties",
        "fields": [
          "extraction",
          "markTheRecordsPublish"
        ]
       },
      "extraction": {
        "type": "field",
        "name": "extraction"
      },
      "markTheRecordsPublish":{
        "type": "field",
        "name": "markTheRecordsPublish"
      }
    },
    "ValidationMediator": {
      "properties": {
        "type": "array",
        "name": "properties",
        "fields": [
          "validations"
        ]
      },
      "validations": {
        "type": "arrayList",
        "name": "validations",
        "fields": [
          "fieldName",
          "fieldPath",
          "validationParameters",
          "warningAndProceed"
        ]
      },
      "fieldName": {
        "type": "field",
        "name": "fieldName"
      },
      "warningAndProceed": {
        "type": "field",
        "name": "warningAndProceed"
      },
      "fieldPath": {
        "type": "array",
        "name": "fieldPath",
        "fields": []
      },
      "validationParameters": {
        "type": "arrayList",
        "name": "validationParameters",
        "fields": [
          "validatorName",
          "params"
        ]
      },
      "validatorName": {
        "type": "field",
        "name": "validatorName"
      },
      "params": {
        "type": "array",
        "name": "params",
        "fields": []
      }
    },
    "DataAggregateMediator": {
      "properties": {
        "type": "array",
        "name": "properties",
        "fields": [
          "aggregations"
        ]
      },
      "aggregations": {
        "type": "arrayList",
        "name": "aggregations",
        "fields": [
          "aggregateFields",
          "separator",
          "aggregatedField"
        ]
      },
      "aggregateFields": {
        "type": "arrayList",
        "name": "aggregateFields",
        "fields": [
          "fieldName",
          "fieldPath",
          "removeField",
          "value"
        ]
      },
      "separator": {
        "type": "field",
        "name": "separator"
      },
      "aggregatedField": {
        "type": "array",
        "name": "aggregatedField",
        "fields": [
          "fieldName",
          "fieldPath"
        ]
      },
      "fieldName": {
        "type": "field",
        "name": "fieldName"
      },
      "removeField": {
        "type": "field",
        "name": "removeField"
      },
      "value": {
        "type": "field",
        "name": "value"
      },
      "fieldPath": {
        "type": "array",
        "name": "fieldPath",
        "fields": []
      }
    },
    "KeyMapMediator": {
      "properties": {
        "type": "array",
        "name": "properties",
        "fields": [
          "dataFields"
        ]
      },
      "dataFields": {
        "type": "arrayList",
        "name": "dataFields",
        "fields": [
          "existingFieldName",
          "alterFieldName",
          "fieldPath",
          "warnAndProceed"
        ]
      },
      "existingFieldName": {
        "type": "field",
        "name": "existingFieldName"
      },
      "alterFieldName": {
        "type": "field",
        "name": "alterFieldName"
      },
      "warnAndProceed": {
        "type": "field",
        "name": "warnAndProceed"
      }
    },
    "StringFormatMediator": {
      "properties": {
        "type": "array",
        "name": "properties",
        "fields": [
          "trimFields"
        ]
      },
      "trimFields": {
        "type": "arrayList",
        "name": "trimFields",
        "fields": [
          "fieldName",
          "fieldPath",
          "length"
        ]
      },
      "fieldPath": {
        "type": "array",
        "name": "fieldPath",
        "fields": []
      },
      "fieldName": {
        "type": "field",
        "name": "fieldName"
      },
      "length": {
        "type": "field",
        "name": "length"
      }
    },
    "DataFilterMediator": {
      "properties": {
        "type": "array",
        "name": "properties",
        "fields": [
          "filterType",
          "dataFields"
        ]
      },
      "dataFields": {
        "type": "arrayList",
        "name": "dataFields",
        "fields": [
          "fieldName",
          "fieldPath"
        ]
      },
      "filterType": {
        "type": "field",
        "name": "filterType"
      },
      "fieldPath": {
        "type": "array",
        "name": "fieldPath",
        "fields": []
      },
      "fieldName": {
        "type": "field",
        "name": "fieldName"
      }
    },
    "DataTypeConvertMediator": {
      "properties": {
        "type": "array",
        "name": "properties",
        "fields": [
          "to",
          "from"
        ]
      },
      "to": {
        "type": "field",
        "name": "to"
      },
      "from": {
        "type": "field",
        "name": "from"
      }
    },
    "FileDataDispatchMediator": {
      "properties": {
        "type": "array",
        "name": "properties",
        "fields": [
          "filePath",
          "flag"
        ]
      },
      "filePath": {
        "type": "field",
        "name": "filePath"
      },
      "flag": {
        "type": "field",
        "name": "flag"
      }
    },
    "FileDataReadMediator": {
      "properties": {
        "type": "array",
        "name": "properties",
        "fields": [
          "filePath",
          "flag"
        ]
      },
      "filePath": {
        "type": "field",
        "name": "filePath"
      },
      "flag": {
        "type": "field",
        "name": "flag"
      }
    },
    "DataExtractAndAggregateMediator": {
      "properties": {
        "type": "array",
        "name": "properties",
        "fields": [
          "extractions"
        ]
      },
      "extractions": {
        "type": "arrayList",
        "name": "extractions",
        "fields": [
          "arrayListPath",
          "extract",
          "source",
          "search",
          "insert"
        ]
      },
      "arrayListPath": {
        "type": "array",
        "name": "arrayListPath",
        "fields": []
      },
      "extract": {
        "type": "array",
        "name": "extract",
        "fields": [
          "fieldPath",
          "fieldName"
        ]
      },
      "source": {
        "type": "array",
        "name": "source",
        "fields": [
          "fieldPath",
          "fieldName",
          "value"
        ]
      },
      "search": {
        "type": "array",
        "name": "search",
        "fields": [
          "fieldPath",
          "fieldName"
        ]
      },
      "insert": {
        "type": "array",
        "name": "insert",
        "fields": [
          "fieldPath",
          "fieldName"
        ]
      },
      "fieldPath": {
        "type": "array",
        "name": "fieldPath",
        "fields": []
      },
      "fieldName": {
        "type": "field",
        "name": "fieldName"
      },
      "value": {
        "type": "field",
        "name": "value"
      }
    },
    "APIDataFetchMediator": {
      "properties": {
        "type": "array",
        "name": "properties",
        "fields": [
          "oauthConfig",
          "oauthConfigData",
          "method",
          "additionalHeaders",
          "expectedResponseCode",
          "dataURl",
          "parameters",
          "parametersDataPath",
          "dataConvertConfig",
          "aggregatedDataSet",
          "aggregatedFieldName"
        ]
      },
      "oauthConfigData": {
        "type": "array",
        "name": "oauthConfigData",
        "fields": [
          "grantType",
          "client_id",
          "redirect_uri",
          "client_secret",
          "scope",
          "url",
          "state",
          "username",
          "password",
          "refresh_token"
        ]
      },
      "parameters": {
        "type": "arrayList",
        "name": "parameters",
        "fields": [
          "parameterName",
          "fieldPath",
          "fieldName"
        ]
      },
      "dataConvertConfig": {
        "type": "array",
        "name": "dataConvertConfig",
        "fields": [
          "from",
          "to"
        ]
      },
      "additionalHeaders": {
        "type": "array",
        "name": "additionalHeaders",
        "fields": []
      },
      "dataURl": {
        "type": "field",
        "name": "dataURl"
      },
      "fieldPath": {
        "type": "array",
        "name": "fieldPath",
        "fields": []
      },
      "method": {
        "type": "field",
        "name": "method"
      },
      "oauthConfig": {
        "type": "field",
        "name": "oauthConfig"
      },
      "parameterName": {
        "type": "field",
        "name": "parameterName"
      },
      "from": {
        "type": "field",
        "name": "from"
      },
      "to": {
        "type": "field",
        "name": "to"
      },
      "aggregatedFieldName": {
        "type": "field",
        "name": "aggregatedFieldName"
      },
      "aggregatedDataSet": {
        "type": "field",
        "name": "aggregatedDataSet"
      },
      "expectedResponseCode": {
        "type": "field",
        "name": "expectedResponseCode"
      },
      "fieldName": {
        "type": "field",
        "name": "fieldName"
      },
      "grantType": {
        "type": "field",
        "name": "grantType"
      },
      "client_id": {
        "type": "field",
        "name": "client_id"
      },
      "redirect_uri": {
        "type": "field",
        "name": "redirect_uri"
      },
      "client_secret": {
        "type": "field",
        "name": "client_secret"
      },
      "scope": {
        "type": "field",
        "name": "scope"
      },
      "url": {
        "type": "field",
        "name": "url"
      },
      "state": {
        "type": "field",
        "name": "state"
      },
      "username": {
        "type": "field",
        "name": "username"
      },
      "password": {
        "type": "field",
        "name": "password"
      },
      "refresh_token": {
        "type": "field",
        "name": "refresh_token"
      },
      "parametersDataPath": {
        "type": "array",
        "name": "parametersDataPath",
        "fields": []
      }
    },"WebhookDispatchMediator": {
      "properties": {
        "type": "array",
        "name": "properties",
        "fields": [
          "method",
          "expectedResponseCode",
          "dataType",
          "additionalHeaders",
          "dataURl",
          "dataToken",
          "parameters",
          "parametersDataPath",
          "dataPath",
          "dataConvertConfig",
          "aggregatedFieldName"
        ]
      },
      "parameters": {
        "type": "arrayList",
        "name": "parameters",
        "fields": [
          "parameterName",
          "fieldPath",
          "fieldName"
        ]
      },
      "dataPath": {
        "type": "array",
        "name": "dataPath",
        "fields": []
      },
      "additionalHeaders": {
        "type": "array",
        "name": "additionalHeaders",
        "fields": []
      },
      "method": {
        "type": "field",
        "name": "method"
      },
      "dataType": {
        "type": "field",
        "name": "dataType"
      },
      "dataURl": {
        "type": "field",
        "name": "dataURl"
      },
      "dataToken": {
        "type": "field",
        "name": "dataToken"
      },
      "fieldPath": {
        "type": "array",
        "name": "fieldPath",
        "fields": []
      },
      "parameterName": {
        "type": "field",
        "name": "parameterName"
      },
      "fieldName": {
        "type": "field",
        "name": "fieldName"
      },
      "expectedResponseCode": {
        "type": "field",
        "name": "expectedResponseCode"
      },
      "parametersDataPath": {
        "type": "array",
        "name": "parametersDataPath",
        "fields": []
      },
      "aggregatedFieldName": {
        "type": "field",
        "name": "aggregatedFieldName"
      }
    },
    "APIDataDispatchMediator": {
      "properties": {
        "type": "array",
        "name": "properties",
        "fields": [
          "oauthConfig",
          "oauthConfigData",
          "method",
          "expectedResponseCode",
          "dataType",
          "additionalHeaders",
          "dataURl",
          "parameters",
          "parametersDataPath",
          "dataPath",
          "dataConvertConfig",
          "aggregatedDataSet",
          "aggregatedFieldName"
        ]
      },
      "oauthConfigData": {
        "type": "array",
        "name": "oauthConfigData",
        "fields": [
          "url",
          "grantType",
          "client_id",
          "client_secret",
          "redirect_uri",
          "scope",
          "state",
          "username",
          "password",
          "refresh_token"
        ]
      },
      "parameters": {
        "type": "arrayList",
        "name": "parameters",
        "fields": [
          "parameterName",
          "fieldPath",
          "fieldName"
        ]
      },
      "dataPath": {
        "type": "array",
        "name": "dataPath",
        "fields": []
      },
      "additionalHeaders": {
        "type": "array",
        "name": "additionalHeaders",
        "fields": []
      },
      "oauthConfig": {
        "type": "field",
        "name": "oauthConfig"
      },
      "method": {
        "type": "field",
        "name": "method"
      },
      "dataType": {
        "type": "field",
        "name": "dataType"
      },
      "dataURl": {
        "type": "field",
        "name": "dataURl"
      },
      "fieldPath": {
        "type": "array",
        "name": "fieldPath",
        "fields": []
      },
      "parameterName": {
        "type": "field",
        "name": "parameterName"
      },
      "fieldName": {
        "type": "field",
        "name": "fieldName"
      },
      "expectedResponseCode": {
        "type": "field",
        "name": "expectedResponseCode"
      },
      "dataConvertConfig": {
        "type": "array",
        "name": "dataConvertConfig",
        "fields": [
          "from",
          "to"
        ]
      },
      "from": {
        "type": "field",
        "name": "from"
      },
      "to": {
        "type": "field",
        "name": "to"
      },
      "url": {
        "type": "field",
        "name": "url"
      },
      "aggregatedFieldName": {
        "type": "field",
        "name": "aggregatedFieldName"
      },
      "aggregatedDataSet": {
        "type": "field",
        "name": "aggregatedDataSet"
      },
      "grantType": {
        "type": "field",
        "name": "grantType"
      },
      "client_id": {
        "type": "field",
        "name": "client_id"
      },
      "client_secret": {
        "type": "field",
        "name": "client_secret"
      },
      "redirect_uri": {
        "type": "field",
        "name": "redirect_uri"
      },
      "scope": {
        "type": "field",
        "name": "scope"
      },
      "state": {
        "type": "field",
        "name": "state"
      },
      "username": {
        "type": "field",
        "name": "username"
      },
      "password": {
        "type": "field",
        "name": "password"
      },
      "refresh_token": {
        "type": "field",
        "name": "client_secret"
      },
      "parametersDataPath": {
        "type": "array",
        "name": "parametersDataPath",
        "fields": []
      }
    },
    "BulkDataProcessMediator": {
      "properties": {
        "type": "array",
        "name": "properties",
        "fields": [
          "arrayPath",
          "iterativeVariables",
          "mediators"
        ]
      },
      "mediators": {
        "type": "arrayListWithRules",
        "name": "mediators",
        "ruleIdentifier": "name",
        "validateDataSet": "properties",
        "rulePath": [
          "DataFormatters"
        ]
      },
      "arrayPath": {
        "type": "array",
        "name": "arrayPath",
        "fields": []
      },
      "iterativeVariables": {
        "type": "array",
        "name": "iterativeVariables",
        "fields": []
      }
    },
    "ProcessTriggerMediator": {
      "properties": {
        "type": "array",
        "name": "properties",
        "fields": [
          "mediators",
          "triggers"
        ]
      },
      "mediators": {
        "type": "arrayListWithRules",
        "name": "mediators",
        "ruleIdentifier": "name",
        "validateDataSet": "properties",
        "rulePath": [
          "DataFormatters"
        ]
      },
      "triggers": {
        "type": "arrayListWithRules",
        "name": "triggers",
        "ruleIdentifier": "triggerType",
        "validateDataSet": "properties",
        "rulePath": [
          "DataFormatters",
          "ProcessTriggerMediator",
          "triggerRules"
        ]
      },
      "triggerRules": {
        "fieldComparisonTrigger": {
          "properties": {
            "type": "array",
            "name": "properties",
            "fields": [
              "triggerFields",
              "comparisonOperator"
            ]
          },
          "triggerFields": {
            "type": "arrayList",
            "name": "triggerFields",
            "fields": [
              "fieldPath",
              "fieldName",
              "value"
            ]
          },
          "fieldPath": {
            "type": "array",
            "name": "fieldPath",
            "fields": []
          },
          "fieldName": {
            "type": "field",
            "name": "fieldName"
          },
          "value": {
            "type": "field",
            "name": "value"
          },
          "comparisonOperator": {
            "type": "field",
            "name": "comparisonOperator"
          }
        }
      }
    },
    "DataFormatValidateMediator": {
      "properties": {
        "type": "array",
        "name": "properties",
        "fields": [
          "validations"
        ]
      },
      "validations": {
        "type": "arrayListWithRules",
        "name": "validations",
        "ruleIdentifier": "validationName",
        "validateDataSet": "properties",
        "rulePath": [
          "DataFormatters",
          "DataFormatValidateMediator",
          "validationRules"
        ]
      },
      "validationRules": {
        "IBAN": {
          "properties": {
            "type": "array",
            "name": "properties",
            "fields": [
              "fieldName",
              "fieldPath",
              "warnAndProceed"
            ]
          },
          "fieldPath": {
            "type": "array",
            "name": "fieldPath",
            "fields": []
          },
          "fieldName": {
            "type": "field",
            "name": "fieldName"
          },
          "warnAndProceed": {
            "type": "field",
            "name": "warnAndProceed"
          }
        }
      }
    },
    "LogMediator": {
      "properties": {
        "type": "array",
        "name": "properties",
        "fields": [
          "fieldName",
          "fieldPath",
          "processStop"
        ]
      },
      "fieldName": {
        "type": "field",
        "name": "fieldName"
      },
      "processStop": {
        "type": "field",
        "name": "processStop"
      },
      "fieldPath": {
        "type": "array",
        "name": "fieldPath",
        "fields": []
      }
    },
    "ArrayManipulateMediator": {
      "properties": {
        "type": "array",
        "name": "properties",
        "fields": [
          "arrayFormats"
        ]
      },
      "arrayFormats": {
        "type": "arrayListWithRules",
        "name": "arrayFormats",
        "ruleIdentifier": "formatName",
        "validateDataSet": "properties",
        "rulePath": [
          "DataFormatters",
          "ArrayManipulateMediator",
          "arrayFormatterRules"
        ]
      },
      "arrayFormatterRules": {
        "getLastElement": {
          "properties": {
            "type": "array",
            "name": "properties",
            "fields": [
              "arrayPath",
              "aggregatedFieldName",
              "fieldPath",
              "fieldNames"
            ]
          },
          "arrayPath": {
            "type": "array",
            "name": "arrayPath",
            "fields": []
          },
          "aggregatedFieldName": {
            "type": "field",
            "name": "aggregatedFieldName"
          },
          "fieldPath": {
            "type": "array",
            "name": "fieldPath",
            "fields": []
          },
          "fieldNames": {
            "type": "array",
            "name": "fieldNames",
            "fields": []
          }
        },
        "changeArrayValues": {
          "properties": {
            "type": "array",
            "name": "properties",
            "fields": [
              "arrayPath",
              "aggregatedFieldName",
              "fieldPath",
              "fieldNames"
            ]
          },
          "arrayPath": {
            "type": "array",
            "name": "arrayPath",
            "fields": []
          },
          "aggregatedFieldName": {
            "type": "field",
            "name": "aggregatedFieldName"
          },
          "fieldPath": {
            "type": "array",
            "name": "fieldPath",
            "fields": []
          },
          "fieldNames": {
            "type": "array",
            "name": "fieldNames",
            "fields": []
          }
        },
        "deleteArrayValues": {
          "properties": {
            "type": "array",
            "name": "properties",
            "fields": [
              "arrayPath",
              "aggregatedFieldName",
              "fieldPath",
              "fieldNames"
            ]
          },
          "arrayPath": {
            "type": "array",
            "name": "arrayPath",
            "fields": []
          },
          "aggregatedFieldName": {
            "type": "field",
            "name": "aggregatedFieldName"
          },
          "fieldPath": {
            "type": "array",
            "name": "fieldPath",
            "fields": []
          },
          "fieldNames": {
            "type": "array",
            "name": "fieldNames",
            "fields": []
          }
        },
        "mergeArrayValues": {
          "properties": {
            "type": "array",
            "name": "properties",
            "fields": [
              "arrayPath",
              "aggregatedFieldName",
              "fieldPath",
              "fieldNames"
            ]
          },
          "arrayPath": {
            "type": "array",
            "name": "arrayPath",
            "fields": []
          },
          "aggregatedFieldName": {
            "type": "field",
            "name": "aggregatedFieldName"
          },
          "fieldPath": {
            "type": "array",
            "name": "fieldPath",
            "fields": []
          },
          "fieldNames": {
            "type": "array",
            "name": "fieldNames",
            "fields": []
          }
        }
      }
    },
    "ChangeVerifierMediator": {
      "properties": {
        "type": "array",
        "name": "properties",
        "fields": [
          "eventsToExecute",
          "preDataPath",
          "postDataPath",
          "comparisons",
          "fieldsToBeExtracted"
        ]
      },
      "eventsToExecute": {
        "type": "array",
        "name": "eventsToExecute",
        "fields": [
          "eventNameFieldName",
          "eventNameFieldPath",
          "eventNames",
          "defaultSave"
        ]
      },
      "preDataPath": {
        "type": "array",
        "name": "preDataPath",
        "fields": []
      },
      "postDataPath": {
        "type": "array",
        "name": "postDataPath",
        "fields": []
      },
      "comparisons": {
        "type": "arrayList",
        "name": "comparisons",
        "fields": [
          "fieldName",
          "mappedReportFieldName",
          "oldFieldPath",
          "newFieldPath"
        ]
      },
      "fieldsToBeExtracted": {
        "type": "arrayList",
        "name": "fieldsToBeExtracted",
        "fields": [
          "currentFieldNames",
          "newFieldNames",
          "fieldPath"
        ]
      },
      "fieldName": {
        "type": "field",
        "name": "fieldName"
      },
      "mappedReportFieldName": {
        "type": "field",
        "isOptional": true,
        "name": "mappedReportFieldName"
      },
      "fieldPath": {
        "type": "array",
        "name": "fieldPath",
        "fields": []
      },
      "eventNames": {
        "type": "array",
        "name": "eventNames",
        "fields": []
      },
      "defaultSave": {
        "type": "field",
        "name": "defaultSave"
      },
      "eventNameFieldName": {
        "type": "field",
        "name": "eventNameFieldName"
      },
      "eventNameFieldPath": {
        "type": "array",
        "name": "eventNameFieldPath",
        "fields": []
      },
      "currentFieldNames": {
        "type": "array",
        "name": "currentFieldNames",
        "fields": []
      },
      "newFieldNames": {
        "type": "array",
        "name": "newFieldNames",
        "fields": []
      },
      "oldFieldPath": {
        "type": "array",
        "name": "oldFieldPath",
        "fields": []
      },
      "newFieldPath": {
        "type": "array",
        "name": "newFieldPath",
        "fields": []
      }
    },
    "DispatchDataToDatabaseMediator": {
      "properties": {
        "type": "array",
        "name": "properties",
        "fields": [
          "changeIdentification",
          "insertMode",
          "extractedData",
          "databaseMapping"
        ]
      },
      "changeIdentification": {
        "type": "array",
        "name": "changeIdentification",
        "fields": [
          "fieldName",
          "fieldPath"
        ]
      },
      "insertMode": {
        "type": "field",
        "name": "insertMode"
      },
      "extractedData": {
        "type": "array",
        "name": "extractedData",
        "fields": [
          "fieldPath"
        ]
      },
      "fieldName": {
        "type": "field",
        "name": "fieldName"
      },
      "fieldPath": {
        "type": "array",
        "name": "fieldPath",
        "fields": []
      },
      "databaseMapping": {
        "type": "arrayList",
        "name": "databaseMapping",
        "fields": [
          "tableName",
          "entityName",
          "mappingfields"
        ]
      },
      "tableName": {
        "type": "field",
        "name": "tableName"
      },
      "entityName": {
        "type": "field",
        "name": "entityName"
      },
      "mappingfields": {
        "type": "arrayList",
        "name": "mappingfields",
        "fields": [
          "entityField",
          "tableField",
          "extractingFieldName",
          "preProcessing"
        ]
      },
      "entityField": {
        "type": "field",
        "name": "entityField"
      },
      "tableField": {
        "type": "field",
        "name": "tableField"
      },
      "extractingFieldName": {
        "type": "field",
        "name": "extractingFieldName"
      },
      "preProcessing": {
        "type": "array",
        "isOptional": true,
        "name": "preProcessing",
        "fields": []
      }
    },
    "ArrayValidationMediator": {
      "properties": {
        "type": "array",
        "name": "properties",
        "fields": [
          "validatingData",
          "validations",
          "nonValidatingSubArrays"
        ]
      },
      "validatingData": {
        "type": "array",
        "name": "validatingData",
        "fields": []
      },
      "validations": {
        "type": "arrayList",
        "name": "validations",
        "fields": [
          "fieldName",
          "fieldPath",
          "fieldIndex",
          "validationParameters",
          "warningAndProceed"
        ]
      },
      "nonValidatingSubArrays": {
        "type": "array",
        "name": "nonValidatingSubArrays",
        "fields": []
      },
      "arrayIndexes": {
        "type": "array",
        "name": "arrayIndexes",
        "fields": []
      },
      "fieldName": {
        "type": "field",
        "name": "fieldName"
      },
      "fieldIndex": {
        "type": "field",
        "name": "fieldIndex"
      },
      "fieldPath": {
        "type": "array",
        "name": "fieldPath",
        "fields": []
      },
      "validationParameters": {
        "type": "arrayList",
        "name": "validationParameters",
        "fields": [
          "validatorName",
          "params"
        ]
      },
      "warningAndProceed": {
        "type": "field",
        "name": "warningAndProceed"
      }
    },
    "ArrayLocalizationMediator": {
      "properties": {
        "type": "array",
        "name": "properties",
        "fields": [
          "dataPath",
          "localizations",
          "nonLocalizingSubArrays"
        ]
      },
      "localizations": {
        "type": "arrayList",
        "name": "localizations",
        "fields": [
          "fieldType",
          "fieldName",
          "fieldIndex"
        ]
      },
      "fieldName": {
        "type": "field",
        "name": "fieldName"
      },
      "fieldType": {
        "type": "field",
        "name": "fieldType"
      },
      "dataPath": {
        "type": "array",
        "name": "dataPath",
        "fields": []
      },
      "fieldIndex": {
        "type": "field",
        "name": "fieldIndex"
      },
      "nonLocalizingSubArrays": {
        "type": "array",
        "name": "nonLocalizingSubArrays",
        "fields": []
      },
      "arrayIndexes": {
        "type": "array",
        "name": "arrayIndexes",
        "fields": []
      }
    },
    "CustomFieldValuesChangeVerifierMediator": {
      "properties": {
        "type": "array",
        "name": "properties",
        "fields": [
          "eventsToExecute",
          "preDataPath",
          "postDataPath",
          "comparisons",
          "comparisonRules",
          "fieldsToBeExtracted"
        ]
      },
      "eventsToExecute": {
        "type": "array",
        "name": "eventsToExecute",
        "fields": [
          "eventNameFieldName",
          "eventNameFieldPath",
          "eventNames",
          "defaultSave"
        ]
      },
      "preDataPath": {
        "type": "array",
        "name": "preDataPath",
        "fields": []
      },
      "postDataPath": {
        "type": "array",
        "name": "postDataPath",
        "fields": []
      },
      "comparisons": {
        "type": "arrayList",
        "name": "comparisons",
        "fields": [
          "fieldName",
          "oldFieldPath",
          "newFieldPath"
        ]
      },
      "comparisonRules": {
        "type": "array",
        "name": "comparisonRules",
        "fields": [
          "comparisonMethod",
          "customSectionIds",
          "customFieldUniqueNames"
        ]
      },
      "fieldsToBeExtracted": {
        "type": "arrayList",
        "name": "fieldsToBeExtracted",
        "fields": [
          "currentFieldNames",
          "newFieldNames",
          "fieldPath"
        ]
      },
      "comparisonMethod": {
        "type": "field",
        "name": "comparisonMethod"
      },
      "customSectionIds": {
        "type": "array",
        "name": "customSectionIds",
        "fields": []
      },
      "customFieldUniqueNames": {
        "type": "array",
        "name": "customFieldUniqueNames",
        "fields": []
      },
      "fieldName": {
        "type": "field",
        "name": "fieldName"
      },
      "fieldPath": {
        "type": "array",
        "name": "fieldPath",
        "fields": []
      },
      "eventNames": {
        "type": "array",
        "name": "eventNames",
        "fields": []
      },
      "defaultSave": {
        "type": "field",
        "name": "defaultSave"
      },
      "eventNameFieldName": {
        "type": "field",
        "name": "eventNameFieldName"
      },
      "eventNameFieldPath": {
        "type": "array",
        "name": "eventNameFieldPath",
        "fields": []
      },
      "currentFieldNames": {
        "type": "array",
        "name": "currentFieldNames",
        "fields": []
      },
      "newFieldNames": {
        "type": "array",
        "name": "newFieldNames",
        "fields": []
      },
      "oldFieldPath": {
        "type": "array",
        "name": "oldFieldPath",
        "fields": []
      },
      "newFieldPath": {
        "type": "array",
        "name": "newFieldPath",
        "fields": []
      }
    },
    "SalaryValueChangeVerifierMediator": {
      "properties": {
        "type": "array",
        "name": "properties",
        "fields": [
          "eventsToExecute",
          "preDataPath",
          "postDataPath",
          "comparisons",
          "fieldsToBeExtracted"
        ]
      },
      "eventsToExecute": {
        "type": "array",
        "name": "eventsToExecute",
        "fields": [
          "eventNameFieldName",
          "eventNameFieldPath",
          "eventNames",
          "defaultSave"
        ]
      },
      "preDataPath": {
        "type": "array",
        "name": "preDataPath",
        "fields": []
      },
      "postDataPath": {
        "type": "array",
        "name": "postDataPath",
        "fields": []
      },
      "comparisons": {
        "type": "arrayList",
        "name": "comparisons",
        "fields": [
          "fieldName",
          "oldFieldPath",
          "newFieldPath"
        ]
      },
      "fieldsToBeExtracted": {
        "type": "arrayList",
        "name": "fieldsToBeExtracted",
        "fields": [
          "currentFieldNames",
          "newFieldNames",
          "fieldPath"
        ]
      },
      "fieldName": {
        "type": "field",
        "name": "fieldName"
      },
      "fieldPath": {
        "type": "array",
        "name": "fieldPath",
        "fields": []
      },
      "eventNames": {
        "type": "array",
        "name": "eventNames",
        "fields": []
      },
      "defaultSave": {
        "type": "field",
        "name": "defaultSave"
      },
      "eventNameFieldName": {
        "type": "field",
        "name": "eventNameFieldName"
      },
      "eventNameFieldPath": {
        "type": "array",
        "name": "eventNameFieldPath",
        "fields": []
      },
      "currentFieldNames": {
        "type": "array",
        "name": "currentFieldNames",
        "fields": []
      },
      "newFieldNames": {
        "type": "array",
        "name": "newFieldNames",
        "fields": []
      },
      "oldFieldPath": {
        "type": "array",
        "name": "oldFieldPath",
        "fields": []
      },
      "newFieldPath": {
        "type": "array",
        "name": "newFieldPath",
        "fields": []
      }
    }
  }
}',1);

CREATE TABLE ohrm_integration_process_queue_consumer (
  id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  consumer_id INT(4) NOT NULL,
  integration_id INT(4) NOT NULL,
    CONSTRAINT `fk_integration_process_consumer_consumer` FOREIGN KEY (`consumer_id`)
    REFERENCES `ohrm_external_data_queue_consumer` (`id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
    CONSTRAINT `fk_integration_process_integration_consumer` FOREIGN KEY (`integration_id`)
    REFERENCES `ohrm_external_integration_process` (`id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE
) ENGINE = INNODB DEFAULT CHARSET=utf8;

SET @notification_type_id = (SELECT `id` FROM `ohrm_notification_type` WHERE `name`='Other');
SET @module_id = (SELECT `id` FROM `ohrm_module` WHERE `name`='core');

INSERT INTO `ohrm_notification`(`name`, `is_enable`, `type_id`, `generator_class`, `parameters`, `workflow_id`, `workflow_action`, `module_id`, `hidden`) VALUES
('Integration Process Failure',1,@notification_type_id,NULL,NULL,NULL,NULL,@module_id,1);

SET @email_media = (SELECT `id` FROM `ohrm_notification_media` WHERE `name` = 'Email');
SET @notification_id = (SELECT `id` FROM `ohrm_notification` WHERE `name` = 'Integration Process Failure');

INSERT INTO `ohrm_notification_subscriber_subscription_template`( `name`, `notification_id`, `media_id`, `locale`, `subject`, `body`)
VALUES ('Integration Process Failure Notification Template',@notification_id,@email_media,'en_US','Integration Process  [FAILURE] | Instance : %instanceName% | Integration Process: %integrationName%',
        '<p>OrangeHRM instance %instanceName% is facing an integration process failure%attempts% This may need your attention.</p>
<p>This is an automated notification.Please do not reply to this email.</p>');
