acknowledgement.service.ts 3.0 KB

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