synchronization.service.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { Observable, Subject } from "rxjs";
  2. import { BaseMessage } from "../dependencies/fisappmessagejsutilty/dependencies/dependencies";
  3. import { LoggingService } from "../dependencies/fisloggingservice/services/logging-service";
  4. import { MessageSynchronisationServiceInterface, MessageSynchronisationServiceSetting } from "../type/datatype";
  5. export class MessageSyncrhonizationService implements MessageSynchronisationServiceInterface {
  6. settings: MessageSynchronisationServiceSetting
  7. sourceSrc: LoggingService = new LoggingService()
  8. targetSrc: LoggingService = new LoggingService()
  9. public async init(settings: MessageSynchronisationServiceSetting): Promise<void> {
  10. this.settings = settings;
  11. // Wrap promise so that init must be instantiated with resolve before proceeding with subscribe method
  12. let promiseInit : Promise<void> = new Promise((resolve, reject) => {
  13. try {
  14. this.sourceSrc.init(settings.incomingSource).then(() => {
  15. this.targetSrc.init(settings.target);
  16. }).then(() => resolve())
  17. }
  18. catch (e) {
  19. console.error(e)
  20. }
  21. })
  22. return promiseInit
  23. }
  24. public subscribe(obs: Observable<string>): Observable<any> {
  25. let subjectOutput = new Subject()
  26. obs.subscribe({
  27. next: element => {
  28. let data = JSON.parse(element)
  29. console.log(data.header.messageID)
  30. }
  31. })
  32. // filter all source tags[0] log data
  33. let set1 = this.sourceSrc.filter(
  34. { msgTag: this.settings.incomingSource.tags[0] })
  35. let set2 = this.targetSrc.filter(
  36. { msgTag: this.settings.target.tags[0] }
  37. )
  38. this.compareResult(set1, set2).then((data) => {
  39. data.forEach(element => {
  40. subjectOutput.next(element)
  41. })
  42. })
  43. return subjectOutput.asObservable()
  44. }
  45. // compare results and return differences
  46. private async compareResult(args: Promise<any>, args2: Promise<any>): Promise<any[]> {
  47. let dataset3
  48. await args.then((data) => {
  49. console.log(data)
  50. args2.then((data2) => {
  51. data.forEach((element) => {
  52. data2.forEach((element2) => {
  53. dataset3 = '' // missing messages
  54. })
  55. })
  56. })
  57. })
  58. return dataset3
  59. }
  60. }