Example usage for org.hibernate.criterion Restrictions between

List of usage examples for org.hibernate.criterion Restrictions between

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions between.

Prototype

public static Criterion between(String propertyName, Object low, Object high) 

Source Link

Document

Apply a "between" constraint to the named property

Usage

From source file:top.sj.dao.impl.ArticlesDaoImpl.java

License:Open Source License

/**
 * ??//w w w.j a va 2s . c  o m
 */
@SuppressWarnings("unchecked")
@Override
public List<SjArticles> getArticlesAccordingToCreateDateSplitPage(final Integer pageIndex,
        final Integer pageSize, String datetimePartion) {
    List<SjArticles> articles = null;
    // ??
    final Date startDate = CalendarTool.getFirstDateTimeFromStringDateResourceAtThisMonth(datetimePartion);

    // ???
    final Date endDate = CalendarTool.getLastDateTimeFromStringDateResourceAtThisMonth(datetimePartion);

    try {
        articles = super.getHibernateTemplate().executeFind(new HibernateCallback<List<SjArticles>>() {
            public List<SjArticles> doInHibernate(Session session) {
                return session.createCriteria(SjArticles.class).setCacheable(true)
                        .add(Restrictions.between("ACreatedate", startDate, endDate))
                        .setFirstResult((pageIndex - 1) * pageSize).setMaxResults(pageSize).list();
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
        System.err.println(e.getMessage());
    }

    return articles;
}

From source file:top.sj.manage.dao.impl.CommentsOrReplyDaoImpl.java

License:Open Source License

/**
 * ?/??//from  ww  w  . ja v a 2s. c o  m
 */
@SuppressWarnings("unchecked")
@Override
public List<SjLeavemessages> getCOrRInfoBySplitPage(final Integer pageIndex, final Integer pageSize,
        final Date searchStartDate, final Date searchEndDate, final Integer searchVerifyStatusId) {
    List<SjLeavemessages> leavemessages = null;
    try {
        leavemessages = super.getHibernateTemplate()
                .executeFind(new HibernateCallback<List<SjLeavemessages>>() {
                    public List<SjLeavemessages> doInHibernate(Session session) {
                        Criteria criteria = session.createCriteria(SjLeavemessages.class).setCacheable(true);
                        if (null != searchStartDate && null != searchEndDate) {
                            criteria.add(Restrictions.between("MPublishdate", searchStartDate, searchEndDate));
                        } else if (null != searchStartDate) {
                            criteria.add(Restrictions.ge("MPublishdate", searchStartDate));
                        }
                        if (null != searchVerifyStatusId) {
                            criteria.add(Restrictions.eq("MVerifystate", searchVerifyStatusId));
                        }

                        return criteria.setFirstResult((pageIndex - 1) * pageSize).setMaxResults(pageSize)
                                .list();
                    }
                });
    } catch (Exception e) {
        e.printStackTrace();
        System.err.println(e.getMessage());
    }
    return leavemessages;
}

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

/**
 * ?//  w ww .  ja  va  2 s.  c o m
 * 
 * @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 printStdSkillList(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);
    CourseManager cm = (CourseManager) getBean(IConstants.COURSE_MANAGER_BEAN_NAME);
    MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME);
    DynaActionForm aForm = (DynaActionForm) form;
    ServletContext context = request.getSession().getServletContext();

    StdSkill skill = new StdSkill();
    skill.setAmount(null); // ??
    Example example = Example.create(skill).ignoreCase().enableLike(MatchMode.ANYWHERE);
    List<Order> orders = new LinkedList<Order>();
    orders.add(Order.asc("schoolYear"));
    orders.add(Order.asc("schoolTerm"));
    orders.add(Order.asc("studentNo"));

    List<Criterion> cris = new LinkedList<Criterion>();
    Criterion cri = null;

    if (aForm.getStrings("year").length != 0) {
        cri = Restrictions.eq("schoolYear", aForm.getStrings("year")[0]);
        cris.add(cri);
    }

    if (StringUtils.isNotBlank(aForm.getString("sterm"))) {
        cri = Restrictions.eq("schoolTerm", aForm.getString("sterm"));
        cris.add(cri);
    }

    if (StringUtils.isNotBlank(aForm.getString("deptCodeOpt"))) {
        cri = Restrictions.eq("deptNo", aForm.getString("deptCodeOpt"));
        cris.add(cri);
    }

    if (StringUtils.isNotBlank(aForm.getString("licenseValidDateStart"))
            || StringUtils.isNotBlank(aForm.getString("licenseValidDateEnd"))) {
        Date from = StringUtils.isBlank(aForm.getString("licenseValidDateStart")) ? null
                : Toolket.parseNativeDate(aForm.getString("licenseValidDateStart"));
        // ???
        Date to = StringUtils.isBlank(aForm.getString("licenseValidDateEnd")) ? Calendar.getInstance().getTime()
                : Toolket.parseNativeDate(aForm.getString("licenseValidDateEnd"));

        if (from != null) {
            cri = Restrictions.between("licenseValidDate", from, to);
            cris.add(cri);
        }
    }

    List<StdSkill> skills = (List<StdSkill>) am.findSQLWithCriteria(StdSkill.class, example, null, orders,
            cris);

    int index = 2;
    List<LicenseCode> codes = null;
    Student student = null;
    Graduate graduate = null;
    Empl empl = null;
    DEmpl dempl = null;
    Csno csno = null;
    DateFormat df = new SimpleDateFormat("yyyy/MM/dd");
    DateFormat df1 = new SimpleDateFormat("yyyy/MM");

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

    for (StdSkill ss : skills) {
        codes = (List<LicenseCode>) am
                .findLicenseCodesBy(new LicenseCode(Integer.valueOf(ss.getLicenseCode())));

        if (!codes.isEmpty())
            ss.setLicense(codes.get(0));

        student = mm.findStudentByNo(ss.getStudentNo().trim());
        if (student == null) {
            graduate = mm.findGraduateByStudentNo(ss.getStudentNo().trim());
            if (graduate != null) {
                ss.setStudentName(graduate.getStudentName().trim());
                ss.setDepartClass(Toolket.getClassFullName(graduate.getDepartClass()));
            }
        } else {
            ss.setStudentName(student.getStudentName().trim());
            ss.setDepartClass(Toolket.getClassFullName(student.getDepartClass()));
        }

        Toolket.setCellValue(sheet, index, 0, ss.getSchoolYear() + "." + ss.getSchoolTerm());
        Toolket.setCellValue(sheet, index, 1, ss.getStudentNo().toUpperCase());
        Toolket.setCellValue(sheet, index, 2, ss.getStudentName());
        Toolket.setCellValue(sheet, index, 3, ss.getDepartClass());
        Toolket.setCellValue(sheet, index, 4, ss.getLicense().getCode().toString());
        Toolket.setCellValue(sheet, index, 5, ss.getLicense().getName().trim());
        Toolket.setCellValue(sheet, index, 6, ss.getLicense().getLocale().toString());
        Toolket.setCellValue(sheet, index, 7, ss.getLicense().getLevel().trim());
        Toolket.setCellValue(sheet, index, 8, ss.getLicense().getType().toString());
        Toolket.setCellValue(sheet, index, 9, ss.getAmount().toString());
        Toolket.setCellValue(sheet, index, 10, Toolket.getAmountType(ss.getAmountType()));
        Toolket.setCellValue(sheet, index, 11,
                ss.getAmountDate() == null ? "" : df1.format(ss.getAmountDate()));
        Toolket.setCellValue(sheet, index, 12, ss.getLicenseNo());
        Toolket.setCellValue(sheet, index, 13, df.format(ss.getLicenseValidDate()));

        if (StringUtils.isBlank(ss.getCscode())) {
            csno = cm.findCourseInfoByCscode(ss.getCscode());
            if (csno != null)
                Toolket.setCellValue(sheet, index, 14, csno.getChiName().trim());
        } else
            Toolket.setCellValue(sheet, index, 14, "");

        if (StringUtils.isBlank(ss.getTechIdno())) {
            empl = mm.findEmplByIdno(ss.getTechIdno());
            if (empl != null)
                Toolket.setCellValue(sheet, index, 15, empl.getEname().trim());
            else {
                dempl = mm.findDEmplByIdno(ss.getTechIdno());
                if (dempl != null)
                    Toolket.setCellValue(sheet, index, 15, dempl.getEname().trim());
            }
        } else
            Toolket.setCellValue(sheet, index, 15, "");

        Toolket.setCellValue(sheet, index, 16, ss.getSerialNo());
        Toolket.setCellValue(sheet, index, 17, Toolket.getCustomNo(ss.getCustomNo()));
        Toolket.setCellValue(sheet, index++, 18, Toolket.getPass(ss.getPass()));
    }

    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, "StdSkillList.xls");
    FileOutputStream fos = new FileOutputStream(output);
    workbook.write(fos);
    fos.close();

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

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

/**
 * ?()/*from www .  ja v a 2  s .c o  m*/
 * 
 * @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 printDeptStdSkillList(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);
    CourseManager cm = (CourseManager) getBean(IConstants.COURSE_MANAGER_BEAN_NAME);
    MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME);
    CourseManager manager = (CourseManager) getBean("courseManager");

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

    CodeEmpl codeEmpl = new CodeEmpl();
    codeEmpl.setIdno(empl.getUnit());
    Example example4CodeEmpl = Example.create(codeEmpl).ignoreCase().enableLike(MatchMode.START);
    List<CodeEmpl> codeEmpls = (List<CodeEmpl>) am.findSQLWithCriteria(CodeEmpl.class, example4CodeEmpl, null,
            null);

    List<StdSkill> skills = null;
    StdSkill skill = new StdSkill();
    skill.setAmount(null); // ??
    Example example = Example.create(skill).ignoreCase().enableLike(MatchMode.ANYWHERE);
    List<Order> orders = new LinkedList<Order>();
    orders.add(Order.asc("schoolYear"));
    orders.add(Order.asc("schoolTerm"));
    orders.add(Order.asc("studentNo"));

    Criterion deptNo = Restrictions.eq("deptNo", codeEmpls.get(0).getIdno2().trim()); // 

    DateFormat df = new SimpleDateFormat("yyyy/MM/dd");
    if (StringUtils.isNotBlank(form.getString("licenseValidDateStart"))
            || StringUtils.isNotBlank(form.getString("licenseValidDateEnd"))) {

        Calendar cal = Calendar.getInstance();
        Calendar cal1 = (Calendar) cal.clone();
        Calendar cal2 = (Calendar) cal.clone();

        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);

        Criterion licenseValidDate = Restrictions.between("licenseValidDate", cal1.getTime(), cal2.getTime());
        skills = (List<StdSkill>) am.findSQLWithCriteria(StdSkill.class, example, null, orders, deptNo,
                licenseValidDate);
    } else
        skills = (List<StdSkill>) am.findSQLWithCriteria(StdSkill.class, example, null, orders, deptNo);

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

    int index = 2;
    List<LicenseCode> codes = null;
    Student student = null;
    Graduate graduate = null;
    DEmpl dempl = null;
    Csno csno = null;
    DateFormat df1 = new SimpleDateFormat("yyyy/MM");
    for (StdSkill ss : skills) {
        codes = (List<LicenseCode>) am.findLicenseCodesBy(new LicenseCode(String.valueOf(ss.getLicenseCode())));

        if (!codes.isEmpty())
            ss.setLicense(codes.get(0));

        student = mm.findStudentByNo(ss.getStudentNo().trim());
        if (student == null) {
            graduate = mm.findGraduateByStudentNo(ss.getStudentNo().trim());
            if (graduate != null) {
                ss.setStudentName(graduate.getStudentName().trim());
                ss.setDepartClass(Toolket.getClassFullName(graduate.getDepartClass()));
            }
        } else {
            ss.setStudentName(student.getStudentName().trim());
            ss.setDepartClass(Toolket.getClassFullName(student.getDepartClass()));
        }

        Toolket.setCellValue(sheet, index, 0, ss.getSchoolYear() + "." + ss.getSchoolTerm());
        Toolket.setCellValue(sheet, index, 1, ss.getStudentNo().toUpperCase());
        Toolket.setCellValue(sheet, index, 2, ss.getStudentName());
        Toolket.setCellValue(sheet, index, 3, ss.getDepartClass());
        Toolket.setCellValue(sheet, index, 4, ss.getLicense().getCode().trim());
        Toolket.setCellValue(sheet, index, 5, ss.getLicense().getDeptName().trim());
        Toolket.setCellValue(sheet, index, 6, ss.getLicense().getName().trim());
        //Toolket.setCellValue(sheet, index, 7, ss.getLicense().getLocale()
        //      .toString());
        String locale = manager
                .ezGetString("SELECT Locale FROM LicenseCode WHERE Code='" + ss.getLicenseCode() + "'");
        String localename = "";
        if (locale.equals("1"))
            localename = "";
        if (locale.equals("2"))
            localename = "";
        if (locale.equals("3"))
            localename = "??";
        Toolket.setCellValue(sheet, index, 7, localename);
        Toolket.setCellValue(sheet, index, 8, ss.getLicense().getLevel().trim());
        //Toolket.setCellValue(sheet, index, 9, ss.getLicense().getType()
        //      .toString());
        String Type = manager
                .ezGetString("SELECT Type FROM LicenseCode WHERE Code='" + ss.getLicenseCode() + "'");
        String Typename = "";
        if (Type.equals("1"))
            Typename = "?";
        if (Type.equals("2"))
            Typename = "";
        if (Type.equals("3"))
            Typename = "";
        if (Type.equals("4"))
            Typename = "";
        Toolket.setCellValue(sheet, index, 9, Typename);
        Toolket.setCellValue(sheet, index, 10, ss.getAmount().toString());
        Toolket.setCellValue(sheet, index, 11, Toolket.getAmountType(ss.getAmountType()));
        Toolket.setCellValue(sheet, index, 12,
                ss.getAmountDate() == null ? "" : df1.format(ss.getAmountDate()));
        Toolket.setCellValue(sheet, index, 13, ss.getLicenseNo());
        Toolket.setCellValue(sheet, index, 14, df.format(ss.getLicenseValidDate()));

        if (StringUtils.isNotBlank(ss.getCscode())) {
            csno = cm.findCourseInfoByCscode(ss.getCscode());
            if (csno != null)
                Toolket.setCellValue(sheet, index, 15, csno.getChiName().trim());
        } else
            Toolket.setCellValue(sheet, index, 15, "");

        if (StringUtils.isNotBlank(ss.getTechIdno())) {
            empl = mm.findEmplByIdno(ss.getTechIdno());
            if (empl != null)
                Toolket.setCellValue(sheet, index, 16, empl.getCname().trim());
            else {
                dempl = mm.findDEmplByIdno(ss.getTechIdno());
                if (dempl != null)
                    Toolket.setCellValue(sheet, index, 16, dempl.getCname().trim());
            }
        } else
            Toolket.setCellValue(sheet, index, 16, "");

        Toolket.setCellValue(sheet, index, 17, ss.getSerialNo());
        Toolket.setCellValue(sheet, index, 18, Toolket.getCustomNo(ss.getCustomNo()));
        Toolket.setCellValue(sheet, index, 19, Toolket.getPass(ss.getPass()));
        Toolket.setCellValue(sheet, index++, 20, Toolket.getApplyType(ss.getApplyType()));
    }

    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, "DeptStdSkillList.xls");
    FileOutputStream fos = new FileOutputStream(output);
    workbook.write(fos);
    fos.close();

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

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

