Commits

Juan Carlos Picado Herrera committed 852581d

Fixed ENCUESTAME-239 and fixed issues with test cases

Comments (0)

Files changed (17)

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

 import org.apache.log4j.Logger;
 import org.encuestame.business.service.imp.SecurityOperations;
 import org.encuestame.business.service.social.signin.SocialSignInOperations;
+import org.encuestame.core.files.PathUtil;
 import org.encuestame.core.security.SecurityUtils;
 import org.encuestame.core.security.util.EnMePasswordUtils;
 import org.encuestame.core.security.util.PasswordGenerator;
 import org.encuestame.core.util.ConvertDomainBean;
 import org.encuestame.core.util.ConvertDomainsToSecurityContext;
+import org.encuestame.core.util.SocialUtils;
 import org.encuestame.persistence.domain.EnMePermission;
 import org.encuestame.persistence.domain.notifications.Notification;
 import org.encuestame.persistence.domain.security.Account;
 @Service
 public class SecurityService extends AbstractBaseService implements SecurityOperations {
 
+    /**
+     * Log.
+     */
     private Logger log = Logger.getLogger(this.getClass());
 
     /** Default User Permission **/
     private static final EnMePermission DEFAULT = EnMePermission.ENCUESTAME_USER;
 
-    /** Default User Permission **/
-    private static final EnMePermission ADMIN = EnMePermission.ENCUESTAME_ADMIN;
-
-    /** Default User Permission **/
-    private static final EnMePermission EDITOR = EnMePermission.ENCUESTAME_EDITOR;
-
-    /** Default User Permission **/
-    private static final EnMePermission OWNER = EnMePermission.ENCUESTAME_OWNER;
-
-    /** Default User Permission **/
-    private static final EnMePermission PUBLISHER = EnMePermission.ENCUESTAME_PUBLISHER;
-
-
-    private final Integer DEFAULT_LENGTH_PASSWORD = 8;
-
-    private static int TWITTER_AUTH_ERROR = 401;
-
+    /**
+     * Dashboard path.
+     */
     private final String DASHBOARD_REDIRECT = "redirect:/user/dashboard";
 
     /**
         final UserAccount userAccount = new UserAccount();
         userAccount.setUsername(singUpBean.getUsername());
         //generate password.
-        final String password = EnMePasswordUtils.createRandomPassword(this.DEFAULT_LENGTH_PASSWORD);
+        final String password = EnMePasswordUtils.createRandomPassword(EnMePasswordUtils.DEFAULT_LENGTH_PASSWORD);
         userAccount.setPassword(encodingPassword(password));
         singUpBean.setPassword(password);
         //invite code
             }
         } catch (TwitterException te) {
             log.error("Twitter Error "+te.getMessage());
-            if (SecurityService.TWITTER_AUTH_ERROR == te.getStatusCode()) {
+            if (SocialUtils.TWITTER_AUTH_ERROR == te.getStatusCode()) {
                 log.error("Twitter Error "+te.getStatusCode());
                 verified = false;
             } else {
             //getAccountDao().saveOrUpdate(connection.getSocialAccount());
             getAccountDao().saveOrUpdate(socialAccount);
             SecurityUtils.socialAuthentication(socialAccount); //TODO: only with OWNER UserAccount.
-            return DASHBOARD_REDIRECT;
+            return PathUtil.DASHBOARD_REDIRECT;
         } else {
             //if user has been never connected, we check if the user exist with the social account email.
             log.info("Connecting: Creating new connection");

encuestame-business/src/test/java/org/encuestame/test/business/service/TestSecurityService.java

     @Test
     @Ignore
     public void testupdateOAuthTokenSocialAccount() throws EnMeExpcetion{
-        SocialAccount account = createDefaultSettedTwitterAccount(this.userPrimary);
+        SocialAccount account = createDefaultSettedSocialAccount(this.secUserSecondary);
         //this.securityService.updateOAuthTokenSocialAccount(account.getId(), "12345", "fakeTokenSecret", this.secUserSecondary.getUsername());
         account = getAccountDao().getSocialAccountById(account.getId());
         assertEquals(account.getSecretToken(), "fakeTokenSecret");

encuestame-business/src/test/java/org/encuestame/test/business/service/TestTweetPollService.java

 
     @Test
     public void testPublicMultiplesTweetAccounts(){
-            createDefaultSettedTwitterAccount(this.userAccount.getAccount());
+            createDefaultSettedSocialAccount(this.userAccount);
             final List<SocialAccount> list = getAccountDao().getSocialAccountByAccount(this.userAccount.getAccount(), SocialProvider.TWITTER);
             final List<SocialAccountBean> listUnitTwitterAccount = ConvertDomainBean.convertListSocialAccountsToBean(list);
              final String tweetText = RandomStringUtils.randomAlphabetic(5);

encuestame-business/src/test/java/org/encuestame/test/business/service/TestTwitterService.java

 import org.encuestame.business.service.social.api.TwitterAPITemplate;
 import org.encuestame.persistence.domain.security.Account;
 import org.encuestame.persistence.domain.security.SocialAccount;
+import org.encuestame.persistence.domain.security.UserAccount;
 import org.encuestame.test.business.service.config.AbstractServiceBase;
 import org.encuestame.test.config.AbstractBaseUnitBeans;
 import org.encuestame.utils.TweetPublishedMetadata;
     /** {@link Account}. **/
     private Account user;
 
+    private UserAccount userAccount;
+
     private SocialAccount socialTwitterAccount;
 
     /**
     @Before
     public void before(){
         this.user = createAccount();
-        this.socialTwitterAccount = createDefaultSettedTwitterAccount(this.user);
+        this.userAccount = createUserAccount("jota", this.user);
+        this.socialTwitterAccount = createDefaultSettedSocialAccount(this.userAccount);
         this.twitterService = new TwitterAPITemplate("", "","", "");
     }
 

encuestame-core/src/main/java/org/encuestame/core/files/PathUtil.java

      *
      */
     public static final String profileUserImage = "/user/picture/profile";
+
+    public static final String DASHBOARD_REDIRECT = "redirect:/user/dashboard";
 }

