List of usage examples for java.util GregorianCalendar getTime
public final Date getTime()
Date
object representing this Calendar
's time value (millisecond offset from the Epoch"). From source file:org.webical.test.web.component.DayViewPanelTest.java
/** * Test whether the panel renders correct without events *///from w ww . j a v a 2 s .c o m public void testWithoutEvents() throws WebicalException { // Add an EventManager annotApplicationContextMock.putBean("eventManager", new MockEventManager()); final GregorianCalendar currentDate = CalendarUtils.newTodayCalendar(getFirstDayOfWeek()); // Create the testpage with with a DayViewPanel wicketTester.startPage(new ITestPageSource() { private static final long serialVersionUID = 1L; public Page getTestPage() { return new PanelTestPage(new DayViewPanel(PanelTestPage.PANEL_MARKUP_ID, 1, currentDate) { private static final long serialVersionUID = 1L; @Override public void onAction(IAction action) { /* NOTHING TO DO */ } }); } }); //Basic assertions wicketTester.assertRenderedPage(PanelTestPage.class); wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID, DayViewPanel.class); // Assert the heading label DateFormat dateFormat = new SimpleDateFormat("EEEE", getTestSession().getLocale()); wicketTester.assertLabel(PanelTestPage.PANEL_MARKUP_ID + ":dayLink", dateFormat.format(currentDate.getTime())); // Assert the number of events rendered wicketTester.assertListView(PanelTestPage.PANEL_MARKUP_ID + ":eventItem", new ArrayList<Event>()); }
From source file:org.webical.test.web.component.WeekViewPanelTest.java
/** * Test week view with less then 7 days// w w w.j a v a 2 s.co m * @throws WebicalException */ public void testNonWeekUse() throws WebicalException { MockCalendarManager mockCalendarManager = (MockCalendarManager) annotApplicationContextMock .getBean("calendarManager"); Calendar calendar1 = mockCalendarManager.getCalendarById("1"); MockEventManager mockEventManager = new MockEventManager(); annotApplicationContextMock.putBean("eventManager", mockEventManager); // Define the current date final GregorianCalendar currentDate = CalendarUtils.newTodayCalendar(getFirstDayOfWeek()); currentDate.setFirstDayOfWeek(GregorianCalendar.MONDAY); // The list containing the different events List<Event> allEvents = new ArrayList<Event>(); GregorianCalendar refcal = CalendarUtils.duplicateCalendar(currentDate); refcal.add(GregorianCalendar.DAY_OF_MONTH, 1); refcal.set(GregorianCalendar.HOUR_OF_DAY, 12); refcal.set(GregorianCalendar.MINUTE, 0); refcal.set(GregorianCalendar.SECOND, 0); GregorianCalendar cal = CalendarUtils.duplicateCalendar(currentDate); // Add a normal event tomorrow Event event = new Event(); event.setUid("e1"); event.setCalendar(calendar1); event.setSummary("Normal Event Description"); event.setLocation("Normal Event Location"); event.setDescription("Event e1"); cal.setTime(refcal.getTime()); event.setDtStart(cal.getTime()); cal.add(GregorianCalendar.HOUR_OF_DAY, 2); event.setDtEnd(cal.getTime()); log.debug( "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd()); allEvents.add(event); mockEventManager.storeEvent(event); // Add a short recurring event, starting today, ending tomorrow event = new Event(); event.setUid("e2"); event.setCalendar(calendar1); event.setSummary("Recurring Event Today"); event.setLocation("Recurring Event Location"); event.setDescription("Event e2"); cal.setTime(refcal.getTime()); cal.add(GregorianCalendar.DAY_OF_MONTH, -1); event.setDtStart(cal.getTime()); cal.add(GregorianCalendar.HOUR_OF_DAY, 2); cal.add(GregorianCalendar.DAY_OF_MONTH, 2); event.setDtEnd(cal.getTime()); RecurrenceUtil.setRecurrenceRule(event, new Recurrence(Recurrence.DAILY, 1, CalendarUtils.getEndOfDay(cal.getTime()))); log.debug( "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd()); allEvents.add(event); mockEventManager.storeEvent(event); // Add a long recurring event, starting last week, ending next week event = new Event(); event.setUid("e3"); event.setCalendar(calendar1); event.setSummary("Recurring Event Last Month"); event.setLocation("Recurring Event Location"); event.setDescription("Event e3"); cal.setTime(refcal.getTime()); cal.add(GregorianCalendar.WEEK_OF_YEAR, -1); event.setDtStart(cal.getTime()); cal.add(GregorianCalendar.HOUR_OF_DAY, 2); cal.add(GregorianCalendar.WEEK_OF_YEAR, 3); event.setDtEnd(cal.getTime()); RecurrenceUtil.setRecurrenceRule(event, new Recurrence(Recurrence.DAILY, 1, CalendarUtils.getEndOfDay(cal.getTime()))); log.debug( "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd()); allEvents.add(event); mockEventManager.storeEvent(event); // Add a (pseudo) all day event, starting day + 1 midnight, ending day + 2 00:00 hours event = new Event(); event.setUid("e4"); event.setCalendar(calendar1); event.setSummary("Pseudo All Day Event"); event.setLocation("All Day Event Location"); event.setDescription("Starting day + 1, ending day + 2 00:00 hours"); cal.setTime(refcal.getTime()); cal.add(GregorianCalendar.DAY_OF_MONTH, 1); cal.set(GregorianCalendar.HOUR_OF_DAY, 0); cal.set(GregorianCalendar.MINUTE, 0); cal.set(GregorianCalendar.SECOND, 0); cal.set(GregorianCalendar.MILLISECOND, 0); event.setDtStart(cal.getTime()); cal.add(GregorianCalendar.DAY_OF_MONTH, 1); event.setDtEnd(cal.getTime()); log.debug( "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd()); allEvents.add(event); mockEventManager.storeEvent(event); // Create test page with a WeekViewPanel wicketTester.startPage(new ITestPageSource() { private static final long serialVersionUID = 1L; public Page getTestPage() { return new PanelTestPage(new WeekViewPanel(PanelTestPage.PANEL_MARKUP_ID, 4, currentDate) { private static final long serialVersionUID = 1L; @Override public void onAction(IAction action) { /* NOTHING TO DO */ } }); } }); // Basic assertions wicketTester.assertRenderedPage(PanelTestPage.class); wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID, WeekViewPanel.class); // Assert number of days rendered // Set the correct dates to find the first and last day of the week GregorianCalendar viewFirstDayCalendar = CalendarUtils.duplicateCalendar(currentDate); // Assert the first day in the view wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID + ":weekColumnRepeater:day" + viewFirstDayCalendar.get(GregorianCalendar.DAY_OF_YEAR), WeekDayPanel.class); GregorianCalendar viewLastDayCalendar = CalendarUtils.duplicateCalendar(currentDate); viewLastDayCalendar.add(GregorianCalendar.DAY_OF_MONTH, 3); // Assert the last day in the view wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID + ":weekColumnRepeater:day" + viewLastDayCalendar.get(GregorianCalendar.DAY_OF_YEAR), WeekDayPanel.class); // Events for days in this 4 day period List<Event> dayEvents = new ArrayList<Event>(); // Assert weekday events GregorianCalendar weekCal = CalendarUtils.duplicateCalendar(currentDate); for (int i = 0; i < 4; ++i) { WeekDayPanel weekDayEventsListView = (WeekDayPanel) wicketTester.getLastRenderedPage() .get(PanelTestPage.PANEL_MARKUP_ID + ":weekColumnRepeater:day" + weekCal.get(GregorianCalendar.DAY_OF_YEAR)); switch (i) { case 0: dayEvents.clear(); dayEvents.add(allEvents.get(1)); // e2 dayEvents.add(allEvents.get(2)); // e3 break; case 1: dayEvents.clear(); dayEvents.add(allEvents.get(0)); // e1 dayEvents.add(allEvents.get(1)); // e2 dayEvents.add(allEvents.get(2)); // e3 break; case 2: dayEvents.clear(); dayEvents.add(allEvents.get(1)); // e2 dayEvents.add(allEvents.get(2)); // e3 dayEvents.add(allEvents.get(3)); // e4 break; case 3: dayEvents.clear(); dayEvents.add(allEvents.get(2)); // e3 break; } String path = weekDayEventsListView.getPageRelativePath() + ":eventItem"; wicketTester.assertListView(path, dayEvents); ListView listView = (ListView) wicketTester.getComponentFromLastRenderedPage(path); Iterator<?> lvIt = listView.iterator(); while (lvIt.hasNext()) { ListItem item = (ListItem) lvIt.next(); Event evt = (Event) item.getModelObject(); List<?> bhvs = item.getBehaviors(); if (evt.getUid().equals("e4")) assertEquals(1, bhvs.size()); // e4 all day event else assertEquals(0, bhvs.size()); } weekCal.add(GregorianCalendar.DAY_OF_WEEK, 1); } }
From source file:com.collabnet.ccf.pi.cee.pt.v50.ProjectTrackerWriter.java
private String convertAttributeValue(FieldValueTypeValue fieldType, Object fieldValue, String targetSystemTimezone) { String attributeValue = null; if (fieldValue == null) return null; if (fieldType == FieldValueTypeValue.STRING) { attributeValue = fieldValue.toString(); } else if (fieldType == FieldValueTypeValue.INTEGER) { attributeValue = fieldValue.toString(); } else if (fieldType == FieldValueTypeValue.DOUBLE) { attributeValue = fieldValue.toString(); } else if (fieldType == FieldValueTypeValue.DATE) { GregorianCalendar gc = (GregorianCalendar) fieldValue; attributeValue = Long.toString(gc.getTime().getTime()); } else if (fieldType == FieldValueTypeValue.DATETIME) { Date date = (Date) fieldValue; if (!StringUtils.isEmpty(targetSystemTimezone) && (!targetSystemTimezone.equals(GenericArtifact.VALUE_UNKNOWN))) { try { date = DateUtil.convertDate(date, targetSystemTimezone); } catch (ParseException e) { // This will never happen }//from ww w . j a v a2 s . com } attributeValue = Long.toString(date.getTime()); } else if (fieldType == FieldValueTypeValue.BOOLEAN) { Boolean value = (Boolean) fieldValue; attributeValue = value.toString(); } else if (fieldType == FieldValueTypeValue.BASE64STRING) { attributeValue = fieldValue.toString(); } else if (fieldType == FieldValueTypeValue.HTMLSTRING) { attributeValue = fieldValue.toString(); } else if (fieldType == FieldValueTypeValue.USER) { attributeValue = fieldValue.toString(); } return attributeValue; }
From source file:org.mifos.accounts.loan.struts.action.LoanAccountAction.java
/** * Resolve repayment start date according to given disbursement date * <p/>//from w ww . jav a2 s . c o m * The resulting date equates to the disbursement date plus MIN_DAYS_BETWEEN_DISBURSAL_AND_FIRST_REPAYMENT_DAY: e.g. * If disbursement date is 18 June 2008, and MIN_DAYS_BETWEEN_DISBURSAL_AND_FIRST_REPAYMENT_DAY is 1 then the * repayment start date would be 19 June 2008 * * @return Date repaymentStartDate * @throws PersistenceException */ private Date resolveRepaymentStartDate(final Date disbursementDate) { int minDaysInterval = configurationPersistence .getConfigurationValueInteger(MIN_DAYS_BETWEEN_DISBURSAL_AND_FIRST_REPAYMENT_DAY); final GregorianCalendar repaymentStartDate = new GregorianCalendar(); repaymentStartDate.setTime(disbursementDate); repaymentStartDate.add(Calendar.DAY_OF_WEEK, minDaysInterval); return repaymentStartDate.getTime(); }
From source file:org.opencms.notification.CmsContentNotification.java
/** * Creates the mail to be sent to the responsible user.<p> * /*from w w w . j a v a 2s . c om*/ * @return the mail to be sent to the responsible user */ protected String generateHtmlMsg() { // set the messages m_messages = Messages.get().getBundle(getLocale()); StringBuffer htmlMsg = new StringBuffer(); htmlMsg.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">"); htmlMsg.append("<tr><td colspan=\"5\"><br/>"); GregorianCalendar tomorrow = new GregorianCalendar(TimeZone.getDefault(), CmsLocaleManager.getDefaultLocale()); tomorrow.add(Calendar.DAY_OF_YEAR, 1); List outdatedResources = new ArrayList(); List resourcesNextDay = new ArrayList(); List resourcesNextWeek = new ArrayList(); // split all resources into three lists: the resources that expire, will be released or get outdated // within the next 24h, within the next week and the resources unchanged since a long time Iterator notificationCauses = m_notificationCauses.iterator(); while (notificationCauses.hasNext()) { CmsExtendedNotificationCause notificationCause = (CmsExtendedNotificationCause) notificationCauses .next(); if (notificationCause.getCause() == CmsExtendedNotificationCause.RESOURCE_OUTDATED) { outdatedResources.add(notificationCause); } else if (notificationCause.getDate().before(tomorrow.getTime())) { resourcesNextDay.add(notificationCause); } else { resourcesNextWeek.add(notificationCause); } } Collections.sort(resourcesNextDay); Collections.sort(resourcesNextWeek); Collections.sort(outdatedResources); appendResourceList(htmlMsg, resourcesNextDay, m_messages.key(Messages.GUI_WITHIN_NEXT_DAY_0)); appendResourceList(htmlMsg, resourcesNextWeek, m_messages.key(Messages.GUI_WITHIN_NEXT_WEEK_0)); appendResourceList(htmlMsg, outdatedResources, m_messages.key(Messages.GUI_FILES_NOT_UPDATED_1, String.valueOf(OpenCms.getSystemInfo().getNotificationTime()))); htmlMsg.append("</td></tr></table>"); String result = htmlMsg.toString(); return result; }
From source file:org.gcaldaemon.core.GCalUtilitiesV3.java
private static final DateTime toOneDayEventDateTime(Date date) throws Exception { // Convert one day event's date to UTC date String text = date.toString(); GregorianCalendar calendar = new GregorianCalendar(UTC); calendar.set(GregorianCalendar.YEAR, Integer.parseInt(text.substring(0, 4))); calendar.set(GregorianCalendar.MONTH, Integer.parseInt(text.substring(4, 6)) - 1); calendar.set(GregorianCalendar.DAY_OF_MONTH, Integer.parseInt(text.substring(6))); calendar.set(GregorianCalendar.HOUR_OF_DAY, 0); calendar.set(GregorianCalendar.MINUTE, 0); calendar.set(GregorianCalendar.SECOND, 0); calendar.set(GregorianCalendar.MILLISECOND, 0); DateTime dateTime = new DateTime(true, calendar.getTime().getTime(), 0); return dateTime; }
From source file:cs.gui.stats.PerformanceStats.java
public PerformanceStats(ModelInterface modelInterfaceRef, StatsManager statsManagerRer) { super(new BorderLayout()); this.modelInterface = modelInterfaceRef; this.statsManager = statsManagerRer; datasets = new TimeSeriesCollection[SUBPLOT_COUNT]; // set the initial date according to the one specified in SystemClock object GregorianCalendar calendar = new GregorianCalendar(); calendar.set(GregorianCalendar.HOUR_OF_DAY, modelInterface.getSimulationClock().getStartTime().get(Calendar.HOUR_OF_DAY)); calendar.set(GregorianCalendar.DAY_OF_MONTH, modelInterface.getSimulationClock().getStartTime().get(Calendar.DAY_OF_MONTH)); calendar.set(GregorianCalendar.MONTH, modelInterface.getSimulationClock().getStartTime().get(Calendar.MONTH)); calendar.set(GregorianCalendar.YEAR, modelInterface.getSimulationClock().getStartTime().get(Calendar.YEAR)); //setup the initial date range GregorianCalendar calendarForInitialDateRange = new GregorianCalendar(); calendarForInitialDateRange.set(GregorianCalendar.HOUR_OF_DAY, modelInterface.getSimulationClock().getStartTime().get(Calendar.HOUR_OF_DAY)); calendarForInitialDateRange.set(GregorianCalendar.DAY_OF_MONTH, modelInterface.getSimulationClock().getStartTime().get(Calendar.DAY_OF_MONTH)); calendarForInitialDateRange.set(GregorianCalendar.MONTH, modelInterface.getSimulationClock().getStartTime().get(Calendar.MONTH)); calendarForInitialDateRange.set(GregorianCalendar.YEAR, modelInterface.getSimulationClock().getStartTime().get(Calendar.YEAR)); initialDateRange = new DateRange(calendarForInitialDateRange.getTime(), calendar.getTime()); initialDateRange1 = new DateRange(calendarForInitialDateRange.getTime(), calendar.getTime()); initialDateRange2 = new DateRange(calendarForInitialDateRange.getTime(), calendar.getTime()); initialDateRange3 = new DateRange(calendarForInitialDateRange.getTime(), calendar.getTime()); initialDateRange4 = new DateRange(calendarForInitialDateRange.getTime(), calendar.getTime()); initialDateRange5 = new DateRange(calendarForInitialDateRange.getTime(), calendar.getTime()); JPanel tabbedPanel = createChartTab(); add(tabbedPanel, "North"); }
From source file:com.workplacesystems.queuj.process.ProcessWrapper.java
public void start() { // Calculate next run time for the process GregorianCalendar nextRun = getNextRunTime(); if (nextRun == null) // No run is due return;/*from w ww .ja v a2s . co m*/ if (log.isDebugEnabled()) { String desc = getDescription(); if (desc == null) desc = getProcessName(); if (desc == null) desc = "Process: " + getProcessKey(); desc = desc.trim(); log.debug("Next run date for " + desc + " is " + nextRun.getTime().toString()); } // Implementations can schedule the job themselves calling start(runTime, isFailed) // closer to the scheduled run time. This may allow the ProcessServer to be unloaded // from memory and re-loaded closer to the time. The default implementation // just returns false and does the scheduling in the ProcessScheduler. if (!getContainingServer().scheduleOverride(this, nextRun)) start(nextRun, isFailed()); }
From source file:org.nuxeo.ecm.core.opencmis.impl.CmisSuiteSession.java
@Test public void testContentStream() throws Exception { Document file = (Document) session.getObjectByPath("/testfolder1/testfile1"); // check Cache Response Headers (eTag and Last-Modified) if (isAtomPub || isBrowser) { RepositoryInfo ri = session.getRepositoryInfo(); String uri = ri.getThinClientUri() + ri.getId() + "/"; uri += isAtomPub ? "content?id=" : "root?objectId="; uri += file.getId();/* w w w . j av a 2 s . c om*/ String eTag = file.getPropertyValue("nuxeo:contentStreamDigest"); GregorianCalendar lastModifiedCalendar = file.getPropertyValue("dc:modified"); String lastModified = DateUtil.formatDate(lastModifiedCalendar.getTime()); String encoding = Base64.encodeBytes(new String(USERNAME + ":" + PASSWORD).getBytes()); DefaultHttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(uri); HttpResponse response = null; request.setHeader("Authorization", "Basic " + encoding); try { request.setHeader("If-None-Match", eTag); response = client.execute(request); assertEquals(HttpServletResponse.SC_NOT_MODIFIED, response.getStatusLine().getStatusCode()); request.removeHeaders("If-None-Match"); request.setHeader("If-Modified-Since", lastModified); response = client.execute(request); String debug = "lastModified=" + lastModifiedCalendar.getTimeInMillis() + " If-Modified-Since=" + lastModified + " NuxeoContentStream last=" + NuxeoContentStream.LAST_MODIFIED; // TODO NXP-16198 there are still timezone issues here // @Ignore // assertEquals(debug, HttpServletResponse.SC_NOT_MODIFIED, response.getStatusLine().getStatusCode()); } finally { client.getConnectionManager().shutdown(); } } // get stream ContentStream cs = file.getContentStream(); assertNotNull(cs); assertEquals("text/plain", cs.getMimeType()); assertEquals("testfile.txt", cs.getFileName()); if (!(isAtomPub || isBrowser)) { // TODO fix AtomPub/Browser case where the length is unknown // (streaming) assertEquals(Helper.FILE1_CONTENT.length(), cs.getLength()); } assertEquals(Helper.FILE1_CONTENT, Helper.read(cs.getStream(), "UTF-8")); // set stream // TODO convenience constructors for ContentStreamImpl byte[] streamBytes = STREAM_CONTENT.getBytes("UTF-8"); ByteArrayInputStream stream = new ByteArrayInputStream(streamBytes); cs = new ContentStreamImpl("foo.txt", BigInteger.valueOf(streamBytes.length), "text/plain; charset=UTF-8", stream); file.setContentStream(cs, true); // refetch stream file = (Document) session.getObject(file); cs = file.getContentStream(); assertNotNull(cs); // AtomPub lowercases charset -> TODO proper mime type comparison String mimeType = cs.getMimeType().toLowerCase().replace(" ", ""); assertEquals("text/plain;charset=utf-8", mimeType); // TODO fix AtomPub case where the filename is null assertEquals("foo.txt", cs.getFileName()); if (!(isAtomPub || isBrowser)) { // TODO fix AtomPub/Browser case where the length is unknown // (streaming) assertEquals(streamBytes.length, cs.getLength()); } assertEquals(STREAM_CONTENT, Helper.read(cs.getStream(), "UTF-8")); // delete file.deleteContentStream(); file.refresh(); assertEquals(null, file.getContentStream()); }
From source file:org.geosdi.geoplatform.services.GPPublisherBasicServiceImpl.java
private void addTifCleanerJob(String userWorkspace, String layerName, String filePath) { if (GPSharedUtils.isEmpty(userWorkspace) || GPSharedUtils.isEmpty(layerName)) { throw new IllegalArgumentException( "The workspace: " + userWorkspace + " or the layerName: " + layerName + " are null"); }/*from w ww .j av a 2 s .c o m*/ TriggerKey triggerKey = new TriggerKey(userWorkspace + ":" + layerName, PublisherScheduler.PUBLISHER_GROUP); GregorianCalendar calendar = new GregorianCalendar(); calendar.add(Calendar.MINUTE, 30); Trigger trigger = TriggerBuilder.newTrigger().forJob(this.scheduler.getCleanerJobTifDetail()) .withIdentity(triggerKey).withDescription("Runs after 30 minutes").startAt(calendar.getTime()) .withSchedule(CalendarIntervalScheduleBuilder.calendarIntervalSchedule() .withMisfireHandlingInstructionFireAndProceed()) .build(); trigger.getJobDataMap().put(PublishUtility.USER_WORKSPACE, userWorkspace); trigger.getJobDataMap().put(PublishUtility.FILE_NAME, layerName); trigger.getJobDataMap().put(PublishUtility.FILE_PATH, filePath); trigger.getJobDataMap().put(PublishUtility.PUBLISHER_SERVICE, this); this.scheduleTrigger(triggerKey, trigger); }