/**
 * ?//  w w  w .ja  v a 2s. c  om
 * 
 * @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 printDeptGStdSkillList(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);
    CourseManager cm = (CourseManager) getBean(IConstants.COURSE_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();

    CodeEmpl codeEmpl = new CodeEmpl();
    codeEmpl.setIdno(empl.getUnit());
    Example example4CodeEmpl = Example.create(codeEmpl).ignoreCase().enableLike(MatchMode.START);
    List<CodeEmpl> codeEmpls = (List<CodeEmpl>) am.findSQLWithCriteria(CodeEmpl.class, example4CodeEmpl, null,
            null);

    List<StdSkill> skills = null;
    StdSkill skill = new StdSkill();
    skill.setAmount(null); // ??
    Example example = Example.create(skill).ignoreCase().enableLike(MatchMode.ANYWHERE);
    List<Order> orders = new LinkedList<Order>();
    orders.add(Order.asc("schoolYear"));
    orders.add(Order.asc("schoolTerm"));
    orders.add(Order.asc("studentNo"));

    Criterion deptNo = Restrictions.eq("deptNo", codeEmpls.get(0).getIdno2().trim()); // 

    DateFormat df = new SimpleDateFormat("yyyy/MM/dd");
    if (StringUtils.isNotBlank(form.getString("licenseValidDateStart"))
            || StringUtils.isNotBlank(form.getString("licenseValidDateEnd"))) {

        Calendar cal = Calendar.getInstance();
        Calendar cal1 = (Calendar) cal.clone();
        Calendar cal2 = (Calendar) cal.clone();

        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);

        Criterion licenseValidDate = Restrictions.between("licenseValidDate", cal1.getTime(), cal2.getTime());
        skills = (List<StdSkill>) am.findSQLWithCriteria(StdSkill.class, example, null, orders, deptNo,
                licenseValidDate);
    } else
        skills = (List<StdSkill>) am.findSQLWithCriteria(StdSkill.class, example, null, orders, deptNo);

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

    int index = 2;
    List<LicenseCode> codes = null;
    Student student = null;
    Graduate graduate = null;
    DEmpl dempl = null;
    Csno csno = null;
    DateFormat df1 = new SimpleDateFormat("yyyy/MM");
    for (StdSkill ss : skills) {
        codes = (List<LicenseCode>) am.findLicenseCodesBy(new LicenseCode(String.valueOf(ss.getLicenseCode())));

        if (!codes.isEmpty())
            ss.setLicense(codes.get(0));

        student = mm.findStudentByNo(ss.getStudentNo().trim());
        if (student == null) {
            graduate = mm.findGraduateByStudentNo(ss.getStudentNo().trim());
            if (graduate != null) {
                ss.setStudentName(graduate.getStudentName().trim());
                ss.setDepartClass(Toolket.getClassFullName(graduate.getDepartClass()));
            }
        } else {
            ss.setStudentName(student.getStudentName().trim());
            ss.setDepartClass(Toolket.getClassFullName(student.getDepartClass()));
        }

        Toolket.setCellValue(sheet, index, 0, ss.getSchoolYear() + "." + ss.getSchoolTerm());
        Toolket.setCellValue(sheet, index, 1, ss.getStudentNo().toUpperCase());
        Toolket.setCellValue(sheet, index, 2, ss.getStudentName());
        Toolket.setCellValue(sheet, index, 3, ss.getDepartClass());
        Toolket.setCellValue(sheet, index, 4, ss.getLicense().getCode().trim());
        Toolket.setCellValue(sheet, index, 5, ss.getLicense().getDeptName().trim());
        Toolket.setCellValue(sheet, index, 6, ss.getLicense().getName().trim());
        Toolket.setCellValue(sheet, index, 7, ss.getLicense().getLocale().toString());
        Toolket.setCellValue(sheet, index, 8, ss.getLicense().getLevel().trim());
        Toolket.setCellValue(sheet, index, 9, ss.getLicense().getType().toString());
        Toolket.setCellValue(sheet, index, 10, ss.getAmount().toString());
        Toolket.setCellValue(sheet, index, 11, Toolket.getAmountType(ss.getAmountType()));
        Toolket.setCellValue(sheet, index, 12,
                ss.getAmountDate() == null ? "" : df1.format(ss.getAmountDate()));
        Toolket.setCellValue(sheet, index, 13, ss.getLicenseNo());
        Toolket.setCellValue(sheet, index, 14, df.format(ss.getLicenseValidDate()));

        if (StringUtils.isNotBlank(ss.getCscode())) {
            csno = cm.findCourseInfoByCscode(ss.getCscode());
            if (csno != null)
                Toolket.setCellValue(sheet, index, 15, csno.getChiName().trim());
        } else
            Toolket.setCellValue(sheet, index, 15, "");

        if (StringUtils.isNotBlank(ss.getTechIdno())) {
            empl = mm.findEmplByIdno(ss.getTechIdno());
            if (empl != null)
                Toolket.setCellValue(sheet, index, 16, empl.getCname().trim());
            else {
                dempl = mm.findDEmplByIdno(ss.getTechIdno());
                if (dempl != null)
                    Toolket.setCellValue(sheet, index, 16, dempl.getCname().trim());
            }
        } else
            Toolket.setCellValue(sheet, index, 16, "");

        Toolket.setCellValue(sheet, index, 17, ss.getSerialNo());
        Toolket.setCellValue(sheet, index, 18, Toolket.getCustomNo(ss.getCustomNo()));
        Toolket.setCellValue(sheet, index, 19, Toolket.getPass(ss.getPass()));
        Toolket.setCellValue(sheet, index++, 20, Toolket.getApplyType(ss.getApplyType()));
    }

    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, "DeptStdSkillList.xls");
    FileOutputStream fos = new FileOutputStream(output);
    workbook.write(fos);
    fos.close();

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

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

/**
 * ?//from   w  w  w  .  j ava 2  s  .  c o  m
 * 
 * @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 printStdSkillList(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);
    CourseManager cm = (CourseManager) getBean(IConstants.COURSE_MANAGER_BEAN_NAME);
    MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME);
    DynaActionForm aForm = (DynaActionForm) form;
    ServletContext context = request.getSession().getServletContext();

    StdSkill skill = new StdSkill();
    skill.setAmount(null); // ??
    Example example = Example.create(skill).ignoreCase().enableLike(MatchMode.ANYWHERE);
    List<Order> orders = new LinkedList<Order>();
    orders.add(Order.asc("schoolYear"));
    orders.add(Order.asc("schoolTerm"));
    orders.add(Order.asc("studentNo"));

    List<Criterion> cris = new LinkedList<Criterion>();
    Criterion cri = null;
    if (aForm.getStrings("year").length != 0) {
        cri = Restrictions.eq("schoolYear", aForm.getStrings("year")[0]);
        cris.add(cri);
    }

    if (StringUtils.isNotBlank(aForm.getString("sterm"))) {
        cri = Restrictions.eq("schoolTerm", aForm.getString("sterm"));
        cris.add(cri);
    }

    if (StringUtils.isNotBlank(aForm.getString("deptCodeOpt"))) {
        cri = Restrictions.eq("deptNo", aForm.getString("deptCodeOpt"));
        cris.add(cri);
    }

    if (StringUtils.isNotBlank(aForm.getString("licenseValidDateStart"))
            || StringUtils.isNotBlank(aForm.getString("licenseValidDateEnd"))) {
        Date from = StringUtils.isBlank(aForm.getString("licenseValidDateStart")) ? null
                : Toolket.parseNativeDate(aForm.getString("licenseValidDateStart"));
        // ???
        Date to = StringUtils.isBlank(aForm.getString("licenseValidDateEnd")) ? Calendar.getInstance().getTime()
                : Toolket.parseNativeDate(aForm.getString("licenseValidDateEnd"));

        if (from != null) {
            cri = Restrictions.between("licenseValidDate", from, to);
            cris.add(cri);
        }
    }

    List<StdSkill> skills = (List<StdSkill>) am.findSQLWithCriteria(StdSkill.class, example, null, orders,
            cris);

    int index = 2;
    List<LicenseCode> codes = null;
    Student student = null;
    Graduate graduate = null;
    Empl empl = null;
    DEmpl dempl = null;
    Csno csno = null;
    DateFormat df = new SimpleDateFormat("yyyy/MM/dd");
    DateFormat df1 = new SimpleDateFormat("yyyy/MM");

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

    for (StdSkill ss : skills) {
        codes = (List<LicenseCode>) am
                .findLicenseCodesBy(new LicenseCode(Integer.valueOf(ss.getLicenseCode())));

        if (!codes.isEmpty())
            ss.setLicense(codes.get(0));

        student = mm.findStudentByNo(ss.getStudentNo().trim());
        if (student == null) {
            graduate = mm.findGraduateByStudentNo(ss.getStudentNo().trim());
            if (graduate != null) {
                ss.setStudentName(graduate.getStudentName().trim());
                ss.setDepartClass(Toolket.getClassFullName(graduate.getDepartClass()));
            }
        } else {
            ss.setStudentName(student.getStudentName().trim());
            ss.setDepartClass(Toolket.getClassFullName(student.getDepartClass()));
        }

        Toolket.setCellValue(sheet, index, 0, ss.getSchoolYear() + "." + ss.getSchoolTerm());
        Toolket.setCellValue(sheet, index, 1, ss.getStudentNo().toUpperCase());
        Toolket.setCellValue(sheet, index, 2, ss.getStudentName());
        Toolket.setCellValue(sheet, index, 3, ss.getDepartClass());
        Toolket.setCellValue(sheet, index, 4, ss.getLicense().getCode().toString());
        Toolket.setCellValue(sheet, index, 5, ss.getLicense().getName().trim());
        Toolket.setCellValue(sheet, index, 6, ss.getLicense().getLocale().toString());
        Toolket.setCellValue(sheet, index, 7, ss.getLicense().getLevel().trim());
        Toolket.setCellValue(sheet, index, 8, ss.getLicense().getType().toString());
        Toolket.setCellValue(sheet, index, 9, ss.getAmount().toString());
        Toolket.setCellValue(sheet, index, 10, Toolket.getAmountType(ss.getAmountType()));
        Toolket.setCellValue(sheet, index, 11,
                ss.getAmountDate() == null ? "" : df1.format(ss.getAmountDate()));
        Toolket.setCellValue(sheet, index, 12, ss.getLicenseNo());
        Toolket.setCellValue(sheet, index, 13, df.format(ss.getLicenseValidDate()));

        if (StringUtils.isBlank(ss.getCscode())) {
            csno = cm.findCourseInfoByCscode(ss.getCscode());
            if (csno != null)
                Toolket.setCellValue(sheet, index, 14, csno.getChiName().trim());
        } else
            Toolket.setCellValue(sheet, index, 14, "");

        if (StringUtils.isBlank(ss.getTechIdno())) {
            empl = mm.findEmplByIdno(ss.getTechIdno());
            if (empl != null)
                Toolket.setCellValue(sheet, index, 15, empl.getEname().trim());
            else {
                dempl = mm.findDEmplByIdno(ss.getTechIdno());
                if (dempl != null)
                    Toolket.setCellValue(sheet, index, 15, dempl.getEname().trim());
            }
        } else
            Toolket.setCellValue(sheet, index, 15, "");

        Toolket.setCellValue(sheet, index, 16, ss.getSerialNo());
        Toolket.setCellValue(sheet, index, 17, Toolket.getCustomNo(ss.getCustomNo()));
        Toolket.setCellValue(sheet, index++, 18, Toolket.getPass(ss.getPass()));
    }

    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, "StdSkillList.xls");
    FileOutputStream fos = new FileOutputStream(output);
    workbook.write(fos);
    fos.close();

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

From source file:ua.gov.uz.pv.entity.controller.worstKMController.java

public List getWorstPch() {
    List<Deviation> otst;/* w w  w.  j  av  a2  s  .  c  om*/
    otst = (List<Deviation>) session.createCriteria(Deviation.class)
            .add(Restrictions.between("dateMeasuring", getStartDate(), getEndDate()))
            .setFetchMode("direction", FetchMode.JOIN).setFetchMode("railway", FetchMode.JOIN)
            .add(Restrictions.eq("railway.idRailway", selectedRailway))
            .setProjection(Projections.projectionList().add(Projections.groupProperty("direction"))
                    .add(Projections.groupProperty("line")).add(Projections.groupProperty("km"))
                    .add(Projections.groupProperty("m")).add(Projections.rowCount(), "deviation"))
            .list();
    return otst;
}

