Commits

Juan Carlos Picado Herrera committed 8223ff3 Merge

Merge branch 'development' of github.com:encuestame/encuestame into dianmorales

Comments (0)

Files changed (235)

encuestame-business/pom.xml

             <classifier>tests</classifier>
         </dependency>
         <dependency>
+            <groupId>org.encuestame</groupId>
+            <artifactId>encuestame-social</artifactId>
+        </dependency>
+        <dependency> <!-- reuse src/test/java code from encuestame-core! -->
+            <groupId>org.encuestame</groupId>
+            <artifactId>encuestame-social</artifactId>
+            <scope>test</scope>
+            <classifier>tests</classifier>
+        </dependency>
+        <dependency>
             <groupId>commons-codec</groupId>
             <artifactId>commons-codec</artifactId>
         </dependency>

encuestame-business/src/main/java/org/encuestame/business/cron/RemoveUnconfirmedAccountJob.java

 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.encuestame.business.service.imp.SecurityOperations;
+import org.encuestame.core.service.imp.SecurityOperations;
 import org.encuestame.persistence.dao.IAccountDao;
 import org.springframework.beans.factory.annotation.Autowired;
 

encuestame-business/src/main/java/org/encuestame/business/search/GlobalSearchItem.java

-/*
- ************************************************************************************
- * Copyright (C) 2001-2011 encuestame: system online surveys Copyright (C) 2009
- * 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.business.search;
-
-/**
- * Represent a global search item on results list.
- *
- * @author Picado, Juan juanATencuestame.org
- * @since Mar 23, 2011
- */
-public class GlobalSearchItem {
-
-    /**
-     * Id.
-     */
-    private Long id;
-
-    /**
-     * URI path.
-     */
-    private String urlLocation;
-
-    /**
-     * Score.
-     */
-    private Long score  = 0L;
-
-    /**
-     * Score hits.
-     */
-    private Long hits = 0L;
-
-    /**
-     * {@link TypeSearchResult}.
-     */
-    private TypeSearchResult typeSearchResult;
-
-    /**
-     * Item search title.
-     */
-    private String itemSearchTitle;
-
-    /**
-     * Description.
-     */
-    private String itemSearchDescription;
-
-    /**
-     * @return the urlLocation
-     */
-    public String getUrlLocation() {
-        return urlLocation;
-    }
-
-    /**
-     * @param urlLocation
-     *            the urlLocation to set
-     */
-    public void setUrlLocation(String urlLocation) {
-        this.urlLocation = urlLocation;
-    }
-
-    /**
-     * @return the score
-     */
-    public Long getScore() {
-        return score;
-    }
-
-    /**
-     * @param score
-     *            the score to set
-     */
-    public void setScore(Long score) {
-        this.score = score;
-    }
-
-    /**
-     * @return the hits
-     */
-    public Long getHits() {
-        return hits;
-    }
-
-    /**
-     * @param hits
-     *            the hits to set
-     */
-    public void setHits(Long hits) {
-        this.hits = hits;
-    }
-
-    /**
-     * @return the typeSearchResult
-     */
-    public TypeSearchResult getTypeSearchResult() {
-        return typeSearchResult;
-    }
-
-    /**
-     * @param typeSearchResult
-     *            the typeSearchResult to set
-     */
-    public void setTypeSearchResult(TypeSearchResult typeSearchResult) {
-        this.typeSearchResult = typeSearchResult;
-    }
-
-    /**
-     * @return the itemSearchTitle
-     */
-    public String getItemSearchTitle() {
-        return itemSearchTitle;
-    }
-
-    /**
-     * @param itemSearchTitle
-     *            the itemSearchTitle to set
-     */
-    public void setItemSearchTitle(String itemSearchTitle) {
-        this.itemSearchTitle = itemSearchTitle;
-    }
-
-    /**
-     * @return the itemSearchDescription
-     */
-    public String getItemSearchDescription() {
-        return itemSearchDescription;
-    }
-
-    /**
-     * @param itemSearchDescription
-     *            the itemSearchDescription to set
-     */
-    public void setItemSearchDescription(String itemSearchDescription) {
-        this.itemSearchDescription = itemSearchDescription;
-    }
-
-    /**
-     * @return the id
-     */
-    public Long getId() {
-        return id;
-    }
-
-    /**
-     * @param id the id to set
-     */
-    public void setId(Long id) {
-        this.id = id;
-    }
-
-    /* (non-Javadoc)
-     * @see java.lang.Object#hashCode()
-     */
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((hits == null) ? 0 : hits.hashCode());
-        result = prime
-                * result
-                + ((itemSearchDescription == null) ? 0 : itemSearchDescription
-                        .hashCode());
-        result = prime * result
-                + ((itemSearchTitle == null) ? 0 : itemSearchTitle.hashCode());
-        result = prime * result + ((score == null) ? 0 : score.hashCode());
-        result = prime
-                * result
-                + ((typeSearchResult == null) ? 0 : typeSearchResult.hashCode());
-        result = prime * result
-                + ((urlLocation == null) ? 0 : urlLocation.hashCode());
-        return result;
-    }
-
-    /* (non-Javadoc)
-     * @see java.lang.Object#equals(java.lang.Object)
-     */
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-        if (obj == null) {
-            return false;
-        }
-        if (!(obj instanceof GlobalSearchItem)){
-            return false;
-        }
-        final GlobalSearchItem other = (GlobalSearchItem) obj;
-        if (hits == null) {
-            if (other.hits != null) {
-                return false;
-            }
-        } else if (!hits.equals(other.hits)) {
-            return false;
-        }
-        if (itemSearchDescription == null) {
-            if (other.itemSearchDescription != null) {
-                return false;
-            }
-        } else if (!itemSearchDescription.equals(other.itemSearchDescription))
-            return false;
-        if (itemSearchTitle == null) {
-            if (other.itemSearchTitle != null) {
-                return false;
-            }
-        } else if (!itemSearchTitle.equals(other.itemSearchTitle))
-            return false;
-        if (score == null) {
-            if (other.score != null) {
-                return false;
-            }
-        } else if (!score.equals(other.score))
-            return false;
-        if (typeSearchResult != other.typeSearchResult) {
-            return false;
-        }
-        if (urlLocation == null) {
-            if (other.urlLocation != null) {
-                return false;
-            }
-        } else if (!urlLocation.equals(other.urlLocation)) {
-            return false;
-        }
-        return true;
-    }
-
-    /* (non-Javadoc)
-     * @see java.lang.Object#toString()
-     */
-    @Override
-    public String toString() {
-        return "GlobalSearchItem [urlLocation=" + urlLocation + ", score="
-                + score + ", hits=" + hits + ", typeSearchResult="
-                + typeSearchResult + ", itemSearchTitle=" + itemSearchTitle
-                + ", itemSearchDescription=" + itemSearchDescription + "]";
-    }
-}

