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:airport.services.dispatcher.GeneratorFlightImpl.java
private void createNewJobAndTrigger() { JobDataMap dataMap = new JobDataMap(); dataMap.put(PARAMETER_FMTDAO_NAME, flyingMachineTypeDao); dataMap.put(PARAMETER_GENFLIGHTJMS_NAME, jMS); GregorianCalendar calendar = new GregorianCalendar(); calendar.add(GregorianCalendar.SECOND, DELAY_TIMER_SEC); jobDetailFlight = newJob(JobAddFlight.class).withIdentity(SCHEDULE_JOBDET_NAME, SCHEDULE_GROUP_NAME) .setJobData(dataMap).build(); triggerFlight = newTrigger().withIdentity(SCHEDULE_TRIGGER_NAME, SCHEDULE_GROUP_NAME) .startAt(calendar.getTime()).withSchedule(SimpleScheduleBuilder.simpleSchedule() .withIntervalInSeconds(DELAY_TIMER_SEC).repeatForever()) .build();// w w w . ja va 2 s.c o m }
From source file:org.openehealth.coala.converter.PXSDateConverterTest.java
/** * @throws java.lang.Exception/* w w w .ja v a 2s. co m*/ */ @Before public void setUp() throws Exception { ResourceBundle properties = ResourceBundle.getBundle("coala-document"); longPattern = properties.getString("coala.consent.longdatepattern"); shortPattern = properties.getString("coala.consent.shortdatepattern"); GregorianCalendar cal = new GregorianCalendar(); cal.set(Calendar.YEAR, 2011); cal.set(Calendar.MONTH, Calendar.JANUARY); cal.set(Calendar.DAY_OF_MONTH, 15); cal.set(Calendar.HOUR, 3); cal.set(Calendar.MINUTE, 36); cal.set(Calendar.SECOND, 50); cal.set(Calendar.MILLISECOND, 0); referenceDateLong = cal.getTime(); cal = new GregorianCalendar(); cal.set(Calendar.YEAR, 2011); cal.set(Calendar.MONTH, Calendar.JANUARY); cal.set(Calendar.DAY_OF_MONTH, 15); cal.set(Calendar.HOUR, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); referenceDateShort = cal.getTime(); }
From source file:org.miloss.fgsms.services.rs.impl.reports.os.DiskIOReport.java
@Override public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files, TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx) throws IOException { Connection con = Utility.getPerformanceDBConnection(); try {/*w ww . j a v a2 s .co m*/ PreparedStatement cmd = null; ResultSet rs = null; JFreeChart chart = null; data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>"); data.append(GetHtmlFormattedHelp() + "<br />"); data.append( "<table class=\"table table-hover\"><tr><th>URI</th><th>Average Free Disk Space (all paritions)</th><th>Average Write KB/s</th><th>Average Read KB/s</th></tr>"); TimeSeriesCollection col = new TimeSeriesCollection(); for (int i = 0; i < urls.size(); i++) { if (!isPolicyTypeOf(urls.get(i), PolicyType.MACHINE)) { continue; } //https://github.com/mil-oss/fgsms/issues/112 if (!UserIdentityUtil.hasReadAccess(currentuser, "getReport", urls.get(i), classification, ctx)) { continue; } String url = Utility.encodeHTML(BaseReportGenerator.getPolicyDisplayName(urls.get(i))); double average = 0; data.append("<tr><td>").append(url).append("</td>"); try { cmd = con.prepareStatement( "select avg(freespace) from rawdatadrives where uri=? and utcdatetime > ? and utcdatetime < ?;"); cmd.setString(1, urls.get(i)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); if (rs.next()) { average = rs.getDouble(1); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } data.append("<td>").append(average + "").append("</td>"); average = 0; try { cmd = con.prepareStatement( "select avg(writekbs) from rawdatadrives where uri=? and utcdatetime > ? and utcdatetime < ?;"); cmd.setString(1, urls.get(i)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); if (rs.next()) { average = rs.getDouble(1); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } data.append("<td>").append(average + "").append("</td>"); average = 0; try { cmd = con.prepareStatement( "select avg(readkbs) from rawdatadrives where uri=? and utcdatetime > ? and utcdatetime < ?;"); cmd.setString(1, urls.get(i)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); if (rs.next()) { average = rs.getDouble(1); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } data.append("<td>").append(average + "").append("</td></tr>"); //ok now get the raw data.... TimeSeriesContainer tsc = new TimeSeriesContainer(); try { cmd = con.prepareStatement( "select readkbs, writekbs,freespace, utcdatetime, driveidentifier from rawdatadrives where uri=? and utcdatetime > ? and utcdatetime < ?;"); cmd.setString(1, urls.get(i)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); while (rs.next()) { TimeSeries ts = tsc.Get(url + " " + rs.getString("driveidentifier") + " Read", Millisecond.class); TimeSeries ts2 = tsc.Get(url + " " + rs.getString("driveidentifier") + " Write", Millisecond.class); //TimeSeries ts2 = tsc.Get(urls.get(i) + " " + rs.getString("driveidentifier") , Millisecond.class); GregorianCalendar gcal = new GregorianCalendar(); gcal.setTimeInMillis(rs.getLong(4)); Millisecond m = new Millisecond(gcal.getTime()); ts.addOrUpdate(m, rs.getLong("readKBs")); ts2.addOrUpdate(m, rs.getLong("writeKBs")); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } for (int ik = 0; ik < tsc.data.size(); ik++) { col.addSeries(tsc.data.get(ik)); } } chart = org.jfree.chart.ChartFactory.createTimeSeriesChart(GetDisplayName(), "Timestamp", "Rate", col, true, false, false); data.append("</table>"); try { // if (set.getRowCount() != 0) { ChartUtilities.saveChartAsPNG(new File( path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart, 1500, 400); data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">"); files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"); // } } catch (IOException ex) { log.log(Level.ERROR, "Error saving chart image for request", ex); } } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(con); } }
From source file:org.nuxeo.ecm.webapp.search.SearchResultsBean.java
public String downloadCSV() throws ClientException { try {/* w w w . j a v a2s . co m*/ if (newProviderName == null) { throw new ClientException("providerName not set"); } PagedDocumentsProvider provider = getProvider(newProviderName); HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance() .getExternalContext().getResponse(); response.setContentType("text/csv"); response.setHeader("Content-Disposition", "attachment; filename=\"search_results.csv\""); char separator = Framework.getProperty("org.nuxeo.ecm.webapp.search.csv.separator", ",").charAt(0); char quotechar = Framework.getProperty("org.nuxeo.ecm.webapp.search.csv.quotechar", "\"").charAt(0); String endOfLine = Framework.getProperty("org.nuxeo.ecm.webapp.search.csv.endofline", "\n"); CSVWriter writer = new CSVWriter(response.getWriter(), separator, quotechar, endOfLine); List<FieldWidget> widgetList = searchColumns.getResultColumns(); Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); String[] columnNames = new String[widgetList.size()]; int i = 0; for (FieldWidget widget : widgetList) { String columnName = resourcesAccessor.getMessages().get(widget.getLabel()); columnNames[i++] = columnName; } writer.writeNext(columnNames); // GR dump all pages... why not, but we need to restore current page // number. int currentPage = provider.getCurrentPageIndex(); int pageCount = provider.getNumberOfPages(); for (int page = 0; page < pageCount; page++) { DocumentModelList docModelList = provider.getPage(page); for (DocumentModel docModel : docModelList) { String[] columns = new String[widgetList.size()]; i = 0; for (FieldWidget widget : widgetList) { String fieldSchema = widget.getSchemaName(); String fieldName = widget.getFieldName(); Object value = docModel.getProperty(fieldSchema, fieldName); if (fieldSchema.equals("dublincore") && fieldName.equals("title")) { value = DocumentModelFunctions.titleOrId(docModel); } else if (fieldSchema.equals("ecm") && fieldName.equals("primaryType")) { value = docModel.getType(); } else if (fieldSchema.equals("ecm") && fieldName.equals("currentLifeCycleState")) { value = docModel.getCurrentLifeCycleState(); } else { value = docModel.getProperty(fieldSchema, fieldName); } String stringValue; if (value == null) { stringValue = ""; } else if (value instanceof GregorianCalendar) { GregorianCalendar gValue = (GregorianCalendar) value; stringValue = df.format(gValue.getTime()); } else { stringValue = String.valueOf(value); } columns[i++] = stringValue; } writer.writeNext(columns); } } writer.close(); response.flushBuffer(); FacesContext.getCurrentInstance().responseComplete(); // restoring current page provider.getPage(currentPage); } catch (IOException e) { throw new ClientException("download csv failed", e); } return null; }
From source file:edu.lternet.pasta.portal.statistics.GrowthStats.java
private ArrayList<String> buildLabels(GregorianCalendar start, GregorianCalendar end, int scale) { ArrayList<String> labels = new ArrayList<String>(); GregorianCalendar lower = (GregorianCalendar) start.clone(); GregorianCalendar upper = new GregorianCalendar(); GregorianCalendar split = new GregorianCalendar(); while (lower.getTimeInMillis() <= end.getTimeInMillis()) { upper.setTime(lower.getTime()); upper.add(scale, 1);/* w w w .j a v a 2s .co m*/ split.setTime( new Date(lower.getTimeInMillis() + (upper.getTimeInMillis() - lower.getTimeInMillis()) / 2)); /* System.out.printf("%s-%s-%s%n", lower.getTime().toString(), split.getTime().toString(), upper.getTime().toString()); */ labels.add(getLabel(scale, split)); lower.setTime(upper.getTime()); } return labels; }
From source file:com.activiti.android.ui.fragments.task.form.TaskFormFoundationFragment.java
@Override public void onDatePicked(String fieldId, GregorianCalendar gregorianCalendar) { formManager.setPropertyValue(fieldId, gregorianCalendar.getTime()); }
From source file:com.betel.flowers.web.bean.VariedadBean.java
private String codigoFoto() { GregorianCalendar calendario = new GregorianCalendar(); SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyy"); return "BETEL-V" + RandomStringUtils.randomNumeric(4) + "-IMG-" + format.format(calendario.getTime()); }
From source file:org.talend.designer.maven.ui.setting.preference.M2eUserSettingForTalendLoginTask.java
@Override public Date getOrder() { GregorianCalendar gc = new GregorianCalendar(2015, 6, 17, 12, 0, 0); return gc.getTime(); }
From source file:org.squale.squalix.stats.ComputeStats.java
/** * @return la date courante moins le nombre de mois dfinis */// www.j a v a 2 s . c om private Date getBeginDate() { GregorianCalendar cal = new GregorianCalendar(); long today = Calendar.getInstance().getTimeInMillis(); cal.add(GregorianCalendar.MONTH, 0 - NB_MONTHS); return cal.getTime(); }
From source file:org.opencms.notification.CmsNotificationCandidates.java
/** * Collects all resources that will expire in short time, or will become valid, or are not modified since a long time.<p> * /* w w w. j a v a2 s . com*/ * @param cms the CmsObject * * @throws CmsException if something goes wrong */ public CmsNotificationCandidates(CmsObject cms) throws CmsException { m_resources = new ArrayList(); m_cms = cms; m_cms.getRequestContext() .setCurrentProject(m_cms.readProject(OpenCms.getSystemInfo().getNotificationProject())); String folder = "/"; GregorianCalendar now = new GregorianCalendar(TimeZone.getDefault(), CmsLocaleManager.getDefaultLocale()); now.setTimeInMillis(System.currentTimeMillis()); GregorianCalendar inOneWeek = (GregorianCalendar) now.clone(); inOneWeek.add(Calendar.WEEK_OF_YEAR, 1); Iterator resources; CmsResource resource; // read all files with the 'notification-interval' property set try { resources = m_cms .readResourcesWithProperty(folder, CmsPropertyDefinition.PROPERTY_NOTIFICATION_INTERVAL) .iterator(); while (resources.hasNext()) { resource = (CmsResource) resources.next(); int notification_interval = Integer.parseInt(m_cms .readPropertyObject(resource, CmsPropertyDefinition.PROPERTY_NOTIFICATION_INTERVAL, true) .getValue()); GregorianCalendar intervalBefore = new GregorianCalendar(TimeZone.getDefault(), CmsLocaleManager.getDefaultLocale()); intervalBefore.setTimeInMillis(resource.getDateLastModified()); intervalBefore.add(Calendar.DAY_OF_YEAR, notification_interval); GregorianCalendar intervalAfter = (GregorianCalendar) intervalBefore.clone(); intervalAfter.add(Calendar.WEEK_OF_YEAR, -1); for (int i = 0; (i < 100) && intervalAfter.getTime().before(now.getTime()); i++) { if (intervalBefore.getTime().after(now.getTime())) { m_resources.add(new CmsExtendedNotificationCause(resource, CmsExtendedNotificationCause.RESOURCE_UPDATE_REQUIRED, intervalBefore.getTime())); } intervalBefore.add(Calendar.DAY_OF_YEAR, notification_interval); intervalAfter.add(Calendar.DAY_OF_YEAR, notification_interval); } } } catch (CmsDbEntryNotFoundException e) { // no resources with property 'notification-interval', ignore } // read all files that were not modified longer than the max notification-time GregorianCalendar oneYearAgo = (GregorianCalendar) now.clone(); oneYearAgo.add(Calendar.DAY_OF_YEAR, -OpenCms.getSystemInfo().getNotificationTime()); // create a resource filter to get the resources with CmsResourceFilter filter = CmsResourceFilter.IGNORE_EXPIRATION .addRequireLastModifiedBefore(oneYearAgo.getTimeInMillis()); resources = m_cms.readResources(folder, filter).iterator(); while (resources.hasNext()) { resource = (CmsResource) resources.next(); m_resources.add(new CmsExtendedNotificationCause(resource, CmsExtendedNotificationCause.RESOURCE_OUTDATED, new Date(resource.getDateLastModified()))); } // get all resources that will expire within the next week CmsResourceFilter resourceFilter = CmsResourceFilter.IGNORE_EXPIRATION .addRequireExpireBefore(inOneWeek.getTimeInMillis()); resourceFilter = resourceFilter.addRequireExpireAfter(now.getTimeInMillis()); resources = m_cms.readResources(folder, resourceFilter).iterator(); while (resources.hasNext()) { resource = (CmsResource) resources.next(); m_resources.add(new CmsExtendedNotificationCause(resource, CmsExtendedNotificationCause.RESOURCE_EXPIRES, new Date(resource.getDateExpired()))); } // get all resources that will release within the next week resourceFilter = CmsResourceFilter.IGNORE_EXPIRATION.addRequireReleaseBefore(inOneWeek.getTimeInMillis()); resourceFilter = resourceFilter.addRequireReleaseAfter(now.getTimeInMillis()); resources = m_cms.readResources(folder, resourceFilter).iterator(); while (resources.hasNext()) { resource = (CmsResource) resources.next(); m_resources.add(new CmsExtendedNotificationCause(resource, CmsExtendedNotificationCause.RESOURCE_RELEASE, new Date(resource.getDateReleased()))); } }