@Test public void followBasicTest() { SocialUser user1 = new SocialUser("user1"); SocialUser user2 = new SocialUser("user2"); user1.follow(user2); assertTrue(user1.getFollowingName().contains(user2.getUserName())); assertTrue(user2.getFollowersName().contains(user1.getUserName())); }
@Override public JsonElement serialize(SocialUser socialUser, Type type, JsonSerializationContext jsonSerializationContext) { final JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("userName", socialUser.getUserName()); jsonObject.addProperty("realName", socialUser.getRealName()); jsonObject.addProperty("email", socialUser.getEmail()); serializeList(socialUser, "following", socialUser.getFollowingName(), jsonObject); serializeList(socialUser, "followers", socialUser.getFollowersName(), jsonObject); return jsonObject; }
public void unfollow(SocialUser anotherUser) { if (!this.equals(anotherUser)) { followingName.remove(anotherUser.getUserName()); anotherUser.removeFollower(this); } }
public void follow(SocialUser anotherUser) { if (validate(anotherUser)) { followingName.add(anotherUser.getUserName()); anotherUser.addFollower(this); } }
@Override public List<SocialActivitiesEvent> execute(String parameterValue, List<SocialActivitiesEvent> events) { List<SocialActivitiesEvent> newList = new ArrayList<SocialActivitiesEvent>(); for (SocialActivitiesEvent event : events) { String name = event.getSocialUser().getUserName(); SocialUser socialUser = new SocialUser(name.toUpperCase()); SocialActivitiesEvent socialEvent = new SocialActivitiesEvent(socialUser, event.getType(), event.getTimestamp()); newList.add(socialEvent); } return newList; }
public static SocialActivitiesEvent getDummyLastWrittenMarker() { if (dummyLastWrittenMarker == null) { dummyLastWrittenMarker = new SocialActivitiesEvent(new SocialUser("DUMMY"), DefaultTypes.DUMMY_EVENT, new Date()); } return dummyLastWrittenMarker; }
public void sync(SocialUser user) { if (!usersNamesCache.contains(user.getUserName())) { usersNamesCache.add(user.getUserName()); } usersCache.put(user.getUserName(), user); } }
public void callback(final List<SocialUser> users) { allusers.clear(); allusersBadge.setText(String.valueOf(users.size())); Collections.sort(users, new SocialUserNameComparator()); for (final SocialUser socialUser : users) { allusers.add(createUserItem(socialUser, socialUser.getFollowersName().contains(socialLoggedUser.getUserName()))); } printAllFollowing(users); printAllFollowers(users); } },
private void printAllFollowing(final List<SocialUser> users) { allfollowing.clear(); followingBadge.setText(String.valueOf(socialLoggedUser.getFollowingName().size())); if (socialLoggedUser.getFollowingName().isEmpty()) { final ListGroupItem user = new ListGroupItem(); user.setText(constants.CurrentlyNotFollowingAnyUser()); allfollowing.add(user); } else { for (final SocialUser following : users) { if (socialLoggedUser.getFollowingName().contains(following.getUserName())) { allfollowing.add(createUserItem(following, true)); } } } }
private ListGroupItem createUserItem(final SocialUser socialUser, final boolean follow) { final ListGroupItem user = new ListGroupItem(); final Image userImage = imageProvider.getImageForSocialUser(socialUser, ImageSize.SMALL); userImage.addStyleName("img-circle"); userImage.addStyleName(Styles.PULL_LEFT); user.getWidget(0).getElement().getStyle().setPaddingLeft(10, Style.Unit.PX); user.add(userImage); user.setText(socialUser.getName()); if (socialUser.getUserName().equals(socialLoggedUser.getUserName()) == false) { user.add(createFollowButton(socialUser, follow)); } return user; }
@Override public void saveUserEvent(SocialActivitiesEvent event) { SocialUser eventUser = event.getSocialUser(); addEventToTimeline(event, eventUser); for (String followerName : eventUser.getFollowersName()) { SocialUser follower = socialUserRepository.findSocialUser(followerName); addEventToTimeline(event, follower); } }
public static Image generate(SocialUser socialUser, ImageSize imageSize) { if (socialUser.getEmail().isEmpty()) { return generateDefaultImage(imageSize); } else { return generateGravatarImage(socialUser, imageSize); } }
@Override public void userFollowAnotherUser(String followerUsername, String followUsername) { SocialUser follower = socialUserPersistenceAPI.getSocialUser(followerUsername); SocialUser follow = socialUserPersistenceAPI.getSocialUser(followUsername); follower.follow(follow); socialUserPersistenceAPI.updateUsers(follower, follow); followedEvent.fire(new SocialUserFollowedEvent(follower, follow)); }
@Override public List<SocialActivitiesEvent> execute(String parameterValue, List<SocialActivitiesEvent> events) { List<SocialActivitiesEvent> newList = new ArrayList<SocialActivitiesEvent>(); for (SocialActivitiesEvent event : events) { String name = event.getSocialUser().getUserName(); SocialUser socialUser = new SocialUser(name.toUpperCase()); SocialActivitiesEvent socialEvent = new SocialActivitiesEvent(socialUser, event.getType(), event.getTimestamp()); newList.add(socialEvent); } return newList; }
@Override public SocialUser deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { final JsonObject jsonObject = jsonElement.getAsJsonObject(); final JsonElement userName = jsonObject.get("userName"); final JsonElement realName = jsonObject.get("realName"); final JsonElement email = jsonObject.get("email"); List<String> followers = deserializeUserNames(jsonObject.get("followers").getAsJsonArray()); List<String> following = deserializeUserNames(jsonObject.get("following").getAsJsonArray()); SocialUser socialUser = new SocialUser(userName.getAsString(), realName.getAsString(), email.getAsString(), followers, following); return socialUser; }
public void sync(SocialUser user) { if (!usersNamesCache.contains(user.getUserName())) { usersNamesCache.add(user.getUserName()); } usersCache.put(user.getUserName(), user); } }
public void callback(final List<SocialUser> users) { allusers.clear(); allusersBadge.setText(String.valueOf(users.size())); Collections.sort(users, new SocialUserNameComparator()); for (final SocialUser socialUser : users) { allusers.add(createUserItem(socialUser, socialUser.getFollowersName().contains(socialLoggedUser.getUserName()))); } printAllFollowing(users); printAllFollowers(users); } },
private void printAllFollowing(final List<SocialUser> users) { allfollowing.clear(); followingBadge.setText(String.valueOf(socialLoggedUser.getFollowingName().size())); if (socialLoggedUser.getFollowingName().isEmpty()) { final ListGroupItem user = new ListGroupItem(); user.setText(constants.CurrentlyNotFollowingAnyUser()); allfollowing.add(user); } else { for (final SocialUser following : users) { if (socialLoggedUser.getFollowingName().contains(following.getUserName())) { allfollowing.add(createUserItem(following, true)); } } } }
private ListGroupItem createUserItem(final SocialUser socialUser, final boolean follow) { final ListGroupItem user = new ListGroupItem(); final Image userImage = imageProvider.getImageForSocialUser(socialUser, ImageSize.SMALL); userImage.addStyleName("img-circle"); userImage.addStyleName(Styles.PULL_LEFT); user.getWidget(0).getElement().getStyle().setPaddingLeft(10, Style.Unit.PX); user.add(userImage); user.setText(socialUser.getName()); if (socialUser.getUserName().equals(socialLoggedUser.getUserName()) == false) { user.add(createFollowButton(socialUser, follow)); } return user; }