SFUserBeanViewer

mail@pastecode.io avatar
unknown
plain_text
a year ago
60 kB
3
Indexable
package com.nsi.storefront.beans;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.nsi.storefront.business.IProduct;
import com.nsi.storefront.business.SFCert;
import com.nsi.storefront.business.SFCodeGuard;
import com.nsi.storefront.business.SFDomain;
import com.nsi.storefront.business.SFDomainBundle;
import com.nsi.storefront.business.SFDomainHosting;
import com.nsi.storefront.business.SFHosting;
import com.nsi.storefront.business.SFPointsToInfo;
import com.nsi.storefront.business.SFProduct;
import com.nsi.storefront.business.SFProductHolder;
import com.nsi.storefront.business.SFSubscriptionProduct;
import com.nsi.storefront.business.SFUserAccountManager;
import com.nsi.storefront.business.utils.SFProductDisplayUtils;
import com.nsi.storefront.business.utils.SFProductUtils;
import com.nsi.storefront.constants.SFAccountChannelConstant;
import com.nsi.storefront.constants.SFAccountTypeConstant;
import com.nsi.storefront.constants.SFClassNameConstant;
import com.nsi.storefront.constants.SFConstant;
import com.nsi.storefront.constants.SFMergeDirectionConstant;
import com.nsi.storefront.constants.SFPackageConstant;
import com.nsi.storefront.constants.SFProductCodeConstant;
import com.nsi.storefront.constants.SFStateConstant;
import com.nsi.storefront.exception.SFFGException;
import com.nsi.storefront.security.SFAccessController;
import com.nsi.storefront.security.SFPermissionRequest;
import com.nsi.storefront.utils.SFArrayUtil;
import com.nsi.storefront.utils.SFESEAccountConstraintChecker;
import com.nsi.storefront.utils.SFLogger;
import com.nsi.storefront.utils.SFRetailAccountConstraintChecker;
import com.nsi.storefront.utils.SFStringUtil;
import com.nsi.storefront.utils.SFSuspendedAccountConstraintChecker;
import com.nsi.storefront.utils.SFUserBeanResolver;
import com.nsi.storefront.utils.SFUtils;
import com.nsi.storefront.xmlschema.logging.types.LogEntryTypeEnum;
import com.nsi.storefront.xmlschema.security.types.ResourceEnum;
import com.nsi.storefront.xmlschema.security.types.RoleEnum;
import com.nsi.storefront.xmlschema.security.types.TaskEnum;
import org.springframework.util.CollectionUtils;

//-------------Copyright(c) 2001 Network Solutions, INC. ------------
/**
 * This class has been created to take out some of the functionality from the
 * SFUserBean. This class is to be used in the web pages (jhtml) to access the
 * SFUserBean. The SFUserBean now should NOT be directly referenced in the jhtml.
 * This class has been created to eliminate the dependancy of the
 * web pages on the SFUserBean. Also some of the properties and methods in the
 * SFUserBean that were only used in the jhtml have been moved to this class.
 *
 * @author  Shahid Masud, McFadyen Consulting
 * @since   August 2001
 * @version 1.0
 * @see     com.nsi.storefront.beans.SFUserBean
 */
//-------------------------------------------------------------------

public class SFUserBeanViewer implements Serializable
{
	/**
	 * SCCS control ID
	 */
	static final String sccsID="%TC-INFO%";
    public static final String MERGE_DIRECTION = "mergeDirection";
    public static final String ACCOUNT_TYPE = "accountType";

	protected SFUserBean user;
    private SFUserAccountManager userAcctManager = null;
    private SFAccessController accessController = null;
    private SFUserBeanResolver userBeanResolver = null;

	public void setUser(SFUserBean user)
	{
		this.user=user;
	}

	public SFUserBean getUser()
	{
		return user;
	}

    public void setUserAccountManager(SFUserAccountManager uam) {
        userAcctManager = uam;
    }

    public void setAccessController(SFAccessController ac) {
        accessController = ac;
    }

	public SFAccountViewer getCurrentAccountViewer()
	{
		return user.getCurrentAccountViewer();
	}

	public List getAccountViewerList()
	{
		return user.getAccountViewerList();
	}

	public String getNicHandle()
	{
		return user.getNicHandleId();
	}
	
	public void setUserBeanResolver(SFUserBeanResolver userBeanResolver)
	{
		this.userBeanResolver = userBeanResolver;
	}

	public SFUserBeanResolver getUserBeanResolver()
	{
		return this.userBeanResolver;
	}

    /**
     * Returns true if user has only one purchasable account.
     */
    public void pullAccount(int acctId) throws SFFGException
    {
            userAcctManager.pullAccount(acctId, user.getUser().getSfCredential());
    }
    /**
     * Returns true if user has only one purchasable account.
     */
    public boolean getHasOnlyOnePuchasableAccount()
    {
        int acctCounter = 0;
        Map accountRel = userAcctManager.getAccountRelations(user.getUser().getUserId());
        List accts = new ArrayList();

        if (accountRel != null) {
            Iterator relations = accountRel.keySet().iterator();
            while (relations.hasNext()) {

                RoleEnum role = (RoleEnum) relations.next();
                List accounts = (List) accountRel.get(role);

                for (int i = 0; i < accounts.size(); i++) {
                    SFAccount acct = (SFAccount) accounts.get(i);

                    if (!accts.contains(acct)) {
                        if (checkPurchasePermission(user.getUser(), acct.getAccountId())) {
                            acctCounter++;
                            accts.add(acct);
                        }
                    }
                    if (acctCounter > 1) {
                        return false;
                    }
                }
            }
        }
        if (acctCounter == 1) {
            return true;
        }
        return false;
    }

	/**
     * Returns true if user has at least one hundred year term in ANY account.
     */
    public boolean getHasAtLeastOneHundredYearTermInAnyAccount()
    {
        Map accountRel = userAcctManager.getAccountRelations(user.getUser().getUserId());
        SFAccountViewer sfacctviewer = new SFAccountViewer();
		SFLogger logger = SFLogger.getInstance();

        if (accountRel != null) {
            Iterator relations = accountRel.keySet().iterator();
            while (relations.hasNext()) {

                RoleEnum role = (RoleEnum) relations.next();
                List accounts = (List) accountRel.get(role);

                logger.logDebug("got to the for loop" + accounts.size());
				for (int i = 0; i < accounts.size(); i++) {
                    SFAccount acct = (SFAccount) accounts.get(i);
					if (acct != null) {
						sfacctviewer.setAccount(acct);
						if (sfacctviewer.getHasAtLeastOneHundredYearTerm() == true)
						{
							return true;
						}
					}
				}
			}
		}
		return false;
	}

    /**
     * Returns the first purchasable account the user has.
     */
    public SFAccount getFirstPurchasableAccount()
    {
        Map accountRel = userAcctManager.getAccountRelations(user.getUser().getUserId());

        SFAccount purchasableAcct = null;
        if (accountRel != null) {
            Iterator relations = accountRel.keySet().iterator();
            while (relations.hasNext()) {

                RoleEnum role = (RoleEnum) relations.next();
                List accounts = (List) accountRel.get(role);

                for (int i = 0; i < accounts.size(); i++) {
                    SFAccount acct = (SFAccount) accounts.get(i);
                    if (checkPurchasePermission(user.getUser(), acct.getAccountId())) {
                        purchasableAcct = acct;
                        break;
                    }
                }
                if (purchasableAcct != null) break;
            }
        }
        return purchasableAcct;
    }

