Example usage for java.util GregorianCalendar setTimeInMillis

List of usage examples for java.util GregorianCalendar setTimeInMillis

Introduction

In this page you can find the example usage for java.util GregorianCalendar setTimeInMillis.

Prototype

public void setTimeInMillis(long millis) 

Source Link

Document

Sets this Calendar's current time from the given long value.

Usage

From source file:org.jamwiki.servlets.PasswordResetServlet.java

private boolean isChallengeOk(HttpServletRequest request, WikiPageInfo pageInfo, WikiUser user,
        String challenge) throws Exception {
    int timeout = Environment.getIntValue(Environment.PROP_EMAIL_SERVICE_FORGOT_PASSWORD_CHALLENGE_TIMEOUT);
    if (user.getChallengeValue() != null && user.getChallengeDate() != null && user.getChallengeIp() != null) {
        // compute some deadlines
        GregorianCalendar currentDate = new GregorianCalendar();
        GregorianCalendar challengeExpires = new GregorianCalendar();
        challengeExpires.setTimeInMillis(user.getChallengeDate().getTime());
        challengeExpires.add(Calendar.MINUTE, timeout);
        if (!user.getChallengeValue().equals(challenge)) {
            pageInfo.addError(new WikiMessage("password.reset.password.error.challenge.nok"));
        } else if (currentDate.after(challengeExpires)) {
            pageInfo.addError(new WikiMessage("password.reset.password.error.challenge.expired"));
            resetChallengeData(user);//from  w w w . j  a  va  2  s .  c  om
        } else {
            resetChallengeData(user);
            return true;
        }
    } else {
        pageInfo.addError(new WikiMessage("password.reset.password.error.challenge.nok"));
    }
    return false;
}

From source file:com.projity.options.CalendarOption.java

public long makeValidEnd(long end, boolean force) {
    end = DateTime.minuteFloor(end);/*www.  j  av a  2  s  .  com*/
    GregorianCalendar cal = DateTime.calendarInstance();
    cal.setTimeInMillis(end);
    if (force || cal.get(GregorianCalendar.HOUR_OF_DAY) == 0 && cal.get(GregorianCalendar.MINUTE) == 0) {
        cal.set(GregorianCalendar.HOUR_OF_DAY, getDefaultEndTime().get(GregorianCalendar.HOUR_OF_DAY));
        cal.set(GregorianCalendar.MINUTE, getDefaultEndTime().get(GregorianCalendar.MINUTE));
    }
    return cal.getTimeInMillis();
}

From source file:org.miloss.fgsms.services.rs.impl.reports.os.NetworkIOReport.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 {/*from ww  w . j  a  v  a 2 s  .  c  om*/
        PreparedStatement cmd = null;
        ResultSet rs = null;
        DefaultCategoryDataset set = new DefaultCategoryDataset();
        JFreeChart chart = null;
        data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>");
        data.append("This represents the network throughput rates of a machine over time.<br />");
        data.append(
                "<table class=\"table table-hover\"><tr><th>URI</th><th>Average Send Rate</th><th>Average Recieve Rate</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)));
            data.append("<tr><td>").append(url).append("</td>");
            double average = 0;
            try {
                cmd = con.prepareStatement(
                        "select avg(sendkbs) from rawdatanic 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(receivekbs) from rawdatanic 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 receivekbs, sendkbs, utcdatetime, nicid from rawdatanic 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("nicid") + " RX", Millisecond.class);
                    TimeSeries ts2 = tsc.Get(url + " " + rs.getString("nicid") + " TX", Millisecond.class);
                    GregorianCalendar gcal = new GregorianCalendar();
                    gcal.setTimeInMillis(rs.getLong(3));
                    Millisecond m = new Millisecond(gcal.getTime());
                    ts.addOrUpdate(m, rs.getLong(1));
                    ts2.addOrUpdate(m, rs.getLong(2));
                }
            } 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:com.projity.options.CalendarOption.java

public long makeValidStart(long start, boolean force) {

    start = DateTime.minuteFloor(start);
    GregorianCalendar cal = DateTime.calendarInstance();
    cal.setTimeInMillis(start);
    int year = cal.get(GregorianCalendar.YEAR);
    int dayOfYear = cal.get(GregorianCalendar.DAY_OF_YEAR);
    if (force || cal.get(GregorianCalendar.HOUR_OF_DAY) == 0 && cal.get(GregorianCalendar.MINUTE) == 0) {
        cal.set(GregorianCalendar.HOUR_OF_DAY, getDefaultStartTime().get(GregorianCalendar.HOUR_OF_DAY));
        cal.set(GregorianCalendar.MINUTE, getDefaultStartTime().get(GregorianCalendar.MINUTE));
        cal.set(GregorianCalendar.YEAR, year);
        cal.set(GregorianCalendar.DAY_OF_YEAR, dayOfYear);
    }// w  w w .j  a va  2  s .c o m
    return cal.getTimeInMillis();
}

From source file:it.cnr.icar.eric.server.persistence.rdb.SubscriptionDAO.java

@SuppressWarnings("unchecked")
protected void loadObject(Object obj, ResultSet rs) throws RegistryException {
    try {/*from ww  w.  java 2 s .co m*/
        if (!(obj instanceof SubscriptionType)) {
            throw new RegistryException(ServerResourceBundle.getInstance()
                    .getString("message.SubscriptionTypeExpected", new Object[] { obj }));
        }

        SubscriptionType ebSubscriptionType = (SubscriptionType) obj;
        super.loadObject(obj, rs);

        String selector = rs.getString("selector");
        ebSubscriptionType.setSelector(selector);

        // Need to work around a bug in PostgreSQL and loading of
        // ClassificationScheme data from NIST tests
        try {
            Timestamp endTimestamp = rs.getTimestamp("endTime");

            if (endTimestamp != null) {
                // Calendar calendar = Calendar.getInstance();
                // calendar.setTimeInMillis(endTime.getTime());

                GregorianCalendar calendar = new GregorianCalendar();
                calendar.setTimeInMillis(endTimestamp.getTime());
                XMLGregorianCalendar endTime = DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar);

                ebSubscriptionType.setEndTime(endTime);
            }
        } catch (StringIndexOutOfBoundsException e) {
            String id = rs.getString("id");
            log.error(ServerResourceBundle.getInstance().getString("message.SubscriptionDAOId",
                    new Object[] { id }), e);
        }

        String notificationIntervalString = rs.getString("notificationInterval");

        if (notificationIntervalString != null) {
            Duration notificationInterval = DatatypeFactory.newInstance()
                    .newDuration(notificationIntervalString);
            ebSubscriptionType.setNotificationInterval(notificationInterval);
        }

        // Need to work around a bug in PostgreSQL and loading of
        // ClassificationScheme data from NIST tests
        try {
            Timestamp startTimestamp = rs.getTimestamp("startTime");

            if (startTimestamp != null) {
                // Calendar calendar = Calendar.getInstance();
                // calendar.setTimeInMillis(startTime.getTime());

                GregorianCalendar calendar = new GregorianCalendar();
                calendar.setTimeInMillis(startTimestamp.getTime());

                XMLGregorianCalendar startTime = DatatypeFactory.newInstance()
                        .newXMLGregorianCalendar(new GregorianCalendar());

                ebSubscriptionType.setStartTime(startTime);
            }
        } catch (StringIndexOutOfBoundsException e) {
            String id = rs.getString("id");
            log.error(ServerResourceBundle.getInstance().getString("message.SubscriptionDAOId",
                    new Object[] { id }), e);
        }

        NotifyActionDAO notifyActionDAO = new NotifyActionDAO(context);
        notifyActionDAO.setParent(ebSubscriptionType);
        @SuppressWarnings("rawtypes")
        List notifyActions = notifyActionDAO.getByParent();
        if (notifyActions != null) {
            bu.getActionTypeListFromElements(ebSubscriptionType.getAction()).addAll(notifyActions);
        }

    } catch (SQLException e) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e);
        throw new RegistryException(e);
    } catch (DatatypeConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.miloss.fgsms.services.rs.impl.reports.os.FreeDiskSpace.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 {//from   www. jav a2s  .  c o 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 Send Rate</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>");
            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();
                average = 0;
                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>");
            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();
                average = 0;
                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 ts2 = tsc.Get(url + " " + rs.getString("driveidentifier"), Millisecond.class);
                    GregorianCalendar gcal = new GregorianCalendar();
                    gcal.setTimeInMillis(rs.getLong(4));
                    Millisecond m = new Millisecond(gcal.getTime());
                    ts2.addOrUpdate(m, rs.getLong("freespace"));
                }
            } 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));
            }

        }

        data.append("</table>");
        chart = org.jfree.chart.ChartFactory.createTimeSeriesChart(GetDisplayName(), "Timestamp", "MBytes", col,
                true, false, false);

        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.sakaiproject.calendar.impl.readers.IcalendarReader.java

public List filterEvents(List events, String[] customFieldNames) throws ImportException {
    Iterator it = events.iterator();
    int lineNumber = 1;

    ///*from   w w  w  . j  av  a2 s.  co  m*/
    // Convert the date/time fields as they appear in the Outlook import to
    // be a synthesized start/end timerange.
    //
    while (it.hasNext()) {
        Map eventProperties = (Map) it.next();

        Date startTime = (Date) eventProperties
                .get(defaultHeaderMap.get(GenericCalendarImporter.START_TIME_DEFAULT_COLUMN_HEADER));
        TimeBreakdown startTimeBreakdown = null;

        if (startTime != null) {
            // if the source time zone were known, this would be
            // a good place to set it: startCal.setTimeZone()
            GregorianCalendar startCal = new GregorianCalendar();
            startCal.setTimeInMillis(startTime.getTime());
            startTimeBreakdown = getTimeService().newTimeBreakdown(0, 0, 0, startCal.get(Calendar.HOUR_OF_DAY),
                    startCal.get(Calendar.MINUTE), startCal.get(Calendar.SECOND), 0);
        } else {
            Integer line = Integer.valueOf(lineNumber);
            String msg = (String) rb.getFormattedMessage("err_no_stime_on", new Object[] { line });
            throw new ImportException(msg);
        }

        Integer durationInMinutes = (Integer) eventProperties
                .get(defaultHeaderMap.get(GenericCalendarImporter.DURATION_DEFAULT_COLUMN_HEADER));

        if (durationInMinutes == null) {
            Integer line = Integer.valueOf(lineNumber);
            String msg = (String) rb.getFormattedMessage("err_no_dtime_on", new Object[] { line });
            throw new ImportException(msg);
        }

        Date endTime = new Date(startTime.getTime() + (durationInMinutes.longValue() * 60 * 1000));

        TimeBreakdown endTimeBreakdown = null;

        if (endTime != null) {
            // if the source time zone were known, this would be
            // a good place to set it: endCal.setTimeZone()
            GregorianCalendar endCal = new GregorianCalendar();
            endCal.setTimeInMillis(endTime.getTime());
            endTimeBreakdown = getTimeService().newTimeBreakdown(0, 0, 0, endCal.get(Calendar.HOUR_OF_DAY),
                    endCal.get(Calendar.MINUTE), endCal.get(Calendar.SECOND), 0);
        }

        Date startDate = (Date) eventProperties
                .get(defaultHeaderMap.get(GenericCalendarImporter.DATE_DEFAULT_COLUMN_HEADER));

        // if the source time zone were known, this would be
        // a good place to set it: startCal.setTimeZone()
        GregorianCalendar startCal = new GregorianCalendar();
        if (startDate != null)
            startCal.setTimeInMillis(startDate.getTime());

        startTimeBreakdown.setYear(startCal.get(Calendar.YEAR));
        startTimeBreakdown.setMonth(startCal.get(Calendar.MONTH) + 1);
        startTimeBreakdown.setDay(startCal.get(Calendar.DAY_OF_MONTH));

        endTimeBreakdown.setYear(startCal.get(Calendar.YEAR));
        endTimeBreakdown.setMonth(startCal.get(Calendar.MONTH) + 1);
        endTimeBreakdown.setDay(startCal.get(Calendar.DAY_OF_MONTH));

        eventProperties.put(GenericCalendarImporter.ACTUAL_TIMERANGE,
                getTimeService().newTimeRange(getTimeService().newTimeLocal(startTimeBreakdown),
                        getTimeService().newTimeLocal(endTimeBreakdown), true, false));

        lineNumber++;
    }

    return events;
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.operations.FetchActivityOperation.java

private GregorianCalendar getLastSuccessfulSyncTime() {
    long timeStampMillis = GBApplication.getPrefs().getLong(getLastSyncTimeKey(), 0);
    if (timeStampMillis != 0) {
        GregorianCalendar calendar = BLETypeConversions.createCalendar();
        calendar.setTimeInMillis(timeStampMillis);
        return calendar;
    }/*  ww w  . j  a va2 s  .c  o  m*/
    GregorianCalendar calendar = BLETypeConversions.createCalendar();
    calendar.add(Calendar.DAY_OF_MONTH, -10);
    return calendar;
}

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 {//from  www  .j  av a 2s. c  o  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:com.cloudbees.hudson.plugins.folder.computed.FolderComputation.java

@Nonnull
public Calendar getTimestamp() {
    GregorianCalendar c = new GregorianCalendar();
    c.setTimeInMillis(timestamp);
    return c;/*from ww w .  j  av  a  2  s  .  c om*/
}