com.aimluck.eip.project.ProjectTaskSelectData.java Source code

Java tutorial

Introduction

Here is the source code for com.aimluck.eip.project.ProjectTaskSelectData.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.project;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.jar.Attributes;

import org.apache.cayenne.DataRow;
import org.apache.commons.lang.StringUtils;
import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
import org.apache.jetspeed.services.logging.JetspeedLogger;
import org.apache.turbine.util.RunData;
import org.apache.velocity.context.Context;

import com.aimluck.commons.field.ALDateTimeField;
import com.aimluck.eip.cayenne.om.portlet.EipTProjectTask;
import com.aimluck.eip.cayenne.om.portlet.EipTProjectTaskFile;
import com.aimluck.eip.common.ALAbstractMultiFilterSelectData;
import com.aimluck.eip.common.ALDBErrorException;
import com.aimluck.eip.common.ALData;
import com.aimluck.eip.common.ALEipConstants;
import com.aimluck.eip.common.ALEipHolidaysManager;
import com.aimluck.eip.common.ALEipUser;
import com.aimluck.eip.common.ALPageNotFoundException;
import com.aimluck.eip.modules.actions.common.ALAction;
import com.aimluck.eip.orm.Database;
import com.aimluck.eip.orm.query.ResultList;
import com.aimluck.eip.orm.query.SQLTemplate;
import com.aimluck.eip.project.util.ProjectFile;
import com.aimluck.eip.project.util.ProjectFormUtils;
import com.aimluck.eip.project.util.ProjectUtils;
import com.aimluck.eip.util.ALEipUtils;

/**
 * ????? <BR>
 *
 */
public class ProjectTaskSelectData extends ALAbstractMultiFilterSelectData<EipTProjectTask, EipTProjectTask>
        implements ALData {

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

    /** ?? */
    private int taskCount;

    /** ? */
    private List<ProjectResultData> allProject;

    /** ????ID */
    private Integer selectedProjectId;

    /** ? */
    private final ProjectFile<EipTProjectTaskFile, EipTProjectTask> pfile = new ProjectFile<EipTProjectTaskFile, EipTProjectTask>(
            EipTProjectTaskFile.class);

    /** ? */
    private List<ALEipUser> projectMembers;

    /** From */
    private ALDateTimeField base_date_from;

    /** To */
    private ALDateTimeField base_date_to;

    /**  */
    private String target_keyword;

    /**  */
    private String target_user_id;

    /**  */
    private String target_tracker;

    /**  */
    private String target_priority;

    /**  */
    private String target_status;

    /** ?FROM */
    private String target_progress_rate_from;

    /** ?TO */
    private String target_progress_rate_to;

    /** ?? */
    private String target_delay;

    /**  */
    private String progress_line_checked;

    /** ? */
    private int viewDateMaxYear;

    /**  */
    private boolean indentFlg = true;

    private Calendar calFrom;

    private Calendar calTo;

    /** Android2???? */
    private boolean isAndroid2;

    private Integer loginUserId;

    private boolean isFileUploadable;

    /**
     * ?
     *
     * @param action
     *          ALAction
     * @param rundata
     *          RunData
     * @param context
     *          Context
     */
    @Override
    public void init(ALAction action, RunData rundata, Context context)
            throws ALPageNotFoundException, ALDBErrorException {

        // ??
        String resetCondition = rundata.getParameters().get("reset_condition");
        if (resetCondition != null && resetCondition.length() > 0) {
            ALEipUtils.setTemp(rundata, context, "target_keyword", "");
            ALEipUtils.setTemp(rundata, context, LIST_SORT_STR, "");
            ALEipUtils.setTemp(rundata, context, LIST_SORT_TYPE_STR, "");
        }

        allProject = ProjectUtils.getAllProject(); // 
        setProject(rundata, context);

        super.init(action, rundata, context);

        // 
        Calendar cal = Calendar.getInstance();
        viewDateMaxYear = cal.get(Calendar.YEAR) + 10;

        // ?
        if (0 != selectedProjectId.intValue()) {
            projectMembers = ProjectUtils.getProjectMembers(selectedProjectId);
        } else {
            projectMembers = ALEipUtils.getUsers("LoginUser");
        }

        // (From,To)
        calFrom = ProjectUtils.getViewCalendar(rundata, context, "base_date_from");
        calTo = ProjectUtils.getViewCalendar(rundata, context, "base_date_to");
        calFrom.set(Calendar.DAY_OF_MONTH, 1);
        calTo.set(Calendar.DAY_OF_MONTH, calTo.getActualMaximum(Calendar.DATE));
        base_date_from = new ALDateTimeField();
        base_date_to = new ALDateTimeField();
        base_date_from.setValue(calFrom.getTime());
        base_date_to.setValue(calTo.getTime());
        // 
        progress_line_checked = ProjectUtils.getParameter(rundata, context, "progress_line_checked");
        // ?Android2?True
        isAndroid2 = ALEipUtils.isAndroid2Browser(rundata);

        loginUserId = ALEipUtils.getUserId(rundata);

        isFileUploadable = ALEipUtils.isFileUploadable(rundata);
    }

    /**
     * ???? <BR>
     *
     * @param rundata
     *          RunData
     * @param context
     *          Context
     * @return ResultList
     */
    @Override
    protected ResultList<EipTProjectTask> selectList(RunData rundata, Context context) {

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

        setSessionParams(rundata, context);

        SQLTemplate<EipTProjectTask> sqltemp = null;
        SQLTemplate<EipTProjectTask> sqlCountTemp = null;

        sqltemp = Database.sql(EipTProjectTask.class, getFetchQuery(rundata, context));
        sqlCountTemp = Database.sql(EipTProjectTask.class, getCountQuery(rundata, context));
        setPostgresParams(sqltemp, sqlCountTemp);

        ResultList<EipTProjectTask> list = new ResultList<EipTProjectTask>();

        // ??
        List<DataRow> result = sqltemp.fetchListAsDataRow();
        for (int i = 0; i < result.size(); i++) {

            DataRow row = result.get(i);

            Object parentTaskId = row.get("parent_task_id");
            Object explanation = row.get("explanation");
            Object startPlanDate = row.get("start_plan_date");
            Object endPlanDate = row.get("end_plan_date");
            Object startDate = row.get("start_date");
            Object endDate = row.get("end_date");
            Object updateDate = row.get("update_date");

            EipTProjectTask task = new EipTProjectTask();
            // ID
            task.setTaskId(row.get("task_id").toString());
            // ??
            task.setTaskName(row.get("task_name").toString());
            // ID
            if (parentTaskId != null) {
                task.setParentTaskId(Integer.valueOf(parentTaskId.toString()));
            }
            // ID
            task.setProjectId(Integer.valueOf(row.get("project_id").toString()));
            // 
            task.setTracker(row.get("tracker").toString());
            // 
            if (explanation != null) {
                task.setExplanation(explanation.toString());
            }
            // 
            task.setStatus(row.get("status").toString());
            // 
            task.setPriority(row.get("priority").toString());
            // 
            if (startPlanDate == null) {
                task.setStartPlanDate(ProjectUtils.getEmptyDate());
            } else {
                task.setStartPlanDate((Date) startPlanDate);
            }
            // 
            if (endPlanDate == null) {
                task.setEndPlanDate(ProjectUtils.getEmptyDate());
            } else {
                task.setEndPlanDate((Date) endPlanDate);
            }
            // 
            if (startDate == null) {
                task.setStartDate(ProjectUtils.getEmptyDate());
            } else {
                task.setStartDate((Date) startDate);
            }
            // 
            if (endDate == null) {
                task.setEndDate(ProjectUtils.getEmptyDate());
            } else {
                task.setEndDate((Date) endDate);
            }
            // 
            task.setPlanWorkload(new BigDecimal(row.get("plan_workload").toString()));
            // ?
            task.setProgressRate(Integer.valueOf(row.get("progress_rate").toString()));
            // 
            task.setUpdateDate((Date) updateDate);
            // ??
            task.setIndent(Integer.valueOf(row.get("indent").toString()));

            list.add(task);
        }

        // ?
        int count = 0;
        List<DataRow> countResult = sqlCountTemp.fetchListAsDataRow();
        for (DataRow row : countResult) {
            Long tmp = (Long) row.get("count");
            count = tmp != null ? tmp.intValue() : 0;
        }

        // ?
        setPageParam(count);
        taskCount = count;

        // 
        if (!getWhereList().isEmpty()) {
            indentFlg = false;
        }

        return list;
    }

    private void setSessionParams(RunData rundata, Context context) {
        // 
        target_keyword = ProjectUtils.getParameter(rundata, context, "target_keyword");
        // 
        target_user_id = ProjectUtils.getParameter(rundata, context, "target_user_id");
        // 
        target_tracker = ProjectUtils.getParameter(rundata, context, "target_tracker");
        // 
        target_priority = ProjectUtils.getParameter(rundata, context, "target_priority");
        // 
        target_status = ProjectUtils.getParameter(rundata, context, "target_status");
        // ?FROM
        target_progress_rate_from = ProjectUtils.getParameter(rundata, context, "target_progress_rate_from");
        // ?TO
        target_progress_rate_to = ProjectUtils.getParameter(rundata, context, "target_progress_rate_to");
        // ??
        target_delay = ProjectUtils.getParameter(rundata, context, "target_delay");

        /** for sql injection */
        {
            if (isRejectParameter(target_user_id)) {
                target_user_id = "0";
            }

            if (isRejectParameter(target_tracker)) {
                target_tracker = "0";
            }

            if (isRejectParameter(target_priority)) {
                target_priority = "0";
            }

            if (isRejectParameter(target_status)) {
                target_status = "0";
            }

            if (isRejectParameter(target_progress_rate_from)) {
                target_progress_rate_from = "0";
            }

            if (isRejectParameter(target_progress_rate_to)) {
                target_progress_rate_to = "0";
            }
        }
    }

    private String getCommonSQL() {
        // -------------------------
        // SELECT?
        // -------------------------
        StringBuilder sb = new StringBuilder();
        sb.append("    FROM");
        sb.append("      eip_t_project_task AS task");
        sb.append("    WHERE ");
        if (0 != selectedProjectId) {
            sb.append("task.project_id = #bind($project_id) AND ");
        }
        sb.append("       task.parent_task_id IS NULL");
        return sb.toString();
    }

    private String getFetchQuery(RunData rundata, Context context) {

        StringBuilder sb = new StringBuilder();
        sb.append("SELECT");
        sb.append(" 0 AS indent");
        sb.append(", task.task_id"); // ID
        sb.append(", task.task_name"); // ??
        sb.append(", task.parent_task_id");// ID
        sb.append(", task.project_id");// ID
        sb.append(", task.tracker");// 
        sb.append(", task.explanation"); // 
        sb.append(", task.status"); // 
        sb.append(", task.priority"); // 
        sb.append(", task.start_plan_date"); // 
        sb.append(", task.end_plan_date"); // 
        sb.append(", task.start_date"); // 
        sb.append(", task.end_date"); // 
        sb.append(", task.plan_workload"); // 
        sb.append(", task.progress_rate"); // ?
        sb.append(", task.update_date"); // 
        sb.append(getCommonSQL());

        List<String> whereList = getWhereList();
        // WHERE?
        for (int i = 0; i < whereList.size(); i++) {
            sb.append(" AND ");
            sb.append(whereList.get(i));
        }

        sb.append(getOrderBy(rundata, context));
        sb.append(" LIMIT ").append(getRowsNum()).append(" OFFSET ").append((current_page - 1) * getRowsNum());
        return sb.toString();
    }

    private String getCountQuery(RunData rundata, Context context) {
        StringBuilder sb = new StringBuilder();
        sb.append("select count(task_id) AS count ");
        sb.append(getCommonSQL());

        List<String> whereList = getWhereList();
        // WHERE?
        for (int i = 0; i < whereList.size(); i++) {
            sb.append(" AND ");
            sb.append(whereList.get(i));
        }

        return sb.toString();
    }

    private List<String> getWhereList() {
        List<String> whereList = new ArrayList<String>();
        // 
        if (target_keyword != null && target_keyword.trim().length() > 0) {
            whereList.add(" task.task_name LIKE #bind($target_keyword)");
        }
        // 
        if (StringUtils.isNotEmpty(target_user_id) && !target_user_id.equals("all")) {
            StringBuilder where = new StringBuilder();
            where.append(" EXISTS(");
            where.append("   SELECT 0");
            where.append("     FROM eip_t_project_task_member AS member");
            where.append("    WHERE member.task_id = task.task_id");
            where.append("      AND member.user_id = #bind($target_user_id)");
            where.append(" )");
            whereList.add(String.valueOf(where));
        }
        // 
        if (StringUtils.isNotEmpty(target_tracker) && !target_tracker.equals("all")) {
            whereList.add(" task.tracker = #bind($target_tracker)");
        }
        // 
        if (StringUtils.isNotEmpty(target_priority) && !target_priority.equals("all")) {
            whereList.add(" task.priority = #bind($target_priority)");
        }
        // 
        if (StringUtils.isNotEmpty(target_status) && !target_status.equals("all")) {
            whereList.add(" task.status = #bind($target_status)");
        }
        // ?FROM
        if (StringUtils.isNotEmpty(target_progress_rate_from) && !target_progress_rate_from.equals("0")) {
            whereList.add(" task.progress_rate >= #bind($target_progress_rate_from)");
        }
        // ?TO
        if (StringUtils.isNotEmpty(target_progress_rate_to) && !target_progress_rate_to.equals("100")) {
            whereList.add(" task.progress_rate <= #bind($target_progress_rate_to)");
        }
        // ??
        if (StringUtils.isNotEmpty(target_delay) && target_delay.equals(ProjectUtils.FLG_ON)) {

            StringBuilder task_days = new StringBuilder();
            task_days.append(" CASE WHEN task.end_plan_date - task.start_plan_date + 1 < 0");
            task_days.append("    THEN 0");
            task_days.append("    ELSE task.end_plan_date - task.start_plan_date + 1");
            task_days.append("  END "); // 

            StringBuilder lapsed_days = new StringBuilder();
            lapsed_days.append(" CASE");
            lapsed_days.append("    WHEN task.start_plan_date IS NULL OR task.end_plan_date IS NULL");
            lapsed_days.append("      THEN 0");
            lapsed_days.append("    WHEN ").append(ProjectUtils.getCurrentDateWithCast())
                    .append(" < task.end_plan_date");
            lapsed_days.append("      THEN");
            lapsed_days.append("        CASE WHEN ").append(ProjectUtils.getCurrentDateWithCast())
                    .append(" - task.start_plan_date + 1 < 0");
            lapsed_days.append("          THEN 0");
            lapsed_days.append("          ELSE ").append(ProjectUtils.getCurrentDateWithCast())
                    .append(" - task.start_plan_date + 1");
            lapsed_days.append("        END");
            lapsed_days.append("      ELSE");
            lapsed_days.append("        task.end_plan_date - task.start_plan_date + 1");
            lapsed_days.append("  END "); // ????

            StringBuilder sb = new StringBuilder();

            sb.append(" ( ");
            sb.append(" ( " + task_days + " ) ");
            sb.append("  <> 0 AND ( ");
            sb.append(" ( " + lapsed_days + " ) ");
            sb.append(" * 100 / ");
            sb.append(" ( " + task_days + " ) ");
            sb.append(" > progress_rate ");
            sb.append(" ) ");
            sb.append(" ) ");
            whereList.add(sb.toString());
        }
        return whereList;
    }

    private void setPostgresParams(SQLTemplate<EipTProjectTask> sqltemp,
            SQLTemplate<EipTProjectTask> sqlCountTemp) {
        sqltemp.param("project_id", selectedProjectId);
        sqlCountTemp.param("project_id", selectedProjectId);

        // 
        if (StringUtils.isNotEmpty(target_keyword) && target_keyword.trim().length() > 0) {
            sqltemp.param("target_keyword", "%" + target_keyword + "%");
            sqlCountTemp.param("target_keyword", "%" + target_keyword + "%");
        }
        // 
        if (StringUtils.isNotEmpty(target_user_id) && !target_user_id.equals("all")) {
            sqltemp.param("target_user_id", Integer.valueOf(target_user_id));
            sqlCountTemp.param("target_user_id", Integer.valueOf(target_user_id));
        }
        // 
        if (StringUtils.isNotEmpty(target_tracker) && !target_tracker.equals("all")) {
            sqltemp.param("target_tracker", target_tracker);
            sqlCountTemp.param("target_tracker", target_tracker);
        }
        // 
        if (StringUtils.isNotEmpty(target_priority) && !target_priority.equals("all")) {
            sqltemp.param("target_priority", target_priority);
            sqlCountTemp.param("target_priority", target_priority);
        }
        // 
        if (StringUtils.isNotEmpty(target_status) && !target_status.equals("all")) {
            sqltemp.param("target_status", target_status);
            sqlCountTemp.param("target_status", target_status);
        }
        // ?FROM
        if (StringUtils.isNotEmpty(target_progress_rate_from) && !target_progress_rate_from.equals("0")) {
            sqltemp.param("target_progress_rate_from", Integer.valueOf(target_progress_rate_from));
            sqlCountTemp.param("target_progress_rate_from", Integer.valueOf(target_progress_rate_from));
        }
        // ?TO
        if (StringUtils.isNotEmpty(target_progress_rate_to) && !target_progress_rate_to.equals("100")) {
            sqltemp.param("target_progress_rate_to", Integer.valueOf(target_progress_rate_to));
            sqlCountTemp.param("target_progress_rate_to", Integer.valueOf(target_progress_rate_to));
        }
    }

    /**
     * ????
     *
     * @param crt
     * @return
     */
    protected String getOrderBy(RunData rundata, Context context) {

        String sort = ALEipUtils.getTemp(rundata, context, LIST_SORT_STR);
        String sort_type = ALEipUtils.getTemp(rundata, context, LIST_SORT_TYPE_STR);
        String crt_key = null;

        Attributes map = getColumnMap();
        if (sort != null && sort.length() > 0) {
            crt_key = map.getValue(sort);
        }

        current_sort = sort;
        current_sort_type = sort_type;

        if (crt_key != null && crt_key.length() > 0) {

            // ?
            indentFlg = false;

            if (sort_type != null && ALEipConstants.LIST_SORT_TYPE_DESC.equals(sort_type)) {
                return "  ORDER BY " + crt_key + " DESC";
            } else {
                return "  ORDER BY " + crt_key;
            }

        } else {
            return "  ORDER BY order_no";
        }
    }

    /**
     * ???? <BR>
     *
     * @param rundata
     *          RunData
     * @param context
     *          Context
     * @return 
     */
    @Override
    protected EipTProjectTask selectDetail(RunData rundata, Context context) {
        // ?
        return ProjectUtils.getEipTProjectTask(rundata, context);
    }

    /**
     * ResultData???? <BR>
     *
     * @param record
     *          
     * @return ResultData
     */
    @Override
    protected Object getResultData(EipTProjectTask record) {
        ProjectTaskResultData data = ProjectUtils.getProjectTaskResultData(record);
        Integer taskId = (int) data.getTaskId().getValue();

        // ?
        int cntChild = ProjectUtils.getCountChildrenTask(taskId);

        // ??2??true
        // ??
        data.setHasChildren(cntChild >= 2);

        // ?
        data.setHasChildrenForForm(cntChild > 0);

        // ?
        int lapsedDays = ProjectUtils.getLapsedDays(ProjectUtils.toString(record.getStartPlanDate()),
                ProjectUtils.toString(Calendar.getInstance().getTime()));
        // 
        int taskDays = ProjectUtils.getLapsedDays(ProjectUtils.toString(record.getStartPlanDate()),
                ProjectUtils.toString(record.getEndPlanDate()));
        data.setPlanTerm(taskDays);

        if (lapsedDays > taskDays) {
            // ???
            lapsedDays = taskDays;
        }

        // ?
        data.setPlanProgressRate(ProjectUtils.getPlanWorkload(lapsedDays, taskDays));

        // 
        List<ProjectTaskMemberResultData> memberList = data.getMemberList();
        BigDecimal workload = BigDecimal.valueOf(0);
        workload = workload.setScale(1);
        for (int i = 0; i < memberList.size(); i++) {
            ProjectTaskMemberResultData member = memberList.get(i);
            workload = workload.add(member.getWorkload());
        }
        data.setWorkload(workload);

        // 
        BigDecimal forecastWorkload = BigDecimal.valueOf(0);
        if (data.getProgressRate().getValue() != 0) {
            forecastWorkload = workload.multiply(BigDecimal.valueOf(100))
                    .divide(BigDecimal.valueOf(data.getProgressRate().getValue()), 2, BigDecimal.ROUND_HALF_UP);
        }
        data.setForecastWorkload(forecastWorkload);

        // 
        data.setIndentFlg(indentFlg);

        data.setEditable(ProjectFormUtils.isEditable(taskId, loginUserId));

        return data;
    }

    /**
     * ResultData???? <BR>
     *
     * @param record
     *          
     * @return ResultData
     */
    @Override
    protected Object getResultDataDetail(EipTProjectTask record) {
        ProjectTaskResultData data = ProjectUtils.getProjectTaskResultData(record);
        int taskId = (int) data.getTaskId().getValue();
        // 
        List<EipTProjectTaskFile> list = pfile.getSelectQueryForFiles(EipTProjectTask.TASK_ID_PK_COLUMN, taskId)
                .fetchList();
        data.setAttachmentFiles(pfile.getFileList(list));
        // 
        data.setCommentList(ProjectUtils.getProjectTaskCommentList("" + taskId));
        // ???
        data.setTopicPath(ProjectUtils.getTaskTopicPath(record.getProjectId()));
        // ID
        data.setLoginUserId(loginUserId.longValue());
        return data;
    }

    /**
     * ??
     *
     * @return 
     */
    @Override
    protected Attributes getColumnMap() {
        Attributes map = new Attributes();
        map.putValue("task_name", "task_name");
        map.putValue("tracker", "tracker");
        map.putValue("status", "status");
        map.putValue("workload", "workload");
        map.putValue("plan_workload", "plan_workload");
        map.putValue("start_plan_date", "start_plan_date");
        map.putValue("end_plan_date", "end_plan_date");
        map.putValue("progress_rate", "progress_rate");
        return map;
    }

    /**
     * ????
     *
     * @return ?
     */
    public int getTaskCount() {
        return taskCount;
    }

    /**
     * ??
     *
     * @return ?
     */
    public List<ProjectResultData> getAllProject() {
        return allProject;
    }

    /**
     * ????ID??
     *
     * @return ID
     */
    public Integer getSelectedProjectId() {
        return selectedProjectId;
    }

    /**
     * ?????
     *
     * @return ?
     */
    public List<ALEipUser> getProjectMembers() {
        return projectMembers;
    }

    /**
     * ??????
     *
     * @return 
     */
    public String getTargetKeyword() {
        return target_keyword;
    }

    /**
     * ??????
     *
     * @return 
     */
    public String getTargetUserId() {
        return target_user_id;
    }

    public String getTargetUserName() {
        if (!"".equals(getTargetUserId()) && getTargetUserId() != null) {
            try {
                return ALEipUtils.getALEipUser(Integer.parseInt(target_user_id)).getAliasName().toString();
            } catch (Exception e) {
                return null;

            }
        } else {
            return null;
        }
    }

    /**
     * ??????
     *
     * @return 
     */
    public String getTargetTracker() {
        return target_tracker;
    }

    public String getTargetTrackerName() {
        if (!"".equals(getTargetTracker()) && getTargetTracker() != null) {
            return getTrackerMap().get(target_tracker);
        } else {
            return null;
        }
    }

    /**
     * ??????
     *
     * @return 
     */
    public String getTargetPriority() {
        return target_priority;
    }

    public String getTargetPriorityName() {
        if (!"".equals(getTargetPriority()) && getTargetPriority() != null) {
            return getPriorityMap().get(target_priority);
        } else {
            return null;
        }
    }

    /**
     * ??????
     *
     * @return 
     */
    public String getTargetStatus() {
        return target_status;
    }

    public String getTargetStatusName() {
        if (!"".equals(getTargetStatus()) && getTargetStatus() != null) {
            return getStatusMap().get(target_status);
        } else {
            return null;
        }
    }

    /**
     * ???FROM????
     *
     * @return ?FROM
     */
    public String getTargetProgressRateFrom() {
        return target_progress_rate_from;
    }

    /**
     * ???TO????
     *
     * @return ?TO
     */
    public String getTargetProgressRateTo() {
        return target_progress_rate_to;
    }

    /**
     * ????????
     *
     * @return ??
     */
    public String getTargetDelay() {
        return target_delay;
    }

    /**
     * ????
     *
     * @return 
     */
    public String getProgressLineChecked() {
        return progress_line_checked;
    }

    /**
     * Android2???????
     *
     * @return Android2????
     */
    public boolean isAndroid2() {
        return isAndroid2;
    }

    /**
     * ???
     *
     * @return 
     */
    public int getViewDateMaxYear() {
        return viewDateMaxYear;
    }

    /**
     * From??
     *
     * @return From
     */
    public ALDateTimeField getBaseDateFrom() {
        return base_date_from;
    }

    /**
     * To??
     *
     * @return To
     */
    public ALDateTimeField getBaseDateTo() {
        return base_date_to;
    }

    /**
     * From???
     *
     * @return From?
     */
    public int getBaseDateFromYear() {
        return calFrom.get(Calendar.YEAR);
    }

    /**
     * To???
     *
     * @return To?
     */
    public int getBaseDateToYear() {
        return calTo.get(Calendar.YEAR);
    }

    /**
     * ????
     *
     * @return ?
     */
    public int getDay(int days) {
        Calendar cal = (Calendar) calFrom.clone();
        cal.add(Calendar.DAY_OF_MONTH, days - 1);
        return cal.get(Calendar.DAY_OF_MONTH);
    }

    /**
     * ??????
     *
     * @return TRUE:??
     */
    public boolean isToday(int days) {
        Calendar today = Calendar.getInstance();
        Calendar cal = (Calendar) calFrom.clone();
        cal.add(Calendar.DAY_OF_MONTH, days - 1);

        return today.get(Calendar.YEAR) == cal.get(Calendar.YEAR)
                && today.get(Calendar.MONTH) == cal.get(Calendar.MONTH)
                && today.get(Calendar.DAY_OF_MONTH) == cal.get(Calendar.DAY_OF_MONTH);
    }

    /**
     * ???
     *
     * @return 
     */
    public int getDays() {
        return ProjectUtils.getLapsedDays(calFrom, calTo);
    }

    /**
     * ???
     *
     * @return 
     */
    public int getDays(Date dateTo) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateTo);
        return ProjectUtils.getLapsedDays(calFrom, cal);
    }

    /**
     * ??
     *
     * @return ?
     */
    public int getYear(int days) {
        Calendar cal = (Calendar) calFrom.clone();
        cal.add(Calendar.DAY_OF_MONTH, days - 1);
        return cal.get(Calendar.YEAR);
    }

    /**
     * ??
     *
     * @return 
     */
    public int getMonth(int days) {
        Calendar cal = (Calendar) calFrom.clone();
        cal.add(Calendar.DAY_OF_MONTH, days - 1);
        return cal.get(Calendar.MONTH);
    }

    /**
     * ??
     *
     * @return ?
     */
    public int getWeek(int days) {
        Calendar cal = (Calendar) calFrom.clone();
        cal.add(Calendar.DAY_OF_MONTH, days - 1);
        return cal.get(Calendar.WEEK_OF_YEAR);
    }

    /**
     * ???
     *
     * @return 
     */
    public Map<String, String> getTrackerMap() {
        return ProjectUtils.getKubunMap("tracker");
    }

    /**
     * ???
     *
     * @return 
     */
    public Map<String, String> getStatusMap() {
        return ProjectUtils.getKubunMap("status");
    }

    /**
     * ???
     *
     * @return 
     */
    public Map<String, String> getPriorityMap() {
        return ProjectUtils.getKubunMap("priority");
    }

    /**
     * ?? long ???
     *
     * @return ?? long 
     */
    public long getNowTime() {
        return Calendar.getInstance().getTimeInMillis();
    }

    /**
     * ??????
     *
     * @return TRUE:??
     */

    public boolean isHoliday(int days) {
        Calendar cal = (Calendar) calFrom.clone();
        cal.add(Calendar.DAY_OF_MONTH, days - 1);

        // ??????
        ALEipHolidaysManager holidaysManager = ALEipHolidaysManager.getInstance();
        return holidaysManager.isHoliday(cal.getTime()) != null;
    }

    /**
     * ??????
     *
     * @return TRUE:??
     */

    public boolean isSaturday(int days) {
        Calendar cal = (Calendar) calFrom.clone();
        cal.add(Calendar.DAY_OF_MONTH, days - 1);
        return Calendar.SATURDAY == cal.get(Calendar.DAY_OF_WEEK);
    }

    /**
     * ??????
     *
     * @return TRUE:??
     */

    public boolean isSunday(int days) {
        Calendar cal = (Calendar) calFrom.clone();
        cal.add(Calendar.DAY_OF_MONTH, days - 1);
        return Calendar.SUNDAY == cal.get(Calendar.DAY_OF_WEEK);
    }

    /**
     * ??
     *
     * @return 
     */
    public String getViewtype() {
        return "project";
    }

    private boolean isRejectParameter(String numeric) {
        return StringUtils.isNotEmpty(numeric) && !"all".equals(numeric) && !StringUtils.isNumeric(numeric);
    }

    public void setProject(RunData rundata, Context context) {
        // validate projectId and reset projectId

        String filter = rundata.getParameters().getString("filter", "");
        String filterType = rundata.getParameters().getString("filtertype", "");
        String sesFilter = ALEipUtils.getTemp(rundata, context, LIST_FILTER_STR);
        String sesFilterType = ALEipUtils.getTemp(rundata, context, LIST_FILTER_TYPE_STR);

        sesFilter = sesFilter == null ? "" : sesFilter;
        sesFilterType = sesFilterType == null ? "" : sesFilterType;

        if (filterType.isEmpty()) {
            filter = sesFilter;
            filterType = sesFilterType;
        }

        if (StringUtils.isEmpty(filter) || StringUtils.isEmpty(filterType)) {
            selectedProjectId = 0;
            setFilter(rundata, context);
            return;
        }

        boolean existProject = false;
        for (ProjectResultData data : allProject) {
            if (filter.equals(data.getProjectId().toString())) {
                existProject = true;
                break;
            }
        }

        if (!existProject) {
            selectedProjectId = 0;
        } else {
            selectedProjectId = Integer.valueOf(filter);
        }
        setFilter(rundata, context);

    }

    private void setFilter(RunData rundata, Context context) {
        ALEipUtils.setTemp(rundata, context, LIST_FILTER_STR, String.valueOf(selectedProjectId));
        ALEipUtils.setTemp(rundata, context, LIST_FILTER_TYPE_STR, "project_id");
    }

    /**
     * @return isFileUploadable
     */
    public boolean isFileUploadable() {
        return isFileUploadable;
    }

}