-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScala_Databricks_Source_Code.txt
More file actions
559 lines (259 loc) · 22.5 KB
/
Scala_Databricks_Source_Code.txt
File metadata and controls
559 lines (259 loc) · 22.5 KB
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
import org.apache.spark.sql.{DataFrame, Dataset, SparkSession,Column}
import org.apache.spark.sql.functions._
import org.apache.spark.sql.types._
import scala.util.matching.Regex
import sqlContext.implicits._
import java.util.regex.Pattern
import org.apache.spark.sql.expressions.Window
import org.apache.spark.sql.functions.row_number
import scala.collection.mutable.ArrayBuffer
import scalaj.http._
import scala.util.parsing.json._
import spray.json._
import java.util.Base64
import java.nio.charset.StandardCharsets
//User Defined function to produce comma seperated strings
//public function setProperties($properties = array()) public,function,setProperties,properties,array
def toExtract(str: String, patternString: String) = {
val pattern = Pattern.compile(patternString)
val tmplist = scala.collection.mutable.ListBuffer.empty[String]
val matcher = pattern.matcher(str)
while (matcher.find()) {
tmplist += matcher.group()
}
tmplist.mkString(",")
}
val Extract = udf(toExtract _)
// HTTP GET REQUEST FROM AIRTABLE API
val response = Http("https://v1.nocodeapi.com/testfypver1/airtable/ebdJjhwHBlWWLCbC?tableName=file&fields=Name,content").asString
val fileContent = response.body;
val readDataFrame = Seq(
("temp")
).toDF("word")
val readDataFrame1 = readDataFrame.withColumn("content", lit(fileContent));
val readDataFrame2 = readDataFrame1.withColumn("base64", regexp_extract(col("content"), ".content.:.(.*).},", 1)).drop(col("content")).drop(col("word"))
// readDataFrame2.show(false)
val fileContentBase64 = readDataFrame2.select("base64").collect().map(_.getString(0)).mkString("");
val decodedByteArray = Base64.getDecoder().decode(fileContentBase64);
val fileContentString = new String(decodedByteArray, StandardCharsets.UTF_8);
// OVERWRITE the content in test.txt if it has any content. Else, write to test.txt with the content of the file from Airtable through HTTP GET Request
dbutils.fs.put("dbfs:/FileStore/tables/test.txt", fileContentString, true)
val RDD = sc.textFile("/FileStore/tables/test.txt");
//trim whitespace
val dftempt:DataFrame = RDD.toDF("row").select(trim(col("row")).as("row"))
////SET 1
val df:DataFrame = dftempt.withColumn("ID", monotonically_increasing_id) //ADD ID to each record
// df.show(false)
val phpIdentitifer = "[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*" // matches a php identifier, thus will remove all special characters
////////////////////////////extract class name////////////////////
val classNametemp = df.filter(col("row").rlike("^class [a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*|(public|private|protected|final)\\s+class [a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*")).select(Extract(col("row"), lit(phpIdentitifer)).as("row"))
// classNametemp.show(false)
val className = classNametemp.withColumn("class", regexp_extract(col("row"), "class,([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)", 1)).drop(col("row"))
// className.show(false)
val classNameString = className.select("class").collect().map(_.getString(0)).mkString("")
// ///////////////////////extract namespace////////////////////////////
val nameSpaceTemp = df.filter(col("row").rlike("^namespace .*;$")).select(Extract(col("row"), lit(phpIdentitifer)).as("row"))
val nameSpaceRemoveKeywords = nameSpaceTemp.withColumn("remove", regexp_replace(col("row"),"namespace,", "" )).drop(col("row"))
val namespace = nameSpaceRemoveKeywords.withColumn("namespace", regexp_replace(col("remove"), "," ,"/")).drop(col("remove"))
// namespace.show(false)
val nameSpaceString = namespace.select("namespace").collect().map(_.getString(0)).mkString("")
////////////////////////extract functions//////////////////////
val functionNameTemp = df.filter(col("row").rlike("(public|private|protected) function.*\\(")).select(Extract(col("row"), lit(phpIdentitifer)).as("row"))
// functionNameTemp.show(false)
val functionName = functionNameTemp.withColumn("id", regexp_extract(col("row"), "function,([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)", 1)).drop(col("row")).withColumn("comboId", lit(classNameString))
// functionName.show(false)
/////////////////// external dependency/////////////////////
//regular expression
val externalDependencyRE = "(^\\s{0,1}require_once|^\\s{0,1}require|^\\s{0,1}include|^\\s{0,1}include_once|^\\s{0,1}use) .*;$"
val externalDependencyTemp = df.filter(col("row").rlike(externalDependencyRE)).filter(!col("row").rlike("^\\s{0,1}use function")).select(Extract(col("row"), lit(phpIdentitifer)).as("row"))
// externalDependencyTemp.show(false)
val removeKeyword = externalDependencyTemp.withColumn("remove", regexp_replace(col("row"),"(require_once,|require,|include,|include_once,|,php|use,)", "" )).drop(col("row"))
val translate = removeKeyword.withColumn("row", regexp_replace(col("remove"), "," ,"/")).drop(col("remove"))
// translate.show(false)
val externalDependency = translate.withColumn("class", lit(s"$classNameString")).withColumn( "external dependency", concat(col("row"), lit(".php"))).drop(col("row"))
// externalDependency.show(false)
// // // // // ///////////////////////Class-level dependency////////////////////////////
val classLevel1 = externalDependency.withColumn("Class-level dependency", regexp_replace(col("external dependency"), "\\w+/" ,"")).drop(col("external dependency"))
val classLevel2 = df.withColumn("class", lit(s"$classNameString")).withColumn("Class-level dependency", when(col("row").rlike("([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)::[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*\\(.*\\)"), regexp_extract(col("row"), "([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)::[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*\\(.*\\)", 1)).when(col("row").rlike("([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)::[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*"), regexp_extract(col("row"), "([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)::[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*", 1))).select(col("Class-level dependency"), concat(col("Class-level dependency"), lit(".php")) ).drop(col("row")).drop(col("ID"))
val classLevel3 = classLevel1.union(classLevel2)
val classLevel = classLevel3.filter(!col("Class-level dependency").rlike("^null$|^parent.php$|^self.php$|^static.php$")).distinct().withColumn("class", lit(s"$classNameString"))
// // //////////////////////////Package-level dependency/////////////////////////
val packageLevel = externalDependency.withColumn("nameSpace", lit(s"$nameSpaceString")).withColumn("Package-level dependency", regexp_replace(col("external dependency"), "/\\w+.\\w+$" ,"")).drop(col("external dependency")).drop(col("class")).distinct()
// // // // // ///////////////////////inheritance dependency////////////////////////////
val InheritanceRE = "^class [a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]* (extends|implements)|(public|private|protected|final)\\s+class [a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]* (extends|implements)"
val inheritanceDependencyTemp = df.filter(col("row").rlike(InheritanceRE)).select(Extract(col("row"),lit(phpIdentitifer)).as("row"))
// inheritanceDependencyTemp.show(false)
val removeKeywords = inheritanceDependencyTemp.withColumn("remove", regexp_replace(col("row"),"(extends,|implements,|class,|private,|public,|final,)", "" )).drop(col("row"))
// removeKeywords.show(false)
val arrayTypeTransform = removeKeywords.select(split(col("remove"),",").as("row"))
// arrayTypeTransform.show(false)
val inheritanceDependency = arrayTypeTransform.select(explode(col("row")).as("inheritance dependency")).withColumn("Class", lit(s"$classNameString"))
// inheritanceDependency.show(false)
val removeClassName= inheritanceDependency.where(!col("inheritance dependency").contains(lit(s"$classNameString")))
// removeClassName.show(false)
// // //////////////////function level dependency ( functions within a class) //////////////////
////SET 2
val dftempt1 = dftempt.withColumn("new_column",lit("ABC"))
@transient val w = Window.partitionBy("new_column").orderBy(lit('A'))
@transient val dataFrame = dftempt1.withColumn("ID", row_number().over(w)).drop("new_column") //ADD ID to each row in order to extract functions
// dataFrame.show(false)
dataFrame.createOrReplaceTempView("dataFrameTable")
val functions = dataFrame.filter(col("row").rlike("(public|private|protected) function.*\\("))
// functions.show(false)
val numOfFunctionRecords = functions.count().toInt
val totalNumOfRecords = dataFrame.count().toInt
val functionID = functions.select("ID").collect.map(_.getInt(0))
val seqOfFunctionDF: Seq[DataFrame] = (0 to (numOfFunctionRecords - 1)).map { i =>
if(i < (numOfFunctionRecords - 1) ) {
val query = "SELECT row AS dependency FROM dataFrameTable WHERE ID between " + functionID(i) + " AND " + (functionID(i + 1) - 1)
spark.sql(query)
}
else {
val query = "SELECT row AS dependency FROM dataFrameTable WHERE ID between " + functionID(i) + " AND " + (totalNumOfRecords - 1)
spark.sql(query)
}
}
val arrayOfFunctionDFtemp = seqOfFunctionDF.toArray // Array of function DataFrames
// arrayOfFunctionDFtemp(numOfFunctionRecords - 1).show(false)
//To clean out excess rows in dataframe
val seqOfCleanedFunctionDF: Seq[DataFrame] = (0 to (numOfFunctionRecords - 1)).map { i =>
val df = arrayOfFunctionDFtemp(i)
val dff1 = df.withColumn("new_column",lit("ABC"))
@transient val windows = Window.partitionBy("new_column").orderBy(lit('A'))
@transient val dff2 = dff1.withColumn("ID", row_number().over(windows)).drop("new_column") //ADD ID to record
val dff3 = dff2.filter(col("dependency").rlike("}"))
var finaldff = spark.emptyDataFrame
if(!dff3.head(1).isEmpty) { // ensure that it is a function with a function body
dff3.createOrReplaceTempView("functionDataFrameTable")
val dff4 = spark.sql("SELECT MAX(ID) AS ID FROM functionDataFrameTable")
val rowNumber = dff4.select("ID").collect().map(_.getInt(0)) // return Array[int]
finaldff = dff2.select(col("dependency")).filter( col("ID").between(1,rowNumber(0)))
}
if(dff3.head(1).isEmpty) { // ensure that it is a function without a function body
finaldff = df
}
finaldff //return finaldff
}
val arrayOfCleanedFunctionDFtemp = seqOfCleanedFunctionDF.toArray
//arrayOfCleanedFunctionDFtemp(5).show(false)
val seqOfFunctionDependencyDF: Seq[DataFrame] = (0 to (numOfFunctionRecords - 1)).map { i =>
val df = arrayOfCleanedFunctionDFtemp(i)
val functionNametemp = df.filter(col("dependency").rlike("(public|private|protected) function.*\\("))
val functionName = functionNametemp.withColumn("function", regexp_extract(col("dependency"), "function ([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)", 1)).drop(col("dependency"))
val functionNameString = functionName.select("function").collect().map(_.getString(0)).mkString("")
val dfFinal = df.withColumn("source", lit(functionNameString)).filter(col("dependency").rlike("->([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)\\(.*\\)|[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*::([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)\\(.*\\)|new\\W+([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)\\(.*|->.*\\W+([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)\\(.*\\)|([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)\\(.*"))
// val dfFinal1 = dfFinal.filter(!col("dependency").rlike("""function|^".*"$|\\/\\/|^\\*"""))
val dfFinal1 = dfFinal.filter(!col("dependency").rlike("""function|^".*"$|\\/\\/"""))
val finaldf = dfFinal1.withColumn("temp", when(col("dependency").rlike("->([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)\\(.*\\)"), regexp_extract(col("dependency"), "->([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)\\(.*\\)", 1)).when(col("dependency").rlike("[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*::([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)\\(.*\\)"), regexp_extract(col("dependency"), "[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*::([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)\\(.*\\)", 1)).when(col("dependency").rlike("new\\W+([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)\\(.*"),regexp_extract(col("dependency"), "new\\W+([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)\\(.*", 1) ).when(col("dependency").rlike("->.*\\W+([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)\\(.*\\)"), regexp_extract(col("dependency"), "->.*\\W+([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)\\(.*\\)", 1) )).withColumn( "target", col("temp")).drop(col("temp"))
val finaldf1 = dfFinal1.withColumn("temp", when(col("dependency").rlike("([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)\\(.*"), regexp_extract(col("dependency"), "([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)\\(.*", 1))).withColumn( "target", col("temp")).drop(col("temp"))
val dependencyString = dfFinal1.filter(col("dependency").rlike("->([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)\\(.*\\)"))
.select("dependency").collect().map(_.getString(0)).mkString("")
val dependencyArray = dependencyString.split("->").filter( x => x.contains("(") )
val dependencydf = sc.parallelize(dependencyArray).toDF("temp")
val dependencydf1 = dependencydf.withColumn("dependency", lit("null")).withColumn("source", lit(functionNameString)).withColumn("target", when(col("temp").rlike("([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)\\("), regexp_extract(col("temp"), "([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)\\(", 1))).drop(col("temp"))
val newfinaldf = finaldf.union(finaldf1).union(dependencydf1).distinct();
val outputResult = newfinaldf.filter(!col("target").rlike("^null$"))
// finaldf //return finaldff
// finaldf1
outputResult;
}
val arrayOfFunctionNameDFTemp = seqOfFunctionDependencyDF.toArray
////////// JSON formatting /////////////
val edgesDFtemp = arrayOfFunctionNameDFTemp.reduce(_ union _)
val edgesDF = edgesDFtemp.select(col("source"), col("target") )
val functionNameId = functionName.select(col("id"))
// functionNameId.show(false)
val nodetemp = edgesDF.select(col("source").alias("id")).union(edgesDF.select(col("target").alias("id")))
val NodeName1 = nodetemp.select("id").collect().map(_.getString(0)).mkString(",")
val NodeName2 = functionNameId.select("id").collect().map(_.getString(0)).mkString(",")
val nodesString = NodeName1 + "," + NodeName2;
val nodeArrayTemp = nodesString.split(",")
val nodeArray = nodeArrayTemp.distinct
println(nodeArray)
val nodesDF = spark.createDataFrame(nodeArray.map(Tuple1(_))).withColumnRenamed("_1","id").withColumn("comboId", lit(classNameString))
val nodes = nodesDF.toJSON.collect.mkString(",")
val edges = edgesDF.toJSON.collect.mkString(",")
////////////////////////////////Functional Dependency//////////////////////////////////
val classNameStringFunc = classNameString;
val packageNameStringFunc = nameSpaceString;
val nodesStringFunc = f"""[ $nodes%s] """
val edgesStringFunc = f"""[ $edges%s ] """
// println(nodesStringFunc)
// println(edgesStringFunc)
val combosStringFunc = f"""[ {"id": "$classNameStringFunc%s", "label": "$classNameStringFunc%s", "parentId": "$packageNameStringFunc%s"}, { "id": "$packageNameStringFunc%s", "label": "$packageNameStringFunc%s", "parentId": null} ] """
val functionalDependencyGraph = f""" { "nodes": $nodesStringFunc%s, "combos": $combosStringFunc%s, "edges": $edgesStringFunc%s } """
//////////////////// Class-level dependency//////////////////////
val someDF = Seq((classNameString)).toDF("id")
val someDF2 = classLevel.select(col("Class-level dependency").alias("id"))
val someDF3 = removeClassName.select(col("inheritance dependency").alias("id"))
val nodesString1 = someDF.union(someDF2).union(someDF3).toJSON.collect.mkString(",")
val nodesStringClass = f"""[ $nodesString1%s] """
val someDF4 = classLevel.select(col("class").alias("source"), col("Class-level dependency").alias("target"))
val someDF5 = removeClassName.select(col("class").alias("source"), col("inheritance dependency").alias("target"))
val edgesString1 = someDF4.union(someDF5).toJSON.collect.mkString(",")
val edgesStringClass = f"""[ $edgesString1%s ] """
val classDependencyGraph = f""" { "nodes": $nodesStringClass%s, "edges": $edgesStringClass%s } """
//////////////////// Package-level dependency///////////////////////
val someDF6 = Seq((nameSpaceString)).toDF("id")
val someDF7 = packageLevel.select(col("Package-level dependency").alias("id"))
val nodesString2 = someDF6.union(someDF7).toJSON.collect.mkString(",")
val nodesStringPackage = f"""[ $nodesString2%s] """
val edgesString2 = packageLevel.select(col("nameSpace").alias("source"), col("Package-level dependency").alias("target")).toJSON.collect.mkString(",")
val edgesStringPackage= f"""[ $edgesString2%s ] """
val packageDependencyGraph = f""" { "nodes": $nodesStringPackage%s, "edges": $edgesStringPackage%s } """
///////////////////////////Source Code Metrics////////////////////
val publicFunctionCount = RDD.filter(!_.contains("/*")).filter(!_.contains("//")).filter(f=> f.contains("public")).filter(a=> a.contains("(")).filter(b=> b.contains(")")).filter(c=>c.contains("function")).collect
val privateFunctionCount = RDD.filter(!_.contains("/*")).filter(!_.contains("//")).filter(f=> f.contains("private")).filter(a=> a.contains("(")).filter(b=> b.contains(")")).filter(c=>c.contains("function")).collect
val protectedFunctionCount = RDD.filter(!_.contains("/*")).filter(!_.contains("//")).filter(f=> f.contains("protected")).filter(a=> a.contains("(")).filter(b=> b.contains(")")).filter(c=>c.contains("function")).collect
val functionCount = publicFunctionCount ++ privateFunctionCount ++ protectedFunctionCount
val noOfFunction = functionCount.size.toString;
// println(functionCount.size)
val totalLinesOfCode = RDD.count().toString
// println(totalLinesOfCode)
val noOfClassDependency = classLevel.count().toString
// println(noOfClassDependency)
val noOfPackageDependency = packageLevel.count().toString
// println(noOfPackageDependency)
val importlibrariesCount = RDD.filter(!_.contains("/*")).filter(!_.contains("//")).filter(a=> a.contains("use")).filter(b=> b.contains(";")).collect
val noOfimportLibraries = importlibrariesCount.size.toString;
// println(noOfimportLibraries)
val objectInstanceCount = RDD.filter(!_.contains("/*")).filter(!_.contains("//")).filter(a=> a.contains("new")).filter(a=> a.contains("(")).filter(b=> b.contains(";")).collect
val noOfobjectInstance = objectInstanceCount.size.toString;
// println(objectInstanceCount.size)
///////////////////////HTTP POST REQUEST TO AIRTABLE//////////////////////////////////
def postRequestUrl(url: String, requestJson: String) = {
val httpRequest = Http(url)
.header("Content-Type", "application/json")//"application/json"
.header("Charset", "UTF-8")
.option(HttpOptions.readTimeout(10000))
val response = (requestJson != null && !requestJson.isEmpty) match {
case true => httpRequest.postData(requestJson).asString
case false => httpRequest.asString
}
response.body
}
//[{ Name: fileData.name, content: fileDataContent }]
val HttpPostURL = "https://v1.nocodeapi.com/testfypver1/airtable/ebdJjhwHBlWWLCbC?tableName=result"
val Name = classNameString + ".php";
val NameBytes = Name.getBytes(StandardCharsets.UTF_8);
val NameBase64 = Base64.getEncoder().encodeToString(NameBytes);
val functionalDependencyGraphBytes = functionalDependencyGraph.getBytes(StandardCharsets.UTF_8);
val functionalDependencyGraphBase64 = Base64.getEncoder().encodeToString(functionalDependencyGraphBytes);
val classDependencyGraphBytes = classDependencyGraph.getBytes(StandardCharsets.UTF_8);
val classDependencyGraphBase64 = Base64.getEncoder().encodeToString(classDependencyGraphBytes);
val packageDependencyGraphBytes = packageDependencyGraph.getBytes(StandardCharsets.UTF_8);
val packageDependencyGraphBase64 = Base64.getEncoder().encodeToString(packageDependencyGraphBytes);
val noOfFunctionBytes = noOfFunction.getBytes(StandardCharsets.UTF_8);
val noOfFunctionBase64 = Base64.getEncoder().encodeToString(noOfFunctionBytes);
val totalLinesOfCodeBytes = totalLinesOfCode.getBytes(StandardCharsets.UTF_8);
val totalLinesOfCodeBase64 = Base64.getEncoder().encodeToString(totalLinesOfCodeBytes);
val noOfClassDependencyBytes = noOfClassDependency.getBytes(StandardCharsets.UTF_8);
val noOfClassDependencyBase64 = Base64.getEncoder().encodeToString(noOfClassDependencyBytes);
val noOfPackageDependencyBytes = noOfPackageDependency.getBytes(StandardCharsets.UTF_8);
val noOfPackageDependencyBase64 = Base64.getEncoder().encodeToString(noOfPackageDependencyBytes);
val noOfimportLibrariesBytes = noOfimportLibraries.getBytes(StandardCharsets.UTF_8);
val noOfimportLibrariesBase64 = Base64.getEncoder().encodeToString(noOfimportLibrariesBytes);
val noOfobjectInstanceBytes = noOfobjectInstance.getBytes(StandardCharsets.UTF_8);
val noOfobjectInstanceBase64 = Base64.getEncoder().encodeToString(noOfobjectInstanceBytes);
val postRequestData = f""" [{ "Name": "$NameBase64%s", "functionalDependencyGraph": "$functionalDependencyGraphBase64%s", "classDependencyGraph": "$classDependencyGraphBase64%s", "packageDependencyGraph": "$packageDependencyGraphBase64%s", "noOfFunction": "$noOfFunctionBase64%s", "totalLinesOfCode": "$totalLinesOfCodeBase64%s", "noOfClassDependency": "$noOfClassDependencyBase64%s", "noOfPackageDependency": "$noOfPackageDependencyBase64%s", "noOfimportLibraries": "$noOfimportLibrariesBase64%s", "noOfobjectInstance": "$noOfobjectInstanceBase64%s", "fileContent": "$fileContentBase64%s" } ]"""
val postResponseBody = postRequestUrl(HttpPostURL, postRequestData);