Commits

Juan Carlos Picado Herrera committed ebbe850 Merge

Merge branch 'juanpicado' into development

  • Participants
  • Parent commits c906e79, 0178606

Comments (0)

Files changed (37)

 *DEADJOE*
 encuestame-war/src/main/webapp/resource/js/dijit/
 encuestame-war/src/main/webapp/resource/js/dojox/
-encuestame-war/src/main/webapp/resource/js/dojo/
+encuestame-war/src/main/webapp/resource/js/dojo/
+encuestame-war/src/main/webapp/resource/js/org/

buildDojo.sh

-#!/bin/bash
-DOJO_PATH=dojo
-SVN_DOJO=http://svn.dojotoolkit.org/src/tags/release-1.5.0/
-
-echo 'Building Dojo'
-
-function createSymbolic {
-        if [ -d ${DOJO_PATH} ]; then
-            if [ -d encuestame-war/src/main/webapp/resource/js/dojo ]; then
-                rm -Rf encuestame-war/src/main/webapp/resource/js/dojo
-            fi
-
-            if [ -d encuestame-war/src/main/webapp/resource/js/dojox ]; then
-                rm -Rf encuestame-war/src/main/webapp/resource/js/dojox
-            fi
-
-            if [ -d encuestame-war/src/main/webapp/resource/js/dijit ]; then
-                rm -Rf encuestame-war/src/main/webapp/resource/js/dijit
-            fi
-            cp -Rf ${DOJO_PATH}/dojo encuestame-war/src/main/webapp/resource/js/
-            cp -Rf ${DOJO_PATH}/dojox encuestame-war/src/main/webapp/resource/js/
-            cp -Rf ${DOJO_PATH}/dijit encuestame-war/src/main/webapp/resource/js/
-        fi
-}
-
-
-if [ -d ${DOJO_PATH} ]; then
-    echo "Create Links"
-    createSymbolic
-else
-    echo "Create Dir"
-    mkdir ${DOJO_PATH}
-    #cd ${DOJO_PATH}
-    echo "SVN Checkout"
-    svn co ${SVN_DOJO} ${DOJO_PATH}
-    echo "Create Links"
-    createSymbolic
-fi
-echo 'Done'
+#!/bin/bash
+DOJO_PATH=dojo
+SVN_DOJO=http://svn.dojotoolkit.org/src/tags/release-1.5.0/
+FILE_DOJO=http://download.dojotoolkit.org/release-1.5.0/dojo-release-1.5.0.zip
+FILE_NAME=dojo-release-1.5.0.zip
+
+function createFromDownload {
+        if [ -d ${DOJO_PATH} ]; then
+            removeCurrentResources
+	    copyResources  
+        else
+            warningNoResources      
+        fi
+}
+
+function removeCurrentResources {
+            if [ -d encuestame-war/src/main/webapp/resource/js/dojo ]; then
+                rm -Rf encuestame-war/src/main/webapp/resource/js/dojo
+            fi
+
+            if [ -d encuestame-war/src/main/webapp/resource/js/dojox ]; then
+                rm -Rf encuestame-war/src/main/webapp/resource/js/dojox
+            fi
+
+            if [ -d encuestame-war/src/main/webapp/resource/js/dijit ]; then
+                rm -Rf encuestame-war/src/main/webapp/resource/js/dijit
+            fi
+	    if [ -d encuestame-war/src/main/webapp/resource/js/org ]; then
+                rm -Rf encuestame-war/src/main/webapp/resource/js/org
+            fi
+}
+
+
+function replaceCometDResources {
+    if [ -d ${DOJO_PATH} ]; then
+	    cp -Rfv lib/dojo-replace/org ${DOJO_PATH}
+	    cp -v lib/dojo-replace/cometd.js ${DOJO_PATH}/dojox/ 
+	    rm -Rf ${DOJO_PATH}/dojox/cometd 
+	    cp -Rfv lib/dojo-replace/cometd ${DOJO_PATH}/dojox/
+    else
+	warningNoResources
+    fi
+}
+
+function copyResources {
+        removeCurrentResources
+	replaceCometDResources
+	if [ -d ${DOJO_PATH} ]; then
+		cp -Rfv ${DOJO_PATH}/dojo encuestame-war/src/main/webapp/resource/js/
+		cp -Rfv ${DOJO_PATH}/dojox encuestame-war/src/main/webapp/resource/js/
+		cp -Rfv ${DOJO_PATH}/dijit encuestame-war/src/main/webapp/resource/js/
+		cp -Rfv ${DOJO_PATH}/org encuestame-war/src/main/webapp/resource/js/
+	else
+		warningNoResources
+	fi                
+}
+
+function warningNoResources {
+    echo "****************************************************************"
+    echo "*  WARNING !!! -- DOJO FOLDER NOT EXIST                        *"
+    echo "*  http://wiki.encuestame.org/en/Build_Project for more info.  *"
+    echo "****************************************************************"
+    exit
+}
+
+function warningShow {
+    echo "****************************************************************"
+    echo "*  WARNING !!! -- DOJO 1.5 IS REQUIRED                         *"
+    echo "*  Download from http://dojotoolkit.org/download               *"
+    echo "*  Copy the content on root folder named DOJO                  *"   
+    echo "*  After that run again this script                            *"
+    echo "*  http://wiki.encuestame.org/en/Build_Project for more info.  *"
+    echo "****************************************************************"
+}
+
+function svnDownload {
+    if [ -d ${DOJO_PATH} ]; then
+	 rm -Rf ${DOJO_PATH}
+    fi	
+    echo "SVN - Remove old resources"
+    echo "SVN - Create work path"
+    mkdir ${DOJO_PATH}
+    echo "SVN - Downloading source code .."
+    svn export ${SVN_DOJO} ${DOJO_PATH} --force
+    echo "SVN - Copy Resources"
+    copyResources
+}
+
+function fileDownload {
+    if [ -d ${DOJO_PATH} ]; then
+	 rm -Rf ${DOJO_PATH}
+    fi	
+    echo "ZIP - Download"
+    wget ${FILE_DOJO}
+    echo "ZIP - Create work path"
+    unzip ${FILE_NAME}
+    mv dojo-release-1.5.0 ${DOJO_PATH}
+    echo "ZIP - Copy Resources"
+    rm ${FILE_NAME}
+    copyResources
+}
+
+
+cmd=(dialog --separate-output --checklist "Select options:" 22 76 16)
+options=(1 "Download DOJO FRAMEWORK Source Code from SVN" off
+         2 "Download DOJO FRAMEWORK on Download ZIP " on
+         3 "Install from local path  DOJO FRAMEWORK" off)
+choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
+clear
+for choice in $choices
+do
+    case $choice in
+        1)
+            svnDownload
+	    exit
+            ;;
+        2)
+            fileDownload
+	    exit
+            ;;
+        3)
+            copyResources
+            exit
+            ;;
+    esac
+done

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

 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.encuestame.business.mail.MailServiceImpl;
+import org.encuestame.business.service.imp.ITwitterService;
 import org.encuestame.core.files.PathUtil;
 import org.encuestame.core.util.ConvertDomainBean;
 import org.encuestame.core.util.MD5Utils;
  * @author Picado, Juan juan@encuestame.org
  * @since 22/05/2009 1:02:45
  */
