List of usage examples for java.util Calendar equals
@SuppressWarnings("EqualsWhichDoesntCheckParameterClass") @Override public boolean equals(Object obj)
Calendar
to the specified Object
. From source file:org.betaconceptframework.astroboa.test.engine.service.ContentServiceTest.java
@Test public void testProfileModifiedChangedUponSave() { RepositoryUser systemUser = getSystemUser(); ContentObject contentObject = createContentObject(systemUser, "testLastModifiedChange"); contentObject = contentService.save(contentObject, false, true, null); markObjectForRemoval(contentObject); Calendar lastModified = ((CalendarProperty) contentObject.getCmsProperty("profile.modified")) .getSimpleTypeValue();/*from w ww. j a va 2s . c om*/ //Resaved object without changing lastModified Date contentObject = contentService.save(contentObject, false, false, null); Calendar newLastModified = ((CalendarProperty) contentObject.getCmsProperty("profile.modified")) .getSimpleTypeValue(); Assert.assertEquals(newLastModified, lastModified, "Content Object profile.modified date has changed."); //Resave object and change profile modified date contentObject = contentService.save(contentObject, false, true, null); newLastModified = ((CalendarProperty) contentObject.getCmsProperty("profile.modified")) .getSimpleTypeValue(); Assert.assertFalse(newLastModified.equals(lastModified), "Content Object profile.modified date has not changed."); //Save new content object with flag set to false contentObject = createContentObject(systemUser, "testLastModifiedChange2"); contentObject = contentService.save(contentObject, false, false, null); markObjectForRemoval(contentObject); //Last modified must exist in newly created object CalendarProperty newLastModifiedProperty = ((CalendarProperty) contentObject .getCmsProperty("profile.modified")); Assert.assertTrue(newLastModifiedProperty != null && newLastModifiedProperty.hasValues(), "Content Object profile.modified date has not been assigned to newly created content object."); //Provide a profile.modified date which is before current modified date Calendar newModifiedDate = Calendar.getInstance(); newModifiedDate.setTimeInMillis(newModifiedDate.getTimeInMillis()); newModifiedDate.add(Calendar.YEAR, -1); ((CalendarProperty) contentObject.getCmsProperty("profile.modified")).setSimpleTypeValue(newModifiedDate); //Save with updateLastModifiedDate flag set to false try { contentObject = contentService.save(contentObject, false, false, null); } catch (CmsConcurrentModificationException ccme) { Assert.assertTrue(ccme.getMessage().startsWith("Content Object " + contentObject.getId() + "/" + contentObject.getSystemName() + " has been concurrently modified by another user or current user has tried to set a value for profile.modified property."), "Invalid error message " + ccme.getMessage()); } //Save with updateLastModifiedDate flag set to true try { contentObject = contentService.save(contentObject, false, true, null); } catch (CmsConcurrentModificationException ccme) { Assert.assertTrue(ccme.getMessage().startsWith("Content Object " + contentObject.getId() + "/" + contentObject.getSystemName() + " has been concurrently modified by another user or current user has tried to set a value for profile.modified property."), "Invalid error message " + ccme.getMessage()); } //Provide a profile.modified date which is after current modified date newModifiedDate.setTimeInMillis(newModifiedDate.getTimeInMillis()); newModifiedDate.add(Calendar.YEAR, 3); ((CalendarProperty) contentObject.getCmsProperty("profile.modified")).setSimpleTypeValue(newModifiedDate); //Save with updateLastModifiedDate flag set to false try { contentObject = contentService.save(contentObject, false, false, null); } catch (CmsConcurrentModificationException ccme) { Assert.assertTrue(ccme.getMessage().startsWith("Content Object " + contentObject.getId() + "/" + contentObject.getSystemName() + " has been concurrently modified by another user or current user has tried to set a value for profile.modified property."), "Invalid error message " + ccme.getMessage()); } //Save with updateLastModifiedDate flag set to true try { contentObject = contentService.save(contentObject, false, true, null); } catch (CmsConcurrentModificationException ccme) { Assert.assertTrue(ccme.getMessage().startsWith("Content Object " + contentObject.getId() + "/" + contentObject.getSystemName() + " has been concurrently modified by another user or current user has tried to set a value for profile.modified property."), "Invalid error message " + ccme.getMessage()); } }
From source file:com.aimluck.eip.schedule.util.ScheduleUtils.java
/** * ????//w ww .j a va 2 s . c o m * * @param start_date * @param end_date * @param repeat_type * @param is_repeat * @param is_span * @param week_0 * @param week_1 * @param week_2 * @param week_3 * @param week_4 * @param week_5 * @param week_6 * @param repeat_week * @param limit_flag * @param limit_start_date * @param limit_end_date * @param month_day * @param login_user * @param entityid * @param msgList * * @param isCellPhone * ????? * @return * @throws ALDBErrorException * @throws ALPageNotFoundException */ public static boolean validateDelegate(ALDateTimeField start_date, ALDateTimeField end_date, ALStringField repeat_type, boolean is_repeat, boolean is_span, ALStringField week_0, ALStringField week_1, ALStringField week_2, ALStringField week_3, ALStringField week_4, ALStringField week_5, ALStringField week_6, ALStringField repeat_week, ALStringField limit_flag, ALDateField limit_start_date, ALDateField limit_end_date, ALNumberField month_day, ALNumberField year_month, ALNumberField year_day, ALEipUser login_user, String entityid, List<String> msgList, boolean isCellPhone) throws ALDBErrorException, ALPageNotFoundException { int YEAR_FIRST = 2004; int YEAR_END = 2016; boolean dayexist = true; switch ((int) year_month.getValue()) { case 2: if (year_day.getValue() == 30 || year_day.getValue() == 31) { dayexist = false; } break; case 4: case 6: case 9: case 11: if (year_day.getValue() == 31) { dayexist = false; } break; default: break; } if (end_date == null) { msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_TYPE_RIGHT_END_DATE")); end_date = start_date; } Calendar startDate = Calendar.getInstance(); startDate.setTime(start_date.getValue()); Calendar endDate = Calendar.getInstance(); endDate.setTime(end_date.getValue()); if (is_repeat) { // ? ?? ???? Calendar tmp_end_date = Calendar.getInstance(); tmp_end_date.set(Calendar.YEAR, Integer.valueOf(start_date.getYear())); tmp_end_date.set(Calendar.MONTH, Integer.valueOf(start_date.getMonth()) - 1); tmp_end_date.set(Calendar.DATE, Integer.valueOf(start_date.getDay())); tmp_end_date.set(Calendar.HOUR_OF_DAY, Integer.valueOf(end_date.getHour())); tmp_end_date.set(Calendar.MINUTE, Integer.valueOf(end_date.getMinute())); tmp_end_date.set(Calendar.SECOND, 0); end_date.setValue(tmp_end_date.getTime()); } if (is_span) { // ? ? 000 ?? Calendar tmp_start_date = Calendar.getInstance(); tmp_start_date.setTime(start_date.getValue()); tmp_start_date.set(Calendar.HOUR_OF_DAY, 0); tmp_start_date.set(Calendar.MINUTE, 0); tmp_start_date.set(Calendar.SECOND, 0); start_date.setValue(tmp_start_date.getTime()); Calendar tmp_end_date = Calendar.getInstance(); tmp_end_date.setTime(end_date.getValue()); tmp_end_date.set(Calendar.HOUR_OF_DAY, 0); tmp_end_date.set(Calendar.MINUTE, 0); tmp_end_date.set(Calendar.SECOND, 0); end_date.setValue(tmp_end_date.getTime()); } // start_date.validate(msgList); int startyear = startDate.get(Calendar.YEAR); if ((startyear < YEAR_FIRST || startyear > YEAR_END) && isCellPhone) { // ??? msgList.add(ALLocalizationUtils.getl10nFormat("SCHEDULE_MESSAGE_SELECT_RIGHT_START_DATE", YEAR_FIRST, YEAR_END)); } if (startDate.get(Calendar.MINUTE) % 15.0 != 0 && isCellPhone) { // ??? msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_START_TIME_PER15")); } // end_date.validate(msgList); int endyear = endDate.get(Calendar.YEAR); if ((endyear < YEAR_FIRST || endyear > YEAR_END) && isCellPhone) { // ??? msgList.add(ALLocalizationUtils.getl10nFormat("SCHEDULE_MESSAGE_SELECT_RIGHT_START_END_DATE", YEAR_FIRST, YEAR_END)); } if (endDate.get(Calendar.MINUTE) % 15.0 != 0 && isCellPhone) { // ??? msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_END_TIME_PER15")); } // if (end_date.getValue().before(start_date.getValue())) { msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_END_DATE_TO_START_DATE")); } if (is_repeat) { try { if ("W".equals(repeat_type.getValue())) { // ,?? if (week_0.getValue() == null && week_1.getValue() == null && week_2.getValue() == null && week_3.getValue() == null && week_4.getValue() == null && week_5.getValue() == null && week_6.getValue() == null) { switch (repeat_week.getValue()) { case "0": msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_EVERY_WEEKLY")); break; case "1": msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_1ST_WEEKLY")); break; case "2": msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_2ND_WEEKLY")); break; case "3": msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_3RD_WEEKLY")); break; case "4": msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_4TH_WEEKLY")); break; case "5": msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_5TH_WEEKLY")); break; default: break; } } } else if ("M".equals(repeat_type.getValue())) { // ?? if (month_day.getValue() == 0 && isCellPhone) { // ??? msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_EVERY_MONTHLY")); } else { month_day.validate(msgList); } } else if ("Y".equals(repeat_type.getValue())) { // ?? if (year_month.getValue() == 0 && isCellPhone) { // ???? msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_EVERY_YEARLY_MONTH")); } else if (year_day.getValue() == 0 && isCellPhone) { // ???? msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_EVERY_YEARLY_DAY")); } else if (!dayexist) { msgList.add(ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_EVERY_YEARLY_DAY_EXIST")); } else { year_month.validate(msgList); year_day.validate(msgList); } } if ("ON".equals(limit_flag.getValue())) { if (!ScheduleUtils.equalsToDate(limit_start_date.getValue().getDate(), limit_end_date.getValue().getDate(), false) && limit_start_date.getValue().getDate().after(limit_end_date.getValue().getDate())) { msgList.add( ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_REPEAT_END_DAY_TO_START_DAY")); } if (isCellPhone) { // ??? Calendar limitStartDate = Calendar.getInstance(); limitStartDate.setTime(limit_start_date.getValue().getDate()); int limitstartyear = limitStartDate.get(Calendar.YEAR); if ((limitstartyear < YEAR_FIRST || limitstartyear > YEAR_END)) { msgList.add(ALLocalizationUtils.getl10nFormat( "SCHEDULE_MESSAGE_SELECT_START_DATE_IN_THIS_TERM", YEAR_FIRST, YEAR_END)); } Calendar limitEndDate = Calendar.getInstance(); limitEndDate.setTime(limit_end_date.getValue().getDate()); int limitendyear = limitEndDate.get(Calendar.YEAR); if ((limitendyear < YEAR_FIRST || limitendyear > YEAR_END)) { msgList.add(ALLocalizationUtils.getl10nFormat( "SCHEDULE_MESSAGE_SELECT_END_DATE_IN_THIS_TERM", YEAR_FIRST, YEAR_END)); } } // ??? // ? char lim = 'N'; Calendar cal = Calendar.getInstance(); cal.setTime(end_date.getValue()); if ("ON".equals(limit_flag.getValue())) { lim = 'L'; } String repeat_pattern; int date_count = 0; if ("D".equals(repeat_type.getValue())) { repeat_pattern = new StringBuffer().append('D').append(lim).toString(); } else if ("W".equals(repeat_type.getValue())) { if ("0".equals(repeat_week.getValue())) { repeat_pattern = new StringBuffer().append('W') .append(week_0.getValue() != null ? 1 : 0) .append(week_1.getValue() != null ? 1 : 0) .append(week_2.getValue() != null ? 1 : 0) .append(week_3.getValue() != null ? 1 : 0) .append(week_4.getValue() != null ? 1 : 0) .append(week_5.getValue() != null ? 1 : 0) .append(week_6.getValue() != null ? 1 : 0).append(lim).toString(); date_count = (week_0.getValue() != null ? 1 : 0) + (week_1.getValue() != null ? 1 : 0) + (week_2.getValue() != null ? 1 : 0) + (week_3.getValue() != null ? 1 : 0) + (week_4.getValue() != null ? 1 : 0) + (week_5.getValue() != null ? 1 : 0) + (week_6.getValue() != null ? 1 : 0); } else { repeat_pattern = new StringBuffer().append('W') .append(week_0.getValue() != null ? 1 : 0) .append(week_1.getValue() != null ? 1 : 0) .append(week_2.getValue() != null ? 1 : 0) .append(week_3.getValue() != null ? 1 : 0) .append(week_4.getValue() != null ? 1 : 0) .append(week_5.getValue() != null ? 1 : 0) .append(week_6.getValue() != null ? 1 : 0) .append(repeat_week.getValue().charAt(0)).append(lim).toString(); date_count = (week_0.getValue() != null ? 1 : 0) + (week_1.getValue() != null ? 1 : 0) + (week_2.getValue() != null ? 1 : 0) + (week_3.getValue() != null ? 1 : 0) + (week_4.getValue() != null ? 1 : 0) + (week_5.getValue() != null ? 1 : 0) + (week_6.getValue() != null ? 1 : 0); } } else if ("M".equals(repeat_type.getValue())) { DecimalFormat format = new DecimalFormat("00"); if (32 == month_day.getValue()) { repeat_pattern = new StringBuffer().append('M').append("XX").append(lim).toString(); } else { repeat_pattern = new StringBuffer().append('M') .append(format.format(month_day.getValue())).append(lim).toString(); } date_count = 1; } else { DecimalFormat format = new DecimalFormat("00"); repeat_pattern = new StringBuffer().append('Y').append(format.format(year_month.getValue())) .append(format.format(year_day.getValue())).append(lim).toString(); date_count = 1; } // (?) Calendar sDate = new GregorianCalendar(); sDate.set(Calendar.YEAR, Integer.valueOf(limit_start_date.getYear())); sDate.set(Calendar.MONTH, Integer.valueOf(limit_start_date.getMonth()) - 1); sDate.set(Calendar.DATE, Integer.valueOf(limit_start_date.getDay())); sDate.set(Calendar.HOUR_OF_DAY, 0); sDate.set(Calendar.MINUTE, 0); sDate.set(Calendar.SECOND, 0); // ?? Calendar finalDate = new GregorianCalendar(); finalDate.set(Calendar.YEAR, Integer.valueOf(limit_end_date.getYear())); finalDate.set(Calendar.MONTH, Integer.valueOf(limit_end_date.getMonth()) - 1); finalDate.set(Calendar.DATE, Integer.valueOf(limit_end_date.getDay())); finalDate.set(Calendar.HOUR_OF_DAY, 23); finalDate.set(Calendar.MINUTE, 59); finalDate.set(Calendar.SECOND, 59); int countAvailableDate = 0; while (sDate.before(finalDate) || sDate.equals(finalDate)) { if (ScheduleUtils.matchDay(sDate, repeat_pattern)) { countAvailableDate++; if (countAvailableDate >= date_count) { break; } } sDate.add(Calendar.DATE, 1); } if (countAvailableDate < date_count) { msgList.add( ALLocalizationUtils.getl10n("SCHEDULE_MESSAGE_SELECT_REPEAT_SPAN_IN_THIS_TERM")); } } } catch (NumberFormatException nfe) { logger.error("[ScheduleFormData] NumberFormatException: Limit Date is wrong."); throw new ALPageNotFoundException(); } catch (ALIllegalDateException ad) { logger.error("[ScheduleFormData] ALIllegalDateException: Limit Date is wrong."); throw new ALPageNotFoundException(); } } return (msgList.size() == 0); }