Repository navigation
Expand file tree
/
Copy pathStudentTest.java
More file actions
234 lines (195 loc) · 9.45 KB
/
Copy pathStudentTest.java
File metadata and controls
234 lines (195 loc) · 9.45 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
package test;
import java.io.File;
import java.sql.Date;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import javax.swing.JFileChooser;
import database.bean.Admin;
import database.bean.student.Biodata;
import database.bean.student.EducationalBackground;
import database.bean.student.MeanOfDiscovery;
import database.bean.student.Phone;
import database.bean.student.ProfessionalExperience;
import database.bean.student.Sponsor;
import database.bean.student.Student;
import database.bean.student.StudentData;
import database.managers.ConnectionManager;
import database.managers.DatabaseManager;
import database.managers.StudentManager;
import exception.InvalidAdminException;
import utils.ValidationType;
public class StudentTest
{
public static void main(String[] args) throws SQLException, InvalidAdminException
{
Admin currentAdmin = new Admin("Chidi", "OguejioforTheGreat" );
DatabaseManager.setCurrentAdmin(currentAdmin);
if( !DatabaseManager.validateAdmin())
throw new InvalidAdminException("The current Admin is invalid");
System.out.println("--------REGISTERING A NEW STUDENT TEST---------");
System.out.println("You'll need to fill the registeration form" );
System.out.println("\n----Creating Student Object---" );
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("Select the image of the student");
chooser.showOpenDialog(null);
System.out.println("Select File" );
File image = chooser.getSelectedFile();
final String studentId = TestUtils.getStringInput("Input Student Id card number: ");
String mail = TestUtils.getStringInput("Input the student emial address: ");
String className = TestUtils.getStringInput("Input the student class: ");
String firstName = TestUtils.getStringInput("Input Student Surname:" );
String lName= TestUtils.getStringInput("Input Student last name: ");
Student student = new Student(firstName, lName, studentId, className, mail, image);
if( student.isValid(ValidationType.NEW_BEAN))
System.out.println("The Student object is valid" );
else{
System.err.println("The Student is not valid");
System.exit(0);
}
System.out.println("\n----Creating Biodata object------");
String state = TestUtils.getStringInput("Input the student state of origin: ");
String country = TestUtils.getStringInput("Input Country of origin: ") ;
String currAddr = TestUtils.getStringInput("Input current address: ");
String permAddr = TestUtils.getStringInput("Input Permanent address: ");
String gender = TestUtils.getStringInput("Input gender: ");
String birthString = TestUtils.getStringInput("Input birth date in the format(dd-mm-yyyy): ");
String birthPlace = TestUtils.getStringInput("Input Place of birth: ");
String religion = TestUtils.getStringInput("What's your religion? " );
String title = TestUtils.getStringInput("input your title(eg Mr, Mrs, Dr etc): ");
DateFormat df = new SimpleDateFormat( "dd-mm-yyyy" );
Date birth = null;
try
{
birth = new Date( df.parse( birthString).getTime());
}
catch (ParseException e)
{
e.printStackTrace();
}
Biodata bio = new Biodata(studentId, state, country, currAddr,
permAddr, gender, birth, birthPlace, religion, title);
if( bio.isValid(ValidationType.NEW_BEAN))
System.out.println("The bio data is valid" );
else{
System.err.println("The bio data object is invalid");
System.exit(0);
}
System.out.println("-------Creating Educational Background object------");
ArrayList<EducationalBackground> educationList = new ArrayList<>();
System.out.println("Input first School you attended" );
EducationalBackground eduBack = TestUtils.getEducationBackground(studentId, df);
educationList.add( eduBack);
System.out.println("Do you want to input information about the next school you attended");
String inputNext = TestUtils.getStringInput("Input 1 if yes else quit");
while( inputNext.trim().equals( "1"))
{
eduBack = TestUtils.getEducationBackground(studentId, df);
educationList.add(eduBack);
System.out.println("Do you want to input information about the next school you attended");
inputNext = TestUtils.getStringInput("Input 1 if yes else quit");
}
System.out.println("--------KEY EDUCATION DATA--------");
String highestQualification = TestUtils.getStringInput("Enter your highest Qualification you have attained: ");
String courseRead = TestUtils.getStringInput("Enter the course you read: " );
String lastInstituteAttended = TestUtils.getStringInput("Enter the last institute you attended: ");
if( educationList.stream().allMatch(e->e.isValid(ValidationType.NEW_BEAN)))
System.out.println("EducationBacground object can be inputed into the database" );
else{
System.err.println("EducationBackground object is invalid");
System.exit(0);
}
System.out.println("-----Creating MeansOfDiscovery objects------" );
ArrayList<MeanOfDiscovery> meanList = new ArrayList<>();
MeanOfDiscovery discObj = TestUtils.getMeansOfDiscovery(studentId);
meanList.add( discObj);
System.out.println("Is there any other way you heard of the program" );
inputNext = TestUtils.getStringInput("Input 1 to if so else 0 " );
while( inputNext.equals( "1" ) ){
discObj = TestUtils.getMeansOfDiscovery(studentId);
meanList.add(discObj);
System.out.println("Is there any other way you heard of the program" );
inputNext = TestUtils.getStringInput("Input 1 to if so else 0 " );
}
if( meanList.stream().allMatch(mean->mean.isValid( ValidationType.NEW_BEAN) ) )
System.out.println("All inputed discovery means are valid" );
else{
System.err.println("A means of discvory was invalid" );
System.exit(0);
}
System.out.println("---Creating phone number objects for the Student------" );
String number = TestUtils.getStringInput("Input phone number" );
Phone phone = new Phone(studentId, number);
Set<Phone> phoneSet = new HashSet<>();
phoneSet.add(phone);
System.out.println("Are there more phone numbers" );
inputNext = TestUtils.getStringInput("Input 1 if there are more: " );
while( inputNext.trim().equals( "1" ) )
{
number = TestUtils.getStringInput("Input phone number" );
phone = new Phone(studentId, number);
phoneSet.add(phone);
System.out.println("Are there more phone numbers" );
inputNext = TestUtils.getStringInput("Input 1 if there are more: " );
}
if( phoneSet.stream().allMatch( pNum-> pNum.isValid(ValidationType.NEW_BEAN) ) )
System.out.println("All the phone numbers format are valid" );
else{
System.err.println("At least one phone number was invalid") ;
System.exit(0);
}
System.out.println("-------Creating ProfessionalExperience object------" );
System.out.println("Have you worked before? " );
inputNext = TestUtils.getStringInput("Input 1 if you have: ");
if( inputNext.equals( "1" ) )
System.out.println("input informations about your first job" );
ProfessionalExperience exp;
ArrayList<ProfessionalExperience> expList = new ArrayList<>();
while( inputNext.equals("1") ){
exp = TestUtils.getExperience(studentId, df);
expList.add( exp);
System.out.println("Have you worked anywhere else?" );
inputNext = TestUtils.getStringInput("Input 1 if so: " );
}
System.out.println("<<<<<<<<<<Key Experience Info>>>>>>>>");
String currentWorkPlace = TestUtils.getStringInput("Enter where you currently work: " );
int yearsExperience = Integer.parseInt( TestUtils.getStringInput("Enter the number of years you have been working: " ));
if( expList.stream().allMatch( ex->ex.isValid( ValidationType.NEW_BEAN) ) )
System.out.println("The ProfessionalExperience object is valid" );
else{
System.err.println("At least one Experience in the list was invalid") ;
System.exit(0);
}
System.out.println("----Creating the Sponsor aray object--------");
System.out.println("Do you have any sponsor? ");
String nextInput = TestUtils.getStringInput("Type 1 if so else no: ");
List<Sponsor> list = new LinkedList<>();
while( nextInput.equals("1") ){
Sponsor sponsor = TestUtils.getSponsor(studentId);
list.add( sponsor);
System.out.println("Do you have any other sponsor? ");
nextInput = TestUtils.getStringInput("Type 1 if so else no: ");
}
Sponsor[] sponsArray = list.toArray(new Sponsor[list.size()] );
EducationalBackground[] eduArray =
educationList.toArray(new EducationalBackground[ educationList.size()] );
Phone[] phoneArray = phoneSet.toArray(new Phone[phoneSet.size()] );
ProfessionalExperience[] expArray = expList.toArray( new ProfessionalExperience[ expList.size()] );
MeanOfDiscovery[] meanArr = meanList.toArray(new MeanOfDiscovery[meanList.size()] );
StudentData studentData =
new StudentData(highestQualification, currentWorkPlace,
courseRead, yearsExperience, lastInstituteAttended, bio, eduArray,phoneArray,expArray, meanArr, sponsArray);
System.out.println( "isStudData valid: " + studentData.isValid(ValidationType.NEW_BEAN));
if( StudentManager.registerStudent(student, studentData))
System.out.println("The new Student was registered successfully" );
else
System.err.println("Student not registered for some reason" );
ConnectionManager.close();
}
}