-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAppFacade.java
98 lines (81 loc) · 2.53 KB
/
AppFacade.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
97
98
import java.util.UUID;
/**
* @author Cam Osterholt
* @version v1.0
* Date: 10/10/2023
*/
public class AppFacade {
private User activeUser;
private Company activeCompany;
private Board activeBoard;
private static AppFacade appFacade;
private AppFacade() {
activeUser = null;
activeCompany = null;
activeBoard = null;
}
public static AppFacade getInstance() {
if(appFacade == null)
appFacade = new AppFacade();
return appFacade;
}
public User getActiveUser() {
return activeUser;
}
public boolean setActiveUser(User active){
if(active == null)
return false;
activeUser = active;
return true;
}
public Board getActiveBoard() {
return activeBoard;
}
public boolean login(String username, String password) {
activeUser = LoginManager.getInstance().getUser(username, password);
if(activeUser == null){
return false;
}
return true;
}
public User getCurrentUser(){
return activeUser;
}
public UUID signUp(String firstName, String lastName, String email, String password) {
User user = new User(firstName, lastName, email, password);
LoginManager.getInstance().addUser(user);
setActiveUser(user);
return user.getId();
}
public User getUser(UUID id) {
return LoginManager.getInstance().getUser(id);
}
public void logOut() {
LoginManager.getInstance().saveUsers();
LoginManager.getInstance().saveTasks();
LoginManager.getInstance().saveCompanies();
System.exit(0);
}
public Company getActiveCompany() {
return activeCompany;
}
public boolean setActiveCompany(String name) {
if(name == null)
return false;
return null != (activeCompany = CompanyManager.getInstance().getCompany(name));
}
public boolean setActiveCompany(Company company) {
if(company == null)
return false;
return null != (activeCompany = company);
}
public boolean setActiveBoard(String name) {
return (activeBoard = AppFacade.getInstance().getActiveCompany().getBoard(name)) != null;
}
public String toString(){
String toReturn = "\nActive User: "+ activeUser.getFirstName()+ " "+ activeUser.getLastName();
toReturn += "\nActive Company: "+ activeCompany.getName();
toReturn += "\nActive Board: "+ activeBoard.getTitle();
return toReturn;
}
}