|
@@ -1,45 +1,91 @@
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+Highly advisable to refer to test3c for the overall explanation of the logic flow in these
|
|
|
+test cases. Test4 is an adjusted version of test3 to cater for the need to deal with
|
|
|
+different types of data aside from messageLogs. */
|
|
|
import * as mongoose from 'mongoose'
|
|
|
import { Observable, map, Subject, takeUntil, take, of, timer, from } from "rxjs";
|
|
|
import { ErrorTrigger, MessageSynchronisationServiceSetting } from "../type/datatype";
|
|
|
import { StreamingService } from "./test-streamOBS";
|
|
|
import { MessageAuditorService } from "../services/message-auditor.service";
|
|
|
-import { LoggingService } from "../dependencies/fisloggingservice/interface/export";
|
|
|
-import { BaseMessage, ResponseMessage } from "../dependencies/fisappmessagejsutilty/interface/export";
|
|
|
-import { LogSetting } from "../dependencies/fisloggingservice/type/datatype";
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-const stream = new StreamingService()
|
|
|
-
|
|
|
-
|
|
|
-subscribers that are going to subsscribe to this source_payload. Please note that
|
|
|
-source_payload will emite the messages stream from the instance of stream service
|
|
|
-and further feed them into the other Subject which is called source_payload_subject. */
|
|
|
+import { LoggingService } from '../dependencies/log/interface/export';
|
|
|
+import { BaseMessage } from '../dependencies/msgutil/interface/export';
|
|
|
+import { LogSetting, MessageLog } from '../dependencies/log/type/datatype';
|
|
|
+import * as fs from "fs"
|
|
|
+
|
|
|
+
|
|
|
+to be used by the interface from logging and audit message features. */
|
|
|
+const Schema = mongoose.Schema;
|
|
|
+
|
|
|
+const fingerPrintSchema = new Schema({
|
|
|
+ uuid: { type: String, required: true, lowercase: true, unique: true },
|
|
|
+ fileName: { type: String, required: true, lowercase: true },
|
|
|
+ fileType: { type: String, required: true, lowercase: true },
|
|
|
+ entityName: { type: String, required: true, lowercase: true },
|
|
|
+ fileData: { type: Object, required: true },
|
|
|
+});
|
|
|
+
|
|
|
+
|
|
|
+const messageSchema = require('../dependencies/log/type/schemas/message.schema')
|
|
|
+
|
|
|
+function convertDataInMongo(url: string) {
|
|
|
+
|
|
|
+ let data: Subject<any> = new Subject()
|
|
|
+ let convertService = new LoggingService()
|
|
|
+
|
|
|
+ let dbConnection = mongoose.createConnection(url)
|
|
|
+ let dataModel = dbConnection.model('genericdata', fingerPrintSchema)
|
|
|
+ let messages = dbConnection.model('message', messageSchema)
|
|
|
+
|
|
|
+
|
|
|
+ dataModel.find().then((res) => {
|
|
|
+
|
|
|
+ res.forEach((element) => {
|
|
|
+ data.next(element)
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ data.subscribe((element) => {
|
|
|
+ let res = convertService.convertCDMStoMessageLog(element, settings.incomingSource.tags)
|
|
|
+ console.log(`Converting fingerprint .... ${res.appData.msgId}`)
|
|
|
+ messages.create(res)
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+let dbConnection = mongoose.createConnection("mongodb+srv://testDB:h1nt1OyXw6QeUnzS@cluster0.29sklte.mongodb.net/secondary")
|
|
|
+let dataModel = dbConnection.model('genericdata', fingerPrintSchema)
|
|
|
+
|
|
|
+function convertMessageLogToCDMS(args: MessageLog){
|
|
|
+ let converted = secondary_log.convertMessageLogtoCDMS(args)
|
|
|
+ dataModel.create(converted)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+the primary and the secondary soures. And then the instantiation of the corresponding subjects.
|
|
|
+The idea is that the subject will receive the missing info provided by the auditor and then log the
|
|
|
+missing data in the designated database location.
|
|
|
+ */
|
|
|
const primary_sync = new MessageAuditorService()
|
|
|
const primary_Log = new LoggingService()
|
|
|
-const primary: Subject<BaseMessage> = new Subject()
|
|
|
-primary.subscribe((e) => {
|
|
|
- console.log(`Primary Received ${e.header.messageID}`)
|
|
|
+const primary: Subject<MessageLog> = new Subject()
|
|
|
+primary.subscribe((element) => {
|
|
|
+ console.log(`Primary Received ${element.appData.msgId}`)
|
|
|
})
|
|
|
|
|
|
-
|
|
|
-to simulate streaming error. We want to see if it will sync the other 2 later
|
|
|
-on. But generall the declarative structure is the same as the above. */
|
|
|
const secondary_log = new LoggingService()
|
|
|
-const secondary: Subject<BaseMessage> = new Subject()
|
|
|
-secondary.subscribe((e) => {
|
|
|
- console.log(`Secondary Received ${e.header.messageID}`)
|
|
|
+const secondary: Subject<MessageLog> = new Subject()
|
|
|
+secondary.subscribe((element: MessageLog) => {
|
|
|
+ console.log(`Secondary Received ${element.appData.msgId}`)
|
|
|
+ convertMessageLogToCDMS(element)
|
|
|
})
|
|
|
|
|
|
|
|
|
-
|
|
|
-Hence here, is the block that definte the target and it's associated specifications.
|
|
|
-This will be the target and will receive the predefined set of data to be logged as
|
|
|
-prepared earlier in the code above.s */
|
|
|
-let publisher_storage: LogSetting = {
|
|
|
+
|
|
|
+let primary_storage: LogSetting = {
|
|
|
cacheMessageLimit: 0,
|
|
|
storage: "MongoDB",
|
|
|
setting: {
|
|
@@ -53,11 +99,7 @@ let publisher_storage: LogSetting = {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-as the target for synching. For such I purposely push only half the of the completed
|
|
|
-dataset in order to test out the sync later. I am using my own cloud atlas mongo
|
|
|
-database on this. The address can always be changed. */
|
|
|
-let subscriber_storage: LogSetting = {
|
|
|
+let secondary_storage: LogSetting = {
|
|
|
cacheMessageLimit: 0,
|
|
|
storage: "MongoDB",
|
|
|
setting: {
|
|
@@ -74,34 +116,22 @@ let subscriber_storage: LogSetting = {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
let settings: MessageSynchronisationServiceSetting = {
|
|
|
incomingSource: {
|
|
|
|
|
|
- ...publisher_storage,
|
|
|
- tags: ['Incoming']
|
|
|
+ ...primary_storage,
|
|
|
+ tags: ['Fingerprint']
|
|
|
},
|
|
|
target: {
|
|
|
- ...subscriber_storage,
|
|
|
- tags: ['Incoming']
|
|
|
+ ...secondary_storage,
|
|
|
+ tags: ['Fingerprint']
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-function initializeData() {
|
|
|
- primary_Log.init(publisher_storage).then(() => {
|
|
|
- primary_Log.subscribe(primary)
|
|
|
- })
|
|
|
- secondary_log.init(subscriber_storage).then(() => {
|
|
|
- secondary_log.subscribe(secondary)
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
primary_sync.init(settings)
|
|
|
|
|
|
|
|
@@ -110,15 +140,13 @@ let errorSubject: Subject<ErrorTrigger> = new Subject()
|
|
|
|
|
|
let sync = primary_sync.subscribe(errorSubject)
|
|
|
sync.subscribe({
|
|
|
- next: (msgToBeSynchronized) => {
|
|
|
- console.log(`passing missing message: ${msgToBeSynchronized.header.messageID} into target/secondary subject.`)
|
|
|
+ next: (msgToBeSynchronized: MessageLog) => {
|
|
|
+ console.log(`passing missing message: ${msgToBeSynchronized.appData.msgId} into target/secondary subject.`)
|
|
|
|
|
|
secondary.next(msgToBeSynchronized)
|
|
|
}
|
|
|
})
|
|
|
|
|
|
-
|
|
|
-
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
@@ -129,7 +157,7 @@ setTimeout(() => {
|
|
|
message: "NO. I dont want to work"
|
|
|
}
|
|
|
errorSubject.next(sampleError)
|
|
|
-}, 10000)
|
|
|
+}, 3000)
|
|
|
|
|
|
|
|
|
to act as additional trigger to exectute the synchronization when there's no internet
|
|
@@ -176,33 +204,11 @@ function countdown() {
|
|
|
|
|
|
countdown()
|
|
|
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-const Schema = mongoose.Schema;
|
|
|
-const fingerPrintSchema = new Schema({
|
|
|
- uuid: { type: String, required: true, lowercase: true, unique: true },
|
|
|
- fileName: { type: String, required: true, lowercase: true },
|
|
|
- fileType: { type: String, required: true, lowercase: true },
|
|
|
- entityName: { type: String, required: true, lowercase: true },
|
|
|
- fileData: { type: Object, required: true },
|
|
|
-});
|
|
|
-
|
|
|
-function convertDataInMongo(url: string) {
|
|
|
- let data: Subject<any> = new Subject()
|
|
|
- let convertService = new LoggingService()
|
|
|
-
|
|
|
- let dbConnection = mongoose.createConnection(url)
|
|
|
- let dataModel = dbConnection.model('genericdata', fingerPrintSchema)
|
|
|
- dataModel.find().then((res) => {
|
|
|
-
|
|
|
- res.forEach((element) => {
|
|
|
- data.next(element)
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- data.subscribe((element) => {
|
|
|
- convertService.
|
|
|
- })
|
|
|
-}
|
|
|
+
|
|
|
+secondary_log.init(settings.target).then(() => {
|
|
|
+ secondary_log.subscribe(secondary)
|
|
|
+})
|
|
|
|
|
|
-convertDataInMongo('mongodb+srv://testDB:h1nt1OyXw6QeUnzS@cluster0.29sklte.mongodb.net/test')
|
|
|
-convertDataInMongo('mongodb://192.168.100.59:27017/hq')
|