-public abstract class AbstractBaseService extends AbstractConfigurationService {
+public abstract class AbstractBaseService extends AbstractSocialService {
 
     private Log log = LogFactory.getLog(this.getClass());
 
     private MailServiceImpl serviceMail;
 
     /**
-     *
-     */
-    private static int TWITTER_AUTH_ERROR = 401;
-
-    /**
      * Constructor.
      */
     public AbstractBaseService() {}
      }
 
     /**
-     * Verify OAuth Credentials
-     * @param token token stored
-     * @param secretToken secret Token
-     * @param pin pin
-     * @return
-     * @throws TwitterException
-     */
-    public Boolean verifyCredentials(final String token,
-                                     final String tokenSecret,
-                                     final String consumerKey,
-                                     final String consumerSecret,
-                final String pin){
-        Boolean verified = false;
-        log.debug("verifyCredentials OAuth");
-        log.debug("Token {"+token);
-        log.debug("secretToken {"+tokenSecret);
-        log.debug("pin {"+pin);
-        log.debug("consumerKey {"+consumerKey);
-        log.debug("consumerSecret {"+consumerSecret);
-        Twitter twitter = null;
-        try {
-             twitter = new TwitterFactory().getInstance();
-            if(token == null || token.isEmpty()){
-                verified = false;
-            } else {
-                log.debug("Exist Previous Token.");
-                final AccessToken accessToken = new AccessToken(token, tokenSecret);
-                log.debug("Created Token "+accessToken);
-                twitter = new TwitterFactory().getOAuthAuthorizedInstance(consumerKey, consumerSecret, accessToken);
-                log.debug("Verifying Credentials");
-                final User user = twitter.verifyCredentials();
-                log.debug("Verifying Credentials User "+user);
-                if (user != null) {
-                    log.debug("Verify OAuth User " + user.getId());
-                    verified = true;
-                }
-            }
-        } catch (TwitterException te) {
-            log.error("Twitter Error "+te.getMessage());
-            if (AbstractBaseService.TWITTER_AUTH_ERROR == te.getStatusCode()) {
-                log.error("Twitter Error "+te.getStatusCode());
-                verified = false;
-            } else {
-                log.error(te);
-            }
-            log.error("Verify OAuth Error " + te.getLocalizedMessage());
-        }
-        log.debug("verified "+verified);
-        return verified;
-    }
-
-    /**
      * Get Access Token.
      * @param token
      * @param tokenSecret
             throw new EnMeExpcetion("error on create directory");
         }
     }
-
 }

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

+
+package org.encuestame.business.service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.encuestame.business.service.imp.ITwitterService;
+import org.encuestame.core.util.ConvertDomainBean;
+import org.encuestame.persistence.domain.security.SocialAccount;
+import org.encuestame.persistence.domain.security.UserAccount;
+import org.encuestame.persistence.domain.security.SocialAccount.TypeAuth;
+import org.encuestame.persistence.domain.social.SocialProvider;
+import org.encuestame.persistence.exception.EnMeExpcetion;
+import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
+import org.encuestame.persistence.exception.IllegalSocialActionException;
+import org.encuestame.utils.security.SocialAccountBean;
+
+import twitter4j.Twitter;
+import twitter4j.TwitterException;
+import twitter4j.TwitterFactory;
+import twitter4j.User;
+import twitter4j.http.AccessToken;
+
+/**
+ * Social service layer.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Mar 7, 2011
+ */
+public class AbstractSocialService extends AbstractConfigurationService {
+
+    /**
+     * Log.
+     */
+    private Logger log = Logger.getLogger(this.getClass());
+
+    /** Twitter Service. **/
+    private ITwitterService twitterService;
+
+   /**
+    * Twitter error code.
+    */
+   private static int TWITTER_AUTH_ERROR = 401;
+
+
+    /**
+     * Update OAuth Secret Twitter Credentials.
+     * @param accountBean {@link SocialAccountBean}
+     * @param username username logged
+     * @throws EnMeExpcetion exception
+     */
+    public void updateSecretTwitterCredentials(final SocialAccountBean accountBean,
+            final String username) throws EnMeExpcetion{
+         //TODO: we should search twitter account filter by username
+         final SocialAccount twitterAccount = this.getSocialAccount(accountBean.getAccountId()); //TODO: filter by Username Too
+         //twitterAccount.setConsumerKey(accountBean.getKey());
+         //twitterAccount.setConsumerSecret(accountBean.getSecret());
+         twitterAccount.setType(ConvertDomainBean.convertStringToEnum(accountBean.getType()));
+         if(accountBean.getPin() != null && !accountBean.getPin().isEmpty()){
+             log.debug("PIN Exists {"+accountBean.getPin());
+             //twitterAccount.setTwitterPin(Integer.valueOf(accountBean.getPin()));
+            //If exist pin, we can verify credentials
+            log.debug("Verify OAuth Credentials");
+                if(verifyCredentials(
+                        //Token and Secret token should be always from database
+                        twitterAccount.getToken(),
+                        twitterAccount.getSecretToken(),
+                        //consumer key's
+                        accountBean.getKey(),
+                        accountBean.getSecret(),
+                        //pin, update by the user.
+                        accountBean.getPin())){
+                    twitterAccount.setVerfied(Boolean.TRUE);
+                } else {
+                    twitterAccount.setVerfied(Boolean.FALSE);
+                }
+         } else {
+             log.info("Account not verified, pin not found");
+             //twitterAccount.setTwitterPin(null);
+             twitterAccount.setVerfied(Boolean.FALSE);
+         }
+        log.debug("Update Secret Twitter Credentials");
+        getAccountDao().saveOrUpdate(twitterAccount);
+        log.info("update Twitter Account");
+    }
+
+    /**
+     * Change state social account.
+     * @param accountId
+     * @param username
+     * @param action
+     * @throws EnMeNoResultsFoundException
+     * @throws IllegalSocialActionException
+     */
+    public void changeStateSocialAccount(
+            final Long accountId,
+            final String username,
+            final String action) throws EnMeNoResultsFoundException, IllegalSocialActionException{
+        final UserAccount userAccount = getUserAccount(username);
+        final SocialAccount social = getAccountDao().getSocialAccount(accountId, userAccount.getAccount());
+        if(social == null){
+            throw new EnMeNoResultsFoundException("social accout not found");
+        }
+        if("default".equals(action)){
+           log.info("update social twitter account");
+           social.setDefaultSelected(!social.getDefaultSelected());
+           getAccountDao().saveOrUpdate(social);
+        } else if("remove".equals(action)){
+            getAccountDao().delete(social);
+        } else if("valid".equals(action)){
+            social.setVerfied(!social.getVerfied());
+            getAccountDao().saveOrUpdate(social);
+        } else {
+            throw new IllegalSocialActionException();
+        }
+    }
+
+    /**
+     * Verify OAuth Credentials
+     * @param token token stored
+     * @param secretToken secret Token
+     * @param pin pin
+     * @return
+     * @throws TwitterException
+     */
+    public Boolean verifyCredentials(final String token,
+                                     final String tokenSecret,
+                                     final String consumerKey,
+                                     final String consumerSecret,
+                final String pin){
+        Boolean verified = false;
+        log.debug("verifyCredentials OAuth");
+        log.debug("Token {"+token);
+        log.debug("secretToken {"+tokenSecret);
+        log.debug("pin {"+pin);
+        log.debug("consumerKey {"+consumerKey);
+        log.debug("consumerSecret {"+consumerSecret);
+        Twitter twitter = null;
+        try {
+             twitter = new TwitterFactory().getInstance();
+            if(token == null || token.isEmpty()){
+                verified = false;
+            } else {
+                log.debug("Exist Previous Token.");
+                final AccessToken accessToken = new AccessToken(token, tokenSecret);
+                log.debug("Created Token "+accessToken);
+                twitter = new TwitterFactory().getOAuthAuthorizedInstance(consumerKey, consumerSecret, accessToken);
+                log.debug("Verifying Credentials");
+                final User user = twitter.verifyCredentials();
+                log.debug("Verifying Credentials User "+user);
+                if (user != null) {
+                    log.debug("Verify OAuth User " + user.getId());
+                    verified = true;
+                }
+            }
+        } catch (TwitterException te) {
+            log.error("Twitter Error "+te.getMessage());
+            if (AbstractSocialService.TWITTER_AUTH_ERROR == te.getStatusCode()) {
+                log.error("Twitter Error "+te.getStatusCode());
+                verified = false;
+            } else {
+                log.error(te);
+            }
+            log.error("Verify OAuth Error " + te.getLocalizedMessage());
+        }
+        log.debug("verified "+verified);
+        return verified;
+    }
+
+
+    /**
+     * Update OAuth Token/Secret Social Account.
+     * @param socialAccountId
+     * @param token
+     * @param tokenSecret
+     * @param username
+     * @param account
+     * @param socialProvider
+     * @throws EnMeExpcetion
+     */
+    public void addOrUpdateOAuthTokenSocialAccount(
+            final Long socialAccountId,
+            final String token,
+            final String tokenSecret,
+            final String username,
+            final UserAccount account,
+            final SocialProvider socialProvider) throws EnMeExpcetion{
+            SocialAccount socialAccount = getAccountDao().getSocialAccount(socialProvider, socialAccountId);
+            if (socialAccount == null) {
+                log.info("adding new social account");
+                socialAccount = new SocialAccount();
+            }
+            log.debug("Updating  Token to {"+token);
+            log.debug("Updating Secret Token to {"+tokenSecret);
+            socialAccount.setToken(token);
+            socialAccount.setVerfied(Boolean.TRUE);
+            socialAccount.setAccounType(socialProvider);
+            socialAccount.setSecUsers(account.getAccount());
+            socialAccount.setSocialAccountName(username);
+            socialAccount.setType(TypeAuth.OAUTH);
+            socialAccount.setSecretToken(tokenSecret);
+            socialAccount.setSocialUserId(socialAccountId);
+            getAccountDao().saveOrUpdate(socialAccount);
+            log.debug("Updated Token");
+    }
+
+
+    /**
+     * Get Twitter Account.
+     * @param twitterAccountId
+     * @return
+     */
+    public SocialAccountBean getTwitterAccount(final Long twitterAccountId){
+        return ConvertDomainBean.convertSocialAccountToBean(getAccountDao().getTwitterAccount(twitterAccountId));
+    }
+
+
+    /**
+     * Get User Logged Scocial Accounts.
+     * @param username
+     * @param provider
+     * @return
+     * @throws EnMeNoResultsFoundException
+     */
+    public List<SocialAccountBean> getUserLoggedSocialAccount(final String username, final SocialProvider provider)
+           throws EnMeNoResultsFoundException{
+         return ConvertDomainBean.convertListSocialAccountsToBean(getAccountDao()
+                                 .getTwitterAccountByUser(getUserAccount(username).getAccount(), provider));
+    }
+
+    /**
+     * Get User Logged Verified Social Accounts.
+     * @param username username
+     * @return list of social accounts.
+     * @throws EnMeNoResultsFoundException exception
+     */
+    public List<SocialAccountBean> getUserLoggedVerifiedTwitterAccount(final String username, final SocialProvider provider)
+             throws EnMeNoResultsFoundException{
+        final List<SocialAccountBean> comfirmedSocialAccounts = new ArrayList<SocialAccountBean>();
+        final List<SocialAccount> socialAccounts = getAccountDao()
+                .getTwitterVerifiedAccountByUser(getUserAccount(username).getAccount(), provider);
+        for (SocialAccount socialAccount : socialAccounts) {
+            if(getTwitterService().verifyCredentials(socialAccount)){
+                log.debug("Confirmed Account  -- "+socialAccount.getSocialAccountName());
+                comfirmedSocialAccounts.add(ConvertDomainBean.convertSocialAccountToBean(socialAccount));
+            }
+        }
+        log.debug("social provider verified "+comfirmedSocialAccounts.size());
+        return comfirmedSocialAccounts;
+   }
+
+   /**
+    * Get social account by id.
+    * @param accountId
+    * @return
+    */
+   protected SocialAccount getSocialAccount(final Long accountId){
+        return  getAccountDao().getTwitterAccount(accountId); //TODO: ENCUESTAME-113
+   }
+
+   /**
+    * Update Twitter Account.
+    * @param accountBean account
+    * @param password password
+    * TODO: this method is close to be deprecated, twitter don't allow password login.
+    */
+   @Deprecated
+   public void updateTwitterAccount(
+           final SocialAccountBean accountBean,
+           final String password,
+           final Boolean verify){
+       if(accountBean.getAccountId() != null){
+           final SocialAccount twitterAccount = getAccountDao().getTwitterAccount(accountBean.getAccountId());
+           if(twitterAccount != null){
+               //twitterAccount.setTwitterPassword(password);
+               twitterAccount.setVerfied(verify);
+               log.debug("Updating twitter password account");
+               getAccountDao().saveOrUpdate(twitterAccount);
+           }
+       }
+       log.info("update Twitter Account");
+   }
+
+   /**
+    * @return the twitterService
+    */
+   public ITwitterService getTwitterService() {
+       return twitterService;
+   }
+
+   /**
+    * @param twitterService the twitterService to set
+    */
+   public void setTwitterService(final ITwitterService twitterService) {
+       this.twitterService = twitterService;
+   }
+}

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

 @Service
 public class AbstractSurveyService extends AbstractChartService {
 
-    /** Twitter Service. **/
-    private ITwitterService twitterService;
-
     /** AnswerPoll Path. **/
     private String answerPollPath;
 
      }
 
     /**
-     * @return the twitterService
-     */
-    public ITwitterService getTwitterService() {
-        return twitterService;
-    }
-
-    /**
-     * @param twitterService the twitterService to set
-     */
-    public void setTwitterService(final ITwitterService twitterService) {
-        this.twitterService = twitterService;
-    }
-
-    /**
      * @return the answerPollPath
      */
     public String getAnswerPollPath() {

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

 import org.encuestame.persistence.domain.security.Account;
 import org.encuestame.persistence.domain.security.Group;
 import org.encuestame.persistence.domain.security.Permission;
-import org.encuestame.persistence.domain.security.SocialAccount;
-import org.encuestame.persistence.domain.security.SocialAccount.TypeAuth;
 import org.encuestame.persistence.domain.security.UserAccount;
-import org.encuestame.persistence.domain.social.SocialProvider;
-import org.encuestame.persistence.exception.EnMeIllegalProviderException;
-import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
 import org.encuestame.persistence.exception.EnMeExpcetion;
+import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
 import org.encuestame.persistence.exception.EnmeFailOperation;
 import org.encuestame.utils.security.SignUpBean;
-import org.encuestame.utils.security.SocialAccountBean;
 import org.encuestame.utils.web.UnitGroupBean;
 import org.encuestame.utils.web.UnitLists;
 import org.encuestame.utils.web.UnitPermission;
     private Logger log = Logger.getLogger(this.getClass());
 
     /** Default User Permission **/
-    private static final String DEFAULT = EnMePermission.ENCUESTAME_USER.name();
+    private static final EnMePermission DEFAULT = EnMePermission.ENCUESTAME_USER;
 
     /** Default User Permission **/
-    private static final String ADMIN = EnMePermission.ENCUESTAME_ADMIN.name();
+    private static final EnMePermission ADMIN = EnMePermission.ENCUESTAME_ADMIN;
 
     /** Default User Permission **/
-    private static final String EDITOR = EnMePermission.ENCUESTAME_EDITOR.name();
+    private static final EnMePermission EDITOR = EnMePermission.ENCUESTAME_EDITOR;
 
     /** Default User Permission **/
-    private static final String OWNER = EnMePermission.ENCUESTAME_OWNER.name();
+    private static final EnMePermission OWNER = EnMePermission.ENCUESTAME_OWNER;
 
     /** Default User Permission **/
-    private static final String PUBLISHER = EnMePermission.ENCUESTAME_PUBLISHER.name();
+    private static final EnMePermission PUBLISHER = EnMePermission.ENCUESTAME_PUBLISHER;
 
 
     private final Integer DEFAULT_LENGTH_PASSWORD = 8;
     }
 
     /**
-     * Update Twitter Account.
-     * @param accountBean account
-     * @param password password
-     * TODO: this method is close to be deprecated, twitter don't allow password login.
-     */
-    @Deprecated
-    public void updateTwitterAccount(
-            final SocialAccountBean accountBean,
-            final String password,
-            final Boolean verify){
-        if(accountBean.getAccountId() != null){
-            final SocialAccount twitterAccount = getAccountDao().getTwitterAccount(accountBean.getAccountId());
-            if(twitterAccount != null){
-                //twitterAccount.setTwitterPassword(password);
-                twitterAccount.setVerfied(verify);
-                log.debug("Updating twitter password account");
-                getAccountDao().saveOrUpdate(twitterAccount);
-            }
-        }
-        log.info("update Twitter Account");
-    }
-
-    /**
-     *
-     * @param accountId
-     * @return
-     */
-    private SocialAccount getSocialAccount(final Long accountId){
-         return  getAccountDao().getTwitterAccount(accountId); //TODO: filter by Username Too
-    }
-
-    /**
-     * Update OAuth Secret Twitter Credentials.
-     * @param accountBean {@link SocialAccountBean}
-     * @param username username logged
-     * @throws EnMeExpcetion exception
-     */
-    public void updateSecretTwitterCredentials(final SocialAccountBean accountBean,
-            final String username) throws EnMeExpcetion{
-         //TODO: we should search twitter account filter by username
-         final SocialAccount twitterAccount = this.getSocialAccount(accountBean.getAccountId()); //TODO: filter by Username Too
-         //twitterAccount.setConsumerKey(accountBean.getKey());
-         //twitterAccount.setConsumerSecret(accountBean.getSecret());
-         twitterAccount.setType(ConvertDomainBean.convertStringToEnum(accountBean.getType()));
-         if(accountBean.getPin() != null && !accountBean.getPin().isEmpty()){
-             log.debug("PIN Exists {"+accountBean.getPin());
-             //twitterAccount.setTwitterPin(Integer.valueOf(accountBean.getPin()));
-            //If exist pin, we can verify credentials
-            log.debug("Verify OAuth Credentials");
-                if(verifyCredentials(
-                        //Token and Secret token should be always from database
-                        twitterAccount.getToken(),
-                        twitterAccount.getSecretToken(),
-                        //consumer key's
-                        accountBean.getKey(),
-                        accountBean.getSecret(),
-                        //pin, update by the user.
-                        accountBean.getPin())){
-                    twitterAccount.setVerfied(Boolean.TRUE);
-                } else {
-                    twitterAccount.setVerfied(Boolean.FALSE);
-                }
-         } else {
-             log.info("Account not verified, pin not found");
-             //twitterAccount.setTwitterPin(null);
-             twitterAccount.setVerfied(Boolean.FALSE);
-         }
-        log.debug("Update Secret Twitter Credentials");
-        getAccountDao().saveOrUpdate(twitterAccount);
-        log.info("update Twitter Account");
-    }
-
-
-    /**
-     * Update OAuth Token/Secret Social Account.
-     * @param socialAccountId
-     * @param token
-     * @param tokenSecret
-     * @param username
-     * @param account
-     * @throws EnMeExpcetion
-     */
-    public void addOAuthTokenSocialAccount(
-            final Long socialAccountId,
-            final String token,
-            final String tokenSecret,
-            final String username,
-            final UserAccount account) throws EnMeExpcetion{
-        final SocialAccount socialAccount = new SocialAccount();
-            log.debug("Updating  Token to {"+token);
-            log.debug("Updating Secret Token to {"+tokenSecret);
-            socialAccount.setToken(token);
-            socialAccount.setVerfied(Boolean.TRUE);
-            socialAccount.setSecUsers(account.getAccount());
-            socialAccount.setSocialAccountName(username);
-            socialAccount.setType(TypeAuth.OAUTH);
-            socialAccount.setSecretToken(tokenSecret);
-            socialAccount.setSocialUserId(socialAccountId);
-            getAccountDao().saveOrUpdate(socialAccount);
-            log.debug("Updated Token");
-    }
-
-
-    /**
-     * Get Twitter Account.
-     * @param twitterAccountId
-     * @return
-     */
-    public SocialAccountBean getTwitterAccount(final Long twitterAccountId){
-        return ConvertDomainBean.convertSocialAccountToBean(getAccountDao().getTwitterAccount(twitterAccountId));
-    }
-
-    /**
      * Assing Group to User.
      * @param user user
      * @param group group
     }
 
     /**
-     * Get Permission By Name
-     * @param permission permission
-     * @return {@link Permission}
-     */
-    public Permission getPermissionByName(final String permission){
-        final Permission permission2 = getPermissionDao().loadPermission(
-              EnMePermission.getPermissionString(permission));
-        return permission2;
-    }
-
-    /**
      * Get Permission by {@link EnMePermission}.
      * @param permission permission.
      * @return
     }
 
     /**
-     * Get User Logged Scocial Accounts.
-     * @return
-     * @throws EnMeNoResultsFoundException
-     */
-    public List<SocialAccountBean> getUserLoggedSocialAccount(final String username) throws EnMeNoResultsFoundException{
-         return ConvertDomainBean.convertListSocialAccountsToBean(getAccountDao()
-                                 .getTwitterAccountByUser(getUserAccount(username).getAccount()));
-    }
-
-    /**
-     * Get User Logged Verified Social Accounts.
-     * @param username username
-     * @return list of social accounts.
-     * @throws EnMeNoResultsFoundException exception
-     */
-    public List<SocialAccountBean> getUserLoggedVerifiedTwitterAccount(final String username, final SocialProvider provider)
-             throws EnMeNoResultsFoundException{
-        final List<SocialAccountBean> socialAccounts = ConvertDomainBean.convertListSocialAccountsToBean(getAccountDao()
-                .getTwitterVerifiedAccountByUser(getUserAccount(username).getAccount(), provider));
-        log.debug("social provider verified "+socialAccounts.size());
-        return socialAccounts;
-   }
-
-    /**
      * Invite some users to register in the system.
      * @param email list of users
      * @param code code
      * @return default user permission.
      */
     public String getDefaultUserPermission() {
-        return  DEFAULT;
+        return  DEFAULT.name();
     }
 
     /**

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

      */
     void setSuspendedNotification(final Boolean suspendedNotification);
 
-    /**
-     * Update Twitter Account.
-     * @param accountBean accountBean
-     * @param password password
-     * @param verify verify
-     */
-     void updateTwitterAccount(final SocialAccountBean accountBean, final String password,
-                               final Boolean verify);
-
-     /**
-      * Update OAuth Secret Twitter Credentials.
-      * @param accountBean
-      * @param username
-      */
-     void updateSecretTwitterCredentials(final SocialAccountBean accountBean,
-             final String username) throws EnMeExpcetion;
-
-     /**
-      * Get Twitter Account.
-      * @param twitterAccountId
-      * @return
-      */
-     SocialAccountBean getTwitterAccount(final Long twitterAccountId);
-
 
     /**
      * Load Groups by Client.
     UserAccountBean findUserByEmail(final String email);
 
     /**
-     * Get User Logged Twitter Accounts.
-     * @return
-     * @throws EnMeNoResultsFoundException
-     */
-    List<SocialAccountBean> getUserLoggedSocialAccount(final String username) throws EnMeNoResultsFoundException;
-
-    /**
-     * Get User Logged Verified Twitter Accounts.
-     * @param username username
-     * @param socialProvider
-     * @return
-     * @throws EnMeNoResultsFoundException
-     */
-    List<SocialAccountBean> getUserLoggedVerifiedTwitterAccount(
-            final String username,
-            final SocialProvider socialProvider) throws EnMeNoResultsFoundException;
-
-    /**
      * Get Email List by Username.
      * @param username
      * @return
     List<UnitLists> getListbyUsername(final String username) throws EnMeNoResultsFoundException;
 
     /**
-     * Update OAuth Token/Secret Social Account.
-     * @param socialAccountId
-     * @param token
-     * @param tokenSecret
-     * @param username
-     * @param account
-     * @throws EnMeExpcetion
-     */
-    public void addOAuthTokenSocialAccount(
-            final Long socialAccountId,
-            final String token,
-            final String tokenSecret,
-            final String username,
-            final UserAccount account) throws EnMeExpcetion;
-
-    /**
      * Assign Permission,
      * @param userId user id
      * @param permission {@link EnMePermission}.

encuestame-business/src/main/java/org/encuestame/business/service/imp/ITwitterService.java

     User verifyCredentials(final String username, final String password) throws TwitterException;
 
     /**
+     * Verify Credentials.
+     * @param socialAccount
+     * @return
+     */
+    Boolean verifyCredentials(final SocialAccount socialAccount);
+
+    /**
      * Get OAuthorized Token.
      * @param socialAccount {@link SocialAccount}.
      * @return {@link Twitter}.

encuestame-business/src/main/java/org/encuestame/business/service/social/provider/TwitterService.java

         //Twitter twitter = new TwitterFactory().getInstance();
         log.debug("publicTweet Before  Token  {"+socialTwitterAccount.getToken());
         log.debug("publicTweet Before Secret Token  {"+socialTwitterAccount.getSecretToken());
-        final AccessToken accessToken = this.createNewOAuthAccessToken(socialTwitterAccount);
-        log.debug("Access Token "+accessToken);
-        final Twitter twitter = this.getOAuthAuthorizedInstance(socialTwitterAccount, accessToken);
+        final Twitter twitter = this.getTwitterInsstance(socialTwitterAccount);
         log.debug("Verify  "+twitter.verifyCredentials());
         log.debug("Update Status "+tweet);
         return twitter.updateStatus(tweet);
     }
 
     /**
+     *
+     * @param socialTwitterAccount
+     * @return
+     */
+    public Twitter getTwitterInsstance(final SocialAccount socialTwitterAccount){
+        final AccessToken accessToken = this.createNewOAuthAccessToken(socialTwitterAccount);
+        log.debug("Access Token "+accessToken);
+        return this.getOAuthAuthorizedInstance(socialTwitterAccount, accessToken);
+    }
+
+    /**
+     * Verify Credentials.
+     * @param socialAccount
+     * @return
+     */
+    public Boolean verifyCredentials(final SocialAccount socialAccount){
+        final Twitter twitter = this.getTwitterInsstance(socialAccount);
+        final Boolean confirmed = twitter.isOAuthEnabled();
+        log.debug("Twitter Account "+socialAccount.getSocialAccountName()+ " is confirmed? "+confirmed);
+        return confirmed;
+    }
+
+    /**
      * Create New OAuth Access Token.
      * @param socialTwitterAccount {@link SocialAccount}.
      * @return {@link AccessToken}.

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

 import org.encuestame.persistence.domain.security.Account;
 import org.encuestame.persistence.domain.security.UserAccount;
 import org.encuestame.persistence.domain.security.SocialAccount;
+import org.encuestame.persistence.domain.social.SocialProvider;
 import org.encuestame.persistence.domain.EnMePermission;
 import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
 import org.encuestame.persistence.exception.EnMeExpcetion;
     @Ignore
     public void testaddNewTwitterAccount() throws EnMeNoResultsFoundException{
         //this.securityService.addNewTwitterAccount("encuestameTest", this.secUserSecondary.getUsername());
-        assertEquals(getAccountDao().getTwitterAccountByUser(this.userPrimary).size(), 1);
+        assertEquals(getAccountDao().getTwitterAccountByUser(this.userPrimary, SocialProvider.SocialProvider.TWITTER).size(), 1);
     }
 
     /**

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

 import org.apache.commons.lang.RandomStringUtils;
 import org.encuestame.business.service.imp.ITweetPollService;
 import org.encuestame.persistence.domain.Question;
+import org.encuestame.persistence.domain.social.SocialProvider;
 import org.encuestame.persistence.domain.survey.QuestionPattern;
 import org.encuestame.persistence.domain.security.Account;
 import org.encuestame.persistence.domain.security.UserAccount;
     @Test
     public void testPublicMultiplesTweetAccounts(){
             createDefaultSettedTwitterAccount(this.userAccount.getAccount());
-            final List<SocialAccount> list = getAccountDao().getTwitterAccountByUser(this.userAccount.getAccount());
+            final List<SocialAccount> list = getAccountDao().getTwitterAccountByUser(this.userAccount.getAccount(), SocialProvider.TWITTER);
             final List<SocialAccountBean> listUnitTwitterAccount = ConvertDomainBean.convertListSocialAccountsToBean(list);
              final String tweetText = RandomStringUtils.randomAlphabetic(5);
             final TweetPoll tweetPoll = createTweetPollPublicated(true, true, new Date(), this.user, question);

encuestame-core/src/main/java/org/encuestame/core/service/IService.java

 import org.encuestame.core.util.MessageSourceFactoryBean;
 
 /**
- * Class Description.
+ * Service Interface.
  * @author Picado, Juan juan@encuestame.org
  * @since 29/11/2009 21:47:14
  * @version $Id$
  */
-public interface IService{
+public interface IService extends SocialOperations{
 
     /**
      * Getter.

encuestame-core/src/main/java/org/encuestame/core/service/SocialOperations.java

+
+package org.encuestame.core.service;
+
+import java.util.List;
+
+import org.encuestame.persistence.domain.security.UserAccount;
+import org.encuestame.persistence.domain.social.SocialProvider;
+import org.encuestame.persistence.exception.EnMeExpcetion;
+import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
+import org.encuestame.persistence.exception.IllegalSocialActionException;
+import org.encuestame.utils.security.SocialAccountBean;
+
+/**
+ * Social Factory.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Mar 8, 2011
+ */
+public interface SocialOperations {
+
+    /**
+     * Change state social account.
+     * @param accountId
+     * @param username
+     * @param action
+     * @throws EnMeNoResultsFoundException
+     * @throws IllegalSocialActionException
+     */
+    void changeStateSocialAccount(
+            final Long accountId,
+            final String username,
+            final String action) throws EnMeNoResultsFoundException, IllegalSocialActionException;
+
+    /**
+     * Update Twitter Account.
+     * @param accountBean accountBean
+     * @param password password
+     * @param verify verify
+     */
+     void updateTwitterAccount(final SocialAccountBean accountBean, final String password,
+                               final Boolean verify);
+
+     /**
+      * Update OAuth Secret Twitter Credentials.
+      * @param accountBean
+      * @param username
+      */
+     void updateSecretTwitterCredentials(final SocialAccountBean accountBean,
+             final String username) throws EnMeExpcetion;
+
+     /**
+      * Get Twitter Account.
+      * @param twitterAccountId
+      * @return
+      */
+     SocialAccountBean getTwitterAccount(final Long twitterAccountId);
+
+     /**
+      * Get User Logged Twitter Accounts.
+      * @param username
+      * @param provider
+      * @return
+      * @throws EnMeNoResultsFoundException
+      */
+     List<SocialAccountBean> getUserLoggedSocialAccount(
+             final String username
+             , final SocialProvider provider) throws EnMeNoResultsFoundException;
+
+     /**
+      * Get User Logged Verified Twitter Accounts.
+      * @param username username
+      * @param socialProvider
+      * @return
+      * @throws EnMeNoResultsFoundException
+      */
+     List<SocialAccountBean> getUserLoggedVerifiedTwitterAccount(
+             final String username,
+             final SocialProvider socialProvider) throws EnMeNoResultsFoundException;
+
+     /**
+      * Update OAuth Token/Secret Social Account.
+      * @param socialAccountId
+      * @param token
+      * @param tokenSecret
+      * @param username
+      * @param account
+      * @param socialProvider
+      * @throws EnMeExpcetion
+      */
+     public void addOrUpdateOAuthTokenSocialAccount(
+             final Long socialAccountId,
+             final String token,
+             final String tokenSecret,
+             final String username,
+             final UserAccount account,
+             final SocialProvider socialProvider) throws EnMeExpcetion;
+
+}

encuestame-mvc/src/main/java/org/encuestame/comet/services/NotificationCometService.java

      * @param remote
      * @param message
      */
-    @Listener("/service/notification")
+    @Listener("/service/notification/status")
     public void processNotification(final ServerSession remote, final ServerMessage.Mutable message) {
         final Map<String, Object> input = message.getDataAsMap();
         log.debug("Notification Input "+input);
-        String name = (String) input.get("name");
         final Map<String, Object> output = new HashMap<String, Object>();
         final UserAccount userAccount = getByUsername(getUserPrincipalUsername());
         if (userAccount != null) {
             final Long totalNewNot = getNotificationDao().retrieveTotalNotReadedNotificationStatus(userAccount.getAccount());
             log.debug("totalNewNot "+totalNewNot);
             output.put("totalNot", totalNot);
-            output.put("totalNot", totalNewNot);
+            output.put("totalNewNot", totalNewNot);
         } else {
-            log.error("Error username ");
+            log.error("Error username");
         }
-        output.put("greeting", "Hello, " + name);
-        remote.deliver(serverSession, "/not", output, null);
+        remote.deliver(serverSession, "/notificationStatus", output, null);
     }
 
     /**

encuestame-mvc/src/main/java/org/encuestame/mvc/controller/json/social/SocialJsonController.java

-package org.encuestame.mvc.controller.json.social;
-
-public class SocialJsonController {
-
-}

encuestame-mvc/src/main/java/org/encuestame/mvc/controller/social/json/SocialAccountsJsonController.java

-
 package org.encuestame.mvc.controller.social.json;
 
 import java.io.IOException;
 import org.encuestame.persistence.domain.security.UserAccount;
 import org.encuestame.persistence.domain.social.SocialProvider;
 import org.encuestame.persistence.exception.EnMeExpcetion;
+import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
+import org.encuestame.persistence.exception.IllegalSocialActionException;
 import org.encuestame.utils.security.SocialAccountBean;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.security.access.prepost.PreAuthorize;
     }
 
     /**
-     * Create or Update Twitter Social Account.
+     * Change state of social account.
      * @param type
-     * @param consumerKey
-     * @param consumerSecret
-     * @param usernameAccount
      * @param socialAccountId
      * @param request
      * @param response
     @RequestMapping(value = "/api/social/twitter/account/{type}.json", method = RequestMethod.GET)
     public ModelMap actionTwitterAccount(
             @PathVariable String type,
-            @RequestParam(value = "consumerKey", required = true) String consumerKey,
-            @RequestParam(value = "consumerSecret", required = true) String consumerSecret,
-            @RequestParam(value = "username", required = true) String usernameAccount,
-            @RequestParam(value = "socialAccountId", required = false) String socialAccountId,
+            @RequestParam(value = "socialAccountId", required = true) Long socialAccountId,
             HttpServletRequest request,
             HttpServletResponse response) throws JsonGenerationException, JsonMappingException, IOException {
-         log.debug("consumerKey "+consumerKey);
-         log.debug("consumerSecret "+ (consumerSecret));
          try {
-           final UserAccount userAccount = getUserAccount();
-           if("create".equals(type)){
-               //getSecurityService().addNewTwitterAccount(userAccount, usernameAccount, consumerKey, consumerSecret);
-               setSuccesResponse();
-           } else if("update".equals(type)){
-              log.info("update social twitter account");
-           } else {
-               setError("type not valid", response);
-           }
-        } catch (EnMeExpcetion e) {
-            setItemResponse("url", "");
+           getSecurityService().changeStateSocialAccount(socialAccountId, getUserPrincipalUsername(), type);
+        } catch (IllegalSocialActionException e) {
+            setError(e.getMessage(), response);
+        } catch (EnMeNoResultsFoundException e) {
             setError(e.getMessage(), response);
         }
         return returnData();
          log.debug("pin "+pin);
          try {
             final HashMap<String, Object> jsonResponse = new HashMap<String, Object>();
-            final HashMap<String, Object> r = this.createOAuthSocialAccountWithPinNumber(pin, getUserAccount());
+            final HashMap<String, Object> r = this.createOAuthSocialAccountWithPinNumber(pin, getUserAccount(), SocialProvider.TWITTER);
             jsonResponse.put("confirm", r.get("confirm"));
-            jsonResponse.put("screenName", r.get("screenName"));
+            jsonResponse.put("message", r.get("message"));
             setItemResponse(jsonResponse);
         } catch (Exception e) {
-            setItemResponse("url", "");
+            final HashMap<String, Object> jsonResponse = new HashMap<String, Object>();
+            jsonResponse.put("confirm", false);
+            jsonResponse.put("message", e.getMessage());
+            setItemResponse(jsonResponse);
             setError(e.getMessage(), response);
         }
          return returnData();
      * @throws IOException
      */
     @PreAuthorize("hasRole('ENCUESTAME_USER')")
-    @RequestMapping(value = "/api/common/social/valid-accounts.json", method = RequestMethod.GET)
+    @RequestMapping(value = "/api/common/social/confirmed-accounts.json", method = RequestMethod.GET)
     public ModelMap get(
             HttpServletRequest request,
             HttpServletResponse response,
     }
 
     /**
+     * Return Social Valid Accounts.
+     * @param request
+     * @param response
+     * @param provider
+     * @return
+     * @throws JsonGenerationException
+     * @throws JsonMappingException
+     * @throws IOException
+     */
+    @PreAuthorize("hasRole('ENCUESTAME_USER')")
+    @RequestMapping(value = "/api/common/social/accounts.json", method = RequestMethod.GET)
+    public ModelMap getSocialAccountByType(
+            HttpServletRequest request,
+            HttpServletResponse response,
+            @RequestParam(value = "provider", required = false) String provider)
+            throws JsonGenerationException, JsonMappingException, IOException {
+        try {
+             final List<SocialAccountBean> accounts = getSecurityService()
+                   .getUserLoggedSocialAccount(getUserPrincipalUsername(), SocialProvider.getProvider(provider));
+             setItemReadStoreResponse("socialAccounts", "id", accounts);
+             log.debug("Twitter Accounts Loaded");
+        } catch (Exception e) {
+            log.error(e);
+            e.printStackTrace();
+            setError(e.getMessage(), response);
+        }
+        return returnData();
+    }
+
+    /**
      * Get Twitter Pin Url.
      * @param ping
      * @param consumerKey
     }
 
     /**
-     *
+     * Create Social Account with Pin Number.
      * @param pin
      * @param account
+     * @param socialProvider
      * @param userId
      * @return
      */
-    public HashMap<String, Object> createOAuthSocialAccountWithPinNumber(final String pin, final UserAccount account){
+    public HashMap<String, Object> createOAuthSocialAccountWithPinNumber(
+            final String pin,
+            final UserAccount account,
+            final SocialProvider socialProvider){
         log.debug("confirmOAuthPin");
         boolean confirmed = false;
         AccessToken accessToken = null;
                          log.debug("Access Token UserId {"+accessToken.getUserId());
                          log.debug("New Token {"+accessToken.getToken());
                          log.debug("New Secret Token {"+accessToken.getTokenSecret());
-                         getSecurityService().addOAuthTokenSocialAccount((long) accessToken.getUserId(),
+                         getSecurityService().addOrUpdateOAuthTokenSocialAccount((long) accessToken.getUserId(),
                                  accessToken.getToken(),
                                  accessToken.getTokenSecret(),
                                  accessToken.getScreenName(),
-                                 account);
+                                 account,
+                                 socialProvider);
                          confirmed = true;
+                         response.put("message", "ok");
                     }
                 }
             } catch (Exception e) {
                 log.error(e);
                 e.printStackTrace();
+                response.put("message", e.getMessage());
             }
         }
+        response.put("confirm", confirmed);
         return response;
     }
 

