com.aimluck.eip.gpdb.util.GpdbUtils.java Source code

Java tutorial

Introduction

Here is the source code for com.aimluck.eip.gpdb.util.GpdbUtils.java

Source

/*
 * Aipo is a groupware program developed by Aimluck,Inc.
 * Copyright (C) 2004-2015 Aimluck,Inc.
 * http://www.aipo.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.aimluck.eip.gpdb.util;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.imageio.ImageIO;

import org.apache.cayenne.DataRow;
import org.apache.cayenne.PersistenceState;
import org.apache.cayenne.access.DataContext;
import org.apache.cayenne.exp.Expression;
import org.apache.cayenne.exp.ExpressionFactory;
import org.apache.commons.lang.StringUtils;
import org.apache.jetspeed.om.security.UserIdPrincipal;
import org.apache.jetspeed.portal.PortletConfig;
import org.apache.jetspeed.portal.portlets.VelocityPortlet;
import org.apache.jetspeed.services.JetspeedSecurity;
import org.apache.jetspeed.services.customlocalization.CustomLocalizationService;
import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
import org.apache.jetspeed.services.logging.JetspeedLogger;
import org.apache.jetspeed.services.resources.JetspeedResources;
import org.apache.jetspeed.util.ServiceUtil;
import org.apache.turbine.services.localization.LocalizationService;
import org.apache.turbine.util.RunData;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.context.Context;

import com.aimluck.eip.cayenne.om.portlet.EipMGpdbKubun;
import com.aimluck.eip.cayenne.om.portlet.EipMGpdbKubunValue;
import com.aimluck.eip.cayenne.om.portlet.EipTGpdb;
import com.aimluck.eip.cayenne.om.portlet.EipTGpdbItem;
import com.aimluck.eip.cayenne.om.portlet.EipTGpdbRecord;
import com.aimluck.eip.cayenne.om.portlet.EipTGpdbRecordFile;
import com.aimluck.eip.cayenne.om.security.TurbineUser;
import com.aimluck.eip.common.ALBaseUser;
import com.aimluck.eip.common.ALDBErrorException;
import com.aimluck.eip.common.ALEipConstants;
import com.aimluck.eip.common.ALEipUser;
import com.aimluck.eip.common.ALPageNotFoundException;
import com.aimluck.eip.fileupload.beans.FileuploadBean;
import com.aimluck.eip.fileupload.beans.FileuploadLiteBean;
import com.aimluck.eip.fileupload.util.FileuploadUtils;
import com.aimluck.eip.fileupload.util.FileuploadUtils.ShrinkImageSet;
import com.aimluck.eip.gpdb.GpdbItemResultData;
import com.aimluck.eip.gpdb.GpdbKubunResultData;
import com.aimluck.eip.gpdb.GpdbKubunValueResultData;
import com.aimluck.eip.gpdb.GpdbRecordResultData;
import com.aimluck.eip.gpdb.GpdbResultData;
import com.aimluck.eip.mail.ALAdminMailContext;
import com.aimluck.eip.mail.ALAdminMailMessage;
import com.aimluck.eip.mail.ALMailService;
import com.aimluck.eip.mail.util.ALEipUserAddr;
import com.aimluck.eip.mail.util.ALMailUtils;
import com.aimluck.eip.orm.Database;
import com.aimluck.eip.orm.query.SQLTemplate;
import com.aimluck.eip.orm.query.SelectQuery;
import com.aimluck.eip.services.orgutils.ALOrgUtilsService;
import com.aimluck.eip.services.storage.ALStorageService;
import com.aimluck.eip.util.ALEipUtils;
import com.aimluck.eip.util.ALLocalizationUtils;

/**
 * Web???
 * 
 */
public class GpdbUtils {

    /** logger */
    private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(GpdbUtils.class.getName());

    /** ?? */
    public static final String ITEM_NAME_DEFAULT = "";

    /** ? */
    public static final String ITEM_TYPE_TEXT = "01";

    /** ? */
    public static final String ITEM_TYPE_TEXTAREA = "02";

    /** ? */
    public static final String ITEM_TYPE_LINK = "03";

    /** ??? */
    public static final String ITEM_TYPE_SELECT = "04";

    /** ??? */
    public static final String ITEM_TYPE_SELECT_MULTI = "05";

    /** ? */
    public static final String ITEM_TYPE_FILE = "06";

    /** ?? */
    public static final String ITEM_TYPE_IMAGE = "07";

    /** ? */
    public static final String ITEM_TYPE_SEQ = "08";

    /** ? */
    public static final String ITEM_TYPE_MAIL = "09";

    /** ? */
    public static final String ITEM_TYPE_DATE = "10";

    /** ?? */
    public static final String ITEM_TYPE_CREATE_DATE = "11";

    /** ? */
    public static final String ITEM_TYPE_UPDATE_DATE = "12";

    /** ? */
    public static final String ITEM_TYPE_CREATE_USER = "13";

    /** ? */
    public static final String ITEM_TYPE_UPDATE_USER = "14";

    /** ??? */
    public static final String ITEM_TYPE_TITLE_TEXT = "";

    /** ??? */
    public static final String ITEM_TYPE_TITLE_TEXTAREA = "";

    /** ??? */
    public static final String ITEM_TYPE_TITLE_LINK = "";

    /** ????? */
    public static final String ITEM_TYPE_TITLE_SELECT = "??";

    /** ????? */
    public static final String ITEM_TYPE_TITLE_SELECT_MULTI = "??";

    /** ??? */
    public static final String ITEM_TYPE_TITLE_FILE = "";

    /** ???? */
    public static final String ITEM_TYPE_TITLE_IMAGE = "?";

    /** ??? */
    public static final String ITEM_TYPE_TITLE_SEQ = "";

    /** ??? */
    public static final String ITEM_TYPE_TITLE_MAIL = "";

    /** ??? */
    public static final String ITEM_TYPE_TITLE_DATE = "";

    /** ???? */
    public static final String ITEM_TYPE_TITLE_CREATE_DATE = "?";

    /** ??? */
    public static final String ITEM_TYPE_TITLE_UPDATE_DATE = "";

    /** ??? */
    public static final String ITEM_TYPE_TITLE_CREATE_USER = "";

    /** ??? */
    public static final String ITEM_TYPE_TITLE_UPDATE_USER = "";

    /** ?? */
    public static final String ERRMSG_TITLE_ITEM_DELETE = "????????";

    /** ??DB?? */
    public static final String ERRMSG_DB_DELETE = "????????????";

    /** ? */
    public static final String SORT_STRING = "sort";

    /** ?? */
    @SuppressWarnings("serial")
    public static final Map<String, String> ITEM_TYPE = Collections
            .unmodifiableMap(new LinkedHashMap<String, String>() {
                {
                    // ??????
                    put(ITEM_TYPE_TEXT, ITEM_TYPE_TITLE_TEXT); // 
                    put(ITEM_TYPE_TEXTAREA, ITEM_TYPE_TITLE_TEXTAREA); // 
                    put(ITEM_TYPE_LINK, ITEM_TYPE_TITLE_LINK); // 
                    put(ITEM_TYPE_SELECT, ITEM_TYPE_TITLE_SELECT); // ??
                    put(ITEM_TYPE_SELECT_MULTI, ITEM_TYPE_TITLE_SELECT_MULTI); // ??
                    put(ITEM_TYPE_FILE, ITEM_TYPE_TITLE_FILE); // 
                    put(ITEM_TYPE_IMAGE, ITEM_TYPE_TITLE_IMAGE); // ?
                    put(ITEM_TYPE_SEQ, ITEM_TYPE_TITLE_SEQ); // 
                    put(ITEM_TYPE_MAIL, ITEM_TYPE_TITLE_MAIL); // 
                    put(ITEM_TYPE_DATE, ITEM_TYPE_TITLE_DATE); // 
                    put(ITEM_TYPE_CREATE_USER, ITEM_TYPE_TITLE_CREATE_USER); // 
                    put(ITEM_TYPE_UPDATE_USER, ITEM_TYPE_TITLE_UPDATE_USER); // 
                    put(ITEM_TYPE_CREATE_DATE, ITEM_TYPE_TITLE_CREATE_DATE); // ?
                    put(ITEM_TYPE_UPDATE_DATE, ITEM_TYPE_TITLE_UPDATE_DATE); // 
                }
            });