encuestame-business/src/main/java/org/encuestame/business/search/IndexFSDirectory.java

 import org.apache.commons.logging.LogFactory;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.FSDirectory;
-import org.encuestame.business.setup.DirectorySetupOperations;
 import org.encuestame.core.search.DirectoryIndexStore;
+import org.encuestame.core.service.DirectorySetupOperations;
 
 /**
  * Index Directory.

encuestame-business/src/main/java/org/encuestame/business/search/IndexWriterManager.java

 import org.apache.lucene.index.CorruptIndexException;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.store.LockObtainFailedException;
-import org.encuestame.business.service.imp.IIndexWriter;
 import org.encuestame.core.search.DirectoryIndexStore;
+import org.encuestame.core.service.imp.IIndexWriter;
 import org.springframework.util.Assert;
 
 /**

encuestame-business/src/main/java/org/encuestame/business/search/ReIndexAttachmentsJob.java

 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.encuestame.business.setup.DirectorySetupOperations;
+import org.encuestame.core.service.DirectorySetupOperations;
 import org.encuestame.persistence.dao.IAccountDao;
 import org.encuestame.persistence.dao.imp.AccountDaoImp;
 import org.encuestame.persistence.exception.EnMeExpcetion;

encuestame-business/src/main/java/org/encuestame/business/search/SearchAttachmentManager.java

 import org.apache.lucene.search.TopDocs;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.Version;
-import org.encuestame.business.setup.DirectorySetupOperations;
 import org.encuestame.core.search.DirectoryIndexStore;
+import org.encuestame.core.service.DirectorySetupOperations;
 
 /**
  * Query Search Manager to Lucene Index.

encuestame-business/src/main/java/org/encuestame/business/search/TypeSearchResult.java

-/*
- ************************************************************************************
- * Copyright (C) 2001-2011 encuestame: system online surveys Copyright (C) 2009
- * 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.business.search;
-
-/**
- * Type search result.
- * @author Picado, Juan juanATencuestame.org
- * @since Mar 23, 2011
- */
-public enum TypeSearchResult {
-    TWEETPOLL, PROFILE, POLL, SURVEY, ATTACHMENT, QUESTION, HASHTAG
-}

encuestame-business/src/main/java/org/encuestame/business/search/UtilConvertToSearchItems.java

 import java.util.ArrayList;
 import java.util.List;
 
+import org.encuestame.core.search.GlobalSearchItem;
+import org.encuestame.core.search.TypeSearchResult;
 import org.encuestame.persistence.domain.HashTag;
 import org.encuestame.persistence.domain.question.Question;
 import org.encuestame.persistence.domain.security.UserAccount;

encuestame-business/src/main/java/org/encuestame/business/security/AbstractSecurityContext.java

-/*
- ************************************************************************************
- * Copyright (C) 2001-2010 encuestame: system online surveys Copyright (C) 2009
- * 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.business.security;
-
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-import org.encuestame.core.security.SecurityUtils;
-import org.encuestame.core.security.details.EnMeUserAccountDetails;
-import org.encuestame.core.security.util.WidgetUtil;
-import org.encuestame.core.util.ConvertDomainsToSecurityContext;
-import org.encuestame.persistence.domain.security.UserAccount;
-import org.encuestame.persistence.exception.EnMeExpcetion;
-import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
-import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.core.context.SecurityContext;
-import org.springframework.security.core.context.SecurityContextHolder;
-
-/**
- * Abstract Security Context.
- * @author Picado, Juan juanATencuestame.org
- * @since Sep 19, 2010 10:58:37 AM
- * @version $Id:$
- */
-public abstract class AbstractSecurityContext {
-
-    /** Log. **/
-    protected Logger log = Logger.getLogger(this.getClass());
-
-
-    /** Obtain {@link SecurityContext}.**/
-    private SecurityContext securityContext;
-
-    /**
-     * Get Username of user client.
-     * @return
-     */
-    public String getUserPrincipalUsername(){
-        String username = "";
-        if (getSecCtx().getAuthentication() != null) {
-            username = getSecCtx().getAuthentication().getName();
-        }
-       return username;
-    }
-
-    /**
-     * Get logged {@link UserAccount}.
-     * @return {@link UserAccount}.
-     */
-    public UserAccount getUserAccountonSecurityContext(){
-        UserAccount account = null;
-        final EnMeUserAccountDetails details = getSecurityDetails();
-        if (details != null) {
-            account = details.getUserAccount();
-            if (log.isDebugEnabled()) {
-                log.debug("info logged user account: "+account);
-                if (account != null) {
-                    log.debug("info logged user account: "+account.getUserEmail());
-                    log.debug("info logged user account: "+account.getUsername());
-                    log.debug("info logged user account: "+account.getUid());
-                }
-            }
-        }
-        return account;
-    }
-
-    /**
-     * Set Spring Authentication
-     * @param username
-     * @param password
-     */
-    public void setSpringSecurityAuthentication(
-            final UserAccount account,
-            final String password){
-         this.setSpringSecurityAuthentication(account, password, Boolean.FALSE);
-    }
-
-    /**
-     *
-     * @param account
-     * @param password
-     * @param socialSignIn
-     */
-    public void setSpringSecurityAuthentication(
-            final UserAccount account,
-            final String password,
-            final Boolean socialSignIn){
-         log.info("Register login user: "+account.getUsername());
-         //building granted authorities
-         final Collection<GrantedAuthority> authorities = ConvertDomainsToSecurityContext.convertEnMePermission(account.getSecUserPermissions());
-         //create user detail based on user account.
-         final EnMeUserAccountDetails details = SecurityUtils.convertUserAccountToUserDetails(account, true);
-         //set the social credentials permission.
-         details.setSocialCredentials(socialSignIn);
-         SecurityContextHolder.getContext().setAuthentication(
-                 new UsernamePasswordAuthenticationToken(details, password, authorities));
-         if (log.isInfoEnabled()) {
-             log.info("Username "+account.getUsername() + " is logged at "+new Date() + " with social account?"+socialSignIn);
-         }
-    }
-
-    /**
-     * @return the secCtx
-     */
-    public SecurityContext getSecCtx() {
-        return this.securityContext = SecurityContextHolder.getContext();
-    }
-
-    /**
-     * Get Details.
-     */
-    public EnMeUserAccountDetails getSecurityDetails(){
-        EnMeUserAccountDetails details = null;
-        log.trace("Authentication Object:{"+getSecCtx().getAuthentication());
-        if(getSecCtx().getAuthentication() != null){
-            if(getSecCtx().getAuthentication().getPrincipal() instanceof EnMeUserAccountDetails){
-                details =  (EnMeUserAccountDetails) getSecCtx().getAuthentication().getPrincipal();
-            }
-        }
-        return details;
-    }
-
-    /**
-     * Check ip in black list.
-     * @param ip
-     * @return
-     */
-    public Boolean checkIPinBlackList(final String ip){
-        System.out.println("IP in Checking --->" + ip);
-        Boolean bannedIp = Boolean.FALSE;
-        try {
-            if(ip!=null){
-                final List<String> blackList = WidgetUtil.getBlackListIP("blacklist.inc");
-                System.out.println("Black List size -----> "+ blackList.size());
-                for (String ipItem : blackList) {
-                    if(ipItem.equals(ip)){
-                        bannedIp = Boolean.TRUE;
-                    }
-                }
-            }
-        } catch (EnMeExpcetion e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-            System.out.println("ERRORR----->"+e);
-        }
-        return bannedIp;
-    }
-}

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

