Commits

Paola Morales  committed 6a6dc0a

New follower Services

  • Participants
  • Parent commits 69ec1cb

Comments (0)

Files changed (3)

File encuestame-business/src/main/java/org/encuestame/business/service/SecurityService.java

     public List<UnitLists> getListbyUsername(final String username) throws EnMeDomainNotFoundException{
             return ConvertDomainBean.convertEmailListToBean(getEmailListsDao().findListbyUser(getPrimaryUser(username)));
     }
+
+    /**
+     * Get Followers User.
+     * @param username
+     * @return
+     * @throws EnMeDomainNotFoundException
+     */
+    public Integer getFollowers(final String username) throws EnMeDomainNotFoundException{
+    	UserAccount userAcc = getUser(username);
+    	final Integer followers = userAcc.getFollowers().size();
+    	return followers;
+    }
+
+
+    /**
+     * Follow Operations.
+     *  FollowOperations.FOLLOW - to follow user.
+     *  FollowOperations.UNFOLLOW - to unfollow user.
+     * @param userAcc
+     * @param myUsername
+     * @param followerUser
+     * @param operation
+     * @throws EnMeDomainNotFoundException
+     */
+	public void followOperations(final UserAccount userAcc,
+			final String myUsername, final String followerUser,
+			final FollowOperations operation) throws EnMeDomainNotFoundException {
+		final UserAccount myAccount = getUser(myUsername);
+		final UserAccount myFollower = getUser(followerUser);
+		if (FollowOperations.FOLLOW.equals(operation)) {
+			myAccount.getFollowers().add(myFollower);
+		} else if (FollowOperations.UNFOLLOW.equals(operation)) {
+			for (UserAccount dataAccount : myAccount.getFollowers()) {
+				if (myFollower.getUsername().equals(dataAccount.getUsername())) {
+					userAcc.getFollowers().remove(dataAccount);
+					getAccountDao().delete(dataAccount);
+				}
+			}
+		}
+		getAccountDao().saveOrUpdate(myAccount);
+	}
+
+    /**
+     * Add Followers.
+     * @param myUser
+     * @param followerUser
+     * @return
+     * @throws EnMeDomainNotFoundException
+     */
+    public UserAccount addFollower(final String myUsername, final String followerUser) throws EnMeDomainNotFoundException{
+    	final UserAccount myAccount = getUser(myUsername);
+    	final UserAccount myFollower = getUser(followerUser);
+    	myAccount.getFollowers().add(myFollower);
+    	getAccountDao().saveOrUpdate(myAccount);
+    	return myAccount;
+    }
+
+    public enum FollowOperations{
+    	FOLLOW,
+    	UNFOLLOW
+    }
 }

File encuestame-business/src/main/java/org/encuestame/business/service/imp/ISecurityService.java

 import java.util.Collection;
 import java.util.List;
 
+import org.encuestame.business.service.SecurityService.FollowOperations;
 import org.encuestame.core.service.IService;
 import org.encuestame.persistence.domain.EnMePermission;
 import org.encuestame.persistence.domain.security.Group;
      * @return
      */
     Boolean isActivated(final SignUpBean signUpBean);
+
+    /**
+     * Add Followers.
+     * @param myUser
+     * @param followerUser
+     * @return
+     * @throws EnMeDomainNotFoundException
+     */
+    UserAccount addFollower(final String myUser, final String followerUser) throws EnMeDomainNotFoundException;
+
+   /**
+    * Follow Operations.
+    * @param userAcc
+    * @param myUsername
+    * @param followerUser
+    * @param operation
+    * @throws EnMeDomainNotFoundException
+    */
+	void followOperations(final UserAccount userAcc,
+			final String myUsername, final String followerUser,
+			final FollowOperations operation) throws EnMeDomainNotFoundException;
 }

File encuestame-persistence/src/main/java/org/encuestame/persistence/domain/security/UserAccount.java

     private String userTwitterAccount;
     private Date lastTimeLogged;
     private String lastIpLogged;
-    private Long followers;
+    private String userProfilePicture;
 
     /**
      * Account Enabled.
     private Group group;
 
     /**
+     * {@link UserAccount}
+     */
+    private Set<UserAccount> followers = new HashSet<UserAccount>();
+
+    /**
      * @return uid
      */
     @Id
     }
 
     /**
-     * @return the followers
-     */
-    public Long getFollowers() {
-        return followers;
-    }
-
-    /**
-     * @param followers the followers to set
-     */
-    @Column(name = "followers")
-    public void setFollowers(final Long followers) {
-        this.followers = followers;
-    }
+	 * @return the seguidores
+	 */
+    @ManyToMany(cascade=CascadeType.ALL)
+    @JoinTable(name="userAccount_followers",
+               joinColumns={@JoinColumn(name="uid")},
+               inverseJoinColumns={@JoinColumn(name="uid_follower")})
+	public Set<UserAccount> getFollowers() {
+		return followers;
+	}
+
+	/**
+	 * @param seguidores the seguidores to set
+	 */
+	public void setFollowers(Set<UserAccount> followers) {
+		this.followers = followers;
+	}
+
+	/**
+	 * @return the userProfilePicture
+	 */
+	public String getUserProfilePicture() {
+		return userProfilePicture;
+	}
+
+	/**
+	 * @param userProfilePicture the userProfilePicture to set
+	 */
+	public void setUserProfilePicture(String userProfilePicture) {
+		this.userProfilePicture = userProfilePicture;
+	}
  }