|
@@ -1,24 +1,22 @@
|
|
|
import { map, Observable, of, Subject } from "rxjs";
|
|
|
import { ErrorTrigger, MessageAuditorServiceInterface, MessageSynchronisationServiceSetting } from "../type/datatype";
|
|
|
-import { LoggingService } from "../dependencies/log/interface/export";
|
|
|
import { MessageLog } from "../dependencies/log/type/datatype";
|
|
|
import { _ } from 'lodash'
|
|
|
-import { BaseMessage, RequestMessage, ResponseMessage } from "../dependencies/msgutil/interface/export";
|
|
|
+import { LoggingService } from "../dependencies/log/interface/export";
|
|
|
+import { BaseMessage } from "../dependencies/log/dependencies/msgutil/interface/export";
|
|
|
|
|
|
export class MessageAuditorService implements MessageAuditorServiceInterface {
|
|
|
private settings: MessageSynchronisationServiceSetting
|
|
|
private sourceSrc: LoggingService = new LoggingService()
|
|
|
private targetSrc: LoggingService = new LoggingService()
|
|
|
private missingMessageSubject: Subject<MessageLog> = new Subject()
|
|
|
- private filter: any
|
|
|
|
|
|
/* Set up the targets or points of synchronization. This is where it will register the 2 different location of
|
|
|
the data to be synchronized */
|
|
|
- public init(settings: MessageSynchronisationServiceSetting, filters?: any): void {
|
|
|
+ public init(settings: MessageSynchronisationServiceSetting): void {
|
|
|
this.settings = settings;
|
|
|
- if (filters) {
|
|
|
- console.log(`Integrating filters: ${Object.keys(this.filter)} in AuditMessage service`)
|
|
|
- this.filter = filters
|
|
|
+ if (settings.filters) {
|
|
|
+ console.log(`Integrating filters: ${Object.keys(this.settings.filters)} in AuditMessage service`)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -32,10 +30,10 @@ export class MessageAuditorService implements MessageAuditorServiceInterface {
|
|
|
obsTrigger.subscribe({
|
|
|
next: obsTrigger => {
|
|
|
console.log(obsTrigger.message)// just checking the message
|
|
|
- if (!this.filter) {
|
|
|
- console.log(`No filter applies`)
|
|
|
+ if (!this.settings.filters) {
|
|
|
+ console.log(`No filters applies`)
|
|
|
} else {
|
|
|
- console.log(`Synchronizating with filters: ${Object.keys(this.filter)}: ${Object.values(this.filter)}`)
|
|
|
+ console.log(`Synchronizating with filters: ${Object.keys(this.settings.filters)}: ${Object.values(this.settings.filters)}`)
|
|
|
}
|
|
|
let missingMsg: Observable<MessageLog> = this.synchronize()
|
|
|
missingMsg.subscribe({
|
|
@@ -51,15 +49,15 @@ export class MessageAuditorService implements MessageAuditorServiceInterface {
|
|
|
|
|
|
|
|
|
/* ________________ Private Functions _________________ */
|
|
|
- // Filtering functions to filter out messages
|
|
|
+ // Filtering functions to filters out messages
|
|
|
private filterData(filters: any, message: MessageLog): boolean {
|
|
|
let response: boolean = true //Just using this like a statemanagement
|
|
|
let payload: BaseMessage = JSON.parse(message.appData.msgPayload as string) // Extract the payload from the messageLog first
|
|
|
- // Making a separate function to cater to different multi filter conditions are coded below
|
|
|
- function checkValues(filter): boolean { //FYI, all parameters are string
|
|
|
- let key = Object.keys(filter)
|
|
|
- console.log(Object.values(filter))
|
|
|
- let value = Object.values(filter)[0]
|
|
|
+ // Making a separate function to cater to different multi filters conditions are coded below
|
|
|
+ function checkValues(filters): boolean { //FYI, all parameters are string
|
|
|
+ let key = Object.keys(filters)
|
|
|
+ console.log(Object.values(filters))
|
|
|
+ let value = Object.values(filters)[0]
|
|
|
let res = _.get(payload, key[0])
|
|
|
// Check first if the payload has the filtering properties/path
|
|
|
if (_.has(payload, key[0])) {
|
|
@@ -88,9 +86,9 @@ export class MessageAuditorService implements MessageAuditorServiceInterface {
|
|
|
let totalCount = Object.keys(filters).length
|
|
|
let matchedCount = 0
|
|
|
Object.entries(filters).forEach(([key, value]) => {
|
|
|
- let filter = { [key]: value }
|
|
|
- // console.log(filter)
|
|
|
- if (checkValues(filter) == true) matchedCount++
|
|
|
+ let filters = { [key]: value }
|
|
|
+ // console.log(filters)
|
|
|
+ if (checkValues(filters) == true) matchedCount++
|
|
|
})
|
|
|
if (totalCount == matchedCount) {
|
|
|
response = true
|
|
@@ -116,7 +114,7 @@ export class MessageAuditorService implements MessageAuditorServiceInterface {
|
|
|
// Acquire the data from both location and return them as an array respectively.
|
|
|
this.acquireData().then((data: { arr1: MessageLog[], arr2: MessageLog[] }) => {
|
|
|
// In the case where there are differences in the array length, then extensive comparison
|
|
|
- // will be carried out to filter out the differences. Differences are the missing data.
|
|
|
+ // will be carried out to filters out the differences. Differences are the missing data.
|
|
|
this.checkArrayDifferences(data).then((data: MessageLog[]) => {
|
|
|
data.forEach(msgElement => {
|
|
|
let refined = JSON.parse(JSON.stringify(msgElement))
|
|
@@ -149,14 +147,14 @@ export class MessageAuditorService implements MessageAuditorServiceInterface {
|
|
|
// Filter also carries out the query aspect of the operation, allowing it to acquire all the relevant data.
|
|
|
this.sourceSrc.filter({ msgTag: this.settings.incomingSource.tags[0] }).then((data: MessageLog[]) => {
|
|
|
data.forEach((message: MessageLog) => {
|
|
|
- if (this.filterData(this.filter, message)) set1.push(message)
|
|
|
+ if (this.filterData(this.settings.filters, message)) set1.push(message)
|
|
|
})
|
|
|
}).catch((err) => {
|
|
|
console.error(err.message)
|
|
|
}).then(() => {
|
|
|
this.targetSrc.filter({ msgTag: this.settings.target.tags[0] }).then((data: MessageLog[]) => {
|
|
|
data.forEach(message => {
|
|
|
- if (this.filterData(this.filter, message)) set2.push(message)
|
|
|
+ if (this.filterData(this.settings.filters, message)) set2.push(message)
|
|
|
})
|
|
|
allSets.arr1 = set1
|
|
|
allSets.arr2 = set2
|