    /** ????? */
    @SuppressWarnings("serial")
    public static final List<String> DISP_FIELD_SELECT_ITEM = Collections.unmodifiableList(new ArrayList<String>() {
        {
            add(ITEM_TYPE_SELECT); // ??
            add(ITEM_TYPE_SELECT_MULTI); // ??
        }
    });

    /** ?? */
    @SuppressWarnings("serial")
    public static final List<String> DISP_FIELD_SIZE_COL = Collections.unmodifiableList(new ArrayList<String>() {
        {
            add(ITEM_TYPE_TEXT); // 
            add(ITEM_TYPE_TEXTAREA); // 
            add(ITEM_TYPE_LINK); // 
            add(ITEM_TYPE_MAIL); // 
        }
    });

    /** ?? */
    @SuppressWarnings("serial")
    public static final List<String> DISP_FIELD_SIZE_ROW = Collections.unmodifiableList(new ArrayList<String>() {
        {
            add(ITEM_TYPE_TEXTAREA); // 
        }
    });

    /** ?? */
    @SuppressWarnings("serial")
    public static final List<String> DISP_FIELD_LINE = Collections.unmodifiableList(new ArrayList<String>() {
        {
            add(ITEM_TYPE_SELECT_MULTI); // ??
        }
    });

    /** ?? */
    @SuppressWarnings("serial")
    public static final List<String> DISP_FIELD_REQUIRED = Collections.unmodifiableList(new ArrayList<String>() {
        {
            add(ITEM_TYPE_TEXT); // 
            add(ITEM_TYPE_TEXTAREA); // 
            add(ITEM_TYPE_LINK); // 
            add(ITEM_TYPE_SELECT); // ??
            add(ITEM_TYPE_SELECT_MULTI); // ??
            add(ITEM_TYPE_FILE); // 
            add(ITEM_TYPE_IMAGE); // ?
            add(ITEM_TYPE_MAIL); // 
            add(ITEM_TYPE_DATE); // 
        }
    });

    /** ?? */
    @SuppressWarnings("serial")
    public static final Map<String, List<String>> ITEM_FIELD = Collections
            .unmodifiableMap(new TreeMap<String, List<String>>() {
                {
                    put("select_kubun", DISP_FIELD_SELECT_ITEM); // ???
                    put("size_col", DISP_FIELD_SIZE_COL); // 
                    put("size_row", DISP_FIELD_SIZE_ROW); // 
                    put("line", DISP_FIELD_LINE); // 
                    put("required", DISP_FIELD_REQUIRED); // 
                }
            });

    /** ON */
    public static final String FLG_ON = "t";

    /** OFF */
    public static final String FLG_OFF = "f";

    /**  */
    public static final int SIZE_COL_DEFAULT = 300;

    /** ??? */
    public static final String KUBUN_VALUE_SEPARATOR = "|";

    /** ?? */
    public static final String KUBUN_VALUE_DISP_SEPARATOR = "?";

    /** ??? */
    private static final String FOLDER_FILEDIR_GPDB = JetspeedResources.getString("aipo.filedir", "");

    /** ???? */
    protected static final String CATEGORY_KEY = JetspeedResources.getString("aipo.gpdb.categorykey", "");;

    /** ??? */
    public static final String FILE_ENCODING = JetspeedResources.getString("content.defaultencoding", "UTF-8");

    /** ??? */
    public static final String GPDB_PORTLET_NAME = "Gpdb";

    // ---------------------------------------------------
    // ?
    // ---------------------------------------------------

    /**
     * ????
     * 
     * @param type
     *          ?
     * @return ???
     */
    public static String getItemTypeName(String type) {
        return ITEM_TYPE.get(type);
    }

    // ---------------------------------------------------
    // Web?
    // ---------------------------------------------------

    /**
     * Web ????
     * 
     * @param rundata
     *          RunData
     * @param context
     *          Context
     * @return Web
     */
    public static EipTGpdb getEipTGpdb(RunData rundata, Context context) {
        String gpdbid = ALEipUtils.getTemp(rundata, context, ALEipConstants.ENTITY_ID);
        return getEipTGpdb(gpdbid);
    }

    /**
     * Web????
     * 
     * @param gpdbId
     *          WebID
     * @return Web 
     */
    public static EipTGpdb getEipTGpdb(String gpdbId) {

        try {
            if (gpdbId == null || Integer.valueOf(gpdbId) == null) {
                // Request ID???
                logger.debug("[GpdbUtils] Empty ID...");
                return null;
            }

            SelectQuery<EipTGpdb> query = Database.query(EipTGpdb.class);
            query.setQualifier(ExpressionFactory.matchDbExp(EipTGpdb.GPDB_ID_PK_COLUMN, gpdbId));

            List<EipTGpdb> gpdbList = query.fetchList();

            if (gpdbList == null || gpdbList.isEmpty()) {
                // ??WebID???????
                logger.debug("[GpdbUtils] Not found ID...");
                return null;
            }
            return gpdbList.get(0);

        } catch (Exception ex) {
            logger.error("Exception", ex);
            return null;
        }
    }

    /**
     * Web?
     * 
     * @return Web
     */
    public static List<GpdbResultData> getGpdbAllList() {
        List<GpdbResultData> gpdbAllList = new ArrayList<GpdbResultData>();

        try {
            List<EipTGpdb> gpdbList = Database.query(EipTGpdb.class).orderAscending(EipTGpdb.GPDB_NAME_PROPERTY)
                    .fetchList();

            for (EipTGpdb gpdb : gpdbList) {
                GpdbResultData data = new GpdbResultData();
                data.initField();
                data.setGpdbId(gpdb.getGpdbId());
                data.setGpdbName(gpdb.getGpdbName());
                gpdbAllList.add(data);
            }
        } catch (Exception ex) {
            logger.error("Exception", ex);
        }

        return gpdbAllList;
    }

    /**
     * WebWebResult?
     * 
     * @param model
     *          Web
     * @return WebResult
     */
    public static GpdbResultData getGpdbResultData(EipTGpdb model) {

        // 
        TurbineUser user = model.getTurbineUser();

        GpdbResultData data = new GpdbResultData();
        data.initField();
        data.setGpdbId(model.getGpdbId()); // WebID
        data.setGpdbName(model.getGpdbName()); // Web??
        data.setMailFlg(model.getMailFlg()); // ?

        data.setCreateUserName(
                new StringBuffer().append(user.getLastName()).append(" ").append(user.getFirstName()).toString()); // ??
        data.setCreateDate(model.getCreateDate());// ?
        data.setUpdateDate(model.getUpdateDate());// 

        data.setRecordCnt(getRecordCount("" + model.getGpdbId())); // 

        return data;
    }

    // ---------------------------------------------------
    // ?
    // ---------------------------------------------------

    /**
     *  ????
     * 
     * @param rundata
     *          RunData
     * @param context
     *          Context
     * @return 
     */
    public static EipTGpdbItem getEipTGpdbItem(RunData rundata, Context context) {
        String gpdbItemId = ALEipUtils.getTemp(rundata, context, ALEipConstants.ENTITY_ID);
        return getEipTGpdbItem(gpdbItemId);
    }

    /**
     *  ????
     * 
     * @param gpdbItemId
     *          ID
     * @return 
     */
    public static EipTGpdbItem getEipTGpdbItem(String gpdbItemId) {

        try {
            if (gpdbItemId == null) {
                // Request ID???
                logger.debug("[GpdbUtils] Empty ID...");
                return null;
            }

            SelectQuery<EipTGpdbItem> query = Database.query(EipTGpdbItem.class);
            query.setQualifier(ExpressionFactory.matchDbExp(EipTGpdbItem.GPDB_ITEM_ID_PK_COLUMN, gpdbItemId));

            List<EipTGpdbItem> gpdbItemList = query.fetchList();

            if (gpdbItemList == null || gpdbItemList.isEmpty()) {
                // ??ID???????
                logger.debug("[GpdbUtils] Not found ID...");
                return null;
            }
            return gpdbItemList.get(0);

        } catch (Exception ex) {
            logger.error("Exception", ex);
            return null;
        }
    }

