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

📄 codehelper.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.code;

import java.util.ArrayList;
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.GenericValue;


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

    /**
     * This function gets the code value for a given code type and code ID
     * @author  John Nutting
     * @param codeTypeId Code Type ID
     * @param codeId Code ID
     * @param delegator Generic delegator for accessing the database
     * @return Code value
     */
    public static String getCodeValue(String codeTypeId, String codeId,
        GenericDelegator delegator) {
        if (codeTypeId == null) {
            Debug.logWarning("Code Type ID is required", module);

            return "";
        }

        if (codeId == null) {
            Debug.logWarning("Code ID is required", module);

            return "";
        }

        HashMap codeFindMap = new HashMap();
        codeFindMap.put("codeTypeId", codeTypeId);
        codeFindMap.put("codeId", codeId);

        try {
            GenericValue codeGV = delegator.findByPrimaryKey("Code", codeFindMap);

            if (codeGV == null) {
                Debug.logWarning("Code not found for code type ID " +
                    codeTypeId + " and code ID " + codeId, module);

                return "";
            }

            String codeValue = (codeGV.getString("codeValue") == null) ? ""
                                                                       : codeGV.getString(
                    "codeValue");

            return codeValue;
        } catch (Exception e) {
            Debug.logError("Error retrieving code for " + codeTypeId + "/" +
                codeId + ": " + e.getLocalizedMessage(), module);
        }

        return "";
    }

    /**
     * This function gets the codes for a given code type
     * @author  John Nutting
     * @param codeTypeId Code Type ID
     * @param delegator Generic delegator for accessing the database
     * @return List of code generic values
     */
    public static List getCodeGVL(String codeTypeId, GenericDelegator delegator) {
        if (codeTypeId == null) {
            Debug.logWarning("Code Type ID is required", module);

            return null;
        }

        // Set default sort order.
        ArrayList sort = new ArrayList();
        sort.add("codeValue");

        return getCodeGVL(codeTypeId, delegator, sort);
    }

    /**
     * This function gets the codes for a given code type
     * @author  John Nutting
     * @param codeTypeId Code Type ID
     * @param delegator Generic delegator for accessing the database
     * @param sort Sort order
     * @return List of code generic values
     */
    public static List getCodeGVL(String codeTypeId,
        GenericDelegator delegator, ArrayList sort) {
        if (codeTypeId == null) {
            Debug.logWarning("Code Type ID is required", module);

            return null;
        }

        HashMap codeFindMap = new HashMap();
        codeFindMap.put("codeTypeId", codeTypeId);

        try {
            return delegator.findByAnd("Code", codeFindMap, sort);
        } catch (GenericEntityException e) {
            Debug.logWarning("Error retrieving codes for code type " +
                codeTypeId + ": " + e.getLocalizedMessage(), module);
        }

        return null;
    }
}

⌨️ 快捷键说明

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