-/*
- ************************************************************************************
- * Copyright (C) 2001-2009 encuestame: system online surveys Copyright (C) 2009
- * 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.business.service;
-
-import java.io.File;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.encuestame.business.service.imp.MailServiceOperations;
-import org.encuestame.business.setup.DirectorySetupOperations;
-import org.encuestame.core.util.ConvertDomainBean;
-import org.encuestame.persistence.domain.Email;
-import org.encuestame.persistence.domain.EmailList;
-import org.encuestame.persistence.domain.EmailSubscribe;
-import org.encuestame.persistence.domain.notifications.Notification;
-import org.encuestame.persistence.domain.notifications.NotificationEnum;
-import org.encuestame.persistence.domain.security.Account;
-import org.encuestame.persistence.domain.security.UserAccount;
-import org.encuestame.persistence.exception.EnMeExpcetion;
-import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
-import org.encuestame.utils.DateUtil;
-import org.encuestame.utils.MD5Utils;
-import org.encuestame.utils.RelativeTimeEnum;
-import org.encuestame.utils.json.TweetPollBean;
-import org.encuestame.utils.web.UnitEmails;
-import org.encuestame.utils.web.UnitLists;
-import org.encuestame.utils.web.UserAccountBean;
-import org.hibernate.HibernateException;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.web.servlet.support.RequestContextUtils;
-
-import twitter4j.Twitter;
-import twitter4j.TwitterException;
-import twitter4j.http.AccessToken;
-
-/**
- * Service.
- * @author Picado, Juan juan@encuestame.org
- * @since 22/05/2009 1:02:45
- */
-@Service
-public abstract class AbstractBaseService extends AbstractDataSource {
-
-    private Log log = LogFactory.getLog(this.getClass());
-
-    /**
-     * {@link MessageSourceFactoryBean}.
-     */
-    @Autowired
-    private MessageSourceFactoryBean messageSourceFactoryBean;
-
-    /**
-     *  {@link MailService}.
-     */
-    @Resource()
-    private MailServiceOperations mailService;
-
-    /**
-     * Constructor.
-     */
-    public AbstractBaseService() {}
-
-
-
-    /**
-     *
-     * @param tpbean
-     * @param request
-     */
-    public TweetPollBean  convertTweetPollRelativeTime(final TweetPollBean tpbean, final HttpServletRequest request){
-        final HashMap<Integer, RelativeTimeEnum> relativeTime =  DateUtil.getRelativeTime(tpbean.getCreatedDateAt());
-        @SuppressWarnings("rawtypes")
-        final Iterator it = relativeTime.entrySet().iterator();
-        while (it.hasNext()) {
-            @SuppressWarnings("unchecked")
-            final Map.Entry<Integer, RelativeTimeEnum> e = (Map.Entry<Integer, RelativeTimeEnum>)it.next();
-            if (log.isDebugEnabled()) {
-                log.debug("--"+e.getKey() + "**" + e.getValue());
-            }
-            tpbean.setRelativeTime(convertRelativeTimeMessage(e.getValue(), e.getKey(), request));
-        }
-        return tpbean;
-    }
-
-    /**
-     * Convert Relative Time Message.
-     * @param relativeTimeEnum
-     * @param number
-     * @param request
-     * @param objects
-     * @return
-     */
-    public String convertRelativeTimeMessage(
-            final RelativeTimeEnum relativeTimeEnum,
-            final Integer number,
-            final HttpServletRequest request){
-        final StringBuilder builder = new StringBuilder();
-        //builder.append(number);
-        //builder.append(" ");
-        log.debug("Convert Message Relative Time");
-        log.debug("Relative ENUM -->"+relativeTimeEnum);
-        log.debug("NUMBER -->"+number);
-        String str[] = {number.toString()};
-        if (relativeTimeEnum.equals(RelativeTimeEnum.ONE_SECOND_AGO)) {
-            builder.append(getMessage("relative.time.one.second.ago", request, str));
-        } else if(relativeTimeEnum.equals(RelativeTimeEnum.SECONDS_AGO)) {
-            builder.append(getMessage("relative.time.one.seconds.ago", request, str));
-        } else if(relativeTimeEnum.equals(RelativeTimeEnum.A_MINUTE_AGO)) {
-            builder.append(getMessage("relative.time.one.minute.ago", request, str));
-        } else if(relativeTimeEnum.equals(RelativeTimeEnum.MINUTES_AGO)) {
-            builder.append(getMessage("relative.time.one.minutes.ago", request, str));
-        } else if(relativeTimeEnum.equals(RelativeTimeEnum.AN_HOUR_AGO)) {
-            builder.append(getMessage("relative.time.one.hour.ago", request, str));
-        } else if(relativeTimeEnum.equals(RelativeTimeEnum.HOURS_AGO)) {
-            builder.append(getMessage("relative.time.one.hours.ago", request, str));
-        } else if(relativeTimeEnum.equals(RelativeTimeEnum.MONTHS_AGO)) {
-            builder.append(getMessage("relative.time.one.months.ago", request, str));
-        } else if(relativeTimeEnum.equals(RelativeTimeEnum.ONE_MONTH_AGO)) {
-            builder.append(getMessage("relative.time.one.month.ago", request, str));
-        } else if(relativeTimeEnum.equals(RelativeTimeEnum.ONE_YEAR_AGO)) {
-            builder.append(getMessage("relative.time.one.year.ago", request, str));
-        } else if(relativeTimeEnum.equals(RelativeTimeEnum.YEARS_AGO)) {
-            builder.append(getMessage("relative.time.one.years.ago", request, str));
-        }
-        return builder.toString();
-    }
-
-    /**
-     * Getter.
-     * @return {@link MessageSourceFactoryBean}
-     */
-    public MessageSourceFactoryBean getMessageSourceFactoryBean() {
-        return messageSourceFactoryBean;
-    }
-
-
-    /**
-     * Setter.
-     * @param messageSource {@link MessageSourceFactoryBean}
-     */
-    public void setMessageSourceFactoryBean(final MessageSourceFactoryBean messageSourceFactoryBean) {
-        this.messageSourceFactoryBean = messageSourceFactoryBean;
-    }
-
-    /**
-     * Getter by propertie Id.
-     * @param propertieId propertieId
-     * @return value of propertie
-     */
-    public String getMessageProperties(String propertieId) {
-        return getMessageSourceFactoryBean() == null ? propertieId : getMessageSourceFactoryBean()
-                .getMessage(propertieId, null, null);
-    }
-
-    private Locale getLocale(final HttpServletRequest request){
-        return RequestContextUtils.getLocale(request);
-    }
-
-    public String getMessage(final String message,
-            final HttpServletRequest request, Object[] args) {
-        String stringValue = "";
-        try {
-            stringValue = getMessageSourceFactoryBean().getMessage(
-                    message, args, getLocale(request));
-        } catch (Exception e) {
-            log.error(e);
-            e.printStackTrace(); //TODO: ENCUESTAME-223 - OPEN
-        }
-        return stringValue;
-    }
-
-    /**
-     * Create Email List.
-     * @param unitLists
-     * @return
-     * @throws EnMeExpcetion
-     */
-    public UnitLists createEmailLists(final UnitLists unitLists) throws EnMeExpcetion{
-        if (unitLists!=null){
-            try {
-                final EmailList listsDomain = new EmailList();
-                listsDomain.setCreatedAt(unitLists.getCreatedAt());
-                listsDomain.setListName(unitLists.getListName());
-                listsDomain.setUsuarioEmail(getAccountDao().getUserById(unitLists.getUserId()));
-                getEmailListsDao().saveOrUpdate(listsDomain);
-                unitLists.setId(listsDomain.getIdList());
-              } catch (HibernateException e) {
-                  throw new EnMeExpcetion(e);
-              } catch (Exception e) {
-                  throw new EnMeExpcetion(e);
-              }
-              return unitLists;
-          } else {
-              throw new EnMeExpcetion("email list is not valid");
-          }
-      }
-
-    /**
-     * Create Emails.
-     * @param unitEmails
-     * @return
-     * @throws EnMeExpcetion
-     */
-    public UnitEmails createEmail(final UnitEmails unitEmails) throws EnMeExpcetion{
-        if(unitEmails!= null){
-            try {//
-                final EmailList emailList = new EmailList();
-                final String codeSubscribe = MD5Utils.md5(String.valueOf(System.currentTimeMillis()));
-                final Email emailsDomain = new Email();
-                emailsDomain.setEmail(unitEmails.getEmailName());
-                emailsDomain.setSubscribed(Boolean.FALSE); //By Default is FALSE, user need subscribe.
-                emailsDomain.setIdListEmail(emailList);
-                getEmailListsDao().saveOrUpdate(emailsDomain);
-                unitEmails.setIdEmail(emailsDomain.getIdEmail());
-                //TODO: Necesitamos crear el registro con el hash !!
-                final EmailSubscribe subscribe = new EmailSubscribe();
-                subscribe.setEmail(emailsDomain);
-                subscribe.setList(emailList);
-                subscribe.setHashCode(codeSubscribe);
-                getEmailListsDao().saveOrUpdate(subscribe);
-                getMailService().send(emailsDomain.getEmail(),"Invitation to Subscribe Encuestame List","Invitation to Subscribe");
-                //TODO:Enviamos correo al usuario para que confirme su subscripcion.
-            }
-            catch (Exception e) {
-                throw new EnMeExpcetion(e);
-            }
-            return unitEmails;
-        } else {
-            throw new EnMeExpcetion("Email is null");
-        }
-    }
-
-    /**
-     * Create Notification.
-     * @param description
-     * @param secUser
-     * @return
-     */
-    @Deprecated
-    public Notification createNotification(final NotificationEnum description, final String additional,  final Account account){
-        final Notification notification = new Notification();
-        notification.setDescription(description);
-        notification.setAccount(account);
-        notification.setAdditionalDescription(additional);
-        getNotificationDao().saveOrUpdate(notification);
-        return notification;
-    }
-
-
-    /**
-     * Create {@link Notification} with url reference.
-     * @param description
-     * @param additional
-     * @param urlReference
-     * @return
-     */
-    public Notification createNotification(
-            final NotificationEnum description,
-            final String additional,
-            final String urlReference,
-            final Boolean group){
-        final Notification notification = new Notification();
-        notification.setDescription(description);
-        notification.setAccount(getUserAccountonSecurityContext().getAccount());
-        notification.setAdditionalDescription(additional);
-        notification.setUrlReference(urlReference);
-        notification.setCreated(Calendar.getInstance().getTime());
-        notification.setGroup(group);
-        getNotificationDao().saveOrUpdate(notification);
-        return notification;
-    }
-
-    /**
-     *
-     * @param subscriptionCode
-     * @param subscriptionOption
-     * @return
-     * @throws EnMeExpcetion
-     */
-    public Boolean subscribeEmails(final String subscriptionCode, final String subscriptionOption) throws EnMeExpcetion{
-        Boolean success = false;
-        EmailSubscribe subscribe = getEmailListsDao().getSubscribeAccount(subscriptionCode);
-        if (subscribe!=null){
-            try {
-                   Email emails = new Email();
-                   if(subscriptionOption.equals("subscribe"))
-                   {
-                       emails.setSubscribed(Boolean.TRUE);
-                   }
-                   else {
-                       emails.setSubscribed(Boolean.FALSE);
-                   }
-                   success = Boolean.TRUE;
-                }
-            catch (Exception e) {
-                 throw new EnMeExpcetion(e);
-            }
-            return success;
-        }
-
-        else {
-            throw new EnMeExpcetion("Email Not Found in Subscribe List");
-        }
-     }
-
-    /**
-     * Get Access Token.
-     * @param token
-     * @param tokenSecret
-     * @param pin
-     * @return
-     * @throws TwitterException
-     */
-    @SuppressWarnings("unused")
-    private AccessToken getAccessToken(
-            final Twitter twitter,
-            final String token,
-            final String tokenSecret) throws TwitterException {
-
-            final AccessToken accessToken =  twitter.getOAuthAccessToken(token, tokenSecret);
-            log.info(String.format("Auth Token {%s Token Secret {%s ", accessToken.getToken(), accessToken.getTokenSecret()));
-            twitter.setOAuthAccessToken(accessToken);
-            if (accessToken != null) {
-                    log.info(String.format("Got access token for user %s", accessToken.getScreenName()));
-            }
-            return accessToken;
-    }
-
-
-    /**
-     * Load list of users.
-     * @return list of users with groups and permission
-     * @throws EnMeNoResultsFoundException
-     * @throws EnMeExpcetion excepcion
-     */
-    public List<UserAccountBean> loadListUsers(
-           final String currentUsername,
-           final Integer maxResults,
-           final Integer start) throws EnMeNoResultsFoundException {
-        log.info("currentUsername "+currentUsername);
-        List<UserAccountBean> loadListUsers = new LinkedList<UserAccountBean>();
-        final UserAccount userAccount = this.getUserAccount(currentUsername);
-        if(userAccount != null){
-            final Collection<UserAccount> listUsers = getAccountDao()
-                 .retrieveListOwnerUsers(userAccount.getAccount(), start, maxResults);
-                log.info("list users "+listUsers.size());
-                loadListUsers = ConvertDomainBean.convertCollectionUsersToBean(listUsers);
-        }
-        return loadListUsers;
-    }
-
-    /**
-     * Validate Owner Group.
-     * @param user
-     * @param loggedUserName
-     * @return
-     */
-    private Boolean validateOwnerGroup(final UserAccount user, final String loggedUserName){
-        Boolean validate = Boolean.FALSE;
-        final UserAccount owner = getAccountDao().getUserByUsername(loggedUserName);
-        if(user != null && owner != null){
-            if(user.getAccount().getUid().equals(owner.getAccount().getUid())){
-                validate = Boolean.TRUE;
-            }
-        }
-        log.debug("validateOwnerGroup info "+validate);
-        return validate;
-    }
-
-    /**
-     * Get User Complete Info.
-     * @param currentUsername
-     * @return
-     * @throws EnMeNoResultsFoundException
-     */
-    public UserAccountBean getUserCompleteInfo(final Long userId, final String currentUsername) throws EnMeNoResultsFoundException {
-        UserAccountBean userInfo = null;
-        final UserAccount user = getAccountDao().getUserAccountById(userId);
-        if(this.validateOwnerGroup(user, currentUsername)){
-            userInfo =  ConvertDomainBean.convertSecondaryUserToUserBean(user);
-            log.debug("getUserCompleteInfo info "+userInfo.getId());
-        }
-        return userInfo;
-    }
-
-    /**
-     * Get Validated User.
-     * @param userId
-     * @param currentUsername
-     * @return
-     */
-    public UserAccount getValidateUser(final Long userId, final String currentUsername){
-        final UserAccount user = getAccountDao().getUserAccountById(userId);
-        UserAccount expetedUser = null;
-        if(this.validateOwnerGroup(user, currentUsername)){
-            expetedUser = user;
-        }
-        return expetedUser;
-    }
-
-    /**
-     *
-     * @param account
-     */
-    public void createDirectoryAccount(final Account account){
-        final File file = new File(DirectorySetupOperations.getProfilesDirectory(account.getUid().toString()));
-        if (!file.exists()) {
-            file.mkdirs();
-        }
-    }
-
-    /**
-     * @return the mailServiceOperations
-     */
-    @Autowired
-    public MailServiceOperations getMailService() {
-        return mailService;
-    }
-
-    /**
-     * @param mailServiceOperations the mailServiceOperations to set
-     */
-    public void setMailService(final MailServiceOperations mailServiceOperations) {
-        this.mailService = mailServiceOperations;
-    }
-}

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