    /**
     * Result?
     * 
     * @param gpdbItemList
     *          
     * @return Result
     */
    public static List<GpdbItemResultData> getGpdbItemResultList(List<EipTGpdbItem> gpdbItemList) {
        List<GpdbItemResultData> resultList = new ArrayList<GpdbItemResultData>();
        for (EipTGpdbItem gpdbItem : gpdbItemList) {
            resultList.add(getGpdbItemResultData(gpdbItem));
        }
        return resultList;
    }

    /**
     * Result?
     * 
     * @param gpdbItem
     *          
     * @return Result
     */
    public static GpdbItemResultData getGpdbItemResultData(EipTGpdbItem gpdbItem) {
        GpdbItemResultData data = new GpdbItemResultData();
        data.initField();
        data.setGpdbItemId(gpdbItem.getGpdbItemId()); // ID
        data.setGpdbItemName(gpdbItem.getGpdbItemName()); // ??
        data.setGpdbId(gpdbItem.getGpdb().getGpdbId()); // WebID
        data.setGpdbName(gpdbItem.getGpdb().getGpdbName()); // Web??
        data.setTitleFlg(gpdbItem.getTitleFlg()); // 
        data.setRequiredFlg(gpdbItem.getRequiredFlg()); // 
        data.setType(gpdbItem.getType()); // ?
        data.setTypeName(ITEM_TYPE.get(gpdbItem.getType())); // ???
        // ?
        data.setListFlg(gpdbItem.getListFlg()); // ?
        data.setDetailFlg(gpdbItem.getDetailFlg()); // ?
        data.setDefaultSortFlg(gpdbItem.getDefaultSortFlg()); // 
        data.setAscDesc(gpdbItem.getAscDesc()); // 

        // 
        EipMGpdbKubun kubun = getEipMGpdbKubun(gpdbItem.getGpdbKubunId());
        if (kubun != null) {
            data.setGpdbKubunId(kubun.getGpdbKubunId());
            data.setGpdbKubunName(kubun.getGpdbKubunName());
        }

        Integer sizeCol = gpdbItem.getSizeCol(); // 
        if (sizeCol != null) {
            data.setSizeCol(sizeCol);
        }
        Integer sizeRow = gpdbItem.getSizeRow(); // 
        if (sizeRow != null) {
            data.setSizeRow(sizeRow);
        }
        Integer line = gpdbItem.getLine(); // 
        if (line != null) {
            data.setLine(line);
        }
        return data;
    }

    /**
     * Result?
     * 
     * @param gpdbId
     *          WebID
     * @return Result
     */
    public static List<GpdbItemResultData> getGpdbItemResultList(String gpdbId) {

        SelectQuery<EipTGpdbItem> query = Database.query(EipTGpdbItem.class);
        query.setQualifier(ExpressionFactory.matchDbExp(EipTGpdbItem.GPDB_PROPERTY, gpdbId));
        query.orderAscending(EipTGpdbItem.ORDER_NO_PROPERTY);

        List<GpdbItemResultData> gpdbItemList = getGpdbItemResultList(query.fetchList());
        if (gpdbItemList.isEmpty()) {
            // ??ID???????
            logger.debug("[GpdbUtils] Not found ID...");
            return null;
        }
        return gpdbItemList;
    }

    // ---------------------------------------------------
    // Web?
    // ---------------------------------------------------

    /**
     * Web ???? <br/>
     * 1?????
     * 
     * @param gpdbId
     *          WebID
     * @return 
     */
    public static List<EipTGpdbRecord> getEipTGpdbRecord(String gpdbId) {
        return getEipTGpdbRecord(gpdbId, null);
    }

    /**
     * Web ???? <br/>
     * ?????
     * 
     * @param gpdbId
     *          WebID
     * @return 
     */
    public static List<EipTGpdbRecord> getEipTGpdbRecordTitle(String gpdbId) {
        return getEipTGpdbRecord(gpdbId, null, true);
    }

    /**
     * Web ???? <br/>
     * 1?????
     * 
     * @param gpdbId
     *          WebID
     * @param recordNo
     *          No
     * @return 
     */
    public static List<EipTGpdbRecord> getEipTGpdbRecord(String gpdbId, String recordNo) {
        return getEipTGpdbRecord(gpdbId, recordNo, false);
    }

    /**
     * Web ???? <br/>
     * 1?????
     * 
     * @param gpdbId
     *          WebID
     * @param recordNo
     *          No
     * @param titleOnly
     *          TRUE:?????
     * @return 
     */
    public static List<EipTGpdbRecord> getEipTGpdbRecord(String gpdbId, String recordNo, boolean titleOnly) {

        try {
            if (gpdbId == null) {
                // Request ID???
                logger.debug("[GpdbUtils] Empty ID...");
                return null;
            }

            SelectQuery<EipTGpdbRecord> query = Database.query(EipTGpdbRecord.class);
            query.setQualifier(ExpressionFactory.matchDbExp(EipTGpdbRecord.GPDB_PROPERTY, gpdbId));

            if (recordNo != null) {
                query.andQualifier(ExpressionFactory.matchExp(EipTGpdbRecord.RECORD_NO_PROPERTY, recordNo));
            }
            if (titleOnly) {
                SelectQuery<EipTGpdbItem> titleQuery = Database.query(EipTGpdbItem.class);
                titleQuery.setQualifier(ExpressionFactory.matchDbExp(EipTGpdbItem.GPDB_PROPERTY, gpdbId));
                titleQuery.andQualifier(ExpressionFactory.matchExp(EipTGpdbItem.TITLE_FLG_PROPERTY, FLG_ON));

                query.andQualifier(
                        ExpressionFactory.matchExp(EipTGpdbRecord.GPDB_ITEM_PROPERTY, titleQuery.fetchSingle()));
            }

            List<EipTGpdbRecord> gpdbRecordList = query.fetchList();

            if (gpdbRecordList == null || gpdbRecordList.isEmpty()) {
                // ??No???????
                logger.debug("[GpdbUtils] Not found ID...");
                return null;
            }
            return gpdbRecordList;

        } catch (Exception ex) {
            logger.error("Exception", ex);
            return null;
        }
    }

    /**
     * Web ???? <br/>
     * 1?????
     * 
     * @param gpdbId
     *          ID
     * @param recordNo
     *          No
     * @param itemId
     *          ID
     * @return 
     */
    public static EipTGpdbRecord getEipTGpdbRecord(String gpdbId, String recordNo, String itemId) {

        try {
            if (gpdbId == null || recordNo == null) {
                // Request ID???
                logger.debug("[GpdbUtils] Empty ID...");
                return null;
            }

            SelectQuery<EipTGpdbRecord> query = Database.query(EipTGpdbRecord.class);
            query.setQualifier(ExpressionFactory.matchDbExp(EipTGpdbRecord.GPDB_PROPERTY, gpdbId));
            query.andQualifier(ExpressionFactory.matchExp(EipTGpdbRecord.RECORD_NO_PROPERTY, recordNo));
            query.andQualifier(ExpressionFactory.matchExp(EipTGpdbRecord.GPDB_ITEM_PROPERTY, itemId));

            EipTGpdbRecord gpdbRecord = query.fetchSingle();

            if (gpdbRecord == null) {
                // ??ID???????
                logger.debug("[GpdbUtils] Not found ID...");
                return null;
            }
            return gpdbRecord;

        } catch (Exception ex) {
            logger.error("Exception", ex);
            return null;
        }
    }

