acknowledgement.service.ts 2.8 KB

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