test3a.ts 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import { resolve } from "path";
  2. import { Observable, map, Subject, takeUntil, take } from "rxjs";
  3. import { BaseMessage } from "../dependencies/fisappmessagejsutilty/dependencies/dependencies";
  4. import { LogSetting } from "../dependencies/fisloggingservice/type/datatype";
  5. import { AcknowledgementService } from "../services/acknowledgement.service";
  6. import { IncomingMessageService } from "../services/incomingMessage.service";
  7. import { MessageSyncrhonizationService } from "../services/synchronization.service";
  8. import { MessageSynchronisationServiceSetting } from "../type/datatype";
  9. import { StreamingService } from "./test-streamOBS";
  10. /* Pre - Defined Data && Settings */
  11. const stream = new StreamingService()
  12. // Declare source Services && Observables (Using File Storage) Simulating Full Logs
  13. const source_synchronize = new MessageSyncrhonizationService()
  14. const source_payload: Observable<BaseMessage> = stream.stream()
  15. const source_incoming = new IncomingMessageService()
  16. const source_acknowledge = new AcknowledgementService()
  17. const source_payload_string = source_payload.pipe(
  18. map((data) => {
  19. return JSON.stringify(data);
  20. })
  21. )
  22. // Declare target Services && Observables (Using MongoDB Storage) Simulating Partial Logs
  23. const target_payload: Observable<BaseMessage> = stream.stream().pipe(take(2))
  24. const target_payload_subject: Subject<BaseMessage> = new Subject()
  25. target_payload.subscribe(
  26. {
  27. next: (data) => {
  28. target_payload_subject.next(data)
  29. }
  30. }
  31. )
  32. const target_incoming = new IncomingMessageService()
  33. const target_syncrhonize = new MessageSyncrhonizationService()
  34. const target_acknowledge = new AcknowledgementService()
  35. const target_payload_string = target_payload.pipe(
  36. map((data) => {
  37. return JSON.stringify(data);
  38. }),
  39. )
  40. // Decalre Source Storage
  41. let source_storage: LogSetting = {
  42. storage: "File",
  43. setting: {
  44. appName: 'Default from client',
  45. appLocName: 'To be generated in client',
  46. logLocName: 'To be generated in client',
  47. }
  48. }
  49. let source_dataSet: LogSetting & { incomingObservable: Observable<BaseMessage> } = {
  50. storage: source_storage.storage,
  51. setting: source_storage.setting,
  52. customSetting: source_storage.customSetting,
  53. incomingObservable: source_payload
  54. }
  55. //Declare Target Storage
  56. let target_storage: LogSetting = {
  57. storage: "MongoDB",
  58. setting: {
  59. appName: 'Default from client',
  60. appLocName: 'To be generated in client',
  61. logLocName: 'To be generated in client',
  62. },
  63. customSetting: {
  64. srv: true,
  65. user: "testDB",
  66. password: "h1nt1OyXw6QeUnzS",
  67. server: "cluster0.29sklte.mongodb.net",
  68. collection: "log",
  69. }
  70. }
  71. let target_dataSet: LogSetting & { incomingObservable: Observable<BaseMessage> } = {
  72. storage: target_storage.storage,
  73. setting: target_storage.setting,
  74. customSetting: target_storage.customSetting,
  75. incomingObservable: target_payload
  76. }
  77. // Combine source and target storage to form MessageSynchronisationServiceSetting
  78. let settings: MessageSynchronisationServiceSetting = {
  79. incomingSource: {
  80. //all of the settings to be combined here
  81. ...source_storage,
  82. tags: ['Incoming']
  83. }, //LogSetting & {tags:string[] },
  84. target: {
  85. ...target_storage,
  86. tags: ['Incoming']
  87. } //LogSetting & {tags:string[] }
  88. }
  89. setTimeout(()=>{
  90. target_payload_subject.next(
  91. <BaseMessage>{
  92. "header": {
  93. "messageType": "Command",
  94. "messageID": "ab05f310-f3c5-4fd0-9af1-15cda97b4444",
  95. "messageName": "Command",
  96. "dateCreated": "2023-02-13T03:33:58.746Z",
  97. "isAggregate": false,
  98. "dataSourceTiming": "",
  99. "serviceId": "",
  100. "userId": "",
  101. "requesterId": "Generatede203a86a-c99e-460e-95ff-f2dc7f484a7d",
  102. "messageProducerInformation": {
  103. "origin": {
  104. "userApplication": {
  105. "userAppId": "FisAppID/Name",
  106. "userAppName": "Client"
  107. }
  108. },
  109. "components": "Presentation"
  110. },
  111. "security": {
  112. "ucpId": "GeneratedFromMessageSync"
  113. },
  114. "messageDataLocation": {
  115. "isEmbaded": true
  116. },
  117. "messageDataFormat": {
  118. "dataFormat": "Json"
  119. },
  120. "requestExecutionMode": 0,
  121. "resquestTimeOut": 0,
  122. "command": "New"
  123. },
  124. "data": {
  125. "header": "fa29074d-9718-4aba-9999-0001",
  126. "data": {
  127. "appLogLocId": "fa29074d-9718-4aba-9999-0001",
  128. "appData": {
  129. "msgId": "6c162cd3-d42d-4ab4-8882-0001",
  130. "msgLogDateTime": "2022-12-06T15:01:46.987Z",
  131. "msgDateTime": "2022-12-06T08:50:33.809Z",
  132. "msgTag": [
  133. "oval",
  134. "likable"
  135. ],
  136. "msgPayload": "Molestias facilis iusto similique iste voluptas facere. Alias est sequi. Quos consequatur temporibus blanditiis numquam vel. Eos repellat eaque. Voluptatibus optio optio magni eveniet. Quidem architecto esse aut sint neque error magnam perspiciatis."
  137. }
  138. }
  139. }
  140. }
  141. )
  142. },2000)
  143. /* -------- SYNCHRONIZATION --------- */
  144. async function initializeData(): Promise<void> {
  145. source_incoming.init(source_dataSet)
  146. target_incoming.init(target_dataSet)
  147. return
  148. }
  149. /* Run this code to pluck some data into the database. 4 in File storage and 2 in Mongo */
  150. // initializeData()
  151. /* Testing to wrap everything into a promise */
  152. // initializeData().then(() => {
  153. // source_synchronize.init(settings).then(() => {
  154. // source_synchronize.subscribe(source_payload_string).subscribe({
  155. // next: msgToBeSynchronized => {
  156. // target_payload_subject.next(msgToBeSynchronized)
  157. // console.log(msgToBeSynchronized) // It does log missing items
  158. // }
  159. // })
  160. // })
  161. // })
  162. /* Type 1 synchronization */
  163. /* Please note that this operation assumes that there's already existing data in the designated storage place. It still cannot perform real-time live streaming dynamically
  164. when there is a streaming occuring. */
  165. source_synchronize.init(settings).then(() => {
  166. source_synchronize.subscribe(source_payload_string).subscribe({
  167. next: msgToBeSynchronized => {
  168. target_payload_subject.next(msgToBeSynchronized)
  169. // console.log(msgToBeSynchronized) // It does log missing items
  170. }
  171. })
  172. })
  173. // Doesnt seem like they do anything