-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdminController.java
96 lines (73 loc) · 2.39 KB
/
AdminController.java
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
import java.util.*;
import Basic.Facility;
import Basic.Member;
import Basic.TimeSlot;
import Basic.User;
import Basic.Utility;
import Common.CreateMemberException;
public class AdminController {
private DataPool DataPool;
private User admin;
private AdminView view2;
public AdminController(User admin, DataPool DataPool) {
this.DataPool = DataPool;
this.admin = admin;
}
public void attachView(AdminView view){
this.view2 = view;
}
public void run(){
view2.show();
}
public void deleteMember(String name) throws InvalidMemberException{
try{
User p = DataPool.getMember(name);
DataPool.removeMember(name);
}
catch(InvalidMemberException ex){
throw new InvalidMemberException();
}
}
public void resetMemberPassword(String name, String password) throws CreateMemberException{
try{
User p = DataPool.getMember(name);
if(!password.matches("^[a-zA-Z]\\w{3,14}$")) throw new CreateMemberException("Strong password required");
password = Utility.getHash(password);
p.setHashedPassword(password);
}
catch(InvalidMemberException ex){
throw new CreateMemberException("Member not found");
}
}
public ArrayList<Facility> getFacilityList(){
return DataPool.getFacilityList();
}
public ArrayList<TimeSlot> getSlotList(){
return DataPool.getSlotList();
}
public void changeAdminPassword(String password1, String password2) throws InvalidPasswordException {
if (password1.equals(password2)) {
password2 = Utility.getHash(password2);
admin.setHashedPassword(password2);
} else {
throw new InvalidPasswordException();
//System.out.println("Different passwords, update failed");
}
}
public void saveMemberData(){
DataPool.saveMembersData();
}
public void createBooking(String date, int facility, int timeSlot, int paxCount, int price) {
// TODO Auto-generated method stub
int a = admin.getId();
DataPool.createBooking(date, a, facility, timeSlot, paxCount, price);
}
public void createFacility(String name, String facility, int pricePeak, int priceNonPeak, int cap) {
// TODO Auto-generated method stub
DataPool.createFacility(name, facility, pricePeak, priceNonPeak, cap);
}
public void updateFacility(int idToUpdate, String name, String facility, int pricePeak, int priceNonPeak, int cap) {
// TODO Auto-generated method stub
DataPool.updateFacility(idToUpdate, name, facility, pricePeak, priceNonPeak, cap);
}
}