acknowledgement.service.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { AnyObject } from "mongoose";
  2. import { map, Observable, of, tap } from "rxjs";
  3. import { Acknowledgemeent, AcknowledgementLogSetting } from "../type/acknowledgement.interface";
  4. import { BaseMessage, Command, FisCreateMessageUtility, ResponseMessage, Uuid } from "../dependencies/fisappmessagejsutilty/interface/export";
  5. import { LogSetting, MessageLog } from "../dependencies/fisloggingservice/type/datatype";
  6. import { LoggingService } from "../dependencies/fisloggingservice/interface/export";
  7. /**
  8. * @deprecated The acknowledgement will be covered by MessageAuditorService.
  9. */
  10. export class AcknowledgementService implements Acknowledgemeent {
  11. private messageUtil: FisCreateMessageUtility = new FisCreateMessageUtility("FisAppID/Name")
  12. private settings: LogSetting = {
  13. storage: '',
  14. setting: {
  15. appId: '',
  16. appName: '',
  17. logLocName: '',
  18. logLocId: '',
  19. appLogLocId: '',
  20. appLocName: '',
  21. appLogId: ''
  22. }
  23. }
  24. constructor(private logService?: LoggingService) {
  25. this.logService = new LoggingService()
  26. }
  27. public async init(settings: AcknowledgementLogSetting) {
  28. let logSetting: LogSetting = {
  29. ...settings,
  30. setting: {
  31. ...settings.setting,
  32. logLocName: "locationName2",
  33. appLocName: "appLocName2"
  34. }
  35. }
  36. this.settings = logSetting
  37. this.logService.init(logSetting)
  38. }
  39. public subscribe(obs: Observable<BaseMessage>): Observable<ResponseMessage> {
  40. let acknowledgementToken: Observable<ResponseMessage> = obs.pipe(
  41. map(
  42. incoming_msg => {
  43. let emulatedId = "GeneratedFromMessageSync"
  44. let emulatedRequest = this.messageUtil.getCommandMessage(emulatedId, Command.New, incoming_msg)
  45. let finalResponse = this.messageUtil.getResponseMessage(emulatedId, { "Acknowledgement": 1 }, emulatedRequest)
  46. return finalResponse
  47. }
  48. ))
  49. let acknowledgementTokenLogging: Observable<MessageLog> = obs.pipe(
  50. map(
  51. incoming_msg => {
  52. let finalResponse:MessageLog = {
  53. appLogLocId: new Uuid().generateId(),
  54. appData: {
  55. msgId: incoming_msg.header.messageID || new Uuid().generateId(),
  56. msgLogDateTime: new Date(),
  57. msgDateTime: new Date(),
  58. msgTag: ['Acknowledgement'],
  59. msgPayload: JSON.stringify(incoming_msg)
  60. }
  61. }
  62. return finalResponse
  63. }
  64. )
  65. )
  66. this.logService.subscribe(acknowledgementTokenLogging)
  67. return acknowledgementToken
  68. }
  69. }