File

C:/GoDev/src/TCSTK-Angular/projects/tibco-tcstk/tc-messaging-lib/src/lib/services/e-ftl-config.service.ts

Index

Methods

Constructor

constructor(location: Location, sharedStateService: TcSharedStateService)
Parameters :
Name Type Optional
location Location No
sharedStateService TcSharedStateService No

Methods

Public createMessagingConfig
createMessagingConfig(sandboxId: number, uiAppId: string, messagingConfig: MessagingConfig)
Parameters :
Name Type Optional
sandboxId number No
uiAppId string No
messagingConfig MessagingConfig No
Public getMessagingConfig
getMessagingConfig(uiAppId: string, useCache: boolean, flushCache: boolean)
Parameters :
Name Type Optional
uiAppId string No
useCache boolean No
flushCache boolean No
Public removeMessagingConfig
removeMessagingConfig(id: number)
Parameters :
Name Type Optional
id number No
Returns : Observable<string>
Public updateMessagingConfig
updateMessagingConfig(sandboxId: number, uiAppId: string, messagingConfig: MessagingConfig, id: string)
Parameters :
Name Type Optional
sandboxId number No
uiAppId string No
messagingConfig MessagingConfig No
id string No
Returns : any
import { Injectable } from '@angular/core';
import {Observable} from 'rxjs';
import {flatMap, map} from 'rxjs/operators';
import {Location} from '@angular/common';
import {TcSharedStateService, TcCoreCommonFunctions, SharedStateContent, SharedStateEntry, SharedStateList} from '@tibco-tcstk/tc-core-lib';
import {MessagingConfig} from '../models/messaging-config';

@Injectable({
  providedIn: 'root'
})
export class EFTLConfigService {

  constructor(private location: Location, private sharedStateService: TcSharedStateService) {
  }

  public createMessagingConfig(sandboxId: number, uiAppId: string, messagingConfig: MessagingConfig): Observable<MessagingConfig> {
    const ssName = uiAppId + '.messaging.config.tibcolabs.client.context.PUBLIC';
    const content: SharedStateContent = new SharedStateContent();
    content.json = TcCoreCommonFunctions.escapeString(JSON.stringify(messagingConfig));

    return this.sharedStateService.createSharedState(ssName, 'PUBLIC', '', sandboxId, undefined, undefined, undefined, content)
      .pipe(
        flatMap(value => {
          return this.getMessagingConfig(uiAppId, false, false);
        })
      );
  }

  public getMessagingConfig(uiAppId: string, useCache: boolean, flushCache: boolean): Observable<MessagingConfig> {
    // if useCache is false this will trigger the service to update the cached version with latest
    const ssName = uiAppId + '.messaging.config.tibcolabs.client.context.PUBLIC';

    return this.sharedStateService.getSharedState(ssName, 'PUBLIC', useCache, flushCache)
      .pipe(
        map(value => {
            if (value.sharedStateEntries.length > 0) {
              const ssresult = new MessagingConfig().deserialize(JSON.parse(value.sharedStateEntries[0].content.json));
              ssresult.id = value.sharedStateEntries[0].id;
              return ssresult;
            } else {
              return undefined;
            }
          }
        )
      );
  }

  public updateMessagingConfig(sandboxId: number, uiAppId: string, messagingConfig: MessagingConfig, id: string) {
    const ssName = uiAppId + '.messaging.config.tibcolabs.client.context.PUBLIC';
    const content: SharedStateContent = new SharedStateContent();
    content.json = TcCoreCommonFunctions.escapeString(JSON.stringify(messagingConfig));
    const entry: SharedStateEntry = new SharedStateEntry();
    entry.content = content;
    entry.sandboxId = sandboxId;
    entry.name = ssName;
    entry.type = 'PUBLIC';
    entry.id = id;
    const ssList: SharedStateList = new SharedStateList();
    ssList.sharedStateEntries = [];
    ssList.sharedStateEntries.push(entry);

    return this.sharedStateService.updateSharedState(ssList.sharedStateEntries)
      .pipe(
        map(value => {
          // flush the cache and return value
          return this.getMessagingConfig(uiAppId, true, true);
          // return new MessagingConfig().deserialize((JSON.parse(value.sharedStateEntries[0].content.json)));
        })
      );
  }

  public removeMessagingConfig(id: number): Observable<string> {
    return this.sharedStateService.deleteSharedState(id);
  }
}

result-matching ""

    No results matching ""