incomingMessage.service.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. /**
  7. * @deprecated The logging is now supported by the Fis-Logging library.
  8. */
  9. export class IncomingMessageService implements IncomingMessageServiceInterface {
  10. constructor(private logService?: LoggingService) {
  11. this.logService = new LoggingService()
  12. }
  13. private settings: LogSetting & { incomingObservable: Observable<BaseMessage>; } = {
  14. storage: '',
  15. setting: {
  16. appId: '',
  17. appName: '',
  18. logLocName: '',
  19. logLocId: '',
  20. appLogLocId: '',
  21. appLocName: '',
  22. appLogId: ''
  23. },
  24. incomingObservable: null
  25. }
  26. /* This function is mainful used for setting the log setting as well as transforming the messages
  27. into log messages and then storing them in the desiganted location of storage as specified. */
  28. public init(settings: LogSetting & { incomingObservable: Observable<BaseMessage>; }): void {
  29. // Restructuring the settings. I think they were some trouble doing this last time
  30. let newSetting: any = settings
  31. newSetting.setting = {
  32. ...this.settings.setting,
  33. ...settings.setting,
  34. customSetting: {
  35. ...this.settings.customSetting,
  36. ...settings.customSetting,
  37. }
  38. }
  39. this.settings = newSetting // Become stateful???
  40. // Transform incoming observables into Observable<MessageLog> to be logged
  41. let transformedOBS: Observable<MessageLog> = settings.incomingObservable.pipe(
  42. map(message => {
  43. let finalResponse: MessageLog = {
  44. appLogLocId: new Uuid().generateId(),
  45. appData: {
  46. msgId: message.header.messageID || new Uuid().generateId(),
  47. msgLogDateTime: new Date(),
  48. msgDateTime: new Date(),
  49. msgTag: ['Incoming'],
  50. msgPayload: JSON.stringify(message)
  51. }
  52. }
  53. return finalResponse
  54. })
  55. )
  56. // Once the messages has been transformed, then the logging can be executed
  57. this.logService.init(this.settings).then(() => {
  58. this.logService.subscribe(transformedOBS)
  59. }).catch((e) => console.error(e))
  60. }
  61. }