Example usage for org.springframework.beans BeanUtils copyProperties

List of usage examples for org.springframework.beans BeanUtils copyProperties

Introduction

In this page you can find the example usage for org.springframework.beans BeanUtils copyProperties.

Prototype

public static void copyProperties(Object source, Object target) throws BeansException 

Source Link

Document

Copy the property values of the given source bean into the target bean.

Usage

From source file:tw.edu.chit.struts.action.language.ReportPrintAction.java

/**
 * ???//from ww  w. j a  va2 s.  com
 * 
 * @param mapping org.apache.struts.action.ActionMapping object
 * @param form org.apache.struts.action.ActionForm object
 * @param request request javax.servlet.http.HttpServletRequest object
 * @param response response javax.servlet.http.HttpServletResponse object
 * @param sterm 
 */
@SuppressWarnings("unchecked")
private void printDeptStdSkillList2(ActionMapping mapping, DynaActionForm form, HttpServletRequest request,
        HttpServletResponse response, String sterm) throws Exception {

    HttpSession session = request.getSession(false);
    AdminManager am = (AdminManager) getBean(IConstants.ADMIN_MANAGER_BEAN_NAME);
    MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME);

    Member member = (Member) getUserCredential(session).getMember();
    Empl empl = mm.findEmplByOid(member.getOid());
    ServletContext context = request.getSession().getServletContext();

    DateFormat df = new SimpleDateFormat("yyyy/MM/dd");
    Calendar cal = Calendar.getInstance();
    Calendar cal1 = (Calendar) cal.clone();
    Calendar cal2 = (Calendar) cal.clone();
    if (StringUtils.isNotBlank(form.getString("licenseValidDateStart"))
            || StringUtils.isNotBlank(form.getString("licenseValidDateEnd"))) {
        Date from = StringUtils.isBlank(form.getString("licenseValidDateStart")) ? null
                : Toolket.parseNativeDate(form.getString("licenseValidDateStart"));
        // ???
        Date to = StringUtils.isBlank(form.getString("licenseValidDateEnd")) ? Calendar.getInstance().getTime()
                : Toolket.parseNativeDate(form.getString("licenseValidDateEnd"));

        cal1.setTime(from);
        cal1.set(Calendar.HOUR_OF_DAY, 0);
        cal1.set(Calendar.MINUTE, 0);
        cal1.set(Calendar.SECOND, 0);
        cal1.set(Calendar.MILLISECOND, 0);

        cal2.setTime(to);
        cal2.set(Calendar.HOUR_OF_DAY, 23);
        cal2.set(Calendar.MINUTE, 59);
        cal2.set(Calendar.SECOND, 59);
        cal2.set(Calendar.MILLISECOND, 999);
    }

    String hql = "FROM StdSkill s WHERE s.amountDate IS NOT NULL AND s.deptNo = ? "
            + "AND s.licenseValidDate BETWEEN ? AND ? ORDER BY s.studentNo";

    List<StdSkill> skills = (List<StdSkill>) am.find(hql, new Object[] { "0", cal1.getTime(), cal2.getTime() }); // 

    File templateXLS = new File(context.getRealPath("/WEB-INF/reports/DeptStdSkillList2.xls"));
    HSSFWorkbook workbook = Toolket.getHSSFWorkbook(templateXLS);
    HSSFSheet sheet = workbook.getSheetAt(0);

    // Header
    Toolket.setCellValue(sheet, 0, 0,
            "?" + Toolket.getEmpUnit(empl.getUnit())
                    + "??? (" + df.format(cal1.getTime()) + "~"
                    + df.format(cal2.getTime()) + ")");

    int index = 2;
    Student student = null;
    Graduate graduate = null;
    List<LicenseCode> codes = null;
    List<LicenseCode961> code961s = null;
    LicenseCode code = null;
    LicenseCode961 code961 = null;
    String checkStr1 = "???\n?\n???";
    String checkStr2 = "?\n?";

    for (StdSkill skill : skills) {

        student = mm.findStudentByNo(skill.getStudentNo());
        if (student == null) {
            graduate = mm.findGraduateByStudentNo(skill.getStudentNo());
            if (graduate != null) {
                student = new Student();
                BeanUtils.copyProperties(graduate, student);
            }
        }

        if (student != null || graduate != null) {
            Toolket.setCellValue(sheet, index, 0, String.valueOf(index - 1));
            Toolket.setCellValue(sheet, index, 1, StringUtils.isBlank(student.getDepartClass()) ? ""
                    : Toolket.getSchoolName(student.getDepartClass()));
            Toolket.setCellValue(sheet, index, 2, Toolket.getClassFullName(student.getDepartClass()));
            Toolket.setCellValue(sheet, index, 3, student.getStudentNo());
            Toolket.setCellValue(sheet, index, 4, student.getStudentName());
            Toolket.setCellValue(sheet, index, 5, student.getIdno());
            Toolket.setCellValue(sheet, index, 9, String.valueOf(skill.getAmount()));
            Toolket.setCellValue(sheet, index, 10, "");
            Toolket.setCellValue(sheet, index, 11, checkStr1);
            Toolket.setCellValue(sheet, index, 12, checkStr2);

            codes = (List<LicenseCode>) am
                    .findLicenseCodesBy(new LicenseCode(Integer.valueOf(skill.getLicenseCode())));

            if (!codes.isEmpty()) {
                code = codes.get(0);
                Toolket.setCellValue(sheet, index, 6, code.getName());
                Toolket.setCellValue(sheet, index, 7, code.getDeptName());
                Toolket.setCellValue(sheet, index, 8, code.getLevel());
            } else {
                code961s = (List<LicenseCode961>) am
                        .findLicenseCode961sBy(new LicenseCode961(Integer.valueOf(skill.getLicenseCode())));
                if (!code961s.isEmpty()) {
                    code961 = code961s.get(0);
                    Toolket.setCellValue(sheet, index, 6, code961.getName());
                    Toolket.setCellValue(sheet, index, 7, code961.getDeptName());
                    Toolket.setCellValue(sheet, index, 8, code961.getLevel());
                }
            }

            index++;
        }
    }

    File tempDir = new File(
            context.getRealPath("/WEB-INF/reports/temp/" + getUserCredential(session).getMember().getIdno()
                    + (new SimpleDateFormat("yyyyMMdd").format(new Date()))));
    if (!tempDir.exists())
        tempDir.mkdirs();

    File output = new File(tempDir, "DeptStdSkillList2.xls");
    FileOutputStream fos = new FileOutputStream(output);
    workbook.write(fos);
    fos.close();

    JasperReportUtils.printXlsToFrontEnd(response, output);
    output.delete();
    tempDir.delete();
}