⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addresshelper.java

📁 国外的一套开源CRM
💻 JAVA
字号:
/*
 * 
 * Copyright (c) 2004 SourceTap - www.sourcetap.com
 *
 *  The contents of this file are subject to the SourceTap Public License 
 * ("License"); You may not use this file except in compliance with the 
 * License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
 * Software distributed under the License is distributed on an  "AS IS"  basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 */

package com.sourcetap.sfa.address;

import java.util.HashMap;
import java.util.List;

import org.ofbiz.base.util.Debug;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericPK;
import org.ofbiz.entity.GenericValue;

import com.sourcetap.sfa.util.UserInfo;


/**
 * DOCUMENT ME!
 *
 */
public class AddressHelper {
	public static final String module = AddressHelper.class.getName();

	public static String getMailingAddress( String mailingAddress, String address1, String address2, String address3)
	{
	    String address = "";
	    boolean hasInfo = false;
	    if ( (mailingAddress != null ) && (mailingAddress.length() > 0))
	        return mailingAddress;
	    
	    if ( ( address1 != null ) && ( address1.length() > 0))
	    {
	        hasInfo = true;
	        address = address1;       
	    }
	    
	    if ( ( address2 != null ) && ( address2.length() > 0))
	    {
	        if ( hasInfo )
	            address += "\n";
	        address += address2;
	        hasInfo = true;
	    }

	    if ( ( address3 != null ) && ( address3.length() > 0))
	    {
	        if ( hasInfo )
	            address += "\n";
	        address += address3;
	        hasInfo = true;
	    }
	    
	    return address;
	      
	}
    /**
     * DOCUMENT ME!
     *
     * @param userInfo 
     * @param delegator 
     * @param entityGV 
     * @param relationTitle 
     *
     * @return 
     */
    public static List findRelated(UserInfo userInfo,
        GenericDelegator delegator, GenericValue entityGV, String relationTitle) {
        // Find instances of an entity related to the current entity.

        if (delegator == null) {
            Debug.logError("[findRelated] Delegator is required.", module);

            return null;
        }

        if (entityGV == null) {
            Debug.logError("[findRelated] Entity generic value is required.", module);

            return null;
        }

        String mainEntityName = entityGV.getEntityName();
        String relatedEntityName = "Address";

        // Find related Address records. Need special processing because
        // the relationship cannot be defined in the sfa-config.xml file.
        GenericPK entityPK = null;
        String entityKeyString = null;

        String entityName = entityGV.getEntityName();
        List relatedGVL = null;

        try {

            HashMap findMap = new HashMap();
            String addressOwnerId = "";

            if (mainEntityName.equals("Account")) {
                addressOwnerId = entityGV.getString("accountId");
            } else if (mainEntityName.equals("Contact")) {
                addressOwnerId = entityGV.getString("contactId");
            } else {
                // Error.
                Debug.logError(
                    "[findRelated] Entity name must be 'Account' or 'Contact', " +
                    "but is '" + mainEntityName + "'.", module);

                return null;
            }

            findMap.put("addressOwnerId", addressOwnerId);
            relatedGVL = delegator.findByAnd(relatedEntityName, findMap);
        } catch (GenericEntityException e) {
            Debug.logError("[findRelated] Error getting " + "the related " +
                relatedEntityName + " records: " + e.getLocalizedMessage(), module);

            return null;
        }

        return relatedGVL;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -