use of codeu.model.data.Activity in project codeu-2018-team12 by codeu-2018-team12.
the class ActivityStoreTest method testAddActivity.
@Test
public void testAddActivity() {
UUID activtiyId = UUID.randomUUID();
Activity inputActivity = new Activity(activtiyId, UUID.randomUUID(), UUID.randomUUID(), Instant.now(), "joinedConvo", "testMessage", new ArrayList<UUID>(), true);
activityStore.addActivity(inputActivity);
Activity resultActivity = activityStore.getActivityWithId(activtiyId);
assertEquals(inputActivity, resultActivity);
Mockito.verify(mockPersistentStorageAgent).writeThrough(inputActivity);
}
use of codeu.model.data.Activity in project codeu-2018-team12 by codeu-2018-team12.
the class ActivityStoreTest method testGetActivitiesPerPrivacy_General.
@Test
public void testGetActivitiesPerPrivacy_General() {
UUID allContentId = UUID.randomUUID();
UUID noContentID = UUID.randomUUID();
User allContentUser = new User(allContentId, "allContentUser", "password", null, Instant.now(), "codeUChatTestEmail@gmail.com");
User noContentUser = new User(noContentID, "noContentUser", "password", null, Instant.now(), "codeUChatTestEmail@gmail.com");
allContentUser.setActivityFeedPrivacy("allContent");
allContentUser.setProfilePrivacy("allContent");
noContentUser.setActivityFeedPrivacy("noContent");
noContentUser.setProfilePrivacy("noContent");
Activity activity1 = new Activity(allContentId, allContentId, allContentId, Instant.ofEpochMilli(2000), "leftConvo", "test_message", users, true);
Activity activity2 = new Activity(allContentId, allContentId, allContentId, Instant.ofEpochMilli(2000), "leftConvo", "test_message", users, true);
Activity activity3 = new Activity(noContentID, noContentID, noContentID, Instant.ofEpochMilli(2000), "leftConvo", "test_message", users, true);
Activity activity4 = new Activity(noContentID, noContentID, noContentID, Instant.ofEpochMilli(2000), "leftConvo", "test_message", users, true);
List<Activity> activityList = new ArrayList<>();
activityList.add(activity1);
activityList.add(activity2);
activityList.add(activity3);
activityList.add(activity4);
List<Activity> activitiesPerPrivacy = activityStore.getActivitiesPerPrivacy(allContentUser, activityList);
Assert.assertEquals(activity1, activitiesPerPrivacy.get(0));
Assert.assertEquals(activity2, activitiesPerPrivacy.get(1));
Assert.assertEquals(2, activitiesPerPrivacy.size());
}
use of codeu.model.data.Activity in project codeu-2018-team12 by codeu-2018-team12.
the class ConversationServlet method doPost.
/**
* This function fires when a user submits the form on the conversations page. It gets the
* logged-in username from the session and the new conversation title from the submitted form
* data. It uses this to create a new Conversation object that it adds to the model.
*/
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
String username = (String) request.getSession().getAttribute("user");
if (username == null) {
// user is not logged in, don't let them create a conversation
response.sendRedirect("/conversations");
return;
}
User user = userStore.getUser(username);
if (user == null) {
// user was not found, don't let them create a conversation
System.out.println("User not found: " + username);
response.sendRedirect("/conversations");
return;
}
String conversationTitle = request.getParameter("conversationTitle");
if (conversationTitle.isEmpty()) {
User loggedInUser = userStore.getUser(username);
List<Conversation> conversations = sort(conversationStore.getAllPermittedConversations(loggedInUser.getId()));
request.setAttribute("conversations", conversations);
request.setAttribute("error", "Please specify a name for this chat.");
request.getRequestDispatcher("/WEB-INF/view/conversations.jsp").forward(request, response);
return;
}
if (!conversationTitle.matches("[\\w*]*")) {
request.setAttribute("error", "Please enter only letters and numbers.");
request.getRequestDispatcher("/WEB-INF/view/conversations.jsp").forward(request, response);
return;
}
if (conversationStore.isTitleTaken(conversationTitle)) {
// conversation title is already taken, just go into that conversation instead of creating a
// new one
User loggedInUser = userStore.getUser(username);
List<Conversation> conversations = sort(conversationStore.getAllPermittedConversations(loggedInUser.getId()));
request.setAttribute("conversations", conversations);
request.setAttribute("error", "This conversation name is already taken.");
request.getRequestDispatcher("/WEB-INF/view/conversations.jsp").forward(request, response);
return;
}
Conversation conversation = new Conversation(UUID.randomUUID(), user.getId(), conversationTitle, Instant.now());
conversationStore.addConversation(conversation);
String activityMessage = " created a new conversation: " + "<a href=\"/chat/" + conversationTitle + "\">" + conversationTitle + "</a>.";
Activity activity = new Activity(UUID.randomUUID(), user.getId(), conversation.getId(), Instant.now(), "createdConvo", activityMessage, conversation.getConversationUsers(), conversation.getIsPublic());
activityStore.addActivity(activity);
response.sendRedirect("/chat/" + conversationTitle);
}
use of codeu.model.data.Activity in project codeu-2018-team12 by codeu-2018-team12.
the class ProfileServlet method doPost.
/**
* This function fires when a user submits the form on the profile page.
*/
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
String requestUrl = request.getRequestURI();
Part image = request.getPart("image");
String biography = request.getParameter("submitBiography");
String name = requestUrl.substring("/profile/".length());
User user = userStore.getUser(name);
if (biography != null) {
if (request.getParameter("newBio").isEmpty()) {
User loggedInUser = userStore.getUser((String) request.getSession().getAttribute("user"));
List<Activity> activities = null;
List<Activity> activitiesPermitted;
if (user != null) {
activitiesPermitted = loggedInUser == null ? sort(activityStore.getAllPublicActivitiesWithUserId(user.getId())) : sort(activityStore.getAllPermittedActivitiesWithUserId(user.getId(), loggedInUser.getId()));
activities = activityStore.getActivitiesPerPrivacy(user, activitiesPermitted);
}
request.setAttribute("error", "Please specify a biography.");
request.setAttribute("activities", activities);
request.setAttribute("loggedInUser", loggedInUser);
request.setAttribute("user", user);
request.getRequestDispatcher("/WEB-INF/view/profile.jsp").forward(request, response);
return;
}
user.setBio(request.getParameter("newBio"));
}
if (image != null) {
ImageStorage imageStorage = new ImageStorage();
String imageName = imageStorage.storeImage(image);
user.setProfilePicture(imageName);
}
response.sendRedirect(requestUrl);
}
use of codeu.model.data.Activity in project codeu-2018-team12 by codeu-2018-team12.
the class ChatServlet method joinConversation.
/**
* Adds a user to a conversation
*/
private void joinConversation(User user, Conversation conversation) {
addConversationFriends(user, conversation);
conversation.addUser(user.getId());
String activityMessage = " joined " + "<a href=\"/chat/" + conversation.getTitle() + "\">" + conversation.getTitle() + "</a>.";
Activity activity = new Activity(UUID.randomUUID(), user.getId(), conversation.getId(), Instant.now(), "leftConvo", activityMessage, conversation.getConversationUsers(), conversation.getIsPublic());
activityStore.addActivity(activity);
}
Aggregations