    /**
     * Returns true if user has permission to merge more than two accounts.
     */
    public boolean getHasMoreThanTwoAccountsToMerge()
    {
        return areMergeableAccountNumberAboveGivenLimit(2);
    }

    /**
     * Returns true if user has permission to merge at least two accounts.
     */
    public boolean getHasAccountsToMerge()
    {
        return areMergeableAccountNumberAboveGivenLimit(1);
    }

    /**
     * Returns all accounts that the current user can merge.
     */
    public List getMergeableAccounts()
    {
        Map accountRel = userAcctManager.getAccountRelations(user.getUser().getUserId());

        List mergeAccts = new ArrayList();

        if (accountRel != null) {
            Iterator relations = accountRel.keySet().iterator();
            while (relations.hasNext()) {

                RoleEnum role = (RoleEnum) relations.next();
                List accounts = (List) accountRel.get(role);

                for (int i = 0; i < accounts.size(); i++) {
                    SFAccount acct = (SFAccount) accounts.get(i);

                    if (!mergeAccts.contains(acct)) {
                        if (checkMergePermission(user.getUser(), acct.getAccountId())) {
                            mergeAccts.add(acct);
                        }
                    }
                }
            }
        }
        return mergeAccts;
    }

    /**
     * Returns true if user has more mergeable accounts that the limit
     */
    private boolean areMergeableAccountNumberAboveGivenLimit(int limit)
    {
        int acctCounter = 0;
        Map accountRel = userAcctManager.getAccountRelations(user.getUser().getUserId());
        List mergeAccts = new ArrayList();

        if (accountRel != null) {
            Iterator relations = accountRel.keySet().iterator();
            while (relations.hasNext()) {

                RoleEnum role = (RoleEnum) relations.next();
                List accounts = (List) accountRel.get(role);

                for (int i = 0; i < accounts.size(); i++) {
                    SFAccount acct = (SFAccount) accounts.get(i);

                    if (!mergeAccts.contains(acct)) {
                        if (checkMergePermission(user.getUser(), acct.getAccountId())) {
                            acctCounter++;
                            mergeAccts.add(acct);
                        }
                    }
                    if (acctCounter > limit) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

	/**
	 * Returns the type of the customer session
	 * Possible values are Customer, Vendor and Contact
	 */
	public String getSessionType()
	{
		return user.getSessionType();
	}


	/**
	 * return true if one of the relationshipNames is a wholesaler
	 */
	public boolean getIsWholesaler()
	{
		return user.getUser() instanceof SFWholesaler;
	}

	public void setChallengeQuestion(String challengeQuestion)
	{
		user.setChallengeQuestion(challengeQuestion);
	}

	public String getChallengeQuestion()
	{
		return user.getChallengeQuestion();
	}

	public void setChallengeAnswer(String challengeAnswer)
	{
		user.setChallengeAnswer(challengeAnswer);
	}

	public String getChallengeAnswer()
	{
		return user.getChallengeAnswer();
	}

	public String getDotusUsageIntentDescription()
	{
		return SFNexusCodesViewer.getNexusDescription(user.getDotusUsageIntent());
	}

	public String getDotusUserCategoryDescription()
	{
		return SFNexusCodesViewer.getNexusDescription(user.getDotusUserCategory());
	}

	public SFUserBeanViewer()
	{
	}

    /**
     * This method checks if the current user can purchase into the specified
     * account
     *
     * @param user the logged in user
     * @param acctId the account Id to check
     * @return boolean
     */
    public boolean checkPurchasePermission(SFUser user, int acctId) {

        RoleEnum roleEnum = userAcctManager.getRelation(user.getUserId(),acctId);
        SFAccount account = userAcctManager.getAccount(acctId);

        if (roleEnum == null || account == null) return false;

        SFPermissionRequest permission =
                new SFPermissionRequest(TaskEnum.PURCHASE,
                        roleEnum, ResourceEnum.ALLPRODUCTS);

        Map constraintData = new Hashtable();
        constraintData.put(SFRetailAccountConstraintChecker.ACCOUNT_TYPE,
                account.getAccountChannelType());
        constraintData.put(SFSuspendedAccountConstraintChecker.ACCOUNT_STATUS,
                           new Integer(account.getStatus()));
        constraintData.put(SFESEAccountConstraintChecker.ACCOUNT_TYPE, 
            	account.getAccountChannelType());
        constraintData.put(SFESEAccountConstraintChecker.IS_CSR, 
    			user.isCSRRep());

        if (accessController.checkPermission(permission, constraintData)) {
            return true;
        } else {
            return false;
        }
    }
    
    /**
     * Does the user have permission to modify auto-renew for the given account?
     * 
     * @param acct
     * @return
     */
    public boolean checkAutoRenewPermission(SFAccount acct)
    {
        final String method = "SFUserBeanViewer.checkAutoRenewPermission";
        
        try {
        	if (acct.getAccountChannelType() == SFAccountChannelConstant.WHOLESALE) {
        			return false;
    		}
    		
    		RoleEnum roleEnum = userAcctManager.getRelation(getUser().getUserId(),acct.getAccountId());
            if (roleEnum != null) 
            {
                SFPermissionRequest permission = new SFPermissionRequest(TaskEnum.AUTO_RENEW, roleEnum, ResourceEnum.ALLPRODUCTS);
                Map constraintDataTable = new Hashtable();
        		constraintDataTable.put(SFESEAccountConstraintChecker.ACCOUNT_TYPE, acct.getAccountChannelType());
        		constraintDataTable.put(SFESEAccountConstraintChecker.IS_CSR, getUser().getIsCSRRep());
                if (!accessController.checkPermission(permission, constraintDataTable)) {
                	return false;
                }
            }
        } catch (Exception e) {
            SFLogger.printError(LogEntryTypeEnum.ERROR_MEDIUM_PROGRAM, method + " - exception when checking" +
                    " permission for user " + getUser().getUserId(), e);
            return false;
        }
        
		return true;
    }

    /**
     * This method checks if the current user has permission to merge an account.
     *
     * @param user the logged in user
     * @param acctId the account Id to check
     * @return boolean
     */
    public boolean checkMergePermission(SFUser user, int acctId) {

        RoleEnum roleEnum = userAcctManager.getRelation(user.getUserId(),acctId);
        SFAccount account = userAcctManager.getAccount(acctId);

        if (roleEnum == null || account == null) return false;

        SFPermissionRequest permission =
                new SFPermissionRequest(TaskEnum.MERGE_ACCOUNTS,
                        roleEnum, ResourceEnum.ACCOUNT);

        Map constraintData = new Hashtable();
        constraintData.put(ACCOUNT_TYPE, account.getAccountChannelType());
        constraintData.put(SFSuspendedAccountConstraintChecker.ACCOUNT_STATUS,
						   new Integer(account.getStatus()));
        constraintData.put(MERGE_DIRECTION, SFMergeDirectionConstant.FROM);

        if (accessController.checkPermission(permission, constraintData)) {
            return true;
        } else {
            constraintData.clear();
            constraintData.put(ACCOUNT_TYPE, account.getAccountChannelType());
            constraintData.put(SFSuspendedAccountConstraintChecker.ACCOUNT_STATUS,
						   new Integer(account.getStatus()));
            constraintData.put(MERGE_DIRECTION, SFMergeDirectionConstant.TO);
            if (accessController.checkPermission(permission, constraintData)) {
                return true;
            }
            return false;
        }
    }

    /**
     * This method is checks if domains are all in one account
     *
     * @param user the current logged in user
     * @param domains the domains being checked
     *
     * @return returns true if all doamins are in a same account, false otherwise
     */
    public boolean areDoaminsInOneAccount(SFUser user, String[] domains) {
        SFAccount firstAccount = null;
        for (int i = 0; i < domains.length; i++) {

            SFAccount account = this.userAcctManager.getAccountByDomainName(user.getUserId(), domains[i]);
            if (account != null) {
                if (firstAccount == null) {
                    firstAccount = account;
                } else {
                    if (firstAccount.getAccountId() != account.getAccountId()) {
                        return false;
                    }
                }
            } else {
                return false;
            }
        }

        return true;
    }

    /**
     * This method obtains a unique list of accounts on which the current user has purchase
     * permissions.
     *
     * @return Vector of accounts the user can purchase into
     */
    public List getPurchasableAccts()
    {
	Map accountRel=userAcctManager.getAccountRelations(user.getUser().getUserId());
	List purchasableAccts=new ArrayList();

        if ( accountRel == null )
	    return purchasableAccts;

	Iterator relations= accountRel.keySet().iterator();
	while ( relations.hasNext() )
	{
	    RoleEnum role = (RoleEnum) relations.next();
	    List accounts = (List) accountRel.get(role);

	    for ( int i = 0; i<accounts.size(); i++ )
	    {
		SFAccount acct=(SFAccount)accounts.get(i);

		if ( !purchasableAccts.contains(acct) )
		{
		    if ( checkPurchasePermission(user.getUser(),acct.getAccountId()) )
		    {
			purchasableAccts.add(acct);
		    }
		}
	    }
	}

	return purchasableAccts;
    }

    /**
     * 
     * @return a list of accounts that the user has primary contact on
     */
    public List<SFAccount> getAccountsUnderSamePrimaryContact()
    {
    	return userAcctManager.getAccounts(user.getUserId(), RoleEnum.PRIMARYUSER);
    }
    
    /**
     * This method returns the Current Account if it has
     * purchase permissions.
     *
     * Otherwise it returns null.
     *
     * @return the current Account if it has purchase permissions.
     */
    public SFAccount getPurchasableCurrentAccount()
    {
	SFAccount account = user.getCurrentAccount();
	SFAccount currentAccount = null;
	if (account == null)
	    return null;

	if (checkPurchasePermission(user.getUser(), account.getAccountId()))
	{
	    currentAccount = account;
	}

	return currentAccount;
    }

    /**
     * This method returns true, if the customer has any valid domains (with appriopriate PR supported tld)
     * without a private registration product, in his current account.
     *
     * ALSO, the current account should HAVE purchase permissions.
     *
     * @return a flag that determines if the user has any domains without private registration product.
     */
    public boolean getHasDomainsWithoutPR()
    {
	Map accountRel=userAcctManager.getAccountRelations(user.getUser().getUserId());

	if ( accountRel == null )
	    return false;

	Iterator relations= accountRel.keySet().iterator();
	while ( relations.hasNext() )
	{
	    RoleEnum role = (RoleEnum) relations.next();
	    List accounts = (List) accountRel.get(role);

	    for ( int i = 0; i<accounts.size(); i++ )
	    {
		SFAccount acct=(SFAccount)accounts.get(i);

		if (SFUtils.hasAcceptableDomainProductWithoutPR(acct))
		{
		    return true;
		}

	    }
	}
	return false;
    }
    
    public boolean getHasPRInAccounts()
    {
		Map accountRel=userAcctManager.getAccountRelations(user.getUser().getUserId());
	
		if ( accountRel == null )
		    return false;
	
		Iterator relations= accountRel.keySet().iterator();
		while ( relations.hasNext() )
		{
		    RoleEnum role = (RoleEnum) relations.next();
		    List accounts = (List) accountRel.get(role);
	
		    for ( int i = 0; i<accounts.size(); i++ )
		    {
		    	SFAccount acct = (SFAccount)accounts.get(i);
	
		    	SFProductHolder productHolder = acct.getProductCollection();
		    	
        		if ( productHolder != null )
        		{
			    	List prs = productHolder.getProductByType("com.nsi.storefront.business.SFPrivateRegistration");
			    	if (prs != null && prs.size() > 0)
			    	{
			    		return true;
			    	}
        		}
		    }
		}
		return false;
    }

    /**
     * This method returns true, if the customer has any valid domains 
     * without a EBL product, in his current account.
     *
     * ALSO, the current account should HAVE purchase permissions.
     *
     * @return a flag that determines if the user has any domains without private registration product.
     */
    public boolean getHasDomainsWithoutEBL()
    {
		Map accountRel=userAcctManager.getAccountRelations(user.getUser().getUserId());
	
		if ( accountRel == null )
		    return false;
	
		Iterator relations= accountRel.keySet().iterator();
		while ( relations.hasNext() )
		{
		    RoleEnum role = (RoleEnum) relations.next();
		    List accounts = (List) accountRel.get(role);
	
		    for ( int i = 0; i<accounts.size(); i++ )
		    {
			SFAccount acct=(SFAccount)accounts.get(i);
	
			if (SFUtils.hasAcceptableDomainProductWithoutEBL(acct))
			{
			    return true;
			}
	
		    }
		}
		return false;
    }
    
    /**
     * This method returns true, if the customer has any valid domains 
     * without a DLS product, in his current account.
     *
     * ALSO, the current account should HAVE purchase permissions.
     *
     * @return a flag that determines if the user has any domains without domain listing service product.
     */
    public boolean getHasDomainsWithoutDLS()
    {
		Map accountRel=userAcctManager.getAccountRelations(user.getUser().getUserId());
	
		if ( accountRel == null )
		    return false;
	
		Iterator relations= accountRel.keySet().iterator();
		while ( relations.hasNext() )
		{
		    RoleEnum role = (RoleEnum) relations.next();
		    List accounts = (List) accountRel.get(role);
	
		    for ( int i = 0; i<accounts.size(); i++ )
		    {
			SFAccount acct=(SFAccount)accounts.get(i);
	
			if (SFUtils.hasAcceptableDomainProductWithoutDLS(acct))
			{
			    return true;
			}
	
		    }
		}
		return false;
    }
    
    /**
     * Determine how many domains the user has access to across all accounts.
     * 
     * @return the number of domains the user has access to across all accounts.
     */
    public int getNumberOfDomains()
    {
        int numDomains = 0;
        
        Map accountRel = userAcctManager.getAccountRelations(user.getUser().getUserId());

        if ( accountRel == null )
            return 0;

        Iterator relations = accountRel.keySet().iterator();
        while ( relations.hasNext() )
        {
            RoleEnum role = (RoleEnum) relations.next();
            List accounts = (List) accountRel.get(role);
            
            if (accounts != null) {
                for ( int i = 0; i<accounts.size(); i++ )
                {
                    SFAccount acct = (SFAccount)accounts.get(i);
                
                    SFAccountViewer acctViewer = new SFAccountViewer();
                    acctViewer.setAccount(acct);
                    
                    numDomains += acctViewer.getNumDomains();
                }
            }
        }
        
        return numDomains;
    }

    
    /**
     * This method hadles the checkbox option, deciding whether the user has agreed to the terms.
     * If this is false then the user will get redirected with an appropriate error message.
     */
    public void setAgreedTerms(boolean agreedTerms) 
    {
		SFUserBean tempUser = userBeanResolver.getSFUserBean(); 
        tempUser.setAgreedTerms(agreedTerms);
    }

    public void setAgreeEVSslSubscriberAgreement(boolean agreeEVSslSubscriberAgreement) 
    {
		SFUserBean tempUser = userBeanResolver.getSFUserBean(); 
        tempUser.setAgreeEVSslSubscriberAgreement(agreeEVSslSubscriberAgreement);
    }

    /**
     * This method hadles the checkbox option, deciding whether the user has agreed to the AOLYellowPages terms.
     * If this is false then the user will get redirected with an appropriate error message.Tr# 23555
     */
    public void setAgreedAOLYPTerms(boolean agreedAOLYPTerms) {
		SFUserBean tempUser = userBeanResolver.getSFUserBean();
        tempUser.setPartnerTerms(SFProductCodeConstant.AOL_YP.getDescription(),
                                      new Boolean(agreedAOLYPTerms));
    }
    /**
     * This method hadles the checkbox option, deciding whether the user has agreed to the Roving CC terms.
     * If this is false then the user will get redirected with an appropriate error message.
     * For partner products with only one product using the product code to qualify the service agreement
     * If new products added for the same partner and service agreement URL is same just remove the product code qualifier.
     */
    public void setAgreedRovingCCTerms(boolean agreedRovingCCTerms) 
    {
		SFUserBean tempUser = userBeanResolver.getSFUserBean();
        tempUser.setPartnerTerms(SFProductCodeConstant.ROV_CC.getDescription(),
                                      new Boolean(agreedRovingCCTerms));
    }
    /**
     * This method hadles the checkbox option, deciding whether the user has agreed to the Website Pro VOLterms.
     * If this is false then the user will get redirected with an appropriate error message.
     */
    public void setAgreedWSPVOLTerms(boolean agreedWSPVOLTerms) 
    {
		SFUserBean tempUser = userBeanResolver.getSFUserBean();
        tempUser.setPartnerTerms(SFProductCodeConstant.WSP_VOL.getDescription(),
                                      new Boolean(agreedWSPVOLTerms));
    }
    
    /**
     * This method hadles the checkbox option, deciding whether the user has agreed to the WSP WSD terms.
     * If this is false then the user will get redirected with an appropriate error message.
     * Adding all the codes as all the product codes share the same service agreement and
     * only one checkbox is displayed on payment page
     */
    public void setAgreedWSPWSDTerms(boolean agreedWSPWSDTerms) 
    {
	   	SFUserBean tempUser = userBeanResolver.getSFUserBean();
      	tempUser.setPartnerTerms(SFProductCodeConstant.SDH.getDescription(),
                                     new Boolean(agreedWSPWSDTerms));
      	tempUser.setPartnerTerms(SFProductCodeConstant.ADH.getDescription(),
                                     new Boolean(agreedWSPWSDTerms));
      	tempUser.setPartnerTerms(SFProductCodeConstant.SDV.getDescription(),
                                       new Boolean(agreedWSPWSDTerms));
      	tempUser.setPartnerTerms(SFProductCodeConstant.ADV.getDescription(),
                                      new Boolean(agreedWSPWSDTerms));
    }
    
    /**
     * This method hadles the checkbox option, deciding whether the user has agreed to the Affinity terms.
     * If this is false then the user will get redirected with an appropriate error message.Tr# 23555
     * Adding all the affinity product codes as all the product codes share the same service agreement and
     * only one checkbox is displayed on payment page
     */
    public void setAgreedAffinityTerms(boolean agreedAffinityTerms) 
    {
		SFUserBean tempUser = userBeanResolver.getSFUserBean();
        tempUser.setPartnerTerms(SFProductCodeConstant.VW_SH.getDescription(),
                                      new Boolean(agreedAffinityTerms));
        tempUser.setPartnerTerms(SFProductCodeConstant.VW_CH.getDescription(),
                                      new Boolean(agreedAffinityTerms));
        tempUser.setPartnerTerms(SFProductCodeConstant.VW_MH.getDescription(),
                                      new Boolean(agreedAffinityTerms));
        tempUser.setPartnerTerms(SFProductCodeConstant.VW_PH.getDescription(),
                					  new Boolean(agreedAffinityTerms));
        tempUser.setPartnerTerms(SFProductCodeConstant.BS_STORE.getDescription(),
                                      new Boolean(agreedAffinityTerms));
    }

    /**
     * This method hadles the checkbox option, deciding whether the user has agreed to the Overture terms.
     * If this is false then the user will get redirected with an appropriate error message.
     * Adding all the overture product codes as all the product codes share the same service agreement and
     * only one checkbox is displayed on payment page
     */
    public void setAgreedOvertureTerms(boolean agreedOvertureTerms) 
    {
		SFUserBean tempUser = userBeanResolver.getSFUserBean();
        tempUser.setPartnerTerms(SFProductCodeConstant.OVER_FT.getDescription(),
                                      new Boolean(agreedOvertureTerms));
        tempUser.setPartnerTerms(SFProductCodeConstant.OVER_SS.getDescription(),
                                      new Boolean(agreedOvertureTerms));
    }

    /**
     * This method hadles the checkbox option, deciding whether the user has agreed to the Poistion Tech terms.
     * If this is false then the user will get redirected with an appropriate error message.Tr# 23555
     * Adding all the position tech product codes as all the product codes share the same service agreement and
     * only one checkbox is displayed on payment page
     */
    public void setAgreedPOSTerms(boolean agreedPOSTerms) 
    {
	   	SFUserBean tempUser = userBeanResolver.getSFUserBean();
      	tempUser.setPartnerTerms(SFProductCodeConstant.POS_INK.getDescription(),
                                     new Boolean(agreedPOSTerms));
      	tempUser.setPartnerTerms(SFProductCodeConstant.POS_AJ.getDescription(),
                                     new Boolean(agreedPOSTerms));
      	tempUser.setPartnerTerms(SFProductCodeConstant.POS_DS.getDescription(),
                                       new Boolean(agreedPOSTerms));
      	tempUser.setPartnerTerms(SFProductCodeConstant.POS_FAST.getDescription(),
                                      new Boolean(agreedPOSTerms));
    }

    /**
     * This method will return the boolean agreed terms.
     *
     * @return java.lang.boolean
     */
    public boolean getAgreedTerms() 
    {
		SFUserBean tempUser = userBeanResolver.getSFUserBean();  	
        return tempUser.getAgreedTerms();
    }

    public boolean getAgreeEVSslSubscriberAgreement() 
    {
		SFUserBean tempUser = userBeanResolver.getSFUserBean();  	
        return tempUser.getAgreeEVSslSubscriberAgreement();
    }

    /**
     * This method will return the boolean AOL Yellow Pages agreed terms.Tr# 23555
     *
     * @return java.lang.boolean
     */
    public boolean getAgreedAOLYPTerms() 
    {
	   SFUserBean tempUser = userBeanResolver.getSFUserBean();  	
       return tempUser.getPartnerTerms(SFProductCodeConstant.AOL_YP.getDescription());
    }
    /**
     * This method will return the boolean Roving CC agreed terms.
     * @return java.lang.boolean
     */
    public boolean getAgreedRovingCCTerms() 
    {
	   SFUserBean tempUser = userBeanResolver.getSFUserBean();  	
       return tempUser.getPartnerTerms(SFProductCodeConstant.ROV_CC.getDescription());
    }
    /**
     * This method will return the boolean Website Pro VOL agreed terms.
     * @return java.lang.boolean
     */
    public boolean getAgreedWSPVOLTerms() 
    {
	   SFUserBean tempUser = userBeanResolver.getSFUserBean();
       return tempUser.getPartnerTerms(SFProductCodeConstant.WSP_VOL.getDescription());
    }
    
    /**
     * This method will return the boolean WSP WSD agreed terms.
     *
     * @return java.lang.boolean
     */
    public boolean getAgreedWSPWSDTerms() 
    {
		SFUserBean tempUser = userBeanResolver.getSFUserBean();
        return (tempUser.getPartnerTerms(SFProductCodeConstant.SDH.getDescription()) ||
                tempUser.getPartnerTerms(SFProductCodeConstant.ADH.getDescription()) ||
                tempUser.getPartnerTerms(SFProductCodeConstant.SDV.getDescription()) ||
                tempUser.getPartnerTerms(SFProductCodeConstant.ADV.getDescription())
		);
    }
    
    /**
     * This method will return the boolean Affinity agreed terms.Tr# 23555
     *
     * @return java.lang.boolean
     */
    public boolean getAgreedAffinityTerms() 
    {
    	SFUserBean tempUser = userBeanResolver.getSFUserBean();  	
        return (tempUser.getPartnerTerms(SFProductCodeConstant.VW_SH.getDescription()) ||
                tempUser.getPartnerTerms(SFProductCodeConstant.VW_CH.getDescription()) ||
                tempUser.getPartnerTerms(SFProductCodeConstant.VW_MH.getDescription()) ||
                tempUser.getPartnerTerms(SFProductCodeConstant.VW_PH.getDescription())
		);
     }
    /**
     * This method will return the boolean Position Tech agreed terms.Tr# 23555
     *
     * @return java.lang.boolean
     */
    public boolean getAgreedPOSTerms() 
    {
		SFUserBean tempUser = userBeanResolver.getSFUserBean();
        return (tempUser.getPartnerTerms(SFProductCodeConstant.POS_INK.getDescription()) ||
                tempUser.getPartnerTerms(SFProductCodeConstant.POS_AJ.getDescription()) ||
                tempUser.getPartnerTerms(SFProductCodeConstant.POS_DS.getDescription()) ||
                tempUser.getPartnerTerms(SFProductCodeConstant.POS_FAST.getDescription())
		);
    }
    /**
     * This method will return the boolean Overture agreed terms.
     *
     * @return java.lang.boolean
     */
    public boolean getAgreedOvertureTerms() 
    {
		SFUserBean tempUser = userBeanResolver.getSFUserBean();  	
        return (tempUser.getPartnerTerms(SFProductCodeConstant.OVER_FT.getDescription()) ||
                tempUser.getPartnerTerms(SFProductCodeConstant.OVER_SS.getDescription())
		);
     }

    /**
     * This method will return the boolean Bigstep Store agreed terms.
     * @return java.lang.boolean
     */
    public boolean getAgreedBigstepTerms() 
    {
	   SFUserBean tempUser = userBeanResolver.getSFUserBean();  	
       return tempUser.getPartnerTerms(SFProductCodeConstant.BS_STORE.getDescription());
    }
    
    
    /** 
     * This return the number of accounts the userBean is associated
     * to for small user
     * 
     * @return the number of accounts for small user for large user
     * return -1;
     */
    public int getNumberOfAccounts()
    {
    	// We can only get this number accurately 
    	// for small user
    	if ( !user.getUser().isProductsThresholdExceeded() && 
    	     !user.getUser().isAccountThresholdExceeded() )
    	{
    		List accounts = userAcctManager.getAccounts(user.getUserId());
    		if ( accounts != null )
    		    return accounts.size();  
    		else
    			return 0;
    	}
    	
    	return -1;
    }
    
    
    public boolean getHasDomainsWithoutPrivateReg(int accountId) {
    	Map accountRel = userAcctManager.getPurchasableAccountRelations(user.getUser().getUserId());
    	if(null == accountRel) {
    		return false;
    	}
    	
    	Iterator en = accountRel.keySet().iterator();
    	while(en.hasNext()) {
    		RoleEnum role = (RoleEnum) en.next();
    		List accounts = (List) accountRel.get(role);
    		for(int i=0; i<accounts.size(); i++) {
    			SFAccount account = (SFAccount) accounts.get(i);
    			if(account.getAccountId() == accountId) {
    				if(SFUtils.hasAcceptableDomainProductWithoutPR(account)) {
    					return true;
    				}
    			}
    		}
    	}
    	return false;
    }
    
    public boolean getShouldUpsellPRForCurrentDomain()
    {
    	Map accountRel=userAcctManager.getPurchasableAccountRelations(user.getUser().getUserId());

		if ( accountRel == null )
		    return false;
	
		Iterator relations= accountRel.keySet().iterator();
		String currentDomainName = user.getDomainName();
		while ( relations.hasNext() )
		{
		    RoleEnum role = (RoleEnum) relations.next();
		    List accounts = (List) accountRel.get(role);
	
		    for ( int i = 0; i<accounts.size(); i++ )
		    {
				SFAccount acct=(SFAccount)accounts.get(i);
		
				if (SFUtils.hasAcceptableDomainProductWithoutPR(acct, currentDomainName))
				{
					return true;
				}	
		    }
		}
		return false;
    }
    
    //return a list of account id which has domain without privReg for the user
    public List getAccountsForDomainWithoutPR() {
		List results = new ArrayList();

    	Map accountRel=userAcctManager.getPurchasableAccountRelations(user.getUser().getUserId());

		if ( accountRel != null )
		{
			Iterator relations= accountRel.keySet().iterator();
			while ( relations.hasNext() )
			{
			    RoleEnum role = (RoleEnum) relations.next();
			    List accounts = (List) accountRel.get(role);

			    for ( int i = 0; i<accounts.size(); i++ )
			    {
					SFAccount acct = (SFAccount)accounts.get(i);

					if (SFUtils.hasAcceptableDomainProductWithoutPR(acct))
					{
						results.add(acct.getAccountId());
					}
			    }
			}
		}
		return results;
    }

    //return a list of account id which has domain without privReg for the user
    public List<Integer> getAccountsForDomainWithoutPriReg() {
		return getPurchasableAccountsForDomainWithoutGivenType(SFClassNameConstant.PRIVATE_REGISTRATION_TYPE.getDescription());
    }

    //return a list of account id which has domain without WF for the user
    public List<Integer> getAccountsForDomainWithoutWF() {
		return getPurchasableAccountsForDomainWithoutGivenType(SFClassNameConstant.WEBFORWARDING_TYPE.getDescription());
    }

    //return a list of account id which has domain without WF for the user
    public List<Integer> getAccountsForDomainWithoutDEP() {
		return getPurchasableAccountsForDomainWithoutGivenType(SFClassNameConstant.DOM_EXP_PROTECT_TYPE.getDescription());
    }

    public List<Integer> getPurchasableAccountsForDomainWithoutGivenType(String type) {
        List results = new ArrayList();

        List<SFAccount> purchasableAccounts = getPurchasableAccts();

        if (!CollectionUtils.isEmpty(purchasableAccounts)) {
            for (SFAccount account : purchasableAccounts) {
                if (SFUtils.hasAcceptableDomainProductWithoutGivenType(account, type)) {
                    results.add(account.getAccountId());
                }
            }
        }
        return results;
    }
    
    /**
     * Does the user have ONLY hosted exchange emails - i.e. no other types of email?
     * 
     * @return
     */
    public boolean getHasHostedExchangeEmailOnly()
    {
        boolean result = true;

        List<SFProduct> hostedExchangeProducts = new ArrayList<SFProduct>();
        userAcctManager.findProductsByProductCodeForAllAccounts(SFProductCodeConstant.HOSTED_EXCHANGE, hostedExchangeProducts);
        if (hostedExchangeProducts.isEmpty()){
            return false;
        }
                
        SFProductSummary productSummary = 
            user.getUser().getUserProductProfile().getProductSummary();

        long nonHostedExchangeEmailCount = 0;
        nonHostedExchangeEmailCount += productSummary.getUnconfiguredAlacartePersonalEmailCount();
        nonHostedExchangeEmailCount += productSummary.getUnconfiguredAlacarteBusinessEmailCount();
        nonHostedExchangeEmailCount += productSummary.getUnconfiguredHostingEmailCount();
        nonHostedExchangeEmailCount += productSummary.getUnconfiguredDomainPkgEmailCount();
        nonHostedExchangeEmailCount += productSummary.getUnconfiguredECommerceEmailCount();
        nonHostedExchangeEmailCount += productSummary.getUnconfiguredFreeWebsiteEmailCount();
        nonHostedExchangeEmailCount += productSummary.getUnconfiguredMessageGuardCount();
        nonHostedExchangeEmailCount += productSummary.getUnconfiguredWebSiteEmailCount();
        
        if (nonHostedExchangeEmailCount > 0) {
            return false;
        }
        
        return result;
    }
    
    public boolean getExpiringProductsWithin90Days() 
    {
    	List<SFAccount> accounts = getUser().getUser().getAccounts();
    	
    	for (SFAccount account : accounts) {
    		SFProductHolder pc = account.getProductCollection();
    		List<SFProduct> products = pc.getProductList();
    		for (SFProduct product : products) {
    			if (SFUtils.isExpireIn90Days(product)) {
    				return true;
    			}
    		}
    	}
    	return false;
    }
    
    // return the first domain in user's purchasable accounts
 	public SFDomain getDomainForEmailConfig() {
 		SFDomain prod = new SFDomain();

 		List accounts = this.user.getUser().getAccounts();

 		for (Iterator iter = accounts.iterator(); iter.hasNext();) {
 			SFAccount acct = (SFAccount) iter.next(); 			
 			if (checkPurchasePermission(user.getUser(), acct.getAccountId())) 
 			{ 			
	 			List domainList = acct.getProductCollection().getAllProductByType(SFClassNameConstant.DOMAIN_TYPE.getDescription());	
	 			if (domainList != null && domainList.size() != 0) {
	 				prod = (SFDomain) domainList.get(0);
	 				break;
	 			}
 			}
 		}
 		return prod;
 	}
 	
 	// return the domain name list in user's purchasable accounts
 	public List<String> getDomainNamesForEmailConfig()
 	{
 		List<String> domainNames = new ArrayList<String>();
 		
 		List accounts = this.user.getUser().getAccounts();

 		for (Iterator iter = accounts.iterator(); iter.hasNext();) 
 		{
 			SFAccount acct = (SFAccount) iter.next(); 			
 			if (checkPurchasePermission(user.getUser(), acct.getAccountId())) 
 			{  				
	 			List<SFDomain> domainList = acct.getProductCollection().getAllProductByType(SFClassNameConstant.DOMAIN_TYPE.getDescription());	 			
	 			if (domainList != null && domainList.size() != 0) 
	 			{
	 				for (SFDomain domain : domainList)
	 				{
	 					domainNames.add(domain.getDomainName());
	 				}
	 			}
 			}
 		}
 		return domainNames;
 	}
 	
 	 /**
     * STOREFRONT-3770: Free Trial Private Reg in CTB 
     * 
     * This method returns true, if the customer has any valid domains (with appriopriate PR supported tld)
     * without a private registration product, in his purchasable account.
     *
     */
    public boolean getHasDomainWithoutPRInPurchasableAccounts()
    {
    	Map accountRel=userAcctManager.getPurchasableAccountRelations(user.getUser().getUserId());

		if ( accountRel == null )
		    return false;
	
		Iterator relations= accountRel.keySet().iterator();
		
		while ( relations.hasNext() )
		{
		    RoleEnum role = (RoleEnum) relations.next();
		    List accounts = (List) accountRel.get(role);
	
		    for ( int i = 0; i<accounts.size(); i++ )
		    {
				SFAccount acct=(SFAccount)accounts.get(i);
		
				if (SFUtils.hasAcceptableDomainProductWithoutPR(acct))
				{
					return true;
				}	
		    }
		}
		return false;
    }
    
    
    /**
     * STOREFRONT-3770: Free Trial Private Reg in CTB 
     * 
     * This method returns first purchasable account which has any valid domains (with appriopriate PR supported tld)
     * without a private registration product, in his purchasable account.
     *
     */
    public int getFirstPurchasableAcctIdHasDomainWithoutPR()
    {
    	Map accountRel=userAcctManager.getPurchasableAccountRelations(user.getUser().getUserId());

		if ( accountRel == null )
		    return -1;
	
		Iterator relations= accountRel.keySet().iterator();
		
		while ( relations.hasNext() )
		{
		    RoleEnum role = (RoleEnum) relations.next();
		    List accounts = (List) accountRel.get(role);
	
		    for ( int i = 0; i<accounts.size(); i++ )
		    {
				SFAccount acct=(SFAccount)accounts.get(i);
		
				if (SFUtils.hasAcceptableDomainProductWithoutPR(acct))
				{
					return acct.getAccountId();
				}	
		    }
		}
		
		return -1;
    }
    
    //STOREFRONT-5047: SF AM AD test for TAP, SiteLock, Premium DNS
    public boolean getLauchSiteLockCTB()
    {
    	//show SiteLock IF customer has hosting or a website AND does not have SiteLock 
    	if (user.getIsLoggedIn())
    	{
    		SFProductSummary productSummary = 
    	   			 user.getUser().getUserProductProfile().getProductSummary();
    		
    		long numOfSiteLock = SFUtils.getNumOfProducts(user.getUser(), SFClassNameConstant.SITE_LOCK_TYPE.getDescription(), -1);
    		
    		if (numOfSiteLock == 0 && 
    			(productSummary.getHostingCount() > 0 || 
    			 productSummary.getWebsiteCount() > 0 ||
    			 productSummary.getECommerceCount() > 0 ) )
    		{
    			return true;
    		}
    		
    	}
    	return false;
    }
    
    public boolean getLauchTakeAPaymentCTB()
    {
    	//show Take a Payment UNLESS customer already has TAP or any other ecom product 
    	if (user.getIsLoggedIn())
    	{
    		long numOfEcomm = SFUtils.getNumOfProducts(user.getUser(), SFClassNameConstant.EC_HOSTING_PRODUCT_TYPE.getDescription(), -1);
    		
    		if (numOfEcomm == 0 )
    		{
    			return true;
    		}
    		
    	}
    	return false;
    }
    
    //STOREFRONT-5218 Email Password Change Wizard     
    //WMS rule to launch email password change wizard
    //user has no more than 20 configured email in accounts
    public boolean getLauchPasswordChangeWizard()
    {
    	int count = userAcctManager.getConfiguredEmailProducts().size();
    	
    	return (count > 0 && count <= SFConfig.getInstance().getMaxNumberEmailsForPasswordChangeWizard());
    }
    
    /**
     * Get the list of products that should be shown in the auto-renew overlay.
     * 
     * @return list of SFProducts
     */
    public List<IProduct> getAutoRenewOverlayProducts()
    {
        final String method = "SFUserBeanViewer.getAutoRenewOverlayProducts";
        
        List<SFAccount> accounts = userAcctManager.getAccounts(getUser().getUserId());
        List<IProduct> arProductList = new ArrayList<IProduct>();
        
        try {
            for (SFAccount acct : accounts) {
                if (checkAutoRenewPermission(acct)) {
                    SFProductHolder ph = acct.getProductCollection();
                    List<SFProduct> pc = ph.getProductList();
                    for (SFProduct product : pc) {
                        // Only consider renewable products
                        if (!(product instanceof SFDomainHosting) && product.getIsRenewable()) {
                            // Only consider subscription-based products
                            if (product instanceof SFSubscriptionProduct) {
                                SFSubscriptionProduct sproduct = (SFSubscriptionProduct) product;
                                if (!sproduct.getAutoRenewal()) {                                    
                                    if (product instanceof SFDomain){
                                    	// block auto renew if domain is on legal lock
                                        if( ((SFDomain)product).getLegalLockIndicator() != null &&
                                           ((SFDomain)product).getLegalLockIndicator().equalsIgnoreCase("Y"))  {
                                                continue;
                                        }
                                        
                                        // block auto renew if domain is on weblock
                                        if (product instanceof SFDomain &&
                                                (SFProductUtils.isWebLockActive( ((SFDomain)product).getWebLockIndicator()) ))  {
                                            continue;
                                        }
                                    }
                                    
                                    if ( product instanceof SFDomainBundle )
                                        continue;
                                    
                                    if (SFProductUtils.isProductAssociatedToBundle(product)) {
                                        continue;
                                    }
                                    
                                    // Some products can't be auto-renewed (most certs, DEP)
                                    if (!SFProductUtils.isPreventAutoRenewForProduct(product.getProductCode())) {
                                        arProductList.add(product);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            SFLogger.printError(LogEntryTypeEnum.ERROR_MEDIUM_PROGRAM, method + " - exception when processing" +
                    " accounts/products for user " + getUser().getUserId(), e);
            // Treating this as a non-blocking error.
        }
        
        return arProductList;
    }
    
    /**
     * Should we launch the auto renew overlay?
     * 
     * @return true/false
     */
    public boolean getLaunchAutoRenewOverlay()
    {
		List<IProduct> arProductList = getAutoRenewOverlayProducts();
		return arProductList == null || arProductList.isEmpty() ? false : true;
    }
    
    public boolean getLaunchDentalOverlay()
    {
		if (!this.user.getUser().getDontShowDental())
		{
			//check if user has any domain name or company name match config list
			 List<SFAccount> accounts = userAcctManager.getAccounts(getUser().getUserId());
			 String[] dentalKeywords = SFConfig.getInstance().getDentalPopUpKeywords();
			 
			 List<SFDomain> domainList = null;

		  	for (Iterator iter = accounts.iterator(); iter.hasNext();) 
		  	{
		  		SFAccount acct = (SFAccount) iter.next(); 		
		  		//check if company name match config keywords
		  		if (acct.getAccountType() == SFAccountTypeConstant.BUSINESS)
		  		{
		  			if (acct.getAccountHolder() != null && acct.getAccountHolder().getCompanyName() != null)
		  			{
		  				String companyName = acct.getAccountHolder().getCompanyName();
		  				for (int i=0; i<dentalKeywords.length; i++)
		  				{
		  					if (companyName.toLowerCase().contains(dentalKeywords[i].toLowerCase()))
		  					{
		  						return true;
		  					}
		  				}
		  			}
		  		}
		  		//check if any domain name match config keywords
		 		domainList = acct.getProductCollection().getAllProductByType(SFClassNameConstant.DOMAIN_TYPE.getDescription());
		 		if (domainList != null && domainList.size() != 0) 
		 		{
	 				for (SFProduct product : domainList) 
	 				{
	 					SFDomain domain = (SFDomain )product;
	 					for (int i=0; i<dentalKeywords.length; i++)
		  				{
		  					if (domain.getDomainName().toLowerCase().contains(dentalKeywords[i].toLowerCase()))
		  					{
		  						return true;
		  					}
		  				}
	 				}
		 		}		 		
		  	}
			 
		}
		return false;
    }
    
    // return the first live domain in user's purchasable accounts
  	public SFDomain getFirstLiveDomain() {
  		List accounts = this.user.getUser().getAccounts();
  		List<SFDomain> domainList = null;

  		for (Iterator iter = accounts.iterator(); iter.hasNext();) {
  			SFAccount acct = (SFAccount) iter.next(); 			
  						
 			domainList = acct.getProductCollection().getAllProductByType(SFClassNameConstant.DOMAIN_TYPE.getDescription());	
 			if (domainList != null && domainList.size() != 0) {
 				for (SFProduct product : domainList) {
 					SFDomain domain = (SFDomain )product;
 					SFPointsToInfo pointsToInfo = domain.getPointsToInfo();
 					if(pointsToInfo != null && (!pointsToInfo.getHostingType().equals(SFPointsToInfo.HostingType.UNDER_CONSTRUCTION) && 
							!pointsToInfo.getHostingType().equals(SFPointsToInfo.HostingType.POINTS_TO_BIZ_PROFILE))) {
 						return domain;
 					}
 				}
 			}
  		}
  		
  		// if no live domain found, return the first one for now
  		if (domainList != null && !domainList.isEmpty()) {
  			return domainList.get(0);
  		}
  		return null;
  	}
  	
  	public boolean getIsUSOrCANCustomer() 
  	{
  		String country = getUser().getUser().getCountry();
		if (country != null && (country.equalsIgnoreCase("US") || country.equalsIgnoreCase("CA")) ) {
			return true;
		}
		
  		return false;
  	}
  	
  	public SFProduct getLastPurchasedProduct() {
  		SFProduct lastProduct = new SFProduct();
  		
  		Date lastPurchasedDate = null;
  		
    	Map accountRel = userAcctManager.getPurchasableAccountRelations(user.getUser().getUserId());
    	if(null == accountRel) {
    		return lastProduct;
    	}
    	
    	Iterator en = accountRel.keySet().iterator();
    	while(en.hasNext()) {
    		RoleEnum role = (RoleEnum) en.next();
    		List accounts = (List) accountRel.get(role);
    		for(int i=0; i<accounts.size(); i++) {
    			SFAccount account = (SFAccount) accounts.get(i);
    			List<SFProduct> products = account.getProductCollection().getProductList();
    			for (SFProduct product : products) {
    				Date purchaseDate = product.getPurchaseDate();
    				if (lastPurchasedDate == null || (purchaseDate != null && lastPurchasedDate != null && lastPurchasedDate.before(purchaseDate)))
    				{
    					lastPurchasedDate = purchaseDate;
    					lastProduct = product;
    				}			
    			}
    		}
    	}
    	return lastProduct;
    }
    
  	//return a String for all purchased products in format "ProductCode:Number,ProductCode:Number" 
  	public String getAllPurchasedProducts() 
  	{
  		String productList = "";
  		Map<String, Integer> prodMap = new Hashtable<String, Integer>();  		
  		
    	Map accountRel = userAcctManager.getPurchasableAccountRelations(user.getUser().getUserId());
    	if(null == accountRel) 
    	{
    		return productList;
    	}
    	
    	//populate prodMap
    	Iterator en = accountRel.keySet().iterator();
    	while(en.hasNext()) {
    		RoleEnum role = (RoleEnum) en.next();
    		List accounts = (List) accountRel.get(role);
    		for(int i=0; i<accounts.size(); i++) 
    		{
    			SFAccount account = (SFAccount) accounts.get(i);
    			List<SFProduct> products = account.getProductCollection().getProductList();
    			for (SFProduct product : products) 
    			{    				
    				int prodCount = 1;
    				String prodCode = product.getProductCode();
    				
    				if (prodMap.containsKey(prodCode))
    				{
    					prodCount = prodCount + (prodMap.get(prodCode)).intValue();    					
    				}
    				prodMap.put(prodCode, new Integer(prodCount));
    			}
    		}
    	}
    	
    	//output prodMap as String
    	for (Map.Entry<String, Integer> entry : prodMap.entrySet()) 
    	{
    	    if (productList.isEmpty())
    	    {
    	    	productList = entry.getKey() + ":" + entry.getValue().toString();
    	    }
    	    else
    	    {
    	    	productList = "," + entry.getKey() + ":" + entry.getValue().toString();
    	    }
    	}
    	return productList;
    }
  	
  	//get a list of hosting prodInstId which has codeGuard associated
  	public String[] getHostingProdInstIdsWithCodeGuard()
    {
    	return user.getHostingProdInstIdsWithCodeGuard();
    }	

  	//check if user has codeGuard product
  	public boolean getHasCodeGuard() 
  	{
  		return userAcctManager.getHasCodeGuard();		 
  	}
		
  	//get a list of hosting product which is eligible for codeGuard upsell
  	public List<String> getHostingProdWithoutCodeGuard()
    {
    	List<String> result = new ArrayList<String>();
    	
    	List<SFAccount> accounts = this.userAcctManager.getAccounts(getUser().getUserId());
        
    	if (accounts != null) {
            for (SFAccount account : accounts) {            	
            	
            	List<SFHosting> hostingList = account.getProductCollection().getAllProductByType("com.nsi.storefront.business.SFHosting");
                 	
            	if (hostingList != null && hostingList.size() > 0) {
                    for (SFHosting hosting : hostingList) {
                    	if (! hosting.getHasCodeGuardAssociated() &&
                    		( hosting.getProductCode().equalsIgnoreCase(SFProductCodeConstant.HP_PKG_B_UNX.getDescription()) ||
                    			hosting.getProductCode().equalsIgnoreCase(SFProductCodeConstant.HP_PKG_L_UNX.getDescription()) ||
                    			hosting.getProductCode().equalsIgnoreCase(SFProductCodeConstant.HP_PKG_L_WIN.getDescription()) ||
                    			hosting.getProductCode().equalsIgnoreCase(SFProductCodeConstant.HP_PKG_START_UNX.getDescription()) ||
                    			hosting.getProductCode().equalsIgnoreCase(SFProductCodeConstant.HP_PKG_START_WIN.getDescription()) ||
                    			hosting.getProductCode().equalsIgnoreCase(SFProductCodeConstant.HP_PKG_S_UNX.getDescription()) ||
                    			hosting.getProductCode().equalsIgnoreCase(SFProductCodeConstant.HP_PKG_S_WIN.getDescription()) ||
                    			hosting.getProductCode().equalsIgnoreCase(SFProductCodeConstant.HP_PKG_A_UNX.getDescription()) ||
                    			hosting.getProductCode().equalsIgnoreCase(SFProductCodeConstant.HP_PKG_A_WIN.getDescription()) ||
                    			hosting.getProductCode().equalsIgnoreCase(SFProductCodeConstant.HP_PKG_P_UNX.getDescription()) ||
                    			hosting.getProductCode().equalsIgnoreCase(SFProductCodeConstant.HP_PKG_P_WIN.getDescription()) ||
                    			hosting.getProductCode().equalsIgnoreCase(SFProductCodeConstant.HP_PKG_E_UNX.getDescription()) ||
                    			hosting.getProductCode().equalsIgnoreCase(SFProductCodeConstant.HP_PKG_E_WIN.getDescription()) ||
                    			hosting.getProductCode().equalsIgnoreCase(SFProductCodeConstant.HP_PKG_M_UNX.getDescription()) ||
                    			hosting.getProductCode().equalsIgnoreCase(SFProductCodeConstant.HP_PKG_M_WIN.getDescription()) ||
                    			hosting.getProductCode().equalsIgnoreCase(SFProductCodeConstant.HP_PKG_WP.getDescription()) ||
                    			hosting.getProductCode().equalsIgnoreCase(SFProductCodeConstant.HP_PKG_WP_E.getDescription()) ||
                    			hosting.getProductCode().equalsIgnoreCase(SFProductCodeConstant.HP_PKG_WP_GB.getDescription()) ||
                    			hosting.getProductCode().equalsIgnoreCase(SFProductCodeConstant.HP_PKG_WP_P.getDescription())) ||
                                hosting.getProductCode().equalsIgnoreCase(SFProductCodeConstant.HP_PKG_WP_ENT_V2.getDescription()) ||
                                hosting.getProductCode().equalsIgnoreCase(SFProductCodeConstant.HP_PKG_WP_BIZ_V2.getDescription()) ||
                                hosting.getProductCode().equalsIgnoreCase(SFProductCodeConstant.HP_PKG_WP_PRO_V2.getDescription()))
                    	{
                    		result.add(hosting.getInstanceName() + " - " + hosting.getDescription() + "|" 
                    					+ hosting.getFGImplementationDetailInfo().getFGProductInstanceId() + "|"
                    					+ account.getAccountId());
                    	}
                    }
            	}
            }
        }  	
    	return result;
    }	
  	
  	//SOFT-26745  - get a list of SSL DV products which allow domain configuration
  	public List<String> getUnconfiguredSslDv()
    {
    	List<String> result = new ArrayList<String>();
    	
    	List<SFAccount> accounts = this.userAcctManager.getAccounts(getUser().getUserId());
        
    	if (accounts != null) {
            for (SFAccount account : accounts) {            	
            	
            	List<SFCert> certList = account.getProductCollection().getAllProductByType("com.nsi.storefront.business.SFCert");
                 	
            	if (certList != null && certList.size() > 0) {
                    for (SFCert cert : certList) {
                    	if (cert.allowDomainConfiguration() &&
                    		 cert.getProductCode().equalsIgnoreCase(SFProductCodeConstant.SSL_DV.getDescription())  )
                    	{
                    			result.add(cert.getDisplayNameWithSecurityInstanceId() + "|" 
	                    					+ cert.getFGImplementationDetailInfo().getFGProductInstanceId() );
                    	}
                    }
            	}
            }
        }  	
    	return result;
    }	  	
}