-/*
- ************************************************************************************
- * Copyright (C) 2001-2009 encuestame: system online surveys Copyright (C) 2009
- * 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.business.service;
-
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.LinkedList;
-
-import javax.annotation.Resource;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.encuestame.business.security.AbstractSecurityContext;
-import org.encuestame.core.util.ConvertDomainBean;
-import org.encuestame.core.util.ValidationUtils;
-import org.encuestame.persistence.dao.IEmail;
-import org.encuestame.persistence.dao.IGeoPoint;
-import org.encuestame.persistence.dao.IGeoPointTypeDao;
-import org.encuestame.persistence.dao.IClientDao;
-import org.encuestame.persistence.dao.IFrontEndDao;
-import org.encuestame.persistence.dao.IHashTagDao;
-import org.encuestame.persistence.dao.INotification;
-import org.encuestame.persistence.dao.IPoll;
-import org.encuestame.persistence.dao.IProjectDao;
-import org.encuestame.persistence.dao.IQuestionDao;
-import org.encuestame.persistence.dao.IGroupDao;
-import org.encuestame.persistence.dao.IPermissionDao;
-import org.encuestame.persistence.dao.IAccountDao;
-import org.encuestame.persistence.dao.ISurvey;
-import org.encuestame.persistence.dao.ITweetPoll;
-import org.encuestame.persistence.dao.imp.GeoPointTypeDao;
-import org.encuestame.persistence.dao.imp.ClientDao;
-import org.encuestame.persistence.dao.imp.HashTagDao;
-import org.encuestame.persistence.dao.imp.NotificationDao;
-import org.encuestame.persistence.dao.imp.ProjectDaoImp;
-import org.encuestame.persistence.dao.imp.AccountDaoImp;
-import org.encuestame.persistence.domain.GeoPoint;
-import org.encuestame.persistence.domain.HashTag;
-import org.encuestame.persistence.domain.Project;
-import org.encuestame.persistence.domain.security.UserAccount;
-import org.encuestame.persistence.exception.EnMeNoResultsFoundException;
-import org.encuestame.persistence.exception.EnMeExpcetion;
-import org.encuestame.utils.web.UnitProjectBean;
-import org.hibernate.HibernateException;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-/**
- * Abstract Data Services.
- * @author Picado, Juan juan@encuestame.org
- * @since April 27, 2009
- * @version $Id: DataSource.java 478 2010-04-07 03:39:10Z dianmorales $
- */
-@Service
-public abstract class AbstractDataSource extends AbstractSecurityContext{
-
-    /** {@link GeoPoint}. */
-    @Autowired
-    private IGeoPoint geoPointDao;
-    /** {@link GeoPointTypeDao}. */
-    @Autowired
-    private IGeoPointTypeDao geoPointTypeDao;
-    /** {@link ProjectDaoImp}. */
-    @Autowired
-    private IProjectDao projectDaoImp;
-    /** {@link ClientDao}. **/
-    @Autowired
-    private IClientDao clientDao;
-    /** {@link AccountDaoImp}. **/
-    @Autowired
-    private IAccountDao accountDao;
-    /** {@link HashTagDao}. **/
-    @Autowired
-    private IHashTagDao hashTagDao;
-    /*** {@link NotificationDao}. **/
-    @Autowired
-    private INotification notificationDao;
-    /** {@link FrontEndService}. **/
-    @Autowired
-    private IFrontEndDao frontEndDao;
-    /** Log. */
-    private Log log = LogFactory.getLog(this.getClass());
-
-    /** {@link IQuestionDao}**/
-    @Autowired
-    private IQuestionDao questionDao;
-
-    /**{@link IPoll}**/
-    @Autowired
-    private IPoll pollDao;
-
-    @Autowired
-    private ISurvey surveyDaoImp;
-
-    /**{@link ITweetPoll}**/
-    @Autowired
-    private ITweetPoll tweetPollDao;
-
-    /** {@link IGroupDao}. **/
-    @Autowired
-    private IGroupDao groupDao;
-
-    /** {@link IPermissionDao} **/
-    @Autowired
-    private IPermissionDao permissionDao;
-
-   /** {@link IEmail} **/
-    @Autowired
-    private IEmail emailListsDao;
-
-    /**
-     * Get {@link UserAccount} by Username.
-     * @param username username
-     * @return user domain
-     * @throws EnMeNoResultsFoundException exception
-     */
-    public final UserAccount getUserAccount(final String username) throws EnMeNoResultsFoundException {
-        final UserAccount userAccount = getUserAccountonSecurityContext() == null
-              ? getAccountDao().getUserByUsername(username) : getUserAccountonSecurityContext();
-        if(userAccount == null){
-            throw new EnMeNoResultsFoundException(" user not found {"+username+"}");
-        } else {
-            //TODO: we can add others validations, like is disabled, banned or the account is expired.
-            return userAccount;
-        }
-    }
-
-    /**
-     * Get {@link UserAccount} by Id.
-     * @param userId user id
-     * @return {@link UserAccount}.
-     * @throws EnMeNoResultsFoundException
-     */
-   public final UserAccount getUserAccount(final Long userId) throws EnMeNoResultsFoundException {
-        final UserAccount userAccount = getAccountDao().getUserAccountById(userId);
-        if(userAccount == null){
-            throw new EnMeNoResultsFoundException(" user id not found {"+userId+"}");
-        } else {
-            //TODO: we can add others validations, like is disabled, banned or the account is expired.
-            return userAccount;
-        }
-    }
-
-    /**
-     * Get {@link UserAccount} by Id.
-     * @param userId user id.
-     * @return
-     * @see user getUserAccount(id);
-     * @deprecated should be use getUserAccount.
-     */
-    @Deprecated
-    public final UserAccount getUser(final Long  userId){
-        return getAccountDao().getUserAccountById(userId);
-    }
-
-    /**
-     * Find {@link UserAccount} by UserName
-     * @param username user name
-     * @return {@link UserAccount}
-     */
-    public UserAccount findUserByUserName(final String username) {
-        return getAccountDao().getUserByUsername(username);
-    }
-
-    /**
-     * Find {@link UserAccount} by email.
-     * @param email
-     * @return
-     */
-    public UserAccount findUserAccountByEmail(final String email) {
-        return getAccountDao().getUserByEmail(email);
-    }
-
-    /**
-     * Get Primary User Id.
-     * @param username
-     * @return
-     * @throws EnMeNoResultsFoundException exception
-     */
-    public final Long getPrimaryUser(final String username) throws EnMeNoResultsFoundException{
-        return getUserAccount(username).getAccount().getUid();
-     }
-
-    /**
-     * Load List of Project.
-     * @param userId user id.
-     * @return {@link Collection} of {@link UnitProjectBean}
-     * @throws EnMeExpcetion exception
-     */
-    public final Collection<UnitProjectBean> loadListProjects(final Long userId) {
-            final Collection<UnitProjectBean> listProjects = new LinkedList<UnitProjectBean>();
-            final Collection<Project> projectList = getProjectDaoImp().findProjectsByUserID(userId);
-            log.info("project by user id: "+projectList.size());
-            for (Project project : projectList) {
-                log.info("adding project "+project.getProjectDescription());
-                log.info("groups available in this project "+project.getGroups().size());
-                listProjects.add(ConvertDomainBean.convertProjectDomainToBean(project));
-            }
-            log.info("projects loaded: "+ listProjects.size());
-            return listProjects;
-    }
-
-    /**
-     * Load project info.
-     * @param projectBean {@link Project}
-     * @return {@link UnitProjectBean}
-     * @throws EnMeExpcetion excepcion
-     */
-    public UnitProjectBean loadProjectInfo(final UnitProjectBean projectBean) throws EnMeExpcetion {
-        if (projectBean.getId()!= null) {
-            final Project projectDomain = getProjectDaoImp().getProjectbyId(projectBean.getId());
-            if (projectDomain != null) {
-                final UnitProjectBean projectBeanRetrieved = ConvertDomainBean.convertProjectDomainToBean(projectDomain);
-                //projectBeanRetrieved.setGroupList(ConvertListDomainSelectBean.convertListGroupDomainToSelect(projectDomain.getGroups()));
-                return projectBeanRetrieved;
-            } else {
-                log.info("id project is not found");
-                throw new EnMeExpcetion("id project is not found");
-            }
-        } else {
-            log.info("id project is null");
-            throw new EnMeExpcetion("id project is null");
-        }
-    }
-
-    /**
-     * Create Project.
-     * @param projectBean {@link UnitProjectBean}
-     * @return {@link UnitProjectBean}
-     * @throws EnMeExpcetion exception
-     */
-    public final UnitProjectBean createProject(final UnitProjectBean projectBean) throws EnMeExpcetion {
-        log.info("create project");
-        if (projectBean != null) {
-            try {
-                final Project projectDomain = new Project();
-                //projectDomain.setStateProject(getState(projectBean.getState()));
-                projectDomain.setProjectDateFinish(projectBean.getDateFinish());
-                projectDomain.setProjectDateStart(projectBean.getDateInit());
-                projectDomain.setProjectDescription(projectBean.getName());
-                projectDomain.setProjectInfo(projectBean.getDescription());
-                projectDomain.setHideProject(projectBean.getHide());
-                projectDomain.setNotifyMembers(projectBean.getNotify());
-                if(projectBean.getLeader()!=null){
-                    projectDomain.setLead(getAccountDao().getUserAccountById(projectBean.getLeader()));
-                }
-                projectDomain.setUsers(getAccountDao().getUserById(projectBean.getUserId()));
-                getProjectDaoImp().saveOrUpdate(projectDomain);
-                projectBean.setId(projectDomain.getProyectId());
-                log.debug("created domain project");
-            } catch (HibernateException e) {
-                throw new EnMeExpcetion(e);
-            } catch (Exception e) {
-                throw new EnMeExpcetion(e);
-            }
-            return projectBean;
-        } else {
-            throw new EnMeExpcetion("project is null");
-        }
-    }
-
-    /**
-     * Create {@link HashTag}.
-     * @param name tag name
-     * @return {@link HashTag}.
-     */
-    public final HashTag createHashTag(final String name){
-        final HashTag hashTag = new HashTag();
-        hashTag.setHashTag(ValidationUtils.removeNonAlphanumericCharacters(name));
-        hashTag.setHits(1L);
-        hashTag.setSize(12L);
-        hashTag.setUpdatedDate(Calendar.getInstance().getTime());
-        getHashTagDao().saveOrUpdate(hashTag);
-        return hashTag;
-    }
-
-    /**
-     * @return the geoPointDao
-     */
-    public final IGeoPoint getGeoPointDao() {
-        return geoPointDao;
-    }
-
-    /**
-     * @param geoPointDao the geoPointDao to set
-     */
-
-    public final void setGeoPointDao(final IGeoPoint geoPointDao) {
-        this.geoPointDao = geoPointDao;
-    }
-
-    /**
-     * @return the projectDaoImp
-     */
-    public final IProjectDao getProjectDaoImp() {
-        return projectDaoImp;
-    }
-
-    /**
-     * @param projectDaoImp the projectDaoImp to set
-     */
-    public void setProjectDaoImp(final IProjectDao projectDaoImp) {
-        this.projectDaoImp = projectDaoImp;
-    }
-
-    /**
-     * @return the geoPointTypeDao
-     */
-    public final IGeoPointTypeDao getGeoPointTypeDao() {
-        return geoPointTypeDao;
-    }
-
-    /**
-     * @param geoPointTypeDao the geoPointTypeDao to set
-     */
-    public final void setGeoPointTypeDao(final IGeoPointTypeDao geoPointTypeDao) {
-        this.geoPointTypeDao = geoPointTypeDao;
-    }
-
-    /**
-     * @return the clientDao
-     */
-    public final IClientDao getClientDao() {
-        return clientDao;
-    }
-
-    /**
-     * @param clientDao the clientDao to set
-     */
-    public final void setClientDao(final IClientDao clientDao) {
-        this.clientDao = clientDao;
-    }
-
-    /**
-     * @return the accountDao
-     */
-    public final IAccountDao getAccountDao() {
-        return accountDao;
-    }
-
-    /**
-     * @param accountDao the accountDao to set
-     */
-    public final void setAccountDao(final IAccountDao accountDao) {
-        this.accountDao = accountDao;
-    }
-
-    /**
-     * @return the questionDao
-     */
-    public final IQuestionDao getQuestionDao() {
-        return questionDao;
-    }
-
-    /**
-     * @param questionDao the questionDao to set
-     */
-    public final void setQuestionDao(final IQuestionDao questionDao) {
-        this.questionDao = questionDao;
-    }
-
-    /**
-     * @return the pollDao
-     */
-    public final IPoll getPollDao() {
-        return pollDao;
-    }
-
-    /**
-     * @param pollDao the pollDao to set
-     */
-    public final void setPollDao(final IPoll pollDao) {
-        this.pollDao = pollDao;
-    }
-
-    /**
-     * @return the surveyDaoImp
-     */
-    public final ISurvey getSurveyDaoImp() {
-        return surveyDaoImp;
-    }
-
-    /**
-     * @param surveyDaoImp the surveyDaoImp to set
-     */
-    public final void setSurveyDaoImp(final ISurvey surveyDaoImp) {
-        this.surveyDaoImp = surveyDaoImp;
-    }
<