incomingMessage.service.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { map, Observable, of, tap } from "rxjs";
  2. import { BaseMessage, Command, ResponseMessage, Uuid } from "../dependencies/fisappmessagejsutilty/interface/export"
  3. import { LoggingService } from "../dependencies/fisloggingservice/services/logging-service";
  4. import { LogSetting, MessageLog } from "../dependencies/fisloggingservice/type/datatype";
  5. import { IncomingMessageServiceInterface } from "../type/datatype";
  6. import { AcknowledgementService } from "./acknowledgement.service";
  7. export class IncomingMessageService implements IncomingMessageServiceInterface {
  8. constructor(private logService?: LoggingService, private acknowledgeService?: AcknowledgementService) {
  9. this.logService = new LoggingService()
  10. }
  11. private settings: LogSetting & { incomingObservable: Observable<BaseMessage>; } = {
  12. storage: '',
  13. setting: {
  14. appId: '',
  15. appName: '',
  16. logLocName: '',
  17. logLocId: '',
  18. appLogLocId: '',
  19. appLocName: '',
  20. appLogId: ''
  21. },
  22. incomingObservable: null
  23. }
  24. public init(settings: LogSetting & { incomingObservable: Observable<BaseMessage>; }): void {
  25. let newSetting: any = settings
  26. newSetting.setting = {
  27. ...this.settings.setting,
  28. ...settings.setting,
  29. customSetting:{
  30. ...this.settings.customSetting,
  31. ...settings.customSetting,
  32. }
  33. }
  34. this.settings = newSetting
  35. // Transform incoming observables into Observable<MessageLog> to be logged
  36. let transformedOBS: Observable<MessageLog> = settings.incomingObservable.pipe(
  37. map(message => {
  38. let finalResponse: MessageLog = {
  39. appLogLocId: new Uuid().generateId(),
  40. appData: {
  41. msgId: message.header.messageID || new Uuid().generateId(),
  42. msgLogDateTime: new Date(),
  43. msgDateTime: new Date(),
  44. msgTag: ['Incoming'],
  45. msgPayload: JSON.stringify(message)
  46. }
  47. }
  48. return finalResponse
  49. }
  50. )
  51. )
  52. this.logService.init(this.settings).then(() => {
  53. this.logService.subscribe(transformedOBS)
  54. }).catch((e) => console.error(e))
  55. }
  56. }