Skip to content

Commit 7b4c6ba

Browse files
committed
Merge branch 'main' into 5-feature-5-user-profile-display
# Conflicts: # src/main/java/interface_adapters/User_search_IA/UserPresenter.java # src/main/java/screens/Profile_screen/UserSearchUI.java # src/main/java/use_cases/user_profile_display_use_case/UserReader.java # src/test/java/TestUserSearch.java
2 parents 648181d + 65b9972 commit 7b4c6ba

File tree

19 files changed

+757
-0
lines changed

19 files changed

+757
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package entities.message;
2+
3+
import java.time.LocalDateTime;
4+
5+
/**
6+
* Message (abstract class) containing the message content and associated metadata
7+
* The type of the message content is dependent on which child(ren) of Message the message is
8+
* The metadata is universal for all message types and includes the ID of the sender, timestamp, ID of message
9+
*/
10+
public abstract class Message {
11+
/**
12+
* ID of message sender (UUID)
13+
*/
14+
private final String senderID;
15+
/**
16+
* Time message was sent
17+
*/
18+
private final LocalDateTime timestamp;
19+
/**
20+
* ID of message (UUID)
21+
*/
22+
private final String msgID;
23+
24+
/**
25+
* Construct a new message
26+
* @param senderID ID of sender
27+
* @param timestamp time message was sent
28+
* @param msgID ID of message
29+
*/
30+
public Message(String senderID, LocalDateTime timestamp, String msgID) {
31+
this.senderID = senderID;
32+
this.timestamp = timestamp;
33+
this.msgID = msgID;
34+
}
35+
36+
/**
37+
* Gets ID of sender
38+
* @return ID of sender
39+
*/
40+
public String getSenderID() {
41+
return senderID;
42+
}
43+
44+
/**
45+
* Gets message timestamp
46+
* @return message timestamp
47+
*/
48+
public LocalDateTime getTimestamp() {
49+
return timestamp;
50+
}
51+
52+
/**
53+
* Gets ID of message
54+
* @return ID of message
55+
*/
56+
public String getMsgID() {
57+
return msgID;
58+
}
59+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package entities.message;
2+
3+
import java.time.LocalDateTime;
4+
import java.util.UUID;
5+
6+
public class MsgFactory {
7+
private final String msgType;
8+
9+
public MsgFactory(String msgType) {
10+
this.msgType = msgType;
11+
}
12+
13+
public Message createMsg(String senderID, Object msgContent) {
14+
if (msgType.equalsIgnoreCase("text")) {
15+
return new TextMessage(senderID, (String) msgContent, LocalDateTime.now(), UUID.randomUUID().toString());
16+
// ID of message's sender, message text/content, timestamp of message, ID of message
17+
} else {
18+
System.out.println("A " + msgType.toLowerCase() + " is an undefined message type for this program.");
19+
// TODO: implement exception
20+
return null;
21+
}
22+
}
23+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package entities.message;
2+
3+
import java.time.LocalDateTime;
4+
5+
/**
6+
* A message with text as its content (child of Message)
7+
*/
8+
public class TextMessage extends Message {
9+
/**
10+
* Text content of message
11+
*/
12+
private String msgContent;
13+
14+
/**
15+
* Construct a text message
16+
* @param senderID ID of sender
17+
* @param msgContent text content
18+
* @param timestamp message timestamp
19+
* @param msgID ID of message
20+
*/
21+
public TextMessage(String senderID, String msgContent, LocalDateTime timestamp, String msgID) {
22+
super(senderID, timestamp, msgID);
23+
this.msgContent = msgContent;
24+
}
25+
26+
/**
27+
* Gets text content of a message
28+
* @return message content
29+
*/
30+
public String getMsgContent() {
31+
return msgContent;
32+
}
33+
34+
/**
35+
* Sets text content of a message
36+
* @param msgContent updated message content
37+
*/
38+
public void setMsgContent(String msgContent) {
39+
this.msgContent = msgContent;
40+
}
41+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package interface_adapters.profile_modification_IA;
2+
3+
public interface ChangeController {
4+
public boolean reportChange(String username, String password, String feature, String newFeature);
5+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package screens.profile_update_screen; /**
2+
* Provides the UI elements
3+
*/
4+
import interface_adapters.profile_modification_IA.ChangeController;
5+
6+
import javax.swing.*;
7+
import java.awt.*;
8+
import java.awt.event.ActionEvent;
9+
import java.awt.event.ActionListener;
10+
11+
public class UserModificationUI implements ChangeController {
12+
private JLabel label;
13+
public UserModificationUI() {
14+
final JFrame frame = new JFrame();
15+
frame.setSize(500, 300);
16+
17+
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
18+
frame.setLayout(new FlowLayout());
19+
20+
// Field for username
21+
final JTextField usernameField = new JTextField("Enter your current username");
22+
usernameField.setBounds(10, 25, 100, 25);
23+
24+
// Field for password
25+
final JTextField passwordField = new JTextField("Enter your current password");
26+
passwordField.setBounds(10, 25, 100, 25);
27+
28+
// to select feature that user wants to change
29+
JLabel lbl = new JLabel("<html>Select what feature<br>you wish to change</html>");
30+
lbl.setVisible(true);
31+
lbl.setBounds(10, 25, 100, 25);
32+
String[] choices = { "Username","Password", "Email"};
33+
final JComboBox<String> cb = new JComboBox<>(choices);
34+
35+
// new value of the feature
36+
final JTextField newFeatureField = new JTextField("Enter the new value for this feature and click OK");
37+
newFeatureField.setBounds(10, 25, 100, 25);
38+
39+
40+
// OK button to process
41+
JButton btn = new JButton("OK");
42+
43+
btn.addActionListener(new ActionListener() {
44+
@Override
45+
public void actionPerformed(ActionEvent e) {
46+
String username = (usernameField.getText());
47+
String password = (passwordField.getText());
48+
String item = cb.getSelectedItem().toString();
49+
String newFeature = (newFeatureField.getText());
50+
boolean success = reportChange(username, password, item, newFeature);
51+
if (success){
52+
label.setText("Your " + item + " was successfully changed.");
53+
}
54+
else{
55+
label.setText("<html>Change was not successful.<br>Please make sure your username and " +
56+
"<br>password match an existing account.</html>");
57+
}
58+
}
59+
});
60+
61+
label = new JLabel();
62+
63+
frame.add(usernameField);
64+
frame.add(passwordField);
65+
frame.add(cb);
66+
frame.add(lbl);
67+
frame.add(newFeatureField);
68+
frame.add(btn);
69+
frame.add(label);
70+
71+
72+
frame.setVisible(true);
73+
}
74+
75+
// profile_modification_IA.ChangeController makes UI implement reportChange to invert the use-case --> UI dependency
76+
@Override
77+
public boolean reportChange(String username, String password, String feature, String newFeature) {
78+
UserDatabase db = new UserDatabase();
79+
if (db.UserExists(username)){
80+
User user = db.getUser(username);
81+
if (user.PasswordMatch(password) & user.getUsername().equals(username)){
82+
user.changeFeature(feature, newFeature);
83+
// this serializes the change
84+
db.modifyUser(username, user);
85+
return true;
86+
}
87+
}
88+
return false;
89+
}
90+
91+
// for trying out the code:
92+
// public static void main(String[] args) {
93+
// new profile_update_screen.UserModificationUI();
94+
//
95+
// }
96+
97+
}

src/main/java/tutorial/Chat.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package tutorial;
2+
import java.util.ArrayList;
3+
4+
/**
5+
* Copied from Branch Chat Initiation
6+
**/
7+
public class Chat {
8+
protected String name;
9+
protected String chatID;
10+
protected String senderUsername;
11+
12+
// chat's conversation history
13+
protected ArrayList<Message> convHist;
14+
15+
16+
/**
17+
* Get the chat's name
18+
* @return name
19+
*/
20+
public String getName(){
21+
return this.name;
22+
}
23+
24+
/**
25+
* Get the chat's ID
26+
* @return chatID
27+
*/
28+
public String getChatID(){
29+
return this.chatID;
30+
}
31+
32+
/**
33+
* Get the sender's username
34+
* @return senderUsername
35+
*/
36+
public String getSenderUsername(){
37+
return this.senderUsername;
38+
}
39+
40+
/**
41+
* Return this conversation history of the chat
42+
* @return convHist
43+
*/
44+
public ArrayList<Message> getConvHist(){
45+
return new ArrayList<Message>(this.convHist);
46+
}
47+
48+
/**
49+
* Add a message to the chat's conversation history when a message is sent or received
50+
* @param message Message that is sent or received
51+
*/
52+
public void addtoconvHist(Message message){
53+
this.convHist.add(message);
54+
}
55+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package tutorial;
2+
import java.time.LocalDateTime;
3+
/**
4+
* Copied from Branch Conversation History
5+
* **/
6+
public abstract class Message {
7+
/**
8+
* ID of message sender (UUID)
9+
*/
10+
private final String senderID;
11+
/**
12+
* Time message was sent
13+
*/
14+
private final LocalDateTime timestamp;
15+
/**
16+
* ID of message (UUID)
17+
*/
18+
private final String msgID;
19+
20+
21+
/**
22+
* Construct a new message
23+
* @param senderID ID of sender
24+
* @param timestamp time message was sent
25+
* @param msgID ID of message
26+
*/
27+
public Message(String senderID, LocalDateTime timestamp, String msgID) {
28+
this.senderID = senderID;
29+
this.timestamp = timestamp;
30+
this.msgID = msgID;
31+
}
32+
33+
/**
34+
* Gets ID of sender
35+
* @return ID of sender
36+
*/
37+
public String getSenderID() {
38+
return senderID;
39+
}
40+
41+
/**
42+
* Gets message timestamp
43+
* @return message timestamp
44+
*/
45+
public LocalDateTime getTimestamp() {
46+
return timestamp;
47+
}
48+
49+
/**
50+
* Gets ID of message
51+
* @return ID of message
52+
*/
53+
public String getMsgID() {
54+
return msgID;
55+
}
56+
57+
//Implemented this method from James' code -Emma
58+
public abstract String getMsgContent();
59+
60+
61+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package tutorial;
2+
3+
import java.time.LocalDateTime;
4+
import java.util.ArrayList;
5+
6+
7+
/**
8+
* The input boundary for the login use case.
9+
*/
10+
// Note: The interface that the SearchUseCase implements
11+
// It specifies what the input (arguments) and output (return type) are.
12+
13+
public interface SearchInputBoundary {
14+
ArrayList<Message> SearchBykeyword(Chat c, String word);
15+
16+
ArrayList<Message> SearchBytime(Chat c, LocalDateTime time);
17+
18+
Message SearchByNewest(ArrayList<Message> ar);
19+
}

0 commit comments

Comments
 (0)