encuestame-persistence/src/main/java/org/encuestame/persistence/dao/IAccountDao.java

     /**
      * Get Twitter Accounts.
      * @param secUsers {@link Account}.
+     * @param provider
      * @return List {@link SocialAccount}.
      *
      */
-    List<SocialAccount> getTwitterAccountByUser(final Account secUsers);
+    List<SocialAccount> getTwitterAccountByUser(final Account secUsers,
+            final SocialProvider provider);
 
     /**
      * Get Twitter Account.
     SocialAccount getTwitterAccount(final Long twitterAccountId);
 
     /**
+     * Get Social Account.
+     * @param socialProvider
+     * @param socialAccountId
+     * @return
+     */
+    SocialAccount getSocialAccount(final SocialProvider socialProvider, final Long socialAccountId);
+
+    /**
+     * Get Social Account.
+     * @param socialAccountId
+     * @param account
+     * @return
+     */
+    SocialAccount getSocialAccount(final Long socialAccountId, final Account account);
+
+    /**
      * Get Twitter Verified Accounts.
      * @param secUsers {@link AccountDaoImp}
      * @param provider {@link SocialProvider}

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

     }
 
     /**
+     * Get Social Account.
+     * @param socialProvider
+     * @param socialAccountId
+     * @return
+     */
+    public SocialAccount getSocialAccount(final SocialProvider socialProvider, final Long socialAccountId){
+        final DetachedCriteria criteria = DetachedCriteria.forClass(SocialAccount.class);
+        log.debug("accounType "+socialProvider);
+        log.debug("socialAccountId "+socialAccountId);
+        criteria.add(Restrictions.eq("accounType", socialProvider));
+        criteria.add(Restrictions.eq("socialUserId", socialAccountId) );
+        return (SocialAccount) DataAccessUtils.uniqueResult(getHibernateTemplate().findByCriteria(criteria));
+    }
+
+    /**
+     * Get Social Account.
+     * @param socialAccountId
+     * @param account
+     * @return
+     */
+    public SocialAccount getSocialAccount(final Long socialAccountId, final Account account){
+        final DetachedCriteria criteria = DetachedCriteria.forClass(SocialAccount.class);
+        criteria.add(Restrictions.eq("secUsers", account));
+        criteria.add(Restrictions.eq("socialUserId", socialAccountId));
+        return (SocialAccount) DataAccessUtils.uniqueResult(getHibernateTemplate().findByCriteria(criteria));
+    }
+
+    /**
      * Get Primary User By Id.
      * @param userId user id
      * @return {@link Account}
     /**
      * Get Twitter Accounts.
      * @param secUsers {@link Account}.
+     * @param provider
      * @return List {@link SocialAccount}.
      *
      */