From source file:ua.gov.uz.pv.helper.RailwayItem.java

private void getDeviations() {
    deviation = new ArrayList<Deviation>();
    session = HibernateUtil.getSessionFactory().openSession();
    deviation = session.createCriteria(Deviation.class).setFetchMode("direction", FetchMode.JOIN)
            .add(Restrictions.eq("direction.idDirection", ii.idDirection)).add(Restrictions.eq("line", ii.line))
            .add(Restrictions.between("coordinate", ii.kmS * 1000 + ii.mS, ii.kmE * 1000 + ii.mE)).list();
    session.close();//ww w .j a  v a  2s .  c  o  m
}

From source file:uk.ac.ox.oucs.vle.CourseDAOImpl.java

License:Educational Community License

public List<Map> findComponentSignups(final String componentId, final Set<Status> statuses,
        final Integer year) {
    // This is an optimisation for exports. It orders by component then
    return getHibernateTemplate().execute(new HibernateCallback<List<Map>>() {

        public List<Map> doInHibernate(Session session) throws HibernateException, SQLException {

            Criteria find = session.createCriteria(CourseComponentDAO.class)
                    .createAlias("signups", "signup", CriteriaSpecification.LEFT_JOIN)
                    .createAlias("signups.group", "group", CriteriaSpecification.LEFT_JOIN)
                    .addOrder(Order.desc("presentationId")).addOrder(Order.desc("group.id"))
                    .addOrder(Order.desc("signup.id"))
                    .setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP);

            // If componentId is null then return all.
            if (componentId != null && !"all".equals(componentId)) {
                find.add(Restrictions.eq("presentationId", componentId));
            }/*from  w w w .j  a v  a2  s. com*/
            if (null != statuses && !statuses.isEmpty()) {
                find.add(Restrictions.in("signup.status", statuses));
            }
            if (null != year) {
                LocalDate startYear = FIRST_DAY_OF_ACADEMIC_YEAR.toLocalDate(year);
                LocalDate endYear = FIRST_DAY_OF_ACADEMIC_YEAR.toLocalDate(year + 1);
                find.add(Restrictions.between("starts", startYear.toDate(), endYear.toDate()));
            }

            Object result = find.list();
            return (List<Map>) result;
        }
    });
}

From source file:uk.org.rbc1b.roms.db.volunteer.HibernateVolunteerDao.java

License:Open Source License

@Override
public List<Volunteer> findVolunteersWhoNeedBiannualEmail(VolunteerSearchCriteria searchCriteria) {
    Session session = this.sessionFactory.getCurrentSession();
    Criteria criteria = createVolunteerSearchCriteria(searchCriteria, session);

    DateTime todayLocalDate = new DateTime();
    DateTime sixMonthsBehindLocalDate = todayLocalDate.minusMonths(6);

    Date todayDate = DataConverterUtil.toSqlDate(todayLocalDate);
    Date sixMonthsBehind = DataConverterUtil.toSqlDate(sixMonthsBehindLocalDate);

    criteria.add(Restrictions.and(/*from  w w w.  j av  a2 s.c  o m*/
            Restrictions.or(Restrictions.isNull("updateContactDetailsEmailLastSent"),
                    Restrictions.not(Restrictions.between("updateContactDetailsEmailLastSent", sixMonthsBehind,
                            todayDate))),
            Restrictions.or(Restrictions.isNull("contactDetailsLastConfirmed"), Restrictions
                    .not(Restrictions.between("contactDetailsLastConfirmed", sixMonthsBehind, todayDate)))));

    if (searchCriteria.getMaxResults() != null) {
        criteria.setMaxResults(searchCriteria.getMaxResults());
    }

    criteria.addOrder(Order.asc("person.personId"));

    return criteria.list();
}