List of usage examples for java.util Date clone
public Object clone()
From source file:com.homeworkreminder.Main.java
@SuppressWarnings("deprecation") protected static void updateListView(boolean terminationCode) { // TODO Auto-generated method stub if (terminationCode) { switch (prevScreen) { case 0:/* w w w . jav a2 s.com*/ adapter = new ItemAdapter(context, R.layout.custom_row, Upcoming, swipelistview, prefs.getString("Color_scheme", "Default")); checkEmpty(Upcoming, 0); break; case 1: subject_adapter.notifyDataSetChanged(); break; case 2: adapter = new ItemAdapter(context, R.layout.custom_row, TaskHolder, swipelistview, prefs.getString("Color_scheme", "Default")); checkEmpty(TaskHolder, 2); break; case 3: Calendar v = Calendar.getInstance(); v.set(Calendar.YEAR, lastSelectedCalendarDate.getYear() + 1900); v.set(Calendar.MONTH, lastSelectedCalendarDate.getMonth()); v.set(Calendar.DAY_OF_MONTH, lastSelectedCalendarDate.getDate()); v.set(Calendar.HOUR_OF_DAY, 0); v.set(Calendar.MINUTE, 0); v.set(Calendar.SECOND, 0); v.set(Calendar.MILLISECOND, 0); if (v.get(Calendar.MONTH) != currCalendarMonth.get(Calendar.MONTH)) { caldroidFragment.setBackgroundResourceForDate(R.color.pure_white, lastSelectedCalendarDate); caldroidFragment.setTextColorForDate(R.color.caldroid_gray, lastSelectedCalendarDate); } else { if (TaskMap.containsKey(v)) { caldroidFragment.setTextColorForDate(R.color.pure_white, lastSelectedCalendarDate); caldroidFragment.setBackgroundResourceForDate(R.color.bg_green, lastSelectedCalendarDate); } else { caldroidFragment.setBackgroundResourceForDate(R.color.pure_white, lastSelectedCalendarDate); caldroidFragment.setTextColorForDate(R.color.black, lastSelectedCalendarDate); } } Calendar k = Calendar.getInstance(); k.set(Calendar.DAY_OF_MONTH, 1); k.set(Calendar.YEAR, currCalendarMonth.get(Calendar.YEAR)); k.set(Calendar.MONTH, currCalendarMonth.get(Calendar.MONTH)); Calendar prev = Calendar.getInstance(); Calendar nxt = Calendar.getInstance(); prev.set(Calendar.YEAR, k.get(Calendar.YEAR)); nxt.set(Calendar.YEAR, k.get(Calendar.YEAR)); prev.set(Calendar.MONTH, k.get(Calendar.MONTH) - 1); nxt.set(Calendar.MONTH, k.get(Calendar.MONTH) + 1); prev.set(Calendar.DAY_OF_MONTH, 1); int prev_month = prev.get(Calendar.MONTH); nxt.set(Calendar.DAY_OF_MONTH, 1); int nxt_month = nxt.get(Calendar.MONTH); while (k.get(Calendar.MONTH) == currCalendarMonth.get(Calendar.MONTH)) { caldroidFragment.setBackgroundResourceForDate(R.color.pure_white, k.getTime()); caldroidFragment.setTextColorForDate(R.color.black, k.getTime()); k.add(Calendar.DAY_OF_MONTH, 1); } while (prev.get(Calendar.MONTH) == prev_month) { caldroidFragment.setBackgroundResourceForDate(R.color.pure_white, prev.getTime()); caldroidFragment.setTextColorForDate(R.color.caldroid_gray, prev.getTime()); prev.add(Calendar.DAY_OF_MONTH, 1); } while (nxt.get(Calendar.MONTH) == nxt_month) { caldroidFragment.setBackgroundResourceForDate(R.color.pure_white, nxt.getTime()); caldroidFragment.setTextColorForDate(R.color.caldroid_gray, nxt.getTime()); nxt.add(Calendar.DAY_OF_MONTH, 1); } setCalendarTaskForMonth(currCalendarMonth.get(Calendar.MONTH), currCalendarMonth.get(Calendar.YEAR)); Date r = new Date(currCalendarMonth.get(Calendar.YEAR) - 1900, currCalendarMonth.get(Calendar.MONTH), 1, 0, 0, 0); if (initInfoListForDate(r)) { caldroidFragment.setTextColorForDate(R.color.pure_white, r); caldroidFragment.setBackgroundResourceForDate(R.drawable.border_bg_green, r); } else { caldroidFragment.setBackgroundResourceForDate(R.drawable.border_bg, r); caldroidFragment.setTextColorForDate(R.color.black, r); } lastSelectedCalendarDate = (Date) r.clone(); caldroidFragment.setBackgroundResourceForDate(R.color.bg_blue, Calendar.getInstance().getTime()); caldroidFragment.setTextColorForDate(R.color.pure_white, Calendar.getInstance().getTime()); caldroidFragment.refreshView(); break; case 4: adapter = new ItemAdapter(context, R.layout.custom_row, Completed, swipelistview, prefs.getString("Color_scheme", "Default")); checkEmpty(Completed, 4); break; } swipelistview.setAdapter(adapter); adapter.notifyDataSetChanged(); } else { } }
From source file:ProcessRequest.java
public JSONObject getWeight(final String host, final int port, final int numChars, final int weightBeginPos, final int weightEndPos, final int termChar, final int statusBeginPos, final int statusEndPos, final int normalChar, final int motionChar, int timeout, final String overcapacity) { //Thread socketThread = new Thread() { // public void run() { //cannot run in thread Socket connection = null;/* w ww. j a v a 2 s . c o m*/ JSONObject returnObject = new JSONObject(); try { System.out.println("opening socket"); connection = new Socket(host, port); System.out.println("getting stream"); InputStreamReader reader = new InputStreamReader(connection.getInputStream()); System.out.println("creating character buffer"); boolean success = false; java.util.Date beginDate = new java.util.Date(); java.util.Date endDate = (java.util.Date) beginDate.clone(); endDate.setSeconds(endDate.getSeconds() + timeout); while (!success) { beginDate = new java.util.Date(); if (beginDate.after(endDate)) { returnObject.put("error", "the operation timed out"); //out.println(returnObject.toString(5)); return returnObject; } String string = new String(); int count = 0; while (reader.read() != (char) (termChar)) { if (count > 5000) { break; } count++; } if (count > 5000) { returnObject.put("error", "termchar was not found in the stream. are you sure the scale is set up correctly?"); //out.println(returnObject.toString(5)); return returnObject; } for (int i = 0; i < numChars; i++) { string += (char) (reader.read()); } //get negative marker also String weight = string.substring(weightBeginPos - 1, weightEndPos); String status = string.substring(statusBeginPos - 1, statusEndPos); String uom = string.substring(9, 11); System.out.println("weight: '" + weight + "'"); System.out.println("status: '" + status + "'"); System.out.println("uom : '" + uom + "'"); if (string.contains(overcapacity)) { returnObject.put("error", "Over Capacity!"); return returnObject; } else { System.out.println("extracting weight value"); returnObject.put("weight", new Integer(weight).toString()); System.out.println("checking motion"); if (status.charAt(0) == ((char) (normalChar))) { returnObject.put("motion", false); } else if (status.charAt(0) == ((char) (motionChar))) { returnObject.put("motion", true); } else { returnObject.put("error", "Invalid Motion Char!\n(check web service settings)"); } System.out.println("checking uom"); if (uom.equals("LB")) { returnObject.put("uom", "lbs"); } else if (uom.equals("KG")) { returnObject.put("uom", "kg"); } else { //unknown weight type, no cause for error here. } } System.out.println("sending resultant json"); //out.println(returnObject.toString(5)); success = true; } } catch (Exception e) { System.out.println("ERROR"); System.out.println("ERROR: could not connect to scale: " + e.toString()); try { returnObject.put("error", "could not connect to scale: " + e.toString()); return returnObject; //out.println(returnObject.toString(5)); } catch (Exception je) { //out.println("parser error?"); returnObject.put("error", je.toString()); return returnObject; } } finally { try { connection.close(); } catch (Exception e) { //don't care at this point. } return returnObject; } // } //}; //socketThread.start(); }
From source file:org.celllife.idart.gui.patient.AddPatient.java
/** * This method loads the details of the patient into the GUI. It used the * localPatient object to get the values * /* w ww. j a v a 2s . co m*/ */ public void loadPatientDetails() { try { // run this first to set isPatientActive loadEpisodeDetails(); // populate the GUI txtFirstNames.setText(localPatient.getFirstNames()); txtSurname.setText(localPatient.getLastname()); char sex = localPatient.getSex(); if (Character.toUpperCase(sex) == 'F') { cmbSex.setText(Messages.getString("patient.sex.female")); //$NON-NLS-1$ } else if (Character.toUpperCase(sex) == 'M') { cmbSex.setText(Messages.getString("patient.sex.male")); //$NON-NLS-1$ } txtAge.setText(String.valueOf(localPatient.getAge())); txtCellphone.setText(localPatient.getCellphone()); originalPatientId = localPatient.getPatientId(); txtPatientId.setText(originalPatientId); Calendar theDOB = Calendar.getInstance(); theDOB.setTime(localPatient.getDateOfBirth()); cmbDOBDay.setText(String.valueOf(theDOB.get(Calendar.DAY_OF_MONTH))); SimpleDateFormat monthFormat = new SimpleDateFormat("MMMM", Locale.ENGLISH); //$NON-NLS-1$ cmbDOBMonth.setText(monthFormat.format(theDOB.getTime())); cmbDOBYear.setText(String.valueOf(theDOB.get(Calendar.YEAR))); if (localPatient.getAge() <= 12) { lblPicChild.setVisible(true); } // Enable the prescription button btnUpdatePrescription.setEnabled(true); epViewer = new EpisodeViewer(getHSession(), getShell(), localPatient, true); epViewer.addChangeListener(this); Episode mostRecentEpisode = localPatient.getMostRecentEpisode(); if (btnDownRefer != null && localPatient.getCurrentClinic().isMainClinic() && (mostRecentEpisode != null && mostRecentEpisode.isOpen())) { btnDownRefer.setEnabled(true); } else { btnDownRefer.setEnabled(false); } // Setting ARV Start Date PatientAttribute pa = localPatient.getAttributeByName(PatientAttribute.ARV_START_DATE); if (pa != null) { try { Date arvStartDate = (Date) pa.getObjectValue(); btnARVStart.setDate((Date) arvStartDate.clone()); } catch (Exception e) { getLog().error("Error when obtaining ARV Start Date", e); //$NON-NLS-1$ } } // load the tabs with data from the patient for (IPatientTab tab : groupTabs) { tab.loadPatientDetails(localPatient, isPatientActive); } } catch (Exception e) { getLog().error(e); } }
From source file:org.celllife.idart.gui.patient.AddPatientIdart.java
/** * This method loads the details of the patient into the GUI. It used the * localPatient object to get the values * /*from w w w .j a v a2 s . c o m*/ */ public void loadPatientDetails() { try { // run this first to set isPatientActive loadEpisodeDetails(); // populate the GUI txtFirstNames.setText(localPatient.getFirstNames()); txtSurname.setText(localPatient.getLastname()); char sex = localPatient.getSex(); if (Character.toUpperCase(sex) == 'F') { cmbSex.setText(Messages.getString("patient.sex.female")); //$NON-NLS-1$ } else if (Character.toUpperCase(sex) == 'M') { cmbSex.setText(Messages.getString("patient.sex.male")); //$NON-NLS-1$ } txtAge.setText(String.valueOf(localPatient.getAge())); txtCellphone.setText(localPatient.getCellphone()); originalPatientId = localPatient.getPatientId(); txtPatientId.setText(originalPatientId); Calendar theDOB = Calendar.getInstance(); theDOB.setTime(localPatient.getDateOfBirth()); cmbDOBDay.setText(String.valueOf(theDOB.get(Calendar.DAY_OF_MONTH))); SimpleDateFormat monthFormat = new SimpleDateFormat("MMMM", Locale.ENGLISH); //$NON-NLS-1$ cmbDOBMonth.setText(monthFormat.format(theDOB.getTime())); cmbDOBYear.setText(String.valueOf(theDOB.get(Calendar.YEAR))); if (localPatient.getAge() <= 12) { lblPicChild.setVisible(true); } // Enable the prescription button btnUpdatePrescription.setEnabled(true); epViewer = new EpisodeViewer(getHSession(), getShell(), localPatient, true); epViewer.addChangeListener(this); Clinic clinic = AdministrationManager.getClinic(getHSession(), cmbClinic.getText().trim()); localPatient.setClinic(clinic); Episode mostRecentEpisode = localPatient.getMostRecentEpisode(); if (btnDownRefer != null && localPatient.getCurrentClinic().isMainClinic() && (mostRecentEpisode != null && mostRecentEpisode.isOpen())) { btnDownRefer.setEnabled(true); } else { btnDownRefer.setEnabled(false); } // Setting ARV Start Date //localPatient.setAttributeValue(PatientAttribute.ARV_START_DATE, btnARVStart.getDate()); PatientAttribute pa = localPatient.getAttributeByName(PatientAttribute.ARV_START_DATE); if (pa != null) { try { Date arvStartDate = (Date) pa.getObjectValue(); btnARVStart.setDate((Date) arvStartDate.clone()); } catch (Exception e) { getLog().error("Error when obtaining ARV Start Date", e); //$NON-NLS-1$ } } // load the tabs with data from the patient for (IPatientTab tab : groupTabs) { tab.loadPatientDetails(localPatient, isPatientActive); } } catch (Exception e) { getLog().error(e); } }
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) { /* *//* www. ja v a2 s .c o m*/ 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; }