Repository navigation
Expand file tree
/
Copy pathMultipleCertReg.java
More file actions
101 lines (76 loc) · 3.07 KB
/
Copy pathMultipleCertReg.java
File metadata and controls
101 lines (76 loc) · 3.07 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
package test;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Set;
import database.bean.Admin;
import database.managers.CertificateRegisterManager;
import database.managers.ConnectionManager;
import database.managers.DatabaseManager;
import exception.InvalidAdminException;
import utils.BeanType;
public class MultipleCertReg
{
public static void main(String[] args) throws SQLException, InvalidAdminException
{
try{
Admin currentAdmin = new Admin("Chidi", "OguejioforTheGreat" );
DatabaseManager.setCurrentAdmin(currentAdmin);
System.out.println("----------MODULES---------");
TestUtils.displayBean(BeanType.MODULE, 0);
System.out.println("---------CERTIFICATES------");
TestUtils.displayBean(BeanType.CERTIFICATE, 0);
String selectedCert = TestUtils.getStringInput("Input a certificate name: ");
viewCertDetails(selectedCert);
System.out.println("--------ADDING MULTIPLE CERT TO MODULE------");
Set<String> set = new HashSet<>();
String userInput = TestUtils.getStringInput("Enter Module name or -1 to quit: ");
while(!userInput.equals("-1")){
set.add(userInput );
userInput = TestUtils.getStringInput("Enter Module name or -1 to quit: ");
}
boolean success = CertificateRegisterManager.addMultipleModules(
selectedCert, set.toArray(new String[set.size()]));
if(success){
System.out.printf("Successfully inserted all the modules to %s\n", selectedCert);;
}else{
System.err.printf("Error occured while inserting some modules to %s\n", selectedCert);;
}
viewCertDetails(selectedCert);
System.out.println("--------REMOVING MULTIPLE CERT TO MODULE------");
set = new HashSet<>();
userInput = TestUtils.getStringInput("Enter Module name or -1 to quit: ");
while(!userInput.equals("-1")){
set.add(userInput );
userInput = TestUtils.getStringInput("Enter Module name or -1 to quit: ");
}
success = CertificateRegisterManager.removeMultipleModules(
selectedCert, set.toArray(new String[set.size()]));
if(success){
System.out.printf("Successfully inserted all the modules to %s\n", selectedCert);;
}else{
System.err.printf("Error occured while inserting some modules to %s\n", selectedCert);;
}
}finally{
ConnectionManager.close();
}
}
/**
* @param selectedCert
* @throws SQLException
*/
public static void viewCertDetails(String selectedCert) throws SQLException
{
String[] moduleRequired = CertificateRegisterManager.getModules(selectedCert, true);
String[] moduleNotRequired = CertificateRegisterManager.getModules(selectedCert, false);
System.out.printf("--------MODULES REQUIRED FOR %S------\n",selectedCert );
for (String module : moduleRequired)
{
System.out.println(module);
}
System.out.printf("\n--------MODULES NOT REQUIRED FOR %S------\n",selectedCert );
for (String module : moduleNotRequired)
{
System.out.println(module);
}
}
}