encuestame-core/src/main/java/org/encuestame/core/security/util/EnMePasswordUtils.java

 
 package org.encuestame.core.security.util;
 
-import java.util.Random;
-
-import org.apache.commons.lang.RandomStringUtils;
 import org.jasypt.util.password.StrongPasswordEncryptor;
 
 /**
 public class EnMePasswordUtils {
 
     /**
+     * Default lenght password.
+     */
+    public static final Integer DEFAULT_LENGTH_PASSWORD = 8;
+
+    /**
      * Create Random Password.
      * @param length
      * @return

encuestame-core/src/main/java/org/encuestame/core/util/ConvertDomainBean.java

         unitTweetPoll.setAllowRepeatedVotes(tweetPoll.getAllowRepatedVotes() == null ? false : tweetPoll.getAllowRepatedVotes());
         //unitTweetPoll.setRelativeTime(tweetPoll.get);
         unitTweetPoll.setHashTags(ConvertDomainBean.convertListHashTagsToBean(new ArrayList<HashTag>(tweetPoll.getHashTags())));
-        unitTweetPoll.setTotalVotes(Long.valueOf(tweetPoll.getNumbervotes()));
+        unitTweetPoll.setTotalVotes(tweetPoll.getNumbervotes() == null ? 0L : Long.valueOf(tweetPoll.getNumbervotes()));
         unitTweetPoll.setCreatedDateAt(tweetPoll.getCreateDate());
         return unitTweetPoll;
     }

encuestame-core/src/main/java/org/encuestame/core/util/SocialUtils.java

     public final static Integer TWITTER_LIMIT = 140;
 
     /**
+     * Twitter authentictation error.
+     * TODO: move to {@link SocialUtils}.
+     */
+    public final static int TWITTER_AUTH_ERROR = 401;
+
+    /**
      * Get Google Stats from google short url.
      * @param googleShortUrl
      * @return

encuestame-mvc/src/main/java/org/encuestame/mvc/controller/social/AbstractAccountConnect.java

  */
 package org.encuestame.mvc.controller.social;
 
-import org.apache.commons.lang.RandomStringUtils;
 import org.apache.log4j.Logger;
 import org.encuestame.business.service.imp.TwitterAPIOperations;
 import org.encuestame.business.service.social.OAuth1RequestFlow;
 import org.encuestame.core.exception.EnMeExistPreviousConnectionException;
 import org.encuestame.core.social.BuzzAPIOperations;
 import org.encuestame.core.social.FacebookAPIOperations;
-import org.encuestame.core.social.FacebookProfile;
 import org.encuestame.core.social.IdentiCaProfile;
 import org.encuestame.core.social.IdenticaAPIOperations;
 import org.encuestame.core.social.LinkedInAPIOperations;
                     log.warn("This account already exist");
                     throw new EnMeExistPreviousConnectionException(getMessage("social.repeated.account"));
                 }
-            } else if (socialProvider.equals(SocialProvider.MYSPACE)) {
                 //FUTURE - Issues with OAuth1 request.
             } else if (socialProvider.equals(SocialProvider.YAHOO)) {
                 //FUTURE - Only valid on defined domain.
+                log.debug("Yahoo provider is disabled");
             }
             log.info("Saved New Social Account");
             return actionToDo;

encuestame-mvc/src/main/java/org/encuestame/mvc/view/UserProfileController.java

