@@ -345,6 +345,32 @@ <h1>Background process</h1>
345345}
346346
347347
348+
349+ /**
350+ * Clean Huawei GExport files.
351+ *
352+ * sed -i -r "
353+ * s/<MO className="(BSC6900GSM|BSC6900UMTS|BSC6900GU|BSC6910GSM|BSC6910UMTS|BSC6910GU)(.*)/<MO className="\1/ig;
354+ * " /mediation/data/cm/huawei/raw/motree/*.xml
355+ *
356+ * @exportFolder String Folder with the MO Tree dump XML files to be cleaned
357+ */
358+ cleanHuaweiMOTreeFiles = async ( exportFolder ) => {
359+ const replaceOptions = {
360+ files : path . join ( exportFolder , '*' ) ,
361+ from : [
362+ / < M O c l a s s N a m e = " ( B S C 6 9 0 0 G S M | B S C 6 9 0 0 U M T S | B S C 6 9 0 0 G U | B S C 6 9 1 0 G S M | B S C 6 9 1 0 U M T S | B S C 6 9 1 0 G U ) / g
363+ ] ,
364+ to : [
365+ "<MO className=\""
366+ ] ,
367+ } ;
368+
369+ return await replace . sync ( replaceOptions )
370+ }
371+
372+
373+
348374/*Use gnu sed.exe on windows
349375*
350376*/
@@ -379,6 +405,42 @@ <h1>Background process</h1>
379405
380406}
381407
408+
409+ /*
410+ * Clean Huawei MO Tree XML files.
411+ * @param string inputFolder
412+ */
413+ cleanHuaweiMOTreeWithSed = ( inputFolder ) => {
414+ let libPath = app . getAppPath ( ) ;
415+
416+ if ( ! isDev ) {
417+ libPath = process . resourcesPath ;
418+ }
419+
420+ let files = fs . readdirSync ( inputFolder , { withFileTypes : true } ) . filter ( dirent => ! dirent . isDirectory ( ) ) . map ( dirent => dirent . name ) ;
421+
422+ const sedScript = path . join ( libPath , 'libraries' , 'motree_cleanup.sed' ) ;
423+ const sed = path . join ( libPath , 'libraries' , 'sed.exe' ) ;
424+
425+ for ( let i = 0 ; i < files . length ; i ++ ) {
426+ f = files [ i ] ;
427+ inputFile = path . join ( inputFolder , f ) ;
428+
429+ log . info ( `Cleaning ${ f } ...` ) ;
430+ sendLogToUI ( 'parse_data' , 'info' , `Cleaning ${ f } ...` ) ;
431+
432+ const child = spawnSync ( sed , [ '-i' , '-r' , '-f' , sedScript , inputFile ] ) ;
433+ log . info ( `${ sed } -i -r -f ${ sedScript } ${ inputFile } ` ) ;
434+
435+ if ( child . error ) {
436+ log . info ( `[parse_cm_job] error:${ child . error . toString ( ) } ` ) ;
437+ throw child . error . toString ( ) ;
438+ }
439+ }
440+
441+ }
442+
443+
382444/*
383445* Take the latest file when there is more than one file from the same node .
384446*
@@ -460,7 +522,7 @@ <h1>Background process</h1>
460522 removeDublicateHuaweiGExportFiles ( inputFolder )
461523
462524 log . info ( `[parse_cm_job] Uncompressing files GExport XML files...` )
463- sendLogToUI ( 'parse_data' , 'info' , ` Uncompressing files GExport XML files...` ) ;
525+ sendLogToUI ( 'parse_data' , 'info' , " Uncompressing files GExport XML files..." ) ;
464526
465527 uncompressFolder ( inputFolder ) ;
466528
@@ -488,17 +550,53 @@ <h1>Background process</h1>
488550 }
489551
490552 }
553+
554+ //Clean Huawei MOTree files
555+ else if ( vendor === 'HUAWEI' && format === 'MOTREE_XML' ) {
556+ try {
557+
558+ log . info ( `Uncompressing files MOTree XML files...` ) ;
559+ sendLogToUI ( 'parse_data' , 'info' , "Uncompressing files MOTree XML files..." ) ;
560+
561+ uncompressFolder ( inputFolder ) ;
562+
563+ log . info ( `Uncompressing files MOTree XML files...` )
564+ sendLogToUI ( 'parse_data' , 'info' , "Cleaning MOTree XML files..." ) ;
565+
566+ if ( process . platform === "win32" ) {
567+ //If windows test, with sed.exe
568+ cleanHuaweiMOTreeWithSed ( inputFolder ) ;
569+ } else {
570+ await cleanHuaweiMOTreeFiles ( inputFolder ) ;
571+ }
572+
573+ log . info ( `Cleanup of MOTree XML files completed.` ) ;
574+ sendLogToUI ( 'parse_data' , 'info' , "Cleanup of MOTree XML files completed." ) ;
575+
576+ } catch ( error ) {
577+ log . error ( 'Error occurred:' , error ) ;
578+ if ( typeof error === 'undefined' ) {
579+ sendLogToUI ( 'parse_data' , 'error' , 'Error occured.' ) ;
580+ return ;
581+ }
582+ sendLogToUI ( 'parse_data' , 'error' , error . toString ( ) ) ;
583+ return ;
584+ }
585+
586+ }
587+
588+
491589 //Uncompress files for other vendor format combinations except huawei gexport
492590 //The reason for this is we want to first remove the duplicates in the dumps, before wasting time
493591 //uncompressing what does not need to be uncompressed
494- //else if(vendor !== 'HUAWEI' && format !== 'GEXPORT_XML'){
592+ //else if(vendor !== 'HUAWEI' && ( format !== 'GEXPORT_XML' || format !== 'MOTREE_XML') ){
495593 else {
496- sendLogToUI ( 'parse_data' , 'info' , ` Uncompressing files...` ) ;
497- log . info ( ` Uncompressing files...` )
594+ sendLogToUI ( 'parse_data' , 'info' , " Uncompressing files..." ) ;
595+ log . info ( " Uncompressing files..." )
498596 uncompressFolder ( inputFolder ) ;
499597 }
500598
501- sendLogToUI ( 'parse_data' , 'info' , ` Parsing files...` ) ;
599+ sendLogToUI ( 'parse_data' , 'info' , " Parsing files..." ) ;
502600 log . info ( "Parsing files..." )
503601
504602
0 commit comments