synchronization.service.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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((data) => {
  15. if (!data) reject()
  16. console.log(`File Storage:`)
  17. data.forEach(e => console.log(e.appLogLocId))
  18. }).then(() => {
  19. this.targetSrc.init(settings.target).then((data) => {
  20. if (!data) reject()
  21. console.log(`Mongo Storage`)
  22. data.forEach(e => console.log(e.appLogLocId))
  23. resolve()
  24. })
  25. })
  26. }
  27. catch (e) {
  28. console.error(e)
  29. }
  30. })
  31. return promiseInit
  32. }
  33. public subscribe(obs: Observable<string>): Observable<any> {
  34. let subjectOutput = new Subject()
  35. // filter all source tags[0] log data
  36. let set1 = this.sourceSrc.filter({ msgTag: this.settings.incomingSource.tags[0] })
  37. set1.then((data) => console.log(data.length))
  38. let set2 = this.targetSrc.filter({ msgTag: this.settings.target.tags[0] })
  39. set2.then((data) => console.log(data.length))
  40. // this.compareResult(set1, set2).then((data) => {
  41. // data.forEach(element => {
  42. // subjectOutput.next(element)
  43. // })
  44. // })
  45. return subjectOutput.asObservable()
  46. }
  47. // compare results and return differences
  48. private async compareResult(args: Promise<any>, args2: Promise<any>): Promise<any> {
  49. let arr1 = []
  50. let arr2 = []
  51. args.then((element) => {
  52. arr1.push(element)
  53. })
  54. args2.then((element) => {
  55. arr2.push(element)
  56. })
  57. console.log(arr1)
  58. console.log(arr2)
  59. return arr1
  60. }
  61. }