+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2011 encuestame: system online surveys Copyright (C) 2011
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to  in writing,  software  distributed
+ * under the License is distributed  on  an  "AS IS"  BASIS,  WITHOUT  WARRANTIES  OR
+ * CONDITIONS OF ANY KIND, either  express  or  implied.  See  the  License  for  the
+ * specific language governing permissions and limitations under the License.
+ ************************************************************************************
+ */
+package org.encuestame.mvc.view;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.encuestame.mvc.controller.AbstractBaseOperations;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+/**
+ * User profile view controller.
+ *
+ * @author Picado, Juan juanATencuestame.org
+ * @since Jul 2, 2011
+ */
+@Controller
+public class UserProfileController extends AbstractBaseOperations {
+
+    private Log log = LogFactory.getLog(this.getClass());
+
+    @RequestMapping(value = "/profile/{username}", method = RequestMethod.GET)
+    public String tweetPollController(
+            final ModelMap model,
+            @PathVariable String username) {
+
+
+
+        return "profile/view";
+    }
+}

encuestame-mvc/src/test/java/org/encuestame/mvc/test/json/SocialAccountsJsonControllerTestCase.java

 import org.encuestame.mvc.test.config.AbstractJsonMvcUnitBeans;
 import org.encuestame.persistence.domain.security.Account;
 import org.encuestame.persistence.domain.security.SocialAccount;
+import org.encuestame.persistence.domain.security.UserAccount;
 import org.junit.Before;
 import org.junit.Ignore;
 
       @Before
       public void beforeSocialTest(){
           this.user = createAccount();
-          this.socialTwitterAccount = createDefaultSettedTwitterAccount(this.user);
+          final UserAccount account = createUserAccount("jota 1", user);
+          this.socialTwitterAccount = createDefaultSettedSocialAccount(account);
       }
 }

encuestame-persistence/src/main/java/org/encuestame/persistence/dao/imp/AbstractSocialAccount.java

             //OAuth1
             //connection.setSecretToken(token.getSecret());
             //TODO: pending OAUTH1.