-    public List<SocialAccount> getTwitterAccountByUser(final Account secUsers){
+    public List<SocialAccount> getTwitterAccountByUser(
+            final Account secUsers,
+            final SocialProvider provider){
         final DetachedCriteria criteria = DetachedCriteria.forClass(SocialAccount.class);
         criteria.add(Restrictions.eq("secUsers", secUsers) );
+        if (provider != null) { //if provider is null, we fetch everything
+            criteria.add(Restrictions.eq("accounType", provider));
+        }
         return   getHibernateTemplate().findByCriteria(criteria);
     }
 

encuestame-persistence/src/main/java/org/encuestame/persistence/domain/EnMePermission.java

     ENCUESTAME_PUBLISHER,
     ENCUESTAME_EDITOR,
     ENCUESTAME_ANONYMOUS,
+    ENCUESTAME_API,
+    ENCUESTAME_READ,
+    ENCUESTAME_WRITE,
 
-    EnMePermission(){
-        //Constructor.
-    };
+    EnMePermission(){};
 
     /**
      * To String.

encuestame-persistence/src/main/java/org/encuestame/persistence/domain/security/SocialAccount.java

     private String secretToken;
 
     /**
+     * Default Selected.
+     */
+    private Boolean defaultSelected = false;
+
+    /**
      * Type.
      */
     private TypeAuth type = TypeAuth.OAUTH; //Twitter only accept OAuth.
     /**
      * @return the twitterAccount
      */
-    @Column (name="social_account_name", nullable = false)
+    @Column (name="social_account_name", nullable = false, unique = true)
     public String getSocialAccountName() {
         return socialAccountName;
     }
     public void setSecretToken(String secretToken) {
         this.secretToken = secretToken;
     }
+
+    /**
+     * @return the defaultSelected
+     */
+    @Column(name = "default_selected", nullable = true)
+    public Boolean getDefaultSelected() {
+        return defaultSelected;
+    }
+
+    /**
+     * @param defaultSelected the defaultSelected to set
+     */
+    public void setDefaultSelected(Boolean defaultSelected) {
+        this.defaultSelected = defaultSelected;
+    }
 }

