List of usage examples for java.util GregorianCalendar getActualMaximum
@Override public int getActualMaximum(int field)
From source file:com.aimluck.eip.schedule.util.ScheduleUtils.java
public static boolean isDuplicateFacilitySchedule(EipTSchedule schedule, List<Integer> facilityIdList, Integer _old_scheduleid, Date _old_viewDate) { /* */// w w w .jav a2 s . c om GregorianCalendar cald = new GregorianCalendar(); boolean result = false; { Date start_date; Date end_date; String repeat_pattern; String repeat_type; String repeat_week = null; boolean week_0; boolean week_1; boolean week_2; boolean week_3; boolean week_4; boolean week_5; boolean week_6; boolean day_of_week_in_month_1; boolean day_of_week_in_month_2; boolean day_of_week_in_month_3; boolean day_of_week_in_month_4; boolean day_of_week_in_month_5; boolean[] day_of_week_in_month_array = new boolean[5]; String limit_flag; int month_day = -1; int year_month = -1; int year_day = -1; Integer db_scheduleid = null; boolean[] week_array = new boolean[7]; boolean unlimited_repeat = false; try { start_date = schedule.getStartDate(); end_date = schedule.getEndDate(); repeat_pattern = schedule.getRepeatPattern(); repeat_type = repeat_pattern.substring(0, 1); day_of_week_in_month_1 = repeat_pattern.matches("W.......1.?"); day_of_week_in_month_2 = repeat_pattern.matches("W.......2.?"); day_of_week_in_month_3 = repeat_pattern.matches("W.......3.?"); day_of_week_in_month_4 = repeat_pattern.matches("W.......4.?"); day_of_week_in_month_5 = repeat_pattern.matches("W.......5.?"); if (repeat_type.equals("W")) { if (repeat_pattern.length() == 9) { repeat_week = "0"; day_of_week_in_month_1 = true; day_of_week_in_month_2 = true; day_of_week_in_month_3 = true; day_of_week_in_month_4 = true; day_of_week_in_month_5 = true; } else { repeat_week = repeat_pattern.substring(8, 9); } } limit_flag = repeat_pattern.substring(repeat_pattern.length() - 1); week_0 = repeat_pattern.matches("W1........?"); week_1 = repeat_pattern.matches("W.1.......?"); week_2 = repeat_pattern.matches("W..1......?"); week_3 = repeat_pattern.matches("W...1.....?"); week_4 = repeat_pattern.matches("W....1....?"); week_5 = repeat_pattern.matches("W.....1...?"); week_6 = repeat_pattern.matches("W......1..?"); if (repeat_pattern.startsWith("M")) { month_day = Integer.parseInt(repeat_pattern.substring(1, 3)); } if (repeat_pattern.startsWith("Y")) { year_month = Integer.parseInt(repeat_pattern.substring(1, 3)); year_day = Integer.parseInt(repeat_pattern.substring(3, 5)); } // ???1?????? if (repeat_pattern.startsWith("N")) { Calendar cal = Calendar.getInstance(); cal.setTime(start_date); int dow = cal.get(Calendar.DAY_OF_WEEK); week_0 = (dow == Calendar.SUNDAY); week_1 = (dow == Calendar.MONDAY); week_2 = (dow == Calendar.TUESDAY); week_3 = (dow == Calendar.WEDNESDAY); week_4 = (dow == Calendar.THURSDAY); week_5 = (dow == Calendar.FRIDAY); week_6 = (dow == Calendar.SATURDAY); month_day = cal.get(Calendar.DAY_OF_MONTH); int dowim = cal.get(Calendar.DAY_OF_WEEK_IN_MONTH); day_of_week_in_month_1 = (dowim == 1); day_of_week_in_month_2 = (dowim == 2); day_of_week_in_month_3 = (dowim == 3); day_of_week_in_month_4 = (dowim == 4); day_of_week_in_month_5 = (dowim == 5); year_month = cal.get(Calendar.MONTH) + 1; year_day = cal.get(Calendar.DAY_OF_MONTH); } else if (repeat_pattern.endsWith("N")) { unlimited_repeat = true; } week_array[0] = week_0; week_array[1] = week_1; week_array[2] = week_2; week_array[3] = week_3; week_array[4] = week_4; week_array[5] = week_5; week_array[6] = week_6; day_of_week_in_month_array[0] = day_of_week_in_month_1; day_of_week_in_month_array[1] = day_of_week_in_month_2; day_of_week_in_month_array[2] = day_of_week_in_month_3; day_of_week_in_month_array[3] = day_of_week_in_month_4; day_of_week_in_month_array[4] = day_of_week_in_month_5; } catch (RuntimeException e) { logger.error("schedule", e); return false; } catch (Exception e) { logger.error("schedule", e); return false; } if (repeat_type.equals("S")) { // ??0:00:00?????23:59:59?? Calendar cal = Calendar.getInstance(); cal.setTime(end_date); cal.add(Calendar.DATE, 1); cal.add(Calendar.MINUTE, -1); end_date = cal.getTime(); } // ??? if (facilityIdList.size() > 0) {// List<Integer> fids = facilityIdList; SelectQuery<EipTScheduleMap> fquery = Database.query(EipTScheduleMap.class); Expression fexp1 = ExpressionFactory.inExp(EipTScheduleMap.USER_ID_PROPERTY, fids); fquery.setQualifier(fexp1); Expression fexp2 = ExpressionFactory.matchExp(EipTScheduleMap.TYPE_PROPERTY, ScheduleUtils.SCHEDULEMAP_TYPE_FACILITY); fquery.andQualifier(fexp2); Expression oneexp = null;// 1 Expression spanexp = null;// Expression rdexp = null;// Expression rwexp = null;// Expression rwexp2 = null; // Expression rwlexp = null; Expression rmexp = null;// Expression ryexp = null; { // ? Expression exp100 = ExpressionFactory.matchExp( EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "N"); try { if (!unlimited_repeat) { Expression exp101 = ExpressionFactory.lessOrEqualExp( EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.START_DATE_PROPERTY, end_date);// EipTSchedule.START_DATE_PROPERTY <= end_date Expression exp102 = ExpressionFactory.greaterExp( EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.END_DATE_PROPERTY, start_date);// EipTSchedule.END_DATE_PROPERTY > start_date oneexp = exp100.andExp(exp101.andExp(exp102)); } else { oneexp = exp100; } } catch (Exception e) { } } { // ? Expression exp200 = ExpressionFactory.matchExp( EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "S"); try { if (!unlimited_repeat) { // ??00:00?????? Calendar cal_end = Calendar.getInstance(); cal_end.setTime(end_date); cal_end = DateUtils.truncate(cal_end, Calendar.DAY_OF_MONTH); Expression exp201 = ExpressionFactory.lessOrEqualExp( EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.START_DATE_PROPERTY, cal_end.getTime()); // EipTSchedule.START_DATE_PROPERTY <= end_date Calendar cal_start = Calendar.getInstance(); cal_start.setTime(start_date); cal_start = DateUtils.truncate(cal_start, Calendar.DAY_OF_MONTH); Expression exp202 = ExpressionFactory.greaterOrEqualExp( EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.END_DATE_PROPERTY, cal_start.getTime()); // EipTSchedule.END_DATE_PROPERTY >= start_date spanexp = exp200.andExp(exp201.andExp(exp202)); } else { spanexp = exp200; } } catch (Exception e) { } } { // ?? // char lim = 'N'; if ("ON".equals(limit_flag)) { // lim = 'L'; } { // "D".equals(repeat_type.getValue()) Expression dexp01 = ExpressionFactory.likeExp( EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "D_"); rdexp = dexp01; } { // "W".equals(repeat_type.getValue()) Expression wexp = null; List<Expression> wexps = new ArrayList<Expression>(); if (week_0 == true) { wexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W1_______"); wexps.add(wexp); } if (week_1 == true) { wexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_1______"); wexps.add(wexp); } if (week_2 == true) { wexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W__1_____"); wexps.add(wexp); } if (week_3 == true) { wexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W___1____"); wexps.add(wexp); } if (week_4 == true) { wexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W____1___"); wexps.add(wexp); } if (week_5 == true) { wexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_____1__"); wexps.add(wexp); } if (week_6 == true) { wexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W______1_"); wexps.add(wexp); } if (wexps.size() > 0) { rwexp = wexps.get(0); int wexpssize = wexps.size(); for (int k = 1; k < wexpssize; k++) { rwexp = rwexp.orExp(wexps.get(k)); } } else { rwexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W________"); } } { Expression wexp2 = null; List<Expression> wexps2 = new ArrayList<Expression>(); Expression wnexp = null; List<Expression> wnexp2 = new ArrayList<Expression>(); if (week_0 == true) { wexp2 = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W1________"); wexps2.add(wexp2); } if (week_1 == true) { wexp2 = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_1_______"); wexps2.add(wexp2); } if (week_2 == true) { wexp2 = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W__1______"); wexps2.add(wexp2); } if (week_3 == true) { wexp2 = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W___1_____"); wexps2.add(wexp2); } if (week_4 == true) { wexp2 = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W____1____"); wexps2.add(wexp2); } if (week_5 == true) { wexp2 = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_____1___"); wexps2.add(wexp2); } if (week_6 == true) { wexp2 = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W______1__"); wexps2.add(wexp2); } if (repeat_week != null && repeat_week.equals("1") || day_of_week_in_month_1) { wnexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_______1_"); wnexp2.add(wnexp); } if (repeat_week != null && repeat_week.equals("2") || day_of_week_in_month_2) { wnexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_______2_"); wnexp2.add(wnexp); } if (repeat_week != null && repeat_week.equals("3") || day_of_week_in_month_3) { wnexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_______3_"); wnexp2.add(wnexp); } if (repeat_week != null && repeat_week.equals("4") || day_of_week_in_month_4) { wnexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_______4_"); wnexp2.add(wnexp); } if (repeat_week != null && repeat_week.equals("5") || day_of_week_in_month_5) { wnexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_______5_"); wnexp2.add(wnexp); } if (wexps2.size() > 0 && wnexp2.size() > 0) { for (int k = 0; k < wexps2.size(); k++) { for (int l = 0; l < wnexp2.size(); l++) { if (k == 0 && l == 0) { rwexp2 = wexps2.get(k).andExp(wnexp2.get(l)); } else { rwexp2 = rwexp2.orExp(wexps2.get(k).andExp(wnexp2.get(l))); } } } } else { rwexp2 = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_________"); } } { // "M".equals(repeat_type.getValue()) if (month_day > 0) { // ???????? DecimalFormat exF = new DecimalFormat("00"); String md_str = exF.format(month_day); rmexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "M" + md_str + "_"); } else if (year_day > 0 && year_month > 0) { // ?? DecimalFormat exG = new DecimalFormat("00"); String yd_str = exG.format(year_day); rmexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "M" + yd_str + "_"); } else { rmexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "M___"); } } { // "Y".equals(repeat_type.getValue()) if (year_day > 0 && year_month > 0) { // ???????? DecimalFormat exG = new DecimalFormat("00"); String ym_str = exG.format(year_month); String yd_str = exG.format(year_day); ryexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "Y" + ym_str + yd_str + "_"); } else if (month_day > 0) { // ?? DecimalFormat exF = new DecimalFormat("00"); String md_str = exF.format(month_day); ryexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "Y__" + md_str + "_"); } else { ryexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "Y_____"); } } Expression repeatexp = oneexp; if (rdexp != null) { repeatexp = repeatexp.orExp(rdexp); } if (rwexp != null) { repeatexp = repeatexp.orExp(rwexp); } if (rwexp2 != null) { repeatexp = repeatexp.orExp(rwexp2); } if (rmexp != null) { repeatexp = repeatexp.orExp(rmexp); } if (spanexp != null) { repeatexp = repeatexp.orExp(spanexp); } if (ryexp != null) { repeatexp = repeatexp.orExp(ryexp); } fquery.andQualifier(repeatexp); } db_scheduleid = schedule.getScheduleId(); if (db_scheduleid != null && db_scheduleid >= 0) { Expression exp00 = ExpressionFactory.noMatchDbExp( EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.SCHEDULE_ID_PK_COLUMN, db_scheduleid); fquery.andQualifier(exp00); } fquery.distinct(true); List<EipTScheduleMap> f_list = fquery.fetchList(); if (f_list != null && f_list.size() > 0) { // ????? boolean existFacility = false; int f_list_size = f_list.size(); for (int i = 0; i < f_list_size; i++) { EipTScheduleMap map = f_list.get(i); Date dbStartDate = map.getEipTSchedule().getStartDate(); Date dbEndDate = map.getEipTSchedule().getEndDate(); boolean containtsRs = false; // ?????? String ptn = map.getEipTSchedule().getRepeatPattern(); if (ptn.charAt(0) == 'S') { // try { // ??0:00:00?????23:59:59?? Calendar cal = Calendar.getInstance(); cal.setTime(dbEndDate); cal.add(Calendar.DATE, 1); cal.add(Calendar.MINUTE, -1); dbEndDate = cal.getTime(); if ((end_date.after(dbStartDate) && start_date.before(dbEndDate)) || unlimited_repeat) { containtsRs = true; } } catch (Exception e) { containtsRs = false; } } else if (ptn.charAt(0) == 'N') { // ? if ("D".equals(repeat_type) || "N".equals(repeat_type)) { // or // ? try { if ((dbStartDate.before(end_date) && dbEndDate.after(start_date)) || unlimited_repeat) { containtsRs = true; } } catch (Exception e) { containtsRs = false; } } else { if ((dbStartDate.before(end_date) && dbEndDate.after(start_date)) || unlimited_repeat) { containtsRs = true; } } } else if (ptn.charAt(0) == 'D') {// if (ptn.charAt(1) == 'L') { try { if ((dbStartDate.before(end_date) && dbEndDate.after(start_date)) || unlimited_repeat) { containtsRs = true; } } catch (Exception e) { containtsRs = false; } } else { containtsRs = true; } } else if (ptn.charAt(0) == 'W') { if (ptn.length() == 9) { if (ptn.charAt(8) == 'L') { try { if ((dbStartDate.before(end_date) && dbEndDate.after(start_date)) || unlimited_repeat) { containtsRs = true; } } catch (Exception e) { containtsRs = false; } } else { containtsRs = true; } } else if (ptn.length() == 10) { if (ptn.charAt(9) == 'L') { try { if ((dbStartDate.before(end_date) && dbEndDate.after(start_date)) || unlimited_repeat) { containtsRs = true; } } catch (Exception e) { containtsRs = false; } } else { containtsRs = true; } } } else if (ptn.charAt(0) == 'M') { if (ptn.charAt(3) == 'L') { try { if ((dbStartDate.before(end_date) && dbEndDate.after(start_date)) || unlimited_repeat) { containtsRs = true; } } catch (Exception e) { containtsRs = false; } } else { containtsRs = true; } } else if (ptn.charAt(0) == 'Y') { if (ptn.charAt(5) == 'L') { try { if ((dbStartDate.before(end_date) && dbEndDate.after(start_date)) || unlimited_repeat) { containtsRs = true; } } catch (Exception e) { containtsRs = false; } } else { containtsRs = true; } } else { containtsRs = true; } if (containtsRs) { /* ?????? */ int ss_flg = ScheduleUtils.compareTime(start_date, dbEndDate); int se_flg = ScheduleUtils.compareTime(end_date, dbStartDate); if (ss_flg > 0 && se_flg < 0) { /* ???????????? */ if (!"N".equals(ptn) && ptn.endsWith("N") && unlimited_repeat) {// ?(?????&&???)&&???? existFacility = true; } else { Date _start_date = null; Date _end_date = null; if (!"N".equals(ptn) && ptn.endsWith("N") && !unlimited_repeat) {// ?(??&&???)&&??? _start_date = (Date) start_date.clone(); _end_date = (Date) end_date.clone(); } else if (("N".equals(ptn) || !ptn.endsWith("N")) && unlimited_repeat) {// ?(?||??)&&???? _start_date = (Date) dbStartDate.clone(); _end_date = (Date) dbEndDate.clone(); } else if (("N".equals(ptn) || !ptn.endsWith("N")) && !unlimited_repeat) {// ?(?||??)&&??? if (dbStartDate.after(start_date)) { _start_date = (Date) dbStartDate.clone(); } else { _start_date = (Date) start_date.clone(); } if (dbEndDate.before(end_date)) { _end_date = (Date) dbEndDate.clone(); } else { _end_date = (Date) end_date.clone(); } } if ((_start_date == null) || (_end_date == null)) { continue; } /* ??? */ Expression dexp1 = ExpressionFactory.matchExp(EipTSchedule.NAME_PROPERTY, "dummy");// Expression dexp2 = ExpressionFactory.matchExp(EipTSchedule.PARENT_ID_PROPERTY, map.getScheduleId()); if (db_scheduleid != null) { Expression dexp21 = ExpressionFactory .matchExp(EipTSchedule.PARENT_ID_PROPERTY, db_scheduleid); dexp2 = dexp2.orExp(dexp21); } Expression dexp3 = null; cald.setTime(_start_date); cald.set(Calendar.MILLISECOND, 0); cald.set(Calendar.SECOND, 0); cald.set(Calendar.MINUTE, 0); cald.set(Calendar.HOUR_OF_DAY, 0); Date ddate = cald.getTime();// _start_date? List<EipTSchedule> temp = null; if ("N".equals(repeat_pattern)) { /* ?????????????? */ if ((_old_scheduleid != null) && (_old_viewDate != null)) { if ((_old_scheduleid.intValue() == map.getScheduleId().intValue()) && compareToDate(_start_date, _old_viewDate) == 0) { continue; } } try { dexp3 = ExpressionFactory.matchExp(EipTSchedule.START_DATE_PROPERTY, ddate); temp = Database .query(EipTSchedule.class, dexp1.andExp(dexp2).andExp(dexp3)) .fetchList(); if (temp == null || temp.size() <= 0) { existFacility = true; break; } } catch (Exception e) { logger.error("[DuplicateFacilityCheck]: ", e); existFacility = true; break; } } else if (repeat_pattern.startsWith("D")) { while (!ddate.after(_end_date)) { if (matchDay(cald, ptn)) { try { dexp3 = ExpressionFactory .matchExp(EipTSchedule.START_DATE_PROPERTY, ddate); temp = Database.query(EipTSchedule.class, dexp1.andExp(dexp2).andExp(dexp3)).fetchList(); if (temp == null || temp.size() <= 0) { existFacility = true; break; } } catch (Exception e) { logger.error("[DuplicateFacilityCheck]: ", e); existFacility = true; break; } } cald.add(Calendar.DATE, 1); ddate = cald.getTime(); } } else if (repeat_pattern.startsWith("S")) { while (!ddate.after(_end_date)) { try { dexp3 = ExpressionFactory.matchExp(EipTSchedule.START_DATE_PROPERTY, ddate); temp = Database.query(EipTSchedule.class, dexp1.andExp(dexp2).andExp(dexp3)).fetchList(); if (temp == null || temp.size() <= 0) { existFacility = true; break; } } catch (Exception e) { logger.error("[DuplicateFacilityCheck]: ", e); existFacility = true; break; } cald.add(Calendar.DATE, 1); ddate = cald.getTime(); } } else if (repeat_pattern.startsWith("W")) { /* ? */ int wlen = week_array.length; int wlen2 = day_of_week_in_month_array.length; if (wlen < 1 || wlen2 < 1) { continue; } int k; int l; while (!ddate.after(_end_date)) { k = (cald.get(Calendar.DAY_OF_WEEK) - 1) % wlen; l = (cald.get(Calendar.DAY_OF_WEEK_IN_MONTH) - 1) % wlen2; if ((week_array[k] == true) && (day_of_week_in_month_array[l] == true) && matchDay(cald, ptn)) { try { dexp3 = ExpressionFactory .matchExp(EipTSchedule.START_DATE_PROPERTY, ddate); temp = Database.query(EipTSchedule.class, dexp1.andExp(dexp2).andExp(dexp3)).fetchList();// SQL if (temp == null || temp.size() <= 0) { existFacility = true;// true???? break; } } catch (Exception e) { logger.error("[DuplicateFacilityCheck]: ", e); existFacility = true; break; } } cald.add(Calendar.DATE, 1); ddate = cald.getTime(); } } else if (repeat_pattern.startsWith("M")) { /* ?? */ cald.setTime(dbStartDate); cald.set(Calendar.MILLISECOND, 0); cald.set(Calendar.SECOND, 0); cald.set(Calendar.MINUTE, 0); cald.set(Calendar.HOUR_OF_DAY, 0); if (month_day > 0) { cald.set(Calendar.DAY_OF_MONTH, month_day); } else { continue; } Date tmp_date = cald.getTime(); while (tmp_date.before(ddate)) { cald.add(Calendar.MONTH, 1); /* ???????????????? */ while (month_day > cald.getActualMaximum(Calendar.DAY_OF_MONTH)) { cald.add(Calendar.MONTH, 1); cald.set(Calendar.DAY_OF_MONTH, month_day); if (tmp_date.before(tmp_date)) { break; } } tmp_date = cald.getTime(); } ddate = tmp_date; /* */ while (!ddate.after(_end_date)) { if (matchDay(cald, ptn)) { try { dexp3 = ExpressionFactory .matchExp(EipTSchedule.START_DATE_PROPERTY, ddate); temp = Database.query(EipTSchedule.class, dexp1.andExp(dexp2).andExp(dexp3)).fetchList(); if (temp == null || temp.size() <= 0) { existFacility = true; break; } } catch (Exception e) { logger.error("[DuplicateFacilityCheck]: ", e); existFacility = true; break; } } cald.add(Calendar.MONTH, 1); /* ???????????????? */ while (month_day > cald.getActualMaximum(Calendar.DAY_OF_MONTH)) { cald.add(Calendar.MONTH, 1); cald.set(Calendar.DAY_OF_MONTH, month_day); if (!ddate.after(_end_date)) { break; } } ddate = cald.getTime(); } } else if (repeat_pattern.startsWith("Y")) { /* ?? */ cald.setTime(dbStartDate); cald.set(Calendar.MILLISECOND, 0); cald.set(Calendar.SECOND, 0); cald.set(Calendar.MINUTE, 0); cald.set(Calendar.HOUR_OF_DAY, 0); if (year_month > 0 && year_day > 0) { cald.set(Calendar.MONTH, year_month - 1); cald.set(Calendar.DAY_OF_MONTH, year_day); } else { continue; } Date tmp_date = cald.getTime(); while (tmp_date.before(ddate)) { cald.add(Calendar.MONTH, 1); /* ???????????????? */ while (year_day > cald.getActualMaximum(Calendar.DAY_OF_MONTH)) { cald.add(Calendar.MONTH, 1); cald.set(Calendar.DAY_OF_MONTH, year_day); if (tmp_date.before(tmp_date)) { break; } } tmp_date = cald.getTime(); } ddate = tmp_date; /* */ while (!ddate.after(_end_date)) { if (matchDay(cald, ptn)) { try { dexp3 = ExpressionFactory .matchExp(EipTSchedule.START_DATE_PROPERTY, ddate); temp = Database.query(EipTSchedule.class, dexp1.andExp(dexp2).andExp(dexp3)).fetchList(); if (temp == null || temp.size() <= 0) { existFacility = true; break; } } catch (Exception e) { logger.error("[DuplicateFacilityCheck]: ", e); existFacility = true; break; } } cald.add(Calendar.MONTH, 1); /* ???????????????? */ while (year_day > cald.getActualMaximum(Calendar.DAY_OF_MONTH)) { cald.add(Calendar.MONTH, 1); cald.set(Calendar.DAY_OF_MONTH, year_day); if (!ddate.after(_end_date)) { break; } } ddate = cald.getTime(); } } else { continue; } } } } if (existFacility) { break; } } if (existFacility) { return existFacility; } } } } return result; }
From source file:op.tools.SYSCalendar.java
public static int eom(GregorianCalendar d) { return d.getActualMaximum(GregorianCalendar.DAY_OF_MONTH); // switch (d.get(GregorianCalendar.MONTH)) { // case GregorianCalendar.JANUARY: { // return 31; // } // case GregorianCalendar.FEBRUARY: { // if (d.isLeapYear(d.get(GregorianCalendar.YEAR))) { // return 29; // } else { // return 28; // } // } // case GregorianCalendar.MARCH: { // return 31; // } // case GregorianCalendar.APRIL: { // return 30; // } // case GregorianCalendar.MAY: { // return 31; // } // case GregorianCalendar.JUNE: { // return 30; // } // case GregorianCalendar.JULY: { // return 31; // } // case GregorianCalendar.AUGUST: { // return 31; // } // case GregorianCalendar.SEPTEMBER: { // return 30; // } // case GregorianCalendar.OCTOBER: { // return 31; // } // case GregorianCalendar.NOVEMBER: { // return 30; // } // case GregorianCalendar.DECEMBER: { // return 31; // } ///*from w ww . j a va 2 s.c o m*/ // default: { // return 0; // } // } }
From source file:org.accada.epcis.repository.query.Schedule.java
/** * Sets the specified field of the given callendar to the next scheduled * value. Returns whether the new value has been set and is valid. * // w ww .j a va2s . c om * @param cal * Calendar to adjust. * @param field * Field to adjust. * @return Returns whether the new value has been set and is valid. * @throws ImplementationException * Almost any error. */ private boolean setToNextScheduledValue(final GregorianCalendar cal, final int field) throws ImplementationExceptionResponse { int next; TreeSet<Integer> vals = getValues(field); if (vals.isEmpty()) { next = cal.get(field) + 1; } else { try { // get next scheduled value which is bigger than current int incrValue = cal.get(field) + 1; next = vals.tailSet(new Integer(incrValue)).first().intValue(); } catch (NoSuchElementException nse) { // there is no bigger scheduled value return false; } } if (next > cal.getActualMaximum(field) || next < cal.getActualMinimum(field)) { return false; } // all is well, set it to next cal.set(field, next); return true; }
From source file:org.accada.epcis.repository.query.Schedule.java
/** * Sets the field of a GregorianCalender to its minimum, which is defined as * the minimal possible value according to the calendar type possibly * superseded by the defined values in the schedule we have. Returns whether * the new value has been set and is valid. * /* w ww.j a va 2 s . c o m*/ * @param cal * Calendar to adjust. * @param field * Field to adjust. * @return Returns whether the new value has been set and is valid. * @throws ImplementationException * Almost any error. */ private boolean setFieldToMinimum(final GregorianCalendar cal, final int field) throws ImplementationExceptionResponse { int min; TreeSet<Integer> values = getValues(field); if (values.isEmpty()) { min = cal.getActualMinimum(field); } else { min = Math.max(values.first().intValue(), cal.getActualMinimum(field)); if (min > cal.getActualMaximum(field)) { min = cal.getActualMaximum(field); if (!values.contains(Integer.valueOf(min)) || min < cal.getActualMinimum(field) || min > cal.getActualMaximum(field)) { return false; } } } cal.set(field, min); return true; }
From source file:org.betaconceptframework.astroboa.console.jsf.browse.ContentObjectSearchByContentType.java
public String findContentObjectsByContentTypeAndPresent_UIAction() { // reset search criteria to begin a new search contentObjectCriteria = null;/*from ww w . j av a 2 s . c om*/ contentObjectCriteria = CmsCriteriaFactory.newContentObjectCriteria(); uiComponentBinding.resetContentObjectTableScrollerComponent(); contentObjectList.resetViewAndStateBeforeNewContentSearchResultsPresentation(); // We add the selected content type into search criteria HtmlTree contentObjectFolderTree = uiComponentBinding.getContentObjectFolderTreeRichFaces(); TreeNode selectedTreeNodeObject = contentObjectFolderTree.getTreeNode(); LazyLoadingContentObjectFolderTreeNodeRichFaces selectedNode; // There is possibly a bug in Rich Faces Tree Implementation. The first time a tree node is selected in the tree the selected tree node // that is returned has type <LazyLoadingContentObjectFolderTreeNodeRichFaces> as it should be. However any subsequent selected tree node // is returned as a <TreeNodeImpl> object which should not happen. // So we should check the returned type to decide how we will access the selected tree node. if (LazyLoadingContentObjectFolderTreeNodeRichFaces.class.isInstance(selectedTreeNodeObject)) { selectedNode = (LazyLoadingContentObjectFolderTreeNodeRichFaces) contentObjectFolderTree.getTreeNode(); } else if (TreeNodeImpl.class.isInstance(selectedTreeNodeObject)) { selectedNode = (LazyLoadingContentObjectFolderTreeNodeRichFaces) selectedTreeNodeObject.getData(); } else throw new RuntimeException("Cannot determine the class of the selected tree node"); contentObjectCriteria.addContentObjectTypeEqualsCriterion(selectedNode.getContentType()); contentObjectCriteria.doNotCacheResults(); // We should find and add the selected date into search criteria if a date folder has been selected String message = ""; if (!selectedNode.getType().equals("contentTypeFolder")) { String fullContentObjectFolderPath = selectedNode.getContentObjectFolder().getFullPath(); //the full path contains date information. Its format is the following: YYYY/M/D eg. 2006/5/2 String[] dateComponents = StringUtils.split(fullContentObjectFolderPath, "/"); // we split the path to the year, month and day components if (dateComponents == null || dateComponents.length == 0 || dateComponents.length > 3) { logger.error("Error while loading content objects. Invalid path for content object folder {}", fullContentObjectFolderPath); JSFUtilities.addMessage(null, "object.list.message.contentObjectRetrievalError", null, FacesMessage.SEVERITY_ERROR); return null; } GregorianCalendar fromDate = new GregorianCalendar(TimeZone.getDefault()); GregorianCalendar toDate = new GregorianCalendar(TimeZone.getDefault()); //Find out whether user has clicked a year, a month or a day if (dateComponents.length == 1) { //User has selected year. //Find all content objects created the selected year //from 01/01/selectedYear //to 31/12/selectedYear fromDate.set(Integer.valueOf(dateComponents[0]), 0, 1, 0, 0, 0); toDate.set(Integer.valueOf(dateComponents[0]), 11, 31, 23, 59, 59); message = DateUtils.format(fromDate, "dd/MM/yyyy") + " - " + DateUtils.format(toDate, "dd/MM/yyyy"); } else if (dateComponents.length == 2) { //User has selected month. //Find all content objects created the selected year //from 01/selectedMonth/selectedYear //to 31/selectedMonth/selectedYear //Fix Month information //In CmsBackEnd. month enumeration starts from 1 for January, 2 for February .etc //Where as in Java Calendar month enumeration is zero based. Thus we need a conversion String month = dateComponents[1]; int javaMonth = Integer.valueOf(month) - 1; fromDate.set(Integer.valueOf(dateComponents[0]), javaMonth, 1, 0, 0, 0); toDate.set(Integer.valueOf(dateComponents[0]), javaMonth, fromDate.getActualMaximum(Calendar.DAY_OF_MONTH), 23, 59, 59); message = DateUtils.format(fromDate, "dd/MM/yyyy") + " - " + DateUtils.format(toDate, "dd/MM/yyyy"); } else { //User has selected a day //from selectedDay at midnight //to selectedDay at 23:59:59.999 //Fix Month information //In CmsBackEnd. month enumeration starts from 1 for January, 2 for February .etc //Where as in Java Calendar month enumeration is zero based. Thus we need a conversion String month = dateComponents[1]; int javaMonth = Integer.valueOf(month) - 1; // we create a date range for the selected date (24 hours) fromDate.set(Integer.valueOf(dateComponents[0]), javaMonth, Integer.valueOf(dateComponents[2]), 0, 0, 0); toDate.set(Integer.valueOf(dateComponents[0]), javaMonth, Integer.valueOf(dateComponents[2]), 23, 59, 59); message = DateUtils.format(fromDate, "dd/MM/yyyy"); } //Above method is setting 0 to hour, minute and second but we also need to clear milliseconds fromDate.clear(Calendar.MILLISECOND); //System.out.println(DateUtils.format(fromDate, "dd/MM/yyyy HH:mm")); toDate.set(Calendar.MILLISECOND, 999); //System.out.println(DateUtils.format(toDate, "dd/MM/yyyy HH:mm")); contentObjectCriteria.addCriterion(CriterionFactory.between("profile.created", fromDate, toDate)); } contentObjectCriteria.setOffsetAndLimit(0, pageController.getRowsPerDataTablePage()); // set required ordering if (searchResultsFilterAndOrdering.getSelectedResultsOrder() != null) { contentObjectCriteria.addOrderProperty("profile.created", Order.valueOf(searchResultsFilterAndOrdering.getSelectedResultsOrder())); } else { contentObjectCriteria.addOrderProperty("profile.created", Order.descending); } // now we are ready to run the query try { long startTime = System.currentTimeMillis(); int resultSetSize = contentObjectStatefulSearchService.searchForContentWithPagedResults( contentObjectCriteria, true, JSFUtilities.getLocaleAsString(), pageController.getRowsPerDataTablePage()); long endTime = System.currentTimeMillis(); getLogger().debug("Find Objects by ContentObject Type and Date: " + (endTime - startTime) + "ms"); if (resultSetSize > 0) { String localisedNameOfBrowsedContentType = selectedNode.getLocalizedLabelOfContentType(); if ("".equals(message)) { contentObjectList.setContentObjectListHeaderMessage(JSFUtilities.getParameterisedStringI18n( "object.list.message.contentObjectListHeaderMessageForSearchByContentTypeWithoutDate", new String[] { localisedNameOfBrowsedContentType, String.valueOf(resultSetSize) })); } else { contentObjectList.setContentObjectListHeaderMessage(JSFUtilities.getParameterisedStringI18n( "object.list.message.contentObjectListHeaderMessageForSearchByContentType", new String[] { localisedNameOfBrowsedContentType, message, String.valueOf(resultSetSize) })); } contentObjectList.setLabelForFileGeneratedWhenExportingListToXml(localisedNameOfBrowsedContentType); } else JSFUtilities.addMessage(null, "object.list.message.noContentObjectsInThisContentObjectFolderInfo", null, FacesMessage.SEVERITY_INFO); } catch (Exception e) { logger.error("Error while loading content objects ", e); JSFUtilities.addMessage(null, "object.list.message.contentObjectRetrievalError", null, FacesMessage.SEVERITY_ERROR); } return null; }
From source file:org.modelibra.type.EasyCalendar.java
/** * Gets the last day in year, month./*from www .ja va 2 s . com*/ * * @param year * year * @param month * month * @return the last day in year, month */ public int getLastDay(int year, int month) { GregorianCalendar calendar = new GregorianCalendar(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month - 1); // months start with 0 int day = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); return day; }
From source file:org.nuclos.common2.DateUtils.java
private static void calc(GregorianCalendar result, CalcFunction cf, CalcPair cp) { switch (cf) { case ADD:// w w w .j a v a 2s . c o m result.add(cp.x, cp.y); break; case SUBTRACT: result.add(cp.x, cp.y * (-1)); break; case SET: switch (cp.x) { case Calendar.YEAR: result.set(Calendar.DAY_OF_YEAR, cp.y == Integer.MIN_VALUE ? result.getActualMinimum(Calendar.DAY_OF_YEAR) : result.getActualMaximum(Calendar.DAY_OF_YEAR)); break; case Calendar.MONTH: result.set(Calendar.DAY_OF_MONTH, cp.y == Integer.MIN_VALUE ? result.getActualMinimum(Calendar.DAY_OF_MONTH) : result.getActualMaximum(Calendar.DAY_OF_MONTH)); break; case Calendar.WEEK_OF_YEAR: result.set(Calendar.DAY_OF_WEEK, cp.y == Integer.MIN_VALUE ? Calendar.MONDAY : Calendar.SUNDAY); break; } break; } }
From source file:org.sakaiproject.calendar.tool.CalendarAction.java
/** * Action doList is requested when the user click on the list in the toolbar *///from www . jav a 2 s . c o m public void doList(RunData data, Context context) { CalendarActionState state = (CalendarActionState) getState(context, data, CalendarActionState.class); String peid = ((JetspeedRunData) data).getJs_peid(); SessionState sstate = ((JetspeedRunData) data).getPortletSessionState(peid); Time m_time = TimeService.newTime(); TimeBreakdown b = m_time.breakdownLocal(); int stateYear = b.getYear(); int stateMonth = b.getMonth(); int stateDay = b.getDay(); if ((sstate.getAttribute(STATE_YEAR) != null) && (sstate.getAttribute(STATE_MONTH) != null) && (sstate.getAttribute(STATE_DAY) != null)) { stateYear = ((Integer) sstate.getAttribute(STATE_YEAR)).intValue(); stateMonth = ((Integer) sstate.getAttribute(STATE_MONTH)).intValue(); stateDay = ((Integer) sstate.getAttribute(STATE_DAY)).intValue(); } String sM; String eM; String sD; String eD; String sY; String eY; CalendarUtil calObj = new CalendarUtil(); calObj.setDay(stateYear, stateMonth, stateDay); String prevState = state.getState().toString(); if (prevState.equals("day")) { sY = Integer.valueOf(calObj.getYear()).toString(); sM = Integer.valueOf(calObj.getMonthInteger()).toString(); sD = Integer.valueOf(calObj.getDayOfMonth()).toString(); eY = Integer.valueOf(calObj.getYear()).toString(); eM = Integer.valueOf(calObj.getMonthInteger()).toString(); eD = Integer.valueOf(calObj.getDayOfMonth()).toString(); } else if (prevState.equals("week")) { int dayofweek = calObj.getDay_Of_Week(true); calObj.setPrevDate(dayofweek - 1); sY = Integer.valueOf(calObj.getYear()).toString(); sM = Integer.valueOf(calObj.getMonthInteger()).toString(); sD = Integer.valueOf(calObj.getDayOfMonth()).toString(); for (int i = 0; i < 6; i++) { calObj.getNextDate(); } eY = Integer.valueOf(calObj.getYear()).toString(); eM = Integer.valueOf(calObj.getMonthInteger()).toString(); eD = Integer.valueOf(calObj.getDayOfMonth()).toString(); } else if (prevState.equals("month")) { sY = Integer.valueOf(calObj.getYear()).toString(); sM = Integer.valueOf(calObj.getMonthInteger()).toString(); sD = String.valueOf("1"); calObj.setDay(stateYear, stateMonth, 1); GregorianCalendar cal = new GregorianCalendar(calObj.getYear(), calObj.getMonthInteger() - 1, 1); int daysInMonth = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH); for (int i = 1; i < daysInMonth; i++) calObj.getNextDate(); eY = Integer.valueOf(calObj.getYear()).toString(); eM = Integer.valueOf(calObj.getMonthInteger()).toString(); eD = Integer.valueOf(calObj.getDayOfMonth()).toString(); } else { // for other conditions: show the current year sY = Integer.valueOf(stateYear).toString(); sM = "1"; sD = "1"; eY = Integer.valueOf(stateYear).toString(); eM = "12"; eD = "31"; } if (sM.length() == 1) sM = "0" + sM; if (eM.length() == 1) eM = "0" + eM; if (sD.length() == 1) sD = "0" + sD; if (eD.length() == 1) eD = "0" + eD; sY = sY.substring(2); eY = eY.substring(2); String startingDateStr = sM + "/" + sD + "/" + sY; String endingDateStr = eM + "/" + eD + "/" + eY; state.getCalendarFilter().setListViewFilterMode(CalendarFilter.SHOW_CUSTOM_RANGE); sstate.removeAttribute(STATE_SCHEDULE_TO); sstate.removeAttribute(STATE_SCHEDULE_TO_GROUPS); // Pass in a buffer for a possible error message. StringBuilder errorMessage = new StringBuilder(); // Try to simultaneously set the start/end dates. // If that doesn't work, add an error message. if (!state.getCalendarFilter().setStartAndEndListViewDates(startingDateStr, endingDateStr, errorMessage)) { addAlert(sstate, errorMessage.toString()); } state.setState("list"); }