-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntegration.java
More file actions
139 lines (114 loc) · 5.02 KB
/
Copy pathIntegration.java
File metadata and controls
139 lines (114 loc) · 5.02 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
package dashboard;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Integration {
private static final String FILE_SEPARATOR = System.getProperty("file.separator");
public static void page() {
CodeUtil.clearScreen();
String path = getPath();
// Ensure the files exist, create them if needed...
ensureFilesExist(path);
// Display stats from intstats.csv:
File intStatsFile = new File(path + FILE_SEPARATOR + "dashboard" + FILE_SEPARATOR + "files" + FILE_SEPARATOR + "intstats.csv");
displayIntStats(intStatsFile);
// Display tables from integration.csv:
File integrationFile = new File(path + FILE_SEPARATOR + "dashboard" + FILE_SEPARATOR + "files" + FILE_SEPARATOR + "integration.csv");
displayIntegrationTable(integrationFile);
System.out.print("\nPress any key to go to the Navigation page...");
waitForUserInput();
Navigation.navbar();
}
private static void waitForUserInput() {
try {
System.in.read();
} catch (IOException e) {
System.out.println("Error while waiting for user input: " + e.getMessage());
}
}
private static String getPath() {
try {
return new File(".").getCanonicalPath();
} catch (IOException e) {
System.out.println("Error: while getting the path of the program.");
return "";
}
}
//Shows the statistics for past integrations:
private static void displayIntStats(File file) {
System.out.println("Integration Stats:\n");
try (Scanner scanner = new Scanner(file)) {
// Display the header
if (scanner.hasNextLine()) {
System.out.println(scanner.nextLine());
}
// Display the data
while (scanner.hasNextLine()) {
System.out.println(scanner.nextLine());
}
} catch (IOException e) {
System.out.println("Error reading file: " + e.getMessage());
}
System.out.println();
// Add a newline for better formatting
}
private static void displayIntegrationTable(File file) {
System.out.println("Integration Table:\n");
try (Scanner scanner = new Scanner(file)) {
// Display the header
if (scanner.hasNextLine()) {
System.out.println(scanner.nextLine());
}
// Display the data with proper formatting
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
String[] fields = line.split(",");
if (fields.length == 5) {
System.out.printf("%-20s%-15s%-15s%-15s%-20s\n", fields[0], fields[1], fields[2], fields[3], fields[4]);
} else {
System.out.println("Error: Missing tokens in the input file. Skipping the current line.");
}
}
} catch (IOException e) {
System.out.println("Error reading file: " + e.getMessage());
}
}
private static void ensureFilesExist(String path) {
try {
// Ensure intstats.csv exists
File intStatsFile = new File(path + FILE_SEPARATOR + "dashboard" + FILE_SEPARATOR + "files" + FILE_SEPARATOR + "intstats.csv");
if (!intStatsFile.exists()) {
createIntStatsFile(intStatsFile);
}
// Ensure integration.csv exists
File integrationFile = new File(path + FILE_SEPARATOR + "dashboard" + FILE_SEPARATOR + "files" + FILE_SEPARATOR + "integration.csv");
if (!integrationFile.exists()) {
createIntegrationFile(integrationFile);
}
} catch (IOException e) {
System.out.println("Error while ensuring files exist: " + e.getMessage());
}
}
//backup option for creating a default file if it doesn't exist:
private static void createIntStatsFile(File file) throws IOException {
// Create intstats.csv with headers and data
try (PrintWriter writer = new PrintWriter(file)) {
writer.println("MonthYear,Deployments");
writer.println("Oct-22,8");
writer.println("Nov-22,12");
writer.println("Dec-22,15");
writer.println("Jan-23,10");
}
}
private static void createIntegrationFile(File file) throws IOException {
// Create integration.csv with headers and data
try (PrintWriter writer = new PrintWriter(file)) {
writer.println("PipelineName,Environment,Branch,Status,LastRunTimestamp");
writer.println("SQL-Analyze-Dev,Dev,Feature-123,Success,30-10-2023 08:00");
writer.println("SQL-Deploy-Dev,Dev,Main,Success,30-10-2023 08:05");
writer.println("SQL-Test-Dev,Dev,Feature-124,Failed,30-10-2023 08:10");
writer.println("SQL-Analyze-Prod,Production,Main,Success,30-10-2023 08:15");
}
}
}