123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- 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: '',
- appName: '',
- logLocName: '',
- logLocId: '',
- appLogLocId: '',
- appLocName: '',
- appLogId: ''
- },
- 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
- }
- )
- )
- this.logService.init(this.settings).then(() => {
- this.logService.subscribe(transformedOBS)
- }).catch((e) => console.error(e))
- }
- }
|