-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUpdate_HCPCS_Part1.gradle
751 lines (628 loc) · 28.3 KB
/
Update_HCPCS_Part1.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
/*
****************************
* HCPCS Vocabulary update *
* Version 0.0.7 *
****************************
*/
group 'com.sci.vocabulary'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'org.apache.poi:poi:3.9'
classpath 'org.apache.poi:poi-ooxml:3.9'
classpath 'javax.mail:javax.mail-api:1.5.5'
classpath group: 'commons-io', name: 'commons-io', version: '2.5'
classpath 'org.apache.commons:commons-lang3:3.5'
}
}
repositories {
mavenLocal()
mavenCentral()
}
configurations {
mail
}
dependencies {
mail 'org.apache.ant:ant-javamail:1.8.1'
}
/**
* JAVA-CODE SECTION.
*
* Temporary java code are located here. If future it's need to move it toi separate java-module.
*/
import groovy.io.FileType
import org.apache.poi.ss.usermodel.Cell
import org.apache.poi.ss.usermodel.Row
import org.apache.poi.ss.usermodel.Workbook
import org.apache.poi.ss.usermodel.WorkbookFactory
import org.apache.poi.ss.usermodel.Sheet
import org.apache.commons.io.FileUtils
import org.apache.commons.lang3.StringUtils
import java.nio.charset.StandardCharsets
/*
task compileOne(type: JavaCompile) {
source = sourceSets.main.java.srcDir
include 'inc.odysseus.utils/StringBuilderWrapper.java'
classpath = sourceSets.main.output.classesDir
destinationDir = sourceSets.main.output.classesDir
}
compileOne.options.compilerArgs = ["-sourcepath", "${projectDir}/src/main/java"]
*/
/**
* Auxiliary classes. TODO: Further should be used java-defined and compiled only
*/
class StringBuilderWrapper implements java.lang.Appendable {
private static final String IDENT_CHAR = " " *4
private StringBuilder wrapped
StringBuilderWrapper() {
wrapped = new StringBuilder()
}
StringBuilderWrapper(String value) {
this()
wrapped.append(IDENT_CHAR).append(value)
}
static StringBuilderWrapper getBuilder() {
return new StringBuilderWrapper()
}
static String readFromFile(File file) {
if (file == null)
return ''
def builder = getBuilder()
def br = new BufferedReader(new FileReader(file))
def strLine
while ((strLine = br.readLine()) != null) {
builder.append('\n').append(strLine)
}
return builder.toString()
}
@Override
Appendable append(CharSequence csq) throws IOException {
wrapped.append(IDENT_CHAR).append(csq)
return this
}
@Override
Appendable append(CharSequence csq, int start, int end) throws IOException {
wrapped.append(IDENT_CHAR).append(csq, start, end)
return this
}
@Override
Appendable append(char c) throws IOException {
wrapped.append(IDENT_CHAR).append(c)
return this
}
@Override
String toString() {
return wrapped.toString()
}
}
class StringHelper {
public static final String CSV_FIELD_SEPARATOR = ";"
public static String normalizeString(String value) {
String result = new String(value);
// If empty - just return
if (StringUtils.isBlank(value))
return result;
boolean doubleQuotesProcessed = false
// Replace all number of double quotes by twice double quotes
if (result.indexOf("\"") >= 0) {
result = result.replaceAll("(\"{1,1})", "\"\"");
doubleQuotesProcessed = true;
}
// Replace all double quotes by
if (result.indexOf(CSV_FIELD_SEPARATOR) >= 0 || doubleQuotesProcessed) {
result = String.format("\"%s\"", result);
}
// Replace all carriage return to space
if (result.indexOf("\n") >= 0) {
result = result.replaceAll("\n", " ");
}
// Replace all carriage return to space
if (result.indexOf("\r") >= 0) {
result = result.replaceAll("\r", " ");
}
// Replace the 'EN DASH' (U+2013) by the 'HYPHEN-MINUS' (U+002D)
if (result.indexOf("\u2013") >= 0) {
result = result.replaceAll("\u2013", "\u002D");
}
return result;
}
}
/**
* JAVA-CODE SECTION
*/
// Load HCPCS properties
Properties props = new Properties()
props.load(new FileInputStream("${project.rootDir}/Update_HCPCS.properties"))
props.each {prop ->
project.ext.set(prop.key, prop.value)
}
props.load(new FileInputStream("${project.getBuildFile().toString().replace('.gradle', '.properties')}"))
props.each {prop ->
project.ext.set(prop.key, prop.value)
}
def tempDir = File.createTempDir()
tempDir.deleteOnExit()
/**
* Just renew user schema and prepare it for further vocabulary update
*/
task fastRecreateSchema(description: project.properties['fastRecreate.description']) << {
println '\n\n***********************************************'
println '* *'
println "* '${description}' action started... *"
println '* *'
println '***********************************************'
// Start action checkpoint
def timeStart = System.currentTimeMillis()
def sqlFile = "${project.properties['basePath']}/${project.properties['fastRecreate.sqlFileName']}"
def logFile = "${project.properties['logPath']}/${project.properties['fastRecreate.logFileName']}"
def streamLogFile = "${project.properties['logPath']}/${project.properties['fastRecreate.streamLogFileName']}"
def streamErrorFile = "${project.properties['logPath']}/${project.properties['fastRecreate.streamErrFileName']}"
def db = [un : project.properties['db.userName'],
pw : project.properties['db.password'],
tns : project.properties['db.tnsName'],
sqlfile: sqlFile,
logfile: logFile]
def sOut = new StringBuilderWrapper(), sErr = new StringBuilderWrapper()
def sqlPlus = """sqlplus -L ${db.un}/${db.pw}@${db.tns} @${db.sqlfile} ${db.logfile}""".execute()
sqlPlus.consumeProcessOutput(sOut, sErr)
sqlPlus.waitFor()
// Finish action checkpoint
def timeFinish = System.currentTimeMillis()
/**
* Write to console.
* Write compact SQLPlus's spool log
*/
File lf = new File(logFile)
if (lf.exists())
System.out.println(StringBuilderWrapper.readFromFile(lf))
// Write to logfile
File f = new File(streamLogFile)
f.write(sOut.toString())
// Write to error file
f = new File(streamErrorFile)
f.write(sErr.toString())
/* Check for errors */
if (Boolean.valueOf(project.properties['stop.on.error'].toString()) && (sqlPlus.exitValue() != 0 || (sErr != null && sErr.toString().length() > 0))) {
throw new GradleException(String.format(project.properties['error.message.with.code'], sqlPlus.exitValue(), name))
}
// Measure time execution
def timeElapsed = (timeFinish - timeStart) / 1000
println "Time elapsed: ${timeElapsed} seconds."
println "*** '${description}' action done ***"
}
/**
* This task will prepare user schema for vocabulary update routine.
* It will create auxiliary table - the "ANWEB_V2" in our case, for example.
*/
task createSourceTable(dependsOn: fastRecreateSchema, description: project.properties['createSourceTable.description']) << {
println '\n\n***********************************************'
println '* *'
println "* '${description}' action started... *"
println '* *'
println '***********************************************'
// Start action checkpoint
def timeStart = System.currentTimeMillis()
def sqlFile = "${project.properties['basePath']}/${project.properties['createSourceTable.sqlFileName']}"
def logFile = "${project.properties['logPath']}/${project.properties['createSourceTable.logFileName']}"
def streamLogFile = "${project.properties['logPath']}/${project.properties['createSourceTable.streamLogFileName']}"
def streamErrorFile = "${project.properties['logPath']}/${project.properties['createSourceTable.streamErrFileName']}"
def db = [un : project.properties['db.userName'],
pw : project.properties['db.password'],
tns : project.properties['db.tnsName'],
sqlfile: sqlFile,
logfile: logFile]
def sOut = new StringBuilderWrapper(), sErr = new StringBuilderWrapper()
def sqlPlus = """sqlplus ${db.un}/${db.pw}@${db.tns} @${db.sqlfile} ${db.logfile}""".execute()
sqlPlus.consumeProcessOutput(sOut, sErr)
sqlPlus.waitFor()
// Finish action checkpoint
def timeFinish = System.currentTimeMillis()
/**
* Write to console.
* Write compact SQLPlus's spool log
*/
File lf = new File(logFile)
if (lf.exists())
System.out.println(StringBuilderWrapper.readFromFile(lf))
// Write to logfile
File f = new File(streamLogFile)
f.write(sOut.toString())
// Write to error file
f = new File(streamErrorFile)
f.write(sErr.toString())
/* Check for errors */
if (Boolean.valueOf(project.properties['stop.on.error'].toString()) && (sqlPlus.exitValue() != 0 || (sErr != null && sErr.toString().length() > 0))) {
throw new GradleException(String.format(project.properties['error.message.with.code'], sqlPlus.exitValue(), name))
}
// Measure time execution
def timeElapsed = (timeFinish - timeStart) / 1000
println "Time elapsed: ${timeElapsed} seconds."
println "*** '${description}' action done ***"
}
/**
* Task which will download vocabulary update package from source host.
* This one - 'http://www.cms.gov/Medicare/Coding/HCPCSReleaseCodeSets/' is our case.
*/
task downloadUpdatePack(dependsOn: createSourceTable, description: project.properties['downloadUpdatePack.description']) << {
println '\n\n***********************************************'
println '* *'
println "* '${description}' action started... *"
println '* *'
println '***********************************************'
/* Downloading file */
// Start action checkpoint
def timeStart = System.currentTimeMillis()
println new StringBuilderWrapper('downloading file...')
println new StringBuilderWrapper("stored to: ${tempDir.getPath()}")
ant.get(src: project.properties['downloadUpdatePack.fileUrl'], dest: tempDir, verbose: true)
println new StringBuilderWrapper('download completed')
// Finish action checkpoint
def timeFinish = System.currentTimeMillis()
def timeElapsed = (timeFinish - timeStart) / 1000
println "Time elapsed: ${timeElapsed} seconds."
println "*** '${description}' action done ***"
}
task extractFiles(dependsOn: downloadUpdatePack, description: project.properties['extractFiles.description']) << {
println '\n\n***********************************************'
println '* *'
println "* '${description}' action started... *"
println '* *'
println '***********************************************'
// Start action checkpoint
def timeStart = System.currentTimeMillis()
/* Extracting file */
def fileList = []
def dir = tempDir
dir.eachFile(FileType.FILES) { file ->
fileList << file
if (file.getPath().endsWith('zip')) {
print new StringBuilderWrapper("Extracting ${file} ...")
ant.unzip(src: file.getPath(), dest: tempDir, overwrite: false)
println ' done'
}
}
// Finish action checkpoint
def timeFinish = System.currentTimeMillis()
// Measure time execution
def timeElapsed = (timeFinish - timeStart) / 1000
println "Time elapsed: ${timeElapsed} seconds."
println "*** '${description}' action done ***"
}
/**
* This task will convert a XLS data file to CSV format.
*/
task xls2Csv(dependsOn: extractFiles, description: project.properties['xls2Csv.description']) << {
println '\n\n*************************************************'
println '* *'
println "* '${description}' action started... *"
println '* *'
println '*************************************************'
def inputFile = "${tempDir.getPath()}/${project.properties['xls2Csv.srcFileName']}"
def outputFile = "${tempDir.getPath()}/${project.properties['xls2Csv.destFileName']}"
// Start action checkpoint
def timeStart = System.currentTimeMillis()
// For storing data into CSV files
StringBuffer data = new StringBuffer()
OutputStream outputStream = null
try {
outputStream = new FileOutputStream(outputFile)
// Get the workbook object for XLS file
Workbook workbook = WorkbookFactory.create(new FileInputStream(inputFile))
// Get first sheet from the workbook
Sheet sheet = workbook.getSheetAt(0)
for (int i = 0; i <= sheet.getLastRowNum(); i++){
Row row = sheet.getRow(i)
if (row!= null){
for (int j = 0; j < row.getLastCellNum(); j++){
Cell cell = row.getCell(j)
if (cell == null){
data.append(";")
} else {
cell.setCellType(Cell.CELL_TYPE_STRING)
String cellText = cell.toString().trim()
data.append(StringHelper.normalizeString(cellText))
if (j < row.getLastCellNum()) {
data.append(";")
}
}
}
data.append('\n')
}
}
println new StringBuilderWrapper('file converted...')
outputStream.write(data.toString().getBytes(StandardCharsets.UTF_8))
outputStream.flush()
} catch (Exception e) {
throw new GradleException(String.format(project.properties['error.message'], e.getMessage(), name))
} finally {
if (outputStream != null)
outputStream.close()
}
// Finish action checkpoint
def timeFinish = System.currentTimeMillis()
// Measure time execution
def timeElapsed = (timeFinish - timeStart) / 1000
println "Time elapsed: ${timeElapsed} seconds."
println "*** '${description}' action done ***"
}
/**
* Task performed import CSV data to database
*/
task importData(dependsOn: xls2Csv, description: project.properties['importData.description']) << {
println '\n\n***********************************************'
println '* *'
println "* '${description}' action started... *"
println '* *'
println '***********************************************'
// Start action checkpoint
def timeStart = System.currentTimeMillis()
def dataFile = "${tempDir.getPath()}/${project.properties['importData.dataFileName']}"
def logFile = "${project.properties['logPath']}/${project.properties['importData.logFileName']}"
def discardFile = "${project.properties['logPath']}/${project.properties['importData.discardFileName']}"
def badFile = "${project.properties['logPath']}/${project.properties['importData.badFileName']}"
def streamLogFile = "${project.properties['logPath']}/${project.properties['importData.streamLogFileName']}"
def streamErrorFile = "${project.properties['logPath']}/${project.properties['importData.streamErrFileName']}"
def bosOut = new ByteArrayOutputStream(), bosErr = new ByteArrayOutputStream()
def sOut = new StringBuilderWrapper(), sErr = new StringBuilderWrapper()
exec {
executable "sqlldr"
args "USERID=${project.properties['db.userName']}/${project.properties['db.password']}@${project.properties['db.tnsName']} " +
"CONTROL=${project.properties['basePath']}/${project.properties['importData.controlFileName']} " +
"DATA=${dataFile} " +
"LOG=${logFile} " +
"DISCARD=${discardFile} " +
"BAD=${badFile}"
standardOutput = bosOut
errorOutput = bosErr
}
def bisOut = new ByteArrayInputStream(bosOut.toByteArray())
bisOut.withReader { out->
out.eachLine {
sOut.append(it).append('\n')
}
}
def bisErr = new ByteArrayInputStream(bosErr.toByteArray())
bisErr.withReader { out ->
out.eachLine {
sErr.append(it).append('\n')
}
}
/**
* Write to console.
* When import prefer to write stream log to console (it's shorter).
*/
System.out.println(sOut.toString())
// Write to logfile
File f = new File(streamLogFile)
f.write(sOut.toString())
// Write to error file
f = new File(streamErrorFile)
f.write(sErr.toString())
// Finish action checkpoint
def timeFinish = System.currentTimeMillis()
// Measure time execution
def timeElapsed = (timeFinish - timeStart) / 1000
println "Time elapsed: ${timeElapsed} seconds."
println "*** '${description}' action done ***"
}
/**
* This task will run 'Load stage' script.
* Seems it's is specific for each vocabulary.
*/
task loadStage(dependsOn: importData, description: project.properties['loadStage.description']) << {
println '\n\n***********************************************'
println '* *'
println "* '${description}' action started... *"
println '* *'
println '***********************************************'
// Start action checkpoint
def timeStart = System.currentTimeMillis()
def sqlFile = "${project.properties['basePath']}/${project.properties['loadStage.sqlFileName']}"
def logFile = "${project.properties['logPath']}/${project.properties['loadStage.logFileName']}"
def streamLogFile = "${project.properties['logPath']}/${project.properties['loadStage.streamLogFileName']}"
def streamErrorFile = "${project.properties['logPath']}/${project.properties['loadStage.streamErrFileName']}"
def logFileProcedureDrug = "${project.properties['logPath']}/${project.properties['loadStage.logProcedureDrugFileName']}"
def db = [un : project.properties['db.userName'],
pw : project.properties['db.password'],
tns : project.properties['db.tnsName'],
devSchema : project.properties['vocabulary.dev.schema'],
sqlfile : sqlFile,
logfile : logFile,
contextPath : "${project.properties['basePath']}",
logfileProcedureDrug: logFileProcedureDrug]
def sOut = new StringBuilderWrapper(), sErr = new StringBuilderWrapper()
def sqlPlus = """sqlplus ${db.un}/${db.pw}@${db.tns} @${db.sqlfile} ${db.logfile} ${db.contextPath} ${db.logfileProcedureDrug} ${db.devSchema}""".execute()
sqlPlus.consumeProcessOutput(sOut, sErr)
sqlPlus.waitFor()
// Finish action checkpoint
def timeFinish = System.currentTimeMillis()
/**
* Write to console.
* Write compact SQLPlus's spool log
*/
File lf = new File(logFile)
if (lf.exists())
System.out.println(StringBuilderWrapper.readFromFile(lf))
lf = new File(logFileProcedureDrug)
if (lf.exists())
System.out.println(StringBuilderWrapper.readFromFile(lf))
// Write to logfile
File f = new File(streamLogFile)
f.write(sOut.toString())
// Write to error file
f = new File(streamErrorFile)
f.write(sErr.toString())
/* Check for errors */
if (Boolean.valueOf(project.properties['stop.on.error'].toString()) && (sqlPlus.exitValue() != 0 || (sErr != null && sErr.toString().length() > 0))) {
throw new GradleException(String.format(project.properties['error.message.with.code'], sqlPlus.exitValue(), name))
}
// Measure time execution
def timeElapsed = (timeFinish - timeStart) / 1000
println "Time elapsed: ${timeElapsed} seconds."
println "*** '${description}' action done ***"
}
/**
* This task will create 'Manual Table' to pass for manual mapping processing
* */
task createManualTable(dependsOn: loadStage, description: project.properties['createManualTable.description']) << {
println '\n\n***********************************************'
println '* *'
println "* '${description}' action started... *"
println '* *'
println '***********************************************'
// Start action checkpoint
def timeStart = System.currentTimeMillis()
def sqlFile = "${project.properties['basePath']}/${project.properties['createManualTable.sqlFileName']}"
def logFile = "${project.properties['logPath']}/${project.properties['createManualTable.logFileName']}"
def streamLogFile = "${project.properties['logPath']}/${project.properties['createManualTable.streamLogFileName']}"
def streamErrorFile = "${project.properties['logPath']}/${project.properties['createManualTable.streamErrFileName']}"
def db = [un : project.properties['db.userName'],
pw : project.properties['db.password'],
tns : project.properties['db.tnsName'],
sqlfile : sqlFile,
tableName: "${project.properties['manualTableName']}",
logfile : logFile]
def sOut = new StringBuilderWrapper(), sErr = new StringBuilderWrapper()
def sqlPlus = """sqlplus ${db.un}/${db.pw}@${db.tns} @${db.sqlfile} ${db.logfile} ${db.tableName}""".execute()
sqlPlus.consumeProcessOutput(sOut, sErr)
sqlPlus.waitFor()
// Finish action checkpoint
def timeFinish = System.currentTimeMillis()
/**
* Write to console.
* Write compact SQLPlus's spool log
*/
File lf = new File(logFile)
if (lf.exists())
System.out.println(StringBuilderWrapper.readFromFile(lf))
// Write to logfile
File f = new File(streamLogFile)
f.write(sOut.toString())
// Write to error file
f = new File(streamErrorFile)
f.write(sErr.toString())
// Measure time execution
def timeElapsed = (timeFinish - timeStart) / 1000
println "Time elapsed: ${timeElapsed} seconds."
println "*** '${description}' action done ***"
}
task extractManualTable(/*dependsOn: [createManualTable, loadStage]*/dependsOn: createManualTable, description: project.properties['extractManualTable.description']) << {
println '\n\n***********************************************'
println '* *'
println "* '${description}' action started... *"
println '* *'
println '***********************************************'
// Start action checkpoint
def timeStart = System.currentTimeMillis()
// TODO: Need to deeply check why piped output does not works here (the > operator below)
def sqlFile = "${project.properties['basePath']}/${project.properties['extractManualTable.sqlFileName']}"
def streamLogFile = "${project.properties['logPath']}/${project.properties['extractManualTable.streamLogFileName']}"
def streamErrorFile = "${project.properties['logPath']}/${project.properties['extractManualTable.streamErrFileName']}"
def db = [un : project.properties['db.userName'],
pw : project.properties['db.password'],
tns : project.properties['db.tnsName'],
expPath : "${project.properties['basePath']}",
sqlfile : sqlFile,
expcsvfile: "${project.properties['manualTableFileName']}",
tableName : "${project.properties['manualTableName']}"]
def sOut = new StringBuilderWrapper(), sErr = new StringBuilderWrapper()
print new StringBuilderWrapper('extracting table...')
def sqlPlus = """sqlplus ${db.un}/${db.pw}@${db.tns} @${db.sqlfile} ${db.expPath} ${db.expcsvfile} ${db.tableName}""".execute()
sqlPlus.consumeProcessOutput(sOut, sErr)
sqlPlus.waitFor()
println 'done'
// Finish action checkpoint
def timeFinish = System.currentTimeMillis()
// Write to logfile
/**
* Skip writing log file because it size could be so big.
* Only error stream should be written.
*/
// File f = new File(streamLogFile)
// f.write(sout.toString())
// Write to error file
File f = new File(streamErrorFile)
f.write(sErr.toString())
// Measure time execution
def timeElapsed = (timeFinish - timeStart) / 1000
println "Time elapsed: ${timeElapsed} seconds."
println "*** '${description}' action done ***"
}
/**
* Send e-mail notification
*/
task sendMail(dependsOn: extractManualTable, description: project.properties['sendMail.description']) << {
println '\n\n***********************************************'
println '* *'
println "* '${description}' action started... *"
println '* *'
println '***********************************************'
// Start action checkpoint
def timeStart = System.currentTimeMillis()
def mailParams = [
mailhost : project.properties['sendMail.mailHost'],
subject : project.properties['sendMail.Subject'],
messagemimetype: "text/plain",
user : project.properties['sendMail.user'],
password : project.properties['sendMail.password']
]
println new StringBuilderWrapper('sending mail...')
configurations.mail.each {
org.apache.tools.ant.Project.class.classLoader.addURL(it.toURI().toURL())
}
ant.mail( mailParams ) {
from(address: project.properties['sendMail.sentFrom'])
to(address: project.properties['sendMail.sentTo'])
message(String.format(project.properties['sendMail.Message'], "${project.properties['basePath']}/${project.properties['manualTableFileName']}"))
}
// Finish action checkpoint
def timeFinish = System.currentTimeMillis()
// Measure time execution
def timeElapsed = (timeFinish - timeStart) / 1000
println "Time elapsed: ${timeElapsed} seconds."
println "*** '${description}' action done ***"
}
/**
* Bootstrap action
*
* TODO: Needs to find solution to measure whole task chain execution.
* TODO: This one via doFirst/doLast actions isn't working.
*/
task startUpdate(dependsOn: sendMail, description: project.properties['startUpdate.description']) {
println '\n\n***********************************************'
println '* *'
println "* '${description}' action started... *"
println '* *'
println '***********************************************'
println "Updating of '${project.properties['vocabulary.display.name']}' vocabulary on the '${project.properties['db.userName']}@${project.properties['db.tnsName']}' schema...\n"
project.ext['logPath'] = "${project.properties['basePath']}/${project.properties['baseLogPath']}"
def folder = new File(project.properties['logPath'])
if (!folder.exists()) {
folder.mkdirs()
println "Log directory is created: ${folder.getPath()}"
} else {
FileUtils.cleanDirectory(folder)
println "Log directory is cleaned: ${folder.getPath()}"
}
// Start action checkpoint
def timeStart = System.currentTimeMillis()
doLast {
// Finish action checkpoint
def timeFinish = System.currentTimeMillis()
// Measure time execution
def timeElapsed = (timeFinish - timeStart) / 1000
println "\n\nTotal time elapsed: ${timeElapsed} seconds."
println "Updating of '${project.properties['vocabulary.display.name']}' vocabulary on the '${project.properties['db.userName']}@${project.properties['db.tnsName']}' schema is completed successfully..."
println '***********************************************'
println '* *'
println "* '${description}' action is done... *"
println '* *'
println '***********************************************\n'
}
}