-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFourthHandler.java
More file actions
58 lines (45 loc) · 2.05 KB
/
FourthHandler.java
File metadata and controls
58 lines (45 loc) · 2.05 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
package Controller.SingletonClasses.Handlers;
import Controller.Profile.Elements.Email.EmailI;
import Controller.Profile.ProfileI;
import Controller.SingletonClasses.Creator;
import Controller.SingletonClasses.Database;
import Controller.SingletonClasses.Deleter;
import java.util.UUID;
public class FourthHandler implements HandlerI{
private final String concern = "MoveToFolder";
private HandlerI successor = FifthHandler.getInstance();
private static FourthHandler instance = null;
private FourthHandler(){}
public static FourthHandler getInstance(){
if(instance == null){
return new FourthHandler();
}else {
return instance;
}
}
@Override
public void handle(String concern, EmailI email, String folderName) throws Exception {
if(concern == this.concern){
Database database = Database.getInstance();
if(database.getProfilebyUsername("", email.getOwner()) == null){
throw new Exception("THERE IS NO PROFILE BY THIS USERNAME");
}
ProfileI owner = database.getProfilebyUsername("", email.getOwner());
String ID = UUID.randomUUID().toString();
if(email.getEmailType().equals("Inbox")){
owner.getProfileFolderbyName(folderName).addEmail(Creator.getInstance().createEmailDataProfileFolder(email, owner, folderName, ID));
}
if(email.getEmailType().equals("Sent")){
owner.getProfileFolderbyName(folderName).addEmail(Creator.getInstance().createEmailDataProfileFolder(email, owner, folderName, ID));
}
if(email.getEmailType().equals("Draft")){
owner.getProfileFolderbyName(folderName).addEmail(Creator.getInstance().createEmailDataProfileFolder(email, owner, folderName, ID));
}
}else{
if(this.successor == null){
throw new Exception("NO HANDLER CAN HANDLE THIS CONCERN");
}
this.successor.handle(concern, email, folderName);
}
}
}