12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- import { map, Observable, of, tap } from "rxjs";
- import { BaseMessage, Command, ResponseMessage, Uuid } from "../dependencies/fisappmessagejsutilty/interface/export"
- import { LoggingService } from "../dependencies/fisloggingservice/services/logging-service";
- import { LogSetting, MessageLog } from "../dependencies/fisloggingservice/type/datatype";
- import { IncomingMessageServiceInterface } from "../type/datatype";
- import { AcknowledgementService } from "./acknowledgement.service";
- export class IncomingMessageService implements IncomingMessageServiceInterface {
- constructor(private logService?: LoggingService, private acknowledgeService?: AcknowledgementService) {
- this.logService = new LoggingService()
- }
- private settings: LogSetting & { incomingObservable: Observable<BaseMessage>; } = {
- storage: '',
- setting: {
- appId: undefined,
- appName: '',
- logLocName: '',
- logLocId: undefined,
- appLogLocId: undefined,
- appLocName: '',
- appLogId: undefined
- },
- incomingObservable: null
- }
- public init(settings: LogSetting & { incomingObservable: Observable<BaseMessage>; }): void {
- let newSetting: any = settings
- newSetting.setting = {
- ...this.settings.setting,
- ...settings.setting,
- customSetting:{
- ...this.settings.customSetting,
- ...settings.customSetting,
- }
- }
- this.settings = newSetting
- // Transform incoming observables into Observable<MessageLog> to be logged
- let transformedOBS: Observable<MessageLog> = settings.incomingObservable.pipe(
- map(message => {
- let finalResponse: MessageLog = {
- appLogLocId: new Uuid().generateId(),
- appData: {
- msgId: message.header.messageID || new Uuid().generateId(),
- msgLogDateTime: new Date(),
- msgDateTime: new Date(),
- msgTag: ['Incoming'],
- msgPayload: JSON.stringify(message)
- }
- }
- return finalResponse
- }
- )
- )
- /* Trying new promise chaining structure */
- this.logService.init(this.settings).then(() => {
- this.logService.subscribe(transformedOBS)
- }).catch((e) => console.error(e))
- }
- }
|