encuestame-persistence/src/main/java/org/encuestame/persistence/exception/IllegalSocialActionException.java

+
+package org.encuestame.persistence.exception;
+
+/**
+ * Illegal social action exception.
+ * @author Picado, Juan juanATencuestame.org
+ * @since Mar 7, 2011
+ */
+public class IllegalSocialActionException  extends EnMeExpcetion{
+
+
+    /**
+     * Serial.
+     */
+    private static final long serialVersionUID = -5547611858006644546L;
+
+    /**
+     * Constructor.
+     */
+    public IllegalSocialActionException() {
+        super("social action not defined");
+    }
+}

encuestame-war/pom.xml

     <build>
     <finalName>encuestame</finalName>
     <plugins>
-    <!--  To optimize JS uncomment this.
         <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-antrun-plugin</artifactId>
                           <pathelement location="../dojo/util/shrinksafe/shrinksafe.jar"/>
                         </classpath>
                         <property file="${basedir}/dojo.properties"/>
+                        <!--  To optimize JS uncomment this.
                         <target unless="build">
                             <java
                              fork="true"
                            </delete>
                           <echo message="Dojo optimized." />
                         </target>
+                        -->
                     </configuration>
                     <goals>
                         <goal>run</goal>
                 </execution>
             </executions>
         </plugin>