+            log.debug("pending OAUTH1 - OAuth 1 social connection is not available right now.");
         } else if(SocialProvider.getTypeAuth(currentSocialAccount.getAccounType()).equals(TypeAuth.OAUTH2)) {
             //OAuth2
             currentSocialAccount.setAccessToken(accessGrant.getAccessToken());

encuestame-persistence/src/test/java/org/encuestame/test/config/AbstractBase.java

      * @param consumerKey
      * @param consumerSecret
      * @param secretToken
-     * @param secUsers
-     * @param twitterAccount
+     * @param userAccount
+     * @param socialProfileUsername
      * @return
      */
     public SocialAccount createSocialAccount(
             final String token,
             final String secretToken,
-            final Account secUsers,
-            final String twitterAccount,
+            final UserAccount userAccount,
+            final String socialProfileUsername,
             final Boolean verified,
             final SocialProvider provider){
-        final SocialAccount socialTwitterAccounts = new SocialAccount();
-        socialTwitterAccounts.setAccessToken(token);
-        socialTwitterAccounts.setSecretToken(secretToken);
-        socialTwitterAccounts.setAccount(secUsers);
+        final SocialAccount socialAccount = new SocialAccount();
+        socialAccount.setAccessToken(token);
+        socialAccount.setSecretToken(secretToken);
+        socialAccount.setAccount(userAccount.getAccount());
+        socialAccount.setUserOwner(userAccount);
         long randomNum = 100 + (int)(Math.random()* 4000);
-        socialTwitterAccounts.setSocialProfileId(String.valueOf(randomNum));
-        socialTwitterAccounts.setVerfied(verified);
-        socialTwitterAccounts.setAccounType(provider);
-        socialTwitterAccounts.setSocialAccountName(twitterAccount+RandomStringUtils.randomAlphanumeric(10));
-        socialTwitterAccounts.setUpgradedCredentials(new Date());
-        socialTwitterAccounts.setAddedAccount(new Date());
-        socialTwitterAccounts.setEmail("email");
-        socialTwitterAccounts.setProfileUrl("urll");
-        socialTwitterAccounts.setRealName("real name");
-        socialTwitterAccounts.setApplicationKey(RandomUtils.nextLong(new Random(50)));
-        socialTwitterAccounts.setRefreshToken("refresh_token_"+RandomStringUtils.randomAlphanumeric(10));
-        socialTwitterAccounts.setType(TypeAuth.OAUTH1);
-        getAccountDao().saveOrUpdate(socialTwitterAccounts);
-        return socialTwitterAccounts;
+        socialAccount.setSocialProfileId(String.valueOf(randomNum)+RandomStringUtils.randomAlphanumeric(10));
+        socialAccount.setVerfied(verified);
+        socialAccount.setAccounType(provider);
+        socialAccount.setSocialAccountName(socialProfileUsername+RandomStringUtils.randomAlphanumeric(10));
+        socialAccount.setUpgradedCredentials(new Date());
+        socialAccount.setAddedAccount(new Date());
+        socialAccount.setEmail("email"+String.valueOf(randomNum));
+        socialAccount.setProfileUrl("url"+String.valueOf(randomNum));
+        socialAccount.setRealName("real name"+String.valueOf(randomNum));
+        socialAccount.setApplicationKey(RandomUtils.nextLong(new Random(50)));
+        socialAccount.setRefreshToken("refresh_token_"+RandomStringUtils.randomAlphanumeric(10));
+        socialAccount.setType(TypeAuth.OAUTH1);
+        getAccountDao().saveOrUpdate(socialAccount);
+        return socialAccount;
      }
 
     /**
      * @param account {@link Account}.
      * @return {@link SocialAccount}.
      */
-    public SocialAccount createDefaultSettedTwitterAccount(final Account account){
+    public SocialAccount createDefaultSettedSocialAccount(final UserAccount account){
         return this.createSocialAccount(
                 getProperty("twitter.test.token"),
                 getProperty("twitter.test.tokenSecret"),
      * @param provider {@link SocialProvider}
      * @return {@link SocialAccount}.
      */
-    public SocialAccount createSocialProviderAccount(final Account account, final SocialProvider provider){
+    public SocialAccount createSocialProviderAccount(final UserAccount account, final SocialProvider provider){
         return this.createSocialAccount(
                 getProperty("twitter.test.token"),
                 getProperty("twitter.test.tokenSecret"),
      * @param account
      * @return
      */
-    public SocialAccount createDefaultSettedVerifiedTwitterAccount(final Account account){
+    public SocialAccount createDefaultSettedVerifiedSocialAccount(final UserAccount account){
         return this.createSocialAccount(
                 getProperty("twitter.test.token"),
                 getProperty("twitter.test.tokenSecret"),

encuestame-persistence/src/test/java/org/encuestame/test/persistence/dao/TestUserDao.java

         this.account = createAccount();
         this.userAccount = createUserAccount("user 1", this.account);
         this.userAccount.setInviteCode(this.inviteCode);
-        this.socialAccount = createDefaultSettedVerifiedTwitterAccount(this.account);
+        this.socialAccount = createDefaultSettedVerifiedSocialAccount(this.userAccount);
         this.question = createQuestion("What day is today?", "");
     }
 
      */
     //@Test
     public void testgetSocialAccount(){
-        final SocialAccount ac = createSocialProviderAccount(this.account, SocialProvider.GOOGLE);
+        final SocialAccount ac = createSocialProviderAccount(this.userAccount, SocialProvider.GOOGLE);
         final SocialAccount ex = getAccountDao().getSocialAccount(ac.getId(), this.account);
         assertEquals("Should be equals", ac.getId(),ex.getId());
         final SocialAccount ex2 = getAccountDao().getSocialAccount(SocialProvider.GOOGLE, ex.getSocialProfileId());

encuestame-war/src/main/webapp/WEB-INF/views/home/mobile/profile.jsp

+<%@ include file="/WEB-INF/jsp/includes/taglibs.jsp"%>
+<div>Cloud Page</div>
+ <c:forEach items="${hashtags}" var="cloud">
+     <span class="item" style="font-size: ${cloud.size}px;">
+         <a href="<%=request.getContextPath()%>/tag/${cloud.hashTagName}/">${cloud.hashTagName}</a>
+     </span>
+   </c:forEach>

encuestame-war/src/main/webapp/WEB-INF/views/home/tiles.xml

         <put-attribute name="content" expression="/WEB-INF/views/home/${currentDevice.mobile ? 'mobile/' : 'web/'}cloud.jsp" />
     </definition>
 
+   <definition name="profile/view" extends="page">
+        <put-attribute name="title" value="Profile | encuestame" />
+        <put-attribute name="content" expression="/WEB-INF/views/home/${currentDevice.mobile ? 'mobile/' : 'web/'}profile.jsp" />
+    </definition>
+
     <definition name="tag/detail" extends="page">
         <put-attribute name="title" value="HashTag Detail" />
         <put-attribute name="content" expression="/WEB-INF/views/home/${currentDevice.mobile ? 'mobile/' : 'web/'}hashtag.jsp" />

encuestame-war/src/main/webapp/WEB-INF/views/home/web/profile.jsp

+<%@ include file="/WEB-INF/jsp/includes/taglibs.jsp"%>
+<div>Cloud Page</div>
+ <c:forEach items="${hashtags}" var="cloud">
+     <span class="item" style="font-size: ${cloud.size}px;">
+         <a href="<%=request.getContextPath()%>/tag/${cloud.hashTagName}/">${cloud.hashTagName}</a>
+     </span>
+   </c:forEach>