    /**
     * WebWebResult?
     * 
     * @param model
     *          Web
     * @return WebResult
     */
    public static GpdbRecordResultData getGpdbRecordResultData(EipTGpdbRecord model) {

        try {
            String value = model.getValue();
            List<String> valueList = new ArrayList<String>();
            if (value != null) {

                EipTGpdbItem item = getEipTGpdbItem("" + model.getGpdbItemId());
                String type = item.getType();

                if (ITEM_TYPE_SELECT.equals(type) || ITEM_TYPE_SELECT_MULTI.equals(type)) {
                    // ?????ID????????
                    String[] list = value.split("\\" + KUBUN_VALUE_SEPARATOR);

                    StringBuilder sbVal = new StringBuilder();
                    for (int i = 0; i < list.length; i++) {
                        if (i > 0) {
                            sbVal.append(KUBUN_VALUE_DISP_SEPARATOR);
                        }
                        EipMGpdbKubunValue kubunValue = getEipMGpdbKubunValue(list[i]);
                        if (kubunValue != null) {
                            sbVal.append(kubunValue.getGpdbKubunValue());
                        }
                        valueList.add(list[i]);
                    }

                    value = String.valueOf(sbVal);

                } else if (ITEM_TYPE_FILE.equals(type) || ITEM_TYPE_IMAGE.equals(type)) {
                    // ?????????
                    value = value.replace(KUBUN_VALUE_SEPARATOR, KUBUN_VALUE_DISP_SEPARATOR);

                } else if (ITEM_TYPE_CREATE_USER.equals(type) || ITEM_TYPE_UPDATE_USER.equals(type)) {
                    // ???????
                    if (!"".equals(value.trim())) {
                        Integer userid = Integer.valueOf(value);
                        value = ALEipUtils.getALEipUser(userid).getAliasName().getValue();
                    }
                } else if (ITEM_TYPE_DATE.equals(type)) {
                    // ?????
                    SimpleDateFormat sdf_data = new SimpleDateFormat(
                            ALLocalizationUtils.getl10n("GPDB_DATE_FORMAT_DATA"));
                    SimpleDateFormat sdf_show = new SimpleDateFormat(
                            ALLocalizationUtils.getl10n("GPDB_DATE_FORMAT_SHOW"));
                    String tmpValue = value;
                    try {
                        Date date = sdf_data.parse(value);
                        value = sdf_show.format(date);
                    } catch (Exception e) {
                        value = tmpValue;
                    }
                } else if (ITEM_TYPE_CREATE_DATE.equals(type) || ITEM_TYPE_UPDATE_DATE.equals(type)) {
                    // ???????
                    SimpleDateFormat sdf_data = new SimpleDateFormat(
                            ALLocalizationUtils.getl10n("GPDB_TIMESTAMP_FORMAT_DATA"));
                    SimpleDateFormat sdf_show = new SimpleDateFormat(
                            ALLocalizationUtils.getl10n("GPDB_TIMESTAMP_FORMAT_SHOW"));
                    String tmpValue = value;
                    try {
                        Date date = sdf_data.parse(value);
                        value = sdf_show.format(date);
                    } catch (Exception e) {
                        value = tmpValue;
                    }
                }
            }

            GpdbRecordResultData rd = new GpdbRecordResultData();
            rd.initField();
            rd.setGpdbItemId(model.getGpdbItemId());
            rd.setGpdbRecordId(model.getGpdbRecordId());
            rd.setRecordNo(model.getRecordNo());
            rd.setValue(model.getValue());
            rd.setDispValue(value);
            rd.setValueList(valueList);
            return rd;
        } catch (RuntimeException ex) {
            logger.error("RuntimeException", ex);
            return null;
        } catch (Exception ex) {
            logger.error("Exception", ex);
            return null;
        }
    }

    /**
     * Web??
     * 
     * @param gpdbId
     *          WebID
     * @param recordNo
     *          No
     * @return Web?
     * @throws ALPageNotFoundException
     */
    public static Map<String, GpdbRecordResultData> getGpdbRecordMap(String gpdbId, String recordNo)
            throws ALPageNotFoundException {
        Map<String, GpdbRecordResultData> map = new HashMap<String, GpdbRecordResultData>();

        List<EipTGpdbRecord> recordList = getEipTGpdbRecord(gpdbId, recordNo);

        // ??gpdbID???????
        if (recordList == null || recordList.size() == 0) {
            logger.error("[GpdbUtils] Not found record.");
            throw new ALPageNotFoundException();
        }

        List<GpdbRecordResultData> list = new ArrayList<GpdbRecordResultData>();
        for (EipTGpdbRecord rec : recordList) {
            list.add(getGpdbRecordResultData(rec));
        }

        // ID?Web???
        for (GpdbRecordResultData data : list) {
            map.put("" + data.getGpdbItemId(), data);
        }

        return map;
    }

    /**
     * Web?????
     * 
     * @param gpdbId
     *          WebID
     * @return 
     */
    public static int getRecordCount(String gpdbId) {
        int cnt = 0;

        try {
            String sql = "SELECT COUNT(0) AS data_cnt" + " FROM (" + "   SELECT record_no FROM eip_t_gpdb_record"
                    + "   WHERE gpdb_id = #bind($gpdb_id)" + "   GROUP BY record_no) a";

            SQLTemplate<EipTGpdbRecord> sqltemp = Database.sql(EipTGpdbRecord.class, String.valueOf(sql));
            sqltemp.param("gpdb_id", Integer.valueOf(gpdbId));

            List<DataRow> result = sqltemp.fetchListAsDataRow();

            if (result == null || result.isEmpty()) {
                return 0;
            }

            cnt = Integer.valueOf(result.get(0).get("data_cnt").toString());

        } catch (Exception ex) {
            logger.error("Exception", ex);
            return 0;
        }
        return cnt;
    }

    /**
     * ????Web?????
     * 
     * @param gpdbKubunValueId
     *          ID
     * @return 
     */
    public static int getRecordCountKubunUsed(String gpdbKubunValueId) {
        int cnt = 0;

        try {
            String sql = "";
            if (Database.isJdbcMySQL()) {
                sql = "SELECT COUNT(0) AS data_cnt" + " FROM eip_t_gpdb_record r"
                        + "   INNER JOIN eip_t_gpdb_item i" + "     ON i.gpdb_item_id = r.gpdb_item_id"
                        + "   WHERE i.type IN (#bind($type1), #bind($type2))"
                        + "   AND r.value REGEXP #bind($gpdb_kubun_value_id)";
            } else if (Database.isJdbcPostgreSQL()) {
                sql = "SELECT COUNT(0) AS data_cnt" + " FROM eip_t_gpdb_record r"
                        + "   INNER JOIN eip_t_gpdb_item i" + "     ON i.gpdb_item_id = r.gpdb_item_id"
                        + "   WHERE i.type IN (#bind($type1), #bind($type2))"
                        + "   AND r.value ~ #bind($gpdb_kubun_value_id)";
            }

            SQLTemplate<EipTGpdbRecord> sqltemp = Database.sql(EipTGpdbRecord.class, String.valueOf(sql));
            sqltemp.param("type1", ITEM_TYPE_SELECT);
            sqltemp.param("type2", ITEM_TYPE_SELECT_MULTI);

            if (Database.isJdbcMySQL()) {
                sqltemp.param("gpdb_kubun_value_id", "(^|\\|)" + gpdbKubunValueId + "(\\||$)");

            } else if (Database.isJdbcPostgreSQL()) {
                sqltemp.param("gpdb_kubun_value_id", "(?:^|\\||)" + gpdbKubunValueId + "(?:\\||$)");
            }

            List<DataRow> result = sqltemp.fetchListAsDataRow();

            if (result == null || result.isEmpty()) {
                return 0;
            }

            cnt = Integer.valueOf(result.get(0).get("data_cnt").toString());

        } catch (Exception ex) {
            logger.error("Exception", ex);
            return 0;
        }
        return cnt;
    }

    // ---------------------------------------------------
    // ?
    // ---------------------------------------------------