+        <!--
+        Customize and Optimize WAR file.
         <plugin>
             <artifactId>maven-war-plugin</artifactId>
             <version>2.1.1</version>
                 </webResources>
             </configuration>
             </plugin> -->
+
         <!-- Development War Configuration - NOT Optimized -->
         <plugin>
             <groupId>org.apache.maven.plugins</groupId>
                     <webAppConfig>
                         <contextPath>/encuestame</contextPath>
                     </webAppConfig>
-                    <scanIntervalSeconds>10</scanIntervalSeconds><!--
+                    <scanIntervalSeconds>5</scanIntervalSeconds><!--
                         <requestLog implementation="org.mortbay.jetty.NCSARequestLog">
                             <filename>target/encuestame.log</filename>
                             <retainDays>90</retainDays>

encuestame-war/src/main/webapp/WEB-INF/jsp/includes/web/menu.jsp

         <li class="item"><a href="<%=request.getContextPath()%>/survey">Surveys</a></li>
     </ul>
     <div style="float: right;">
-        <div dojoType="encuestame.org.core.commons.notifications.Notification" delay="40000"></div>
+        <div dojoType="encuestame.org.core.commons.notifications.Notification"></div>
     </div>
     <br style="clear: left" />
     </div>

encuestame-war/src/main/webapp/WEB-INF/layouts/standard/page.jsp

          dojo.require("encuestame.org.core.commons.error.ErrorSessionHandler");
          dojo.require("encuestame.org.core.commons.error.ErrorConexionHandler");
          dojo.require("encuestame.org.core.commons.error.ErrorHandler");
+         //cometd libs
+         dojo.require("dojox.cometd");
+         dojo.require("dojo.io.script");
+         dojo.require("dojox.cometd");
+         //dojo.require("dojox.cometd.callbackPollTransport");
     </script>
+<script type="text/javascript">
+    var config = {
+        contextPath: '<%=request.getContextPath()%>'
+    };
+    var cometd = dojox.cometd;
+</script>
+<script src="<%=request.getContextPath()%>/resource/js/cometd.js"></script>
 </head>
 <body class="claro">
 <div id="contextWidget" dojoType="encuestame.org.core.contextWidget" contextPath="<%=request.getContextPath()%>"></div>

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

 <%@ page session="false" %>
 <%@ taglib uri="http://www.springframework.org/tags" prefix="s" %>
 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
-
 <script type="text/javascript">
   dojo.require("encuestame.org.core.commons.dashboard.chart.DashboardPie");
   dojo.require("encuestame.org.core.commons.dashboard.chart.DashboardColumn2D");
   dojo.require("encuestame.org.core.commons.dashboard.chart.DashboardLine");
   dojo.require("encuestame.org.core.commons.dashboard.Dashboard");
-  dojo.require("dojox.cometd");
-  dojo.require("dojo.io.script");
-  dojo.require("dojox.cometd");
-  dojo.require("dojox.cometd.callbackPollTransport");
-</script>
-<script type="text/javascript">
-dojo.addOnLoad(function()
-{
-
-    //More Info: http://cometd.org/node/49
-    var cometd = dojox.cometd;
-    console.debug("comentD",cometd);
-    var config = {
-            contextPath: '/encuestame'
-        };
-
-    function _connectionEstablished()
-    {
-        dojo.byId('body').innerHTML += '<div>CometD Connection Established</div>';
-    }
-
-    function _connectionBroken()
-    {
-        dojo.byId('body').innerHTML += '<div>CometD Connection Broken</div>';
-    }
-
-    function _connectionClosed()