    /**
     *  ????
     * 
     * @param rundata
     *          RunData
     * @param context
     *          Context
     * @return 
     */
    public static EipMGpdbKubun getEipMGpdbKubun(RunData rundata, Context context) {
        String gpdbKubunId = ALEipUtils.getTemp(rundata, context, ALEipConstants.ENTITY_ID);
        try {
            if (gpdbKubunId == null) {
                // Request ID???
                logger.debug("[GpdbUtils] Empty ID...");
                return null;
            }

            SelectQuery<EipMGpdbKubun> query = Database.query(EipMGpdbKubun.class);
            query.setQualifier(ExpressionFactory.matchDbExp(EipMGpdbKubun.GPDB_KUBUN_ID_PK_COLUMN, gpdbKubunId));

            List<EipMGpdbKubun> kubunList = query.fetchList();

            if (kubunList == null || kubunList.isEmpty()) {
                // ??ID???????
                logger.debug("[GpdbUtils] Not found ID...");
                return null;
            }
            return kubunList.get(0);

        } catch (Exception ex) {
            logger.error("Exception", ex);
            return null;
        }
    }

    /**
     *  ????
     * 
     * @param gpdbKubunId
     *          ID
     * @return 
     */
    public static EipMGpdbKubun getEipMGpdbKubun(Integer gpdbKubunId) {
        try {

            if (gpdbKubunId == null) {
                return null;
            }

            SelectQuery<EipMGpdbKubun> query = Database.query(EipMGpdbKubun.class);
            query.setQualifier(ExpressionFactory.matchDbExp(EipMGpdbKubun.GPDB_KUBUN_ID_PK_COLUMN, gpdbKubunId));

            List<EipMGpdbKubun> kubunList = query.fetchList();

            if (kubunList == null || kubunList.isEmpty()) {
                // ??ID???????
                logger.debug("[GpdbUtils] Not found ID...");
                return null;
            }
            return kubunList.get(0);

        } catch (Exception ex) {
            logger.error("Exception", ex);
            return null;
        }
    }

    /**
     *  ????
     * 
     * @param rundata
     *          RunData
     * @param context
     *          Context
     * @return 
     */
    public static EipMGpdbKubunValue getEipMGpdbKubunValue(RunData rundata, Context context) {
        String gpdbKubunValueId = ALEipUtils.getTemp(rundata, context, ALEipConstants.ENTITY_ID);
        return getEipMGpdbKubunValue(gpdbKubunValueId);
    }

    /**
     *  ????
     * 
     * @param gpdbKubunValueId
     *          ID
     * @return 
     */
    public static EipMGpdbKubunValue getEipMGpdbKubunValue(String gpdbKubunValueId) {
        try {

            if (gpdbKubunValueId == null || gpdbKubunValueId.isEmpty()) {
                // Request ID???
                logger.debug("[GpdbUtils] Empty ID...");
                return null;
            }

            SelectQuery<EipMGpdbKubunValue> query = Database.query(EipMGpdbKubunValue.class);
            query.setQualifier(ExpressionFactory.matchDbExp(EipMGpdbKubunValue.GPDB_KUBUN_VALUE_ID_PK_COLUMN,
                    gpdbKubunValueId));

            List<EipMGpdbKubunValue> kubunValueList = query.fetchList();

            if (kubunValueList == null || kubunValueList.isEmpty()) {
                // ??ID???????
                logger.debug("[GpdbUtils] Not found ID...");
                return null;
            }
            return kubunValueList.get(0);

        } catch (Exception ex) {
            logger.error("Exception", ex);
            return null;
        }
    }

    /**
     * ??
     * 
     * @return 
     */
    public static List<GpdbKubunResultData> getGpdbKubunAllList() {
        List<GpdbKubunResultData> kubunAllList = new ArrayList<GpdbKubunResultData>();

        try {
            List<EipMGpdbKubun> kubunList = Database.query(EipMGpdbKubun.class)
                    .orderAscending(EipMGpdbKubun.GPDB_KUBUN_NAME_PROPERTY).fetchList();

            for (EipMGpdbKubun kubun : kubunList) {
                GpdbKubunResultData data = new GpdbKubunResultData();
                data.initField();
                data.setGpdbKubunId(kubun.getGpdbKubunId());
                data.setGpdbKubunName(kubun.getGpdbKubunName());
                kubunAllList.add(data);
            }
        } catch (Exception ex) {
            logger.error("Exception", ex);
        }

        return kubunAllList;
    }

    /**
     * ??
     * 
     * @param gpdbKubunId
     *          ID
     * @return 
     */
    public static List<GpdbKubunValueResultData> getGpdbKubunValueList(String gpdbKubunId) {
        List<GpdbKubunValueResultData> kubunValueResultList = new ArrayList<GpdbKubunValueResultData>();

        try {

            SelectQuery<EipMGpdbKubunValue> query = Database.query(EipMGpdbKubunValue.class);
            query.orderAscending(EipMGpdbKubunValue.GPDB_KUBUN_PROPERTY);
            query.orderAscending(EipMGpdbKubunValue.ORDER_NO_PROPERTY);
            if (gpdbKubunId != null) {
                query.setQualifier(
                        ExpressionFactory.matchDbExp(EipMGpdbKubunValue.GPDB_KUBUN_PROPERTY, gpdbKubunId));
            }

            List<EipMGpdbKubunValue> kubunValueList = query.fetchList();

            for (EipMGpdbKubunValue kubunValue : kubunValueList) {
                GpdbKubunValueResultData data = new GpdbKubunValueResultData();
                data.initField();
                data.setGpdbKubunValueId(kubunValue.getGpdbKubunValueId());
                data.setGpdbKubunValue(kubunValue.getGpdbKubunValue());
                data.setGpdbKubunId(kubunValue.getGpdbKubun().getGpdbKubunId());
                data.setGpdbKubunName(kubunValue.getGpdbKubun().getGpdbKubunName());
                kubunValueResultList.add(data);
            }
        } catch (Exception ex) {
            logger.error("Exception", ex);
        }

        return kubunValueResultList;
    }

    /**
     * ??
     * 
     * @return 
     */
    public static List<GpdbKubunValueResultData> getGpdbKubunValueAllList() {
        return getGpdbKubunValueList(null);
    }

    /**
     * ID?????
     * 
     * @return ?
     */
    public static Map<String, List<GpdbKubunValueResultData>> getKubunMap() {
        Map<String, List<GpdbKubunValueResultData>> map = new HashMap<String, List<GpdbKubunValueResultData>>();

        // ?
        List<GpdbKubunValueResultData> allList = getGpdbKubunValueAllList();

        // ?????
        List<GpdbKubunValueResultData> list = null;

        // ID
        String compareKubunId = null;

        for (GpdbKubunValueResultData data : allList) {
            String kubunId = data.getGpdbKubunId().toString();
            if (!kubunId.equals(compareKubunId)) {
                // ID?????
                list = new ArrayList<GpdbKubunValueResultData>();
                map.put(kubunId, list);
            }
            list.add(data);
            compareKubunId = kubunId;
        }

        return map;
    }

    /**
     * Result?
     * 
     * @param gpdbKubunValueList
     *          
     * @return Result
     */
    public static List<GpdbKubunValueResultData> getGpdbKubunValueResultList(
            List<EipMGpdbKubunValue> gpdbKubunValueList) {
        List<GpdbKubunValueResultData> resultList = new ArrayList<GpdbKubunValueResultData>();
        for (EipMGpdbKubunValue gpdbKubunValue : gpdbKubunValueList) {
            resultList.add(getGpdbKubunValueResultData(gpdbKubunValue));
        }
        return resultList;
    }

    /**
     * Result?
     * 
     * @param model
     *          
     * @return Result
     */
    public static GpdbKubunValueResultData getGpdbKubunValueResultData(EipMGpdbKubunValue model) {
        GpdbKubunValueResultData data = new GpdbKubunValueResultData();
        data.initField();
        data.setGpdbKubunValueId(model.getGpdbKubunValueId());
        data.setGpdbKubunName(model.getGpdbKubun().getGpdbKubunName());
        data.setGpdbKubunValue(model.getGpdbKubunValue());
        return data;
    }

    // ---------------------------------------------------
    // ?
    // ---------------------------------------------------

    /**
     * Web??????
     * 
     * @param gpdb
     *          Web
     * @return TRUE ? FALSE 
     */
    public static boolean removeGpdbItem(EipTGpdb gpdb) {

        try {
            // Web?????
            SelectQuery<EipTGpdbItem> query = Database.query(EipTGpdbItem.class);
            query.setQualifier(ExpressionFactory.matchExp(EipTGpdbItem.GPDB_PROPERTY, gpdb.getGpdbId()));

            List<EipTGpdbItem> gpdbItemList = query.fetchList();

            if (gpdbItemList == null || gpdbItemList.isEmpty()) {
                return true;
            }

            // Web?????
            Database.deleteAll(gpdbItemList);

        } catch (Exception ex) {
            logger.error("Exception", ex);
            return false;
        }

        return true;
    }

    /**
     * ??????
     * 
     * @param rundata
     *          RunData
     * @param gpdbItem
     *          
     * @return TRUE ? FALSE 
     */
    public static boolean removeGpdbRecord(RunData rundata, EipTGpdbItem gpdbItem) {

        try {
            // ?????
            SelectQuery<EipTGpdbRecord> query = Database.query(EipTGpdbRecord.class);
            query.setQualifier(
                    ExpressionFactory.matchExp(EipTGpdbRecord.GPDB_ITEM_PROPERTY, gpdbItem.getGpdbItemId()));

            List<EipTGpdbRecord> gpdbRecordList = query.fetchList();
            if (gpdbRecordList == null || gpdbRecordList.isEmpty()) {
                return true;
            }

            // ?????
            Database.deleteAll(gpdbRecordList);

            // 
            removeGpdbRecordFile(rundata, gpdbRecordList);

        } catch (Exception ex) {
            logger.error("Exception", ex);
            return false;
        }

        return true;
    }

    /**
     * ?<br/>
     * DB?????
     * 
     * @param rundata
     *          RunData
     * @param gpdbRecordList
     *          Web
     * @return TRUE ? FALSE 
     */
    public static boolean removeGpdbRecordFile(RunData rundata, List<EipTGpdbRecord> gpdbRecordList) {

        try {
            // 
            List<String> fpaths = new ArrayList<String>();
            List<Integer> fownerIds = new ArrayList<Integer>();
            if (gpdbRecordList != null) {
                for (EipTGpdbRecord record : gpdbRecordList) {
                    List<EipTGpdbRecordFile> fileList = getEipTGpdbRecordFileList(record.getGpdbRecordId());
                    Database.deleteAll(fileList);

                    for (EipTGpdbRecordFile file : fileList) {
                        if (file.getFilePath() != null && file.getOwnerId() != null) {
                            fpaths.add(file.getFilePath());
                            fownerIds.add(file.getOwnerId());
                        }
                    }
                }
            }

            if (!fpaths.isEmpty()) {
                // ?????
                int fsize = fpaths.size();
                for (int i = 0; i < fsize; i++) {
                    ALStorageService.deleteFile(GpdbUtils.getSaveDirPath(fownerIds.get(i)) + fpaths.get(i));
                }
            }

        } catch (Exception ex) {
            logger.error("Exception", ex);
            return false;
        }
        return true;
    }

    /**
     * ?????
     * 
     * @return TRUE ? FALSE 
     */
    public static boolean removeGpdbKubunNoValue() {

        try {
            String sql = "SELECT * FROM eip_m_gpdb_kubun a" + " WHERE NOT EXISTS("
                    + "   SELECT 0 FROM eip_m_gpdb_kubun_value b" + "   WHERE a.gpdb_kubun_id = b.gpdb_kubun_id)";

            List<EipMGpdbKubun> kubunList = Database.sql(EipMGpdbKubun.class, sql).fetchList();

            if (kubunList == null || kubunList.isEmpty()) {
                return true;
            }

            for (EipMGpdbKubun kubun : kubunList) {
                // SQL????EipMGpdbKubun??TRANSIENT???
                // ????????????COMMITTED
                DataContext.getThreadDataContext().registerNewObject(kubun);
                kubun.setPersistenceState(PersistenceState.COMMITTED);
            }

            Database.deleteAll(kubunList);

        } catch (Exception ex) {
            logger.error("Exception", ex);
            return false;
        }
        return true;
    }

    /**
     * ?????OFF??
     * 
     * @param gpdb
     *          Web
     * @return TRUE ? FALSE 
     */
    public static boolean gpdbItemTitleOff(EipTGpdb gpdb) {
        // ?????OFF??
        SelectQuery<EipTGpdbItem> query = Database.query(EipTGpdbItem.class);
        query.setQualifier(ExpressionFactory.matchExp(EipTGpdbItem.GPDB_PROPERTY, gpdb));
        query.andQualifier(ExpressionFactory.matchExp(EipTGpdbItem.TITLE_FLG_PROPERTY, FLG_ON));

        EipTGpdbItem titleItem = query.fetchSingle();
        if (titleItem == null) {
            return true;
        }
        titleItem.setTitleFlg(FLG_OFF);

        return true;
    }

    /**
     * ?????OFF??
     * 
     * @param gpdb
     *          Web
     * @return TRUE ? FALSE 
     */
    public static boolean gpdbItemDefaultSortOff(EipTGpdb gpdb) {
        // ?????OFF??
        SelectQuery<EipTGpdbItem> query = Database.query(EipTGpdbItem.class);
        query.setQualifier(ExpressionFactory.matchExp(EipTGpdbItem.GPDB_PROPERTY, gpdb));
        query.andQualifier(ExpressionFactory.matchExp(EipTGpdbItem.DEFAULT_SORT_FLG_PROPERTY, FLG_ON));

        EipTGpdbItem titleItem = query.fetchSingle();
        if (titleItem == null) {
            return true;
        }
        titleItem.setDefaultSortFlg(FLG_OFF);
        titleItem.setAscDesc("");

        return true;
    }

    // ---------------------------------------------------
    // ?
    // ---------------------------------------------------

    /**
     * rundata.getParameters().getStrings()????????
     * 
     * @param str
     *          ??
     * @return ?
     */
    public static String convertEncording(String str) {
        try {
            String replace = new String(str.getBytes("8859_1"), "UTF-8");
            if (replace != null && replace.matches("^\\?+$")) {
                // ????????????
                // firefox???rundata.getParameters().getStrings()???????????
                // TODO ??
                return str;
            }
            return replace;
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * ??????
     * 
     * @param rundata
     *          RunData
     * @param field
     *          
     * @return ?
     */
    public static String getParamValueString(RunData rundata, String field) {
        String[] param = rundata.getParameters().getStrings(field);
        if (param == null) {
            return null;
        }
        List<String> list = new ArrayList<String>();
        for (int i = 0; i < param.length; i++) {
            param[i] = convertEncording(param[i]);
            if (param[i] != null && !"".equals(param[i].trim())) {
                list.add(param[i]);
            }
        }
        return StringUtils.join(list.toArray(), KUBUN_VALUE_SEPARATOR);
    }

    // ---------------------------------------------------
    // ?
    // ---------------------------------------------------

    /**
     * ????????
     * 
     * @param field
     *          ??
     * @param type
     *          ?
     * @return ?TRUE ???FALSE
     */
    public static boolean dipslayField(String field, String type) {
        if (type == null || "".equals(type.trim())) {
            type = ITEM_TYPE_TEXT;
        }
        if (!ITEM_FIELD.containsKey(field)) {
            return false;
        }
        List<String> list = ITEM_FIELD.get(field);
        return list.contains(type);
    }

    /**
     * URL???????
     * 
     * @param str
     *          ?
     * @return URL????true????false
     */
    public static boolean isUrl(String str) {
        Pattern mailPattern = Pattern.compile("^(https?|ftp)(:\\/\\/[-_.!~*\\'()a-zA-Z0-9;\\/?:\\@&=+\\$,%#]+)$",
                Pattern.CASE_INSENSITIVE);
        Matcher objMch = mailPattern.matcher(str);
        return objMch.matches();
    }

    // ---------------------------------------------------
    // 
    // ---------------------------------------------------

    /**
     * ????
     * 
     * @param rundata
     *          RunData
     * @param destUser
     *          ?
     * @param gpdb
     *          
     * @param gpdbItemList
     * @return ?TRUE FALSE
     * @throws Exception
     *           
     */
    public static boolean sendMail(RunData rundata, ALEipUser destUser, EipTGpdb gpdb, String gpdbItemName,
            String dispValue) throws Exception {

        String orgId = Database.getDomainName();
        String subject = "[" + ALOrgUtilsService.getAlias() + "]Web";

        try {
            List<ALEipUser> memberList = new ArrayList<ALEipUser>();
            memberList.add(destUser);

            List<ALEipUserAddr> destMemberList = ALMailUtils.getALEipUserAddrs(memberList,
                    ALEipUtils.getUserId(rundata), false);

            List<ALAdminMailMessage> messageList = new ArrayList<ALAdminMailMessage>();

            for (ALEipUserAddr destMember : destMemberList) {
                ALAdminMailMessage message = new ALAdminMailMessage(destMember);
                message.setPcSubject(subject);
                message.setCellularSubject(subject);
                message.setPcBody(createMsgForPc(rundata, gpdb, gpdbItemName, dispValue, true));
                message.setCellularBody(createMsgForCellPhone(rundata, gpdb, gpdbItemName, dispValue, true));
                messageList.add(message);
            }

            ALMailService.sendAdminMailAsync(new ALAdminMailContext(orgId, ALEipUtils.getUserId(rundata),
                    messageList, ALMailUtils.getSendDestType(ALMailUtils.KEY_MSGTYPE_WORKFLOW)));

        } catch (Exception ex) {
            logger.error("Exception", ex);
            return false;
        }
        return true;
    }

    /**
     * ??????
     * 
     * @param gpdbItemList
     * 
     * @return
     */
    public static String createMsgForPc(RunData rundata, EipTGpdb gpdb, String gpdbItemName, String dispValue,
            Boolean isNew) throws ALDBErrorException {
        VelocityContext context = new VelocityContext();
        boolean enableAsp = JetspeedResources.getBoolean("aipo.asp", false);
        ALEipUser loginUser = null;
        ALBaseUser user = null;

        try {
            loginUser = ALEipUtils.getALEipUser(rundata);
            user = (ALBaseUser) JetspeedSecurity.getUser(new UserIdPrincipal(loginUser.getUserId().toString()));
        } catch (Exception e) {
            return "";
        }
        context.put("loginUser", loginUser.getAliasName().toString());
        context.put("hasEmail", !user.getEmail().equals(""));
        context.put("email", user.getEmail());
        context.put("isNew", isNew);
        // 
        context.put("GpdbName", gpdb.getGpdbName());
        // ??
        context.put("GpdbItemName", gpdbItemName);
        context.put("DispValue", dispValue);

        // 
        context.put("serviceAlias", ALOrgUtilsService.getAlias());
        // Aipo??
        context.put("enableAsp", enableAsp);
        context.put("globalurl", ALMailUtils.getGlobalurl());
        context.put("localurl", ALMailUtils.getLocalurl());
        CustomLocalizationService locService = (CustomLocalizationService) ServiceUtil
                .getServiceByName(LocalizationService.SERVICE_NAME);
        String lang = locService.getLocale(rundata).getLanguage();
        StringWriter writer = new StringWriter();
        try {
            if (lang != null && lang.equals("ja")) {
                Template template = Velocity.getTemplate("portlets/mail/" + lang + "/gpdb-notification-mail.vm",
                        "utf-8");
                template.merge(context, writer);
            } else {
                Template template = Velocity.getTemplate("portlets/mail/gpdb-notification-mail.vm", "utf-8");
                template.merge(context, writer);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        writer.flush();
        String ret = writer.getBuffer().toString();
        return ret;
    }

    /**
     * ???????
     * 
     * @param gpdbItemList
     * 
     * @return
     */
    public static String createMsgForCellPhone(RunData rundata, EipTGpdb gpdb, String gpdbItemName,
            String dispValue, Boolean isNew) throws ALDBErrorException {
        return createMsgForPc(rundata, gpdb, gpdbItemName, dispValue, isNew);
    }

    // ---------------------------------------------------
    // ?
    // ---------------------------------------------------

    /**
     * ?
     * 
     * @param rundata
     *          RunData
     * @param context
     *          Context
     * @param record
     *          Web
     * @param fileuploadList
     *          
     * @param folderName
     *          ??
     * @param msgList
     *          
     * @return ?TRUE FALSE
     */
    public static boolean insertFileDataDelegate(RunData rundata, Context context, EipTGpdbRecord record,
            List<FileuploadLiteBean> fileuploadList, String folderName, List<String> msgList) {
        if (fileuploadList == null || fileuploadList.size() <= 0) {
            fileuploadList = new ArrayList<FileuploadLiteBean>();
        }

        int uid = ALEipUtils.getUserId(rundata);
        String orgId = Database.getDomainName();

        List<Integer> hadfileids = new ArrayList<Integer>();
        for (FileuploadLiteBean file : fileuploadList) {
            if (!file.isNewFile()) {
                hadfileids.add(file.getFileId());
            }
        }

        SelectQuery<EipTGpdbRecordFile> dbquery = Database.query(EipTGpdbRecordFile.class);
        dbquery.andQualifier(ExpressionFactory.matchDbExp(EipTGpdbRecordFile.EIP_TGPDB_RECORD_PROPERTY,
                record.getGpdbRecordId()));
        List<EipTGpdbRecordFile> existsFiles = dbquery.fetchList();
        List<EipTGpdbRecordFile> delFiles = new ArrayList<EipTGpdbRecordFile>();
        for (EipTGpdbRecordFile file : existsFiles) {
            if (!hadfileids.contains(file.getFileId())) {
                delFiles.add(file);
            }
        }

        // ??????
        if (delFiles.size() > 0) {
            int delsize = delFiles.size();
            for (int i = 0; i < delsize; i++) {
                ALStorageService
                        .deleteFile(getSaveDirPath(delFiles.get(i).getOwnerId()) + (delFiles.get(i)).getFilePath());
            }
            // ??
            Database.deleteAll(delFiles);
        }

        // ?
        try {
            for (FileuploadLiteBean filebean : fileuploadList) {
                if (!filebean.isNewFile()) {
                    continue;
                }

                // ??
                String[] acceptExts = ImageIO.getWriterFormatNames();
                ShrinkImageSet shrinkImageSet = FileuploadUtils.getBytesShrinkFilebean(orgId, folderName, uid,
                        filebean, acceptExts, FileuploadUtils.DEF_THUMBNAIL_WIDTH,
                        FileuploadUtils.DEF_THUMBNAIL_HEIGHT, msgList, true);

                String filename = "0_" + String.valueOf(System.nanoTime());

                // ?
                EipTGpdbRecordFile file = Database.create(EipTGpdbRecordFile.class);
                // 
                file.setOwnerId(Integer.valueOf(uid));
                // ID
                file.setEipTGpdbRecord(record);
                // ??
                file.setFileName(filebean.getFileName());
                // 
                file.setFilePath(getRelativePath(filename));
                // ??
                if (shrinkImageSet != null && shrinkImageSet.getShrinkImage() != null) {
                    file.setFileThumbnail(shrinkImageSet.getShrinkImage());
                }
                // ?
                file.setCreateDate(Calendar.getInstance().getTime());
                // 
                file.setUpdateDate(Calendar.getInstance().getTime());

                if (shrinkImageSet != null && shrinkImageSet.getFixImage() != null) {
                    // ??
                    ALStorageService.createNewFile(new ByteArrayInputStream(shrinkImageSet.getFixImage()),
                            FOLDER_FILEDIR_GPDB + ALStorageService.separator() + Database.getDomainName()
                                    + ALStorageService.separator() + CATEGORY_KEY + ALStorageService.separator()
                                    + uid + ALStorageService.separator() + filename);
                } else {
                    // ?
                    ALStorageService.copyTmpFile(uid, folderName, String.valueOf(filebean.getFileId()),
                            FOLDER_FILEDIR_GPDB, CATEGORY_KEY + ALStorageService.separator() + uid, filename);
                }
            }

            // ??
            if (folderName != null && !"".equals(folderName.trim())) {
                ALStorageService.deleteTmpFolder(uid, folderName);
            }
        } catch (Exception e) {
            Database.rollback();
            logger.error("Exception", e);
            return false;
        }
        return true;
    }

    /**
     * ??????
     * 
     * @param uid
     *          ID
     * @return 
     */
    public static String getSaveDirPath(int uid) {
        return ALStorageService.getDocumentPath(FOLDER_FILEDIR_GPDB,
                CATEGORY_KEY + ALStorageService.separator() + uid);
    }

    /**
     * ??????
     * 
     * @param fileName
     *          ??
     * @return 
     */
    public static String getRelativePath(String fileName) {
        return new StringBuffer().append("/").append(fileName).toString();
    }

    /**
     * ????
     * 
     * @param rundata
     *          RunData
     * @param keyid
     *          ??ID
     * @return 
     */
    public static List<FileuploadLiteBean> getFileuploadList(RunData rundata, String keyid) {

        String[] fileids = rundata.getParameters().getStrings(FileuploadUtils.KEY_FILEUPLOAD_ID_LIST + "_" + keyid);
        if (fileids == null) {
            return null;
        }

        ArrayList<String> hadfileids = new ArrayList<String>();
        ArrayList<String> newfileids = new ArrayList<String>();

        for (int j = 0; j < fileids.length; j++) {
            if (fileids[j].trim().startsWith("s")) {
                hadfileids.add(fileids[j].trim().substring(1));
            } else {
                newfileids.add(fileids[j].trim());
            }
        }

        ArrayList<FileuploadLiteBean> fileNameList = new ArrayList<FileuploadLiteBean>();
        FileuploadLiteBean filebean = null;

        // ??????
        if (newfileids.size() > 0) {
            String folderName = rundata.getParameters()
                    .getString(FileuploadUtils.KEY_FILEUPLOAD_FODLER_NAME + "_" + keyid);
            if (folderName == null || folderName.equals("")) {
                return null;
            }

            for (String newfileid : newfileids) {
                if ("".equals(newfileid)) {
                    continue;
                }
                int fileid = 0;
                try {
                    fileid = Integer.parseInt(newfileid);
                } catch (Exception e) {
                    continue;
                }

                if (fileid == 0) {
                    filebean = new FileuploadLiteBean();
                    filebean.initField();
                    filebean.setFolderName("photo");
                    filebean.setFileName("??");
                    fileNameList.add(filebean);
                } else {
                    BufferedReader reader = null;
                    try {
                        reader = new BufferedReader(
                                new InputStreamReader(
                                        ALStorageService.getFile(FileuploadUtils.FOLDER_TMP_FOR_ATTACHMENT_FILES,
                                                ALEipUtils.getUserId(rundata) + ALStorageService.separator()
                                                        + folderName,
                                                fileid + FileuploadUtils.EXT_FILENAME),
                                        FILE_ENCODING));
                        String line = reader.readLine();
                        if (line == null || line.length() <= 0) {
                            continue;
                        }
                        filebean = new FileuploadLiteBean();
                        filebean.initField();
                        filebean.setFolderName(newfileid);
                        filebean.setFileId(fileid);
                        filebean.setFileName(line);
                        fileNameList.add(filebean);
                    } catch (Exception e) {
                        logger.error("Exception", e);
                    } finally {
                        try {
                            reader.close();
                        } catch (Exception e) {
                            logger.error("Exception", e);
                        }
                    }
                }
            }
        }

        // ??????
        if (hadfileids.size() > 0) {
            ArrayList<Integer> hadfileidsValue = new ArrayList<Integer>();
            for (String hadfileid : hadfileids) {
                int fileid = 0;
                try {
                    fileid = Integer.parseInt(hadfileid);
                    hadfileidsValue.add(fileid);
                } catch (Exception e) {
                    continue;
                }
            }

            try {
                SelectQuery<EipTGpdbRecordFile> reqquery = Database.query(EipTGpdbRecordFile.class);
                Expression reqexp1 = ExpressionFactory.inDbExp(EipTGpdbRecordFile.FILE_ID_PK_COLUMN,
                        hadfileidsValue);
                reqquery.setQualifier(reqexp1);
                List<EipTGpdbRecordFile> requests = reqquery.fetchList();
                for (EipTGpdbRecordFile file : requests) {
                    filebean = new FileuploadBean();
                    filebean.initField();
                    filebean.setFileId(file.getFileId());
                    filebean.setFileName(file.getFileName());
                    filebean.setFlagNewFile(false);
                    fileNameList.add(filebean);
                }
            } catch (Exception ex) {
                logger.error("[BlogUtils] Exception.", ex);
            }
        }
        return fileNameList;
    }

    /**
     * ???? <BR>
     * 
     * @param rundata
     *          RunData
     * @return 
     * @exception ALPageNotFoundException
     *              
     * @exception ALDBErrorException
     *              DB
     */
    public static EipTGpdbRecordFile getEipTGpdbRecordFile(RunData rundata)
            throws ALPageNotFoundException, ALDBErrorException {
        try {
            int attachmentIndex = rundata.getParameters().getInt("attachmentIndex", -1);
            if (attachmentIndex < 0) {
                // ID ???
                logger.debug("[GpdbUtils] Empty ID...");
                throw new ALPageNotFoundException();

            }

            SelectQuery<EipTGpdbRecordFile> query = Database.query(EipTGpdbRecordFile.class);
            Expression exp = ExpressionFactory.matchDbExp(EipTGpdbRecordFile.FILE_ID_PK_COLUMN,
                    Integer.valueOf(attachmentIndex));
            query.andQualifier(exp);

            List<EipTGpdbRecordFile> files = query.fetchList();
            if (files == null || files.size() == 0) {
                // ?? ID ???????
                logger.debug("[GpdbUtils] Not found ID...");
                throw new ALPageNotFoundException();
            }
            return files.get(0);
        } catch (Exception ex) {
            logger.error("[GpdbUtils]", ex);
            throw new ALDBErrorException();
        }
    }

    /**
     * ??
     * 
     * @param gpdbRecordId
     *          WebID
     * @return 
     */
    public static List<EipTGpdbRecordFile> getEipTGpdbRecordFileList(int gpdbRecordId) {

        // SQL
        SelectQuery<EipTGpdbRecordFile> query = Database.query(EipTGpdbRecordFile.class);
        query.setQualifier(ExpressionFactory.matchDbExp(EipTGpdbRecord.GPDB_RECORD_ID_PK_COLUMN, gpdbRecordId));

        return query.fetchList();
    }

    /**
     * ??
     * 
     * @param gpdbRecordId
     *          WebID
     * @return 
     */
    public static List<FileuploadBean> getAttachmentFiles(int gpdbRecordId) {

        List<EipTGpdbRecordFile> fileList = getEipTGpdbRecordFileList(gpdbRecordId);

        if (fileList != null && fileList.size() > 0) {

            List<FileuploadBean> attachmentFileList = new ArrayList<FileuploadBean>();
            FileuploadBean filebean = null;
            EipTGpdbRecordFile file = null;

            int size = fileList.size();
            for (int i = 0; i < size; i++) {
                file = fileList.get(i);
                String realname = file.getFileName();
                javax.activation.DataHandler hData = new javax.activation.DataHandler(
                        new javax.activation.FileDataSource(realname));

                filebean = new FileuploadBean();
                filebean.setFileId(file.getFileId().intValue());
                filebean.setFileName(realname);
                if (hData != null) {
                    filebean.setContentType(hData.getContentType());
                }
                filebean.setIsImage(FileuploadUtils.isImage(realname));
                attachmentFileList.add(filebean);
            }
            return attachmentFileList;
        }
        return new ArrayList<FileuploadBean>();
    }

    /**
     * 
     * PSML??????? value??????????PSML??
     * 
     * 
     * @param rundata
     * @param context
     * @param config
     * @return
     */
    public static String passPSML(RunData rundata, Context context, String key, String value) {
        VelocityPortlet portlet = ALEipUtils.getPortlet(rundata, context);
        PortletConfig config = portlet.getPortletConfig();
        if (value == null || "".equals(value)) {
            value = config != null ? config.getInitParameter(key) : "";
        } else {
            ALEipUtils.setPsmlParameters(rundata, context, key, value);
        }
        return value;
    }

}