List of usage examples for java.util TimeZone getDefault
public static TimeZone getDefault()
From source file:io.teak.sdk.Session.java
private void identifyUser() { final Session _this = this; new Thread(new Runnable() { public void run() { synchronized (_this.stateMutex) { HashMap<String, Object> payload = new HashMap<>(); if (_this.state == State.UserIdentified) { payload.put("do_not_track_event", Boolean.TRUE); }/*from w w w. j a v a2s.c o m*/ TimeZone tz = TimeZone.getDefault(); long rawTz = tz.getRawOffset(); if (tz.inDaylightTime(new Date())) { rawTz += tz.getDSTSavings(); } long minutes = TimeUnit.MINUTES.convert(rawTz, TimeUnit.MILLISECONDS); String tzOffset = new DecimalFormat("#0.00").format(minutes / 60.0f); payload.put("timezone", tzOffset); String locale = Locale.getDefault().toString(); payload.put("locale", locale); if (_this.deviceConfiguration.advertsingInfo != null) { payload.put("android_ad_id", _this.deviceConfiguration.advertsingInfo.getId()); payload.put("android_limit_ad_tracking", _this.deviceConfiguration.advertsingInfo.isLimitAdTrackingEnabled()); } if (_this.facebookAccessToken != null) { payload.put("access_token", _this.facebookAccessToken); } if (_this.launchedFromTeakNotifId != null) { payload.put("teak_notif_id", Long.valueOf(_this.launchedFromTeakNotifId)); } if (_this.launchedFromDeepLink != null) { payload.put("deep_link", _this.launchedFromDeepLink); } if (_this.deviceConfiguration.gcmId != null) { payload.put("gcm_push_key", _this.deviceConfiguration.gcmId); } else { payload.put("gcm_push_key", ""); } Log.d(LOG_TAG, "Identifying user: " + _this.userId); Log.d(LOG_TAG, " Timezone: " + tzOffset); Log.d(LOG_TAG, " Locale: " + locale); new Request("/games/" + _this.appConfiguration.appId + "/users.json", payload, _this) { @Override protected void done(int responseCode, String responseBody) { try { JSONObject response = new JSONObject(responseBody); // TODO: Grab 'id' and 'game_id' from response and store for Parsnip // Enable verbose logging if flagged boolean enableVerboseLogging = response.optBoolean("verbose_logging"); if (Teak.debugConfiguration != null) { Teak.debugConfiguration.setPreferenceForceDebug(enableVerboseLogging); } // Server requesting new push key. if (response.optBoolean("reset_push_key", false)) { _this.deviceConfiguration.reRegisterPushToken(_this.appConfiguration); } if (response.has("country_code")) { _this.countryCode = response.getString("country_code"); } // Prevent warning for 'do_not_track_event' if (_this.state != State.UserIdentified) { _this.setState(State.UserIdentified); } } catch (Exception ignored) { } super.done(responseCode, responseBody); } }.run(); } } }).start(); }
From source file:com.jaspersoft.jasperserver.api.engine.scheduling.quartz.ReportExecutionJob.java
protected void updateExecutionContextDetails() { ExecutionContextImpl context = (ExecutionContextImpl) executionContext; context.setLocale(getLocale());/*from w ww . j a v a 2s . c o m*/ // using default system timezone, and not job trigger timezone context.setTimeZone(TimeZone.getDefault()); }
From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java
private static JFreeChart createTimeSeriesCollectionChart( final TimeSeriesCollectionChartDefinition chartDefinition) { JFreeChart chart = null;//w w w .j a va2s .c o m // TODO Make the following accessible from the chartDefinition String domainAxisLabel = null; String rangeAxisLabel = null; boolean tooltips = true; boolean urls = true; // ----------------------------------------------------------- String title = chartDefinition.getTitle(); boolean legend = chartDefinition.isLegendIncluded(); DateAxis domainAxis = new DateAxis(domainAxisLabel, TimeZone.getDefault()); ValueAxis rangeAxis = new NumberAxis(rangeAxisLabel); XYItemRenderer renderer = null; switch (chartDefinition.getChartType()) { case LINE_CHART_TYPE: renderer = chartDefinition.isThreeD() ? new XYLine3DRenderer() : new XYLineAndShapeRenderer(true, false); ((XYLineAndShapeRenderer) renderer).setShapesVisible(chartDefinition.isMarkersVisible()); ((XYLineAndShapeRenderer) renderer).setBaseShapesFilled(chartDefinition.isMarkersVisible()); break; case AREA_CHART_TYPE: renderer = new XYAreaRenderer(); break; case STEP_CHART_TYPE: renderer = new XYStepRenderer(); break; case STEP_AREA_CHART_TYPE: renderer = new XYStepAreaRenderer(); break; case DIFFERENCE_CHART_TYPE: renderer = new XYDifferenceRenderer(); break; case DOT_CHART_TYPE: renderer = new XYDotRenderer(); ((XYDotRenderer) renderer).setDotHeight(chartDefinition.getDotHeight()); ((XYDotRenderer) renderer).setDotWidth(chartDefinition.getDotWidth()); break; default: // should log an error if invalid chart type passed in - at least return null for no renderer return null; } if (tooltips) { XYToolTipGenerator generator = new StandardXYToolTipGenerator(chartDefinition.getTooltipContent(), new SimpleDateFormat(chartDefinition.getTooltipXFormat()), new DecimalFormat(chartDefinition.getTooltipYFormat())); renderer.setToolTipGenerator(generator); } if (urls) { renderer.setURLGenerator(new StandardXYURLGenerator()); } renderer.setStroke(JFreeChartEngine.getLineStyleStroke(chartDefinition.getLineStyle(), chartDefinition.getLineWidth())); XYPlot plot = new XYPlot(chartDefinition, domainAxis, rangeAxis, renderer); JFreeChartEngine.updatePlot(plot, chartDefinition); chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:com.tempescope.wunderground.WundergroundManager.java
public List<WundergroundQueryResult> forecastForCoords(Coordinate coord) { InputStream in = null;/*from w w w . j a v a 2 s . c o m*/ ArrayList<WundergroundQueryResult> results = new ArrayList<WundergroundQueryResult>(); try { rateLimiter.waitEnoughTime(); URL url = getForecastURLForConditions(coord); URLConnection con = url.openConnection(); in = con.getInputStream(); JSONParser parser = new JSONParser(); JSONObject rootObj = (JSONObject) parser.parse(new InputStreamReader(in)); JSONArray hourly_forecast = (JSONArray) rootObj.get("hourly_forecast"); if (hourly_forecast != null) { for (Object hourlyObj : hourly_forecast) { JSONObject hourlyForecast = (JSONObject) hourlyObj; // for(Object key:hourlyForecast.keySet()) // System.out.println(key+"\t"+hourlyForecast.get(key)); JSONObject fctime = (JSONObject) hourlyForecast.get("FCTTIME"); Date time = fctimeFormatter.parse("" + fctime.get("pretty")); String condition = "" + hourlyForecast.get("condition"); WundergroundQueryResult result = new WundergroundQueryResult(TimeZone.getDefault(), condition, null, time); results.add(result); } // String weather=""+currentObservation.get("weather"); // String timezone=""+currentObservation.get("local_tz_long"); // WeatherLocation location=new WeatherLocation((JSONObject)currentObservation.get("observation_location")); // // return new WundergroundQueryResult(TimeZone.getTimeZone(timezone), weather, location); } } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { if (in != null) try { in.close(); } catch (IOException e1) { e1.printStackTrace(); } } return results; }
From source file:com.ah.be.admin.restoredb.RestoreAdmin.java
/** * Get all information from hm_domain table * * @return List<HmDomain> all HmDomain BO * @throws Exception/* ww w .j av a 2 s . c o m*/ * - */ private static List<HmDomain> getAllDomains() throws Exception { AhRestoreGetXML xmlParser = new AhRestoreGetXML(); /** * Check validation of hm_user_group.xml */ boolean restoreRet = xmlParser.readXMLFile("hm_domain"); if (!restoreRet) { return null; } /** * No one row data stored in hm_domain table is allowed */ int rowCount = xmlParser.getRowCount(); List<HmDomain> domains = new ArrayList<HmDomain>(); boolean isColPresent; String colName; for (int i = 0; i < rowCount; i++) { HmDomain domain = new HmDomain(); /** * Set domain id */ colName = "id"; isColPresent = AhRestoreCommons.isColumnPresent(xmlParser, "hm_domain", colName); String id = isColPresent ? xmlParser.getColVal(i, colName) : "1"; long lId; try { lId = Long.parseLong(id); } catch (Exception ex) { BeLogTools.restoreLog(BeLogTools.ERROR, ex); lId = System.currentTimeMillis(); } domain.setId(lId); /** * Set timeZone */ colName = "timeZone"; isColPresent = AhRestoreCommons.isColumnPresent(xmlParser, "hm_domain", colName); String timeZone = isColPresent ? xmlParser.getColVal(i, colName) : TimeZone.getDefault().getID(); domain.setTimeZone(timeZone); /** * Set domain name */ colName = "domainname"; isColPresent = AhRestoreCommons.isColumnPresent(xmlParser, "hm_domain", colName); String name = isColPresent ? AhRestoreCommons.convertString(xmlParser.getColVal(i, colName)) : ""; if (name.equals("")) { BeLogTools.debug(HmLogConst.M_RESTORE, "Restore table 'hm_domain' data be lost, cause: 'domainname' column is not exist."); continue; } // map id - name // AhRestoreMapTool.setMapDomain(id, name); if (name.equals(HmDomain.GLOBAL_DOMAIN) || name.equalsIgnoreCase(HmDomain.HOME_DOMAIN)) { // we need update. HmDomain domain_ = QueryUtil.findBoByAttribute(HmDomain.class, "domainName", name); if (domain_ != null) { domain_.setTimeZone(timeZone); QueryUtil.updateBo(domain_); //add to the map if (!AhRestoreNewMapTools.getHmDomainMap().containsKey(lId)) { AhRestoreNewMapTools.setHmDomain(lId, domain_); } } continue; } domain.setDomainName(name); /** * Set domain maxApNum */ colName = "maxApNum"; isColPresent = AhRestoreCommons.isColumnPresent(xmlParser, "hm_domain", colName); int maxApNum = isColPresent ? AhRestoreCommons.convertInt(xmlParser.getColVal(i, colName)) : 0; domain.setMaxApNum(maxApNum); /** * Set domain maxSimuAp */ colName = "maxSimuAp"; isColPresent = AhRestoreCommons.isColumnPresent(xmlParser, "hm_domain", colName); int maxSimuAp = isColPresent ? AhRestoreCommons.convertInt(xmlParser.getColVal(i, colName)) : HmDomain.MAX_SIMULATE_HIVEAP_DEFAULT; domain.setMaxSimuAp(maxSimuAp); /** * Set domain maxSimuClient */ colName = "maxSimuClient"; isColPresent = AhRestoreCommons.isColumnPresent(xmlParser, "hm_domain", colName); int maxSimuClient = isColPresent ? AhRestoreCommons.convertInt(xmlParser.getColVal(i, colName)) : HmDomain.MAX_SIMULATE_CLIENT_PERAP_DEFAULT; domain.setMaxSimuClient(maxSimuClient); /** * Set domain runStatus */ colName = "runStatus"; isColPresent = AhRestoreCommons.isColumnPresent(xmlParser, "hm_domain", colName); int runStatus = isColPresent ? AhRestoreCommons.convertInt(xmlParser.getColVal(i, colName)) : HmDomain.DOMAIN_DEFAULT_STATUS; domain.setRunStatus(runStatus); /** * Set supportGM */ colName = "supportGM"; isColPresent = AhRestoreCommons.isColumnPresent(xmlParser, "hm_domain", colName); boolean supportGM = isColPresent && AhRestoreCommons.convertStringToBoolean(xmlParser.getColVal(i, colName)); domain.setSupportGM(supportGM); /** * Set comment */ colName = "comment"; isColPresent = AhRestoreCommons.isColumnPresent(xmlParser, "hm_domain", colName); String comment = isColPresent ? AhRestoreCommons.convertString(xmlParser.getColVal(i, colName)) : ""; domain.setComment(comment); /** * Set supportFullMode */ colName = "supportFullMode"; isColPresent = AhRestoreCommons.isColumnPresent(xmlParser, "hm_domain", colName); boolean supportFullMode = !isColPresent || AhRestoreCommons.convertStringToBoolean(xmlParser.getColVal(i, colName)); domain.setSupportFullMode(supportFullMode); /** * Set vhmID */ colName = "vhmID"; isColPresent = AhRestoreCommons.isColumnPresent(xmlParser, "hm_domain", colName); String vhmID = isColPresent ? AhRestoreCommons.convertString(xmlParser.getColVal(i, colName)) : ""; domain.setVhmID(vhmID); /** * owner user */ colName = "user_id"; isColPresent = AhRestoreCommons.isColumnPresent(xmlParser, "hm_domain", colName); if (isColPresent) { Long user_id = AhRestoreCommons.convertLong(xmlParser.getColVal(i, colName)); if (null != user_id) { // cannot query user because restore domain at first, we need refresh the user id // value later AhRestoreNewMapTools.setDomainNameVADID(name, user_id); } } /** * Set partner id */ colName = "partnerId"; isColPresent = AhRestoreCommons.isColumnPresent(xmlParser, "hm_domain", colName); String partnerId = isColPresent ? AhRestoreCommons.convertString(xmlParser.getColVal(i, colName)) : ""; domain.setPartnerId(partnerId); /** * accessMode */ if (!NmsUtil.isHostedHMApplication()) { // for HMOP, access mode should always 4 (config and monitor) fix bug CFD-125 (Jira) domain.setAccessMode(HmDomain.ACCESS_MODE_TECH_OP_PARTNER_RW); } else { // for HMOL, restore access mode as value in backup file colName = "accessMode"; isColPresent = AhRestoreCommons.isColumnPresent(xmlParser, "hm_domain", colName); int accessMode = isColPresent ? AhRestoreCommons.convertInt(xmlParser.getColVal(i, colName)) : HmDomain.ACCESS_MODE_TECH_OP_PARTNER_RW; domain.setAccessMode((short) accessMode); } /** * authorizationEndDate */ colName = "authorizationEndDate"; isColPresent = AhRestoreCommons.isColumnPresent(xmlParser, "hm_domain", colName); Long authorizationEndDate = isColPresent ? AhRestoreCommons.convertString2Long(xmlParser.getColVal(i, colName)) : -1; domain.setAuthorizationEndDate(authorizationEndDate); /** * accessChanged */ colName = "accessChanged"; isColPresent = AhRestoreCommons.isColumnPresent(xmlParser, "hm_domain", colName); boolean accessChanged = isColPresent ? AhRestoreCommons.convertStringToBoolean(xmlParser.getColVal(i, colName)) : true; domain.setAccessChanged(accessChanged); /** * authorizedTime */ colName = "authorizedTime"; isColPresent = AhRestoreCommons.isColumnPresent(xmlParser, "hm_domain", colName); int authorizedTime = isColPresent ? AhRestoreCommons.convertInt(xmlParser.getColVal(i, colName)) : -1; domain.setAuthorizedTime(authorizedTime); domains.add(domain); } return !domains.isEmpty() ? domains : null; }
From source file:org.jfree.data.time.WeekTest.java
/** * A test for a problem in constructing a new Week instance. */// w w w. jav a 2 s . c o m @Test public void testConstructor() { Locale savedLocale = Locale.getDefault(); TimeZone savedZone = TimeZone.getDefault(); Locale.setDefault(new Locale("da", "DK")); TimeZone.setDefault(TimeZone.getTimeZone("Europe/Copenhagen")); GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault()); // first day of week is monday assertEquals(Calendar.MONDAY, cal.getFirstDayOfWeek()); cal.set(2007, Calendar.AUGUST, 26, 1, 0, 0); cal.set(Calendar.MILLISECOND, 0); Date t = cal.getTime(); Week w = new Week(t, TimeZone.getTimeZone("Europe/Copenhagen")); assertEquals(34, w.getWeek()); Locale.setDefault(Locale.US); TimeZone.setDefault(TimeZone.getTimeZone("US/Detroit")); cal = (GregorianCalendar) Calendar.getInstance(TimeZone.getDefault()); // first day of week is Sunday assertEquals(Calendar.SUNDAY, cal.getFirstDayOfWeek()); cal.set(2007, Calendar.AUGUST, 26, 1, 0, 0); cal.set(Calendar.MILLISECOND, 0); t = cal.getTime(); w = new Week(t, TimeZone.getTimeZone("Europe/Copenhagen")); assertEquals(35, w.getWeek()); w = new Week(t, TimeZone.getTimeZone("Europe/Copenhagen"), new Locale("da", "DK")); assertEquals(34, w.getWeek()); Locale.setDefault(savedLocale); TimeZone.setDefault(savedZone); }
From source file:com.cm.android.beercellar.ui.ImageDetailFragment.java
private void save() { try {//from w ww . jav a2 s . c o m Note note = new Note(); note.id = mRowId; note.beer = mBeer.getText().toString(); note.rating = String.valueOf(mRatingBar.getRating()); note.textExtract = mTextExtract.getText().toString(); note.notes = mNotes.getText().toString(); //default to Y note.share = "Y"; note.picture = mRowId + Utils.PICTURES_EXTENSION; //note.share = mShare.isChecked() ? "Y" : "N"; if (mIsNew) { mDbHelper.createNote(note); mIsNew = false; } else { mDbHelper.updateNote(note); } // Do the real work in an async task, because we need to use the network anyway new android.os.AsyncTask<Object, Void, Void>() { @Override protected Void doInBackground(Object... params) { NotesDbAdapter dbHelper = null; long rowId = (Long) params[0]; try { HttpTransport httpTransport = new NetHttpTransport(); HttpRequestFactory requestFactory = httpTransport.createRequestFactory(new MyInitializer()); JSONObject jsonObject = new JSONObject(); dbHelper = new NotesDbAdapter(getActivity()); dbHelper.open(); Note note = dbHelper.fetchNote(rowId); jsonObject.put("rowId", note.id); jsonObject.put("beer", note.beer); jsonObject.put("rating", note.rating); jsonObject.put("textExtract", note.textExtract); jsonObject.put("notes", note.notes); jsonObject.put("uri", note.uri); jsonObject.put("timeCreatedMs", note.created); jsonObject.put("timeCreatedTimeZoneOffsetMs", TimeZone.getDefault().getRawOffset()); jsonObject.put("timeUpdatedMs", note.updated); jsonObject.put("timeUpdatedTimeZoneOffsetMs", TimeZone.getDefault().getRawOffset()); HttpResponse httpPostResponse = null; try { httpPostResponse = requestFactory.buildPutRequest( new GenericUrl(Configuration.CONTENTS_URL), new ByteArrayContent("application/json", jsonObject.toString().getBytes())) .execute(); Log.i(sTag, "HTTP STATUS:: " + httpPostResponse.getStatusCode()); } finally { httpPostResponse.disconnect(); } } catch (Throwable e) { Log.e(sTag, "error: " + ((e.getMessage() != null) ? e.getMessage().replace(" ", "_") : ""), e); } finally { if (dbHelper != null) dbHelper.close(); } return null; } }.execute(mRowId); } catch (Throwable e) { Log.e(sTag, "error: " + ((e.getMessage() != null) ? e.getMessage().replace(" ", "_") : ""), e); } }
From source file:com.iisigroup.cap.batch.handler.BatchHandler.java
/** * //w ww . j a v a2 s.c o m * * @param request * IRequest * @return IResult */ public Result executionStop(Request request) { AjaxFormResult result = new AjaxFormResult(); long jobExecutionId = Long.parseLong(request.get("jobExeId")); try { JobExecution jobExecution = jobService.stop(jobExecutionId); new JobExecutionInfo(jobExecution, TimeZone.getDefault()); } catch (NoSuchJobExecutionException e) { throw new CapMessageException("msg.job.noSuchJob", getClass()); } catch (JobExecutionNotRunningException e) { JobExecution jobExecution; try { jobExecution = jobService.getJobExecution(jobExecutionId); new JobExecutionInfo(jobExecution, TimeZone.getDefault()); } catch (NoSuchJobExecutionException e1) { e1.getMessage(); } throw new CapMessageException("msg.job.noRunnigJob", getClass()) .setExtraInformation(new Object[] { jobExecutionId }); } return result; }
From source file:com.duroty.application.files.manager.FilesManager.java
/** * DOCUMENT ME!/* ww w .ja v a 2s . com*/ * * @param hsession DOCUMENT ME! * @param repositoryName DOCUMENT ME! * @param folderName DOCUMENT ME! * @param page DOCUMENT ME! * @param messagesByPage DOCUMENT ME! * @param order DOCUMENT ME! * @param orderType DOCUMENT ME! * * @return DOCUMENT ME! * * @throws FilesException DOCUMENT ME! */ public Vector getFiles(Session hsession, String repositoryName, String folderName, int label, int page, int messagesByPage, int order, String orderType) throws FilesException { Vector files = new Vector(); try { Users user = getUser(hsession, repositoryName); Locale locale = new Locale(user.getUseLanguage()); TimeZone timeZone = TimeZone.getDefault(); Date now = new Date(); Calendar calendar = Calendar.getInstance(timeZone, locale); calendar.setTime(now); SimpleDateFormat formatter1 = new SimpleDateFormat("MMM dd", locale); SimpleDateFormat formatter2 = new SimpleDateFormat("HH:mm:ss", locale); SimpleDateFormat formatter3 = new SimpleDateFormat("MM/yy", locale); Query hquery = null; String[] folderNameList = new String[0]; try { folderName = parseFolder(folderName); folderNameList = new String[] { folderName }; if (folderName.equals(this.folderAll) || folderName.equals(this.folderHidden)) { folderNameList = new String[] { this.folderAll, this.folderDraft, this.folderHidden, this.folderImportant, this.folderInbox, this.folderSent }; } } catch (Exception ex) { } if ((folderNameList.length == 0) && (label <= 0)) { hquery = hsession.getNamedQuery("attachments"); } else if ((folderNameList.length > 0) && (label <= 0)) { hquery = hsession.getNamedQuery("attachments-by-folder"); } else if ((folderNameList.length == 0) && (label > 0)) { hquery = hsession.getNamedQuery("attachments-by-label"); } else if ((folderNameList.length > 0) && (label > 0)) { hquery = hsession.getNamedQuery("attachments-by-folder-label"); } String aux = hquery.getQueryString(); switch (order) { case ORDER_BY_SIZE: if (orderType.equals("ASC")) { aux += " order by att_size asc"; } else { aux += " order by att_size desc"; } break; case ORDER_BY_DATE: if (orderType.equals("ASC")) { aux += " order by mes_date asc"; } else { aux += " order by mes_date desc"; } break; case ORDER_BY_TYPE: if (orderType.equals("ASC")) { aux += " order by att_content_type asc"; } else { aux += " order by att_content_type desc"; } break; default: if (!orderType.equals("ASC")) { aux += " order by att_name desc"; } else { aux += " order by att_name asc"; } break; } SQLQuery h2query = hsession.createSQLQuery(aux); if ((folderNameList.length == 0) && (label <= 0)) { h2query.setParameterList("no_boxes", new String[] { this.folderTrash, this.folderChat, this.folderSpam, FOLDER_DELETE }); h2query.setInteger("user", getUser(hsession, repositoryName).getUseIdint()); } else if ((folderNameList.length > 0) && (label <= 0)) { h2query.setParameterList("boxes", folderNameList); h2query.setInteger("user", getUser(hsession, repositoryName).getUseIdint()); } else if ((folderNameList.length == 0) && (label > 0)) { h2query.setInteger("label", label); h2query.setParameterList("no_boxes", new String[] { this.folderTrash, this.folderChat, this.folderSpam, FOLDER_DELETE }); h2query.setInteger("user", getUser(hsession, repositoryName).getUseIdint()); } else if ((folderNameList.length > 0) && (label > 0)) { h2query.setInteger("label", label); h2query.setParameterList("boxes", folderNameList); h2query.setInteger("user", getUser(hsession, repositoryName).getUseIdint()); } h2query.setFirstResult(page * messagesByPage); h2query.setMaxResults(messagesByPage); h2query.addEntity("testo", AttachmentWithDate.class); ScrollableResults scroll = h2query.scroll(); while (scroll.next()) { AttachmentWithDate attachment = (AttachmentWithDate) scroll.get(0); AttachmentObj obj = new AttachmentObj(); obj.setContentType(attachment.getAttContentType()); Date date = attachment.getAttDate(); if (date != null) { Calendar calendar2 = Calendar.getInstance(timeZone, locale); calendar2.setTime(date); if ((calendar.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR)) && (calendar.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH)) && (calendar.get(Calendar.DATE) == calendar2.get(Calendar.DATE))) { obj.setDateStr(formatter2.format(calendar2.getTime())); } else if (calendar.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR)) { obj.setDateStr(formatter1.format(calendar2.getTime())); } else { obj.setDateStr(formatter3.format(calendar2.getTime())); } } obj.setDate(date); obj.setDate(date); obj.setIdint(attachment.getAttIdint()); obj.setName(attachment.getAttName()); obj.setPart(attachment.getAttPart()); int size = attachment.getAttSize(); size /= 1024; if (size > 1024) { size /= 1024; obj.setSize(size + " MB"); } else { obj.setSize(((size > 0) ? (size + "") : "<1") + " kB"); } String extension = (String) this.extensions.get(attachment.getAttContentType()); if (StringUtils.isBlank(extension)) { extension = "generic"; } obj.setExtension(extension); Message message = attachment.getMessage(); if (message.isMesFlagged()) { obj.setFlagged(true); } else { obj.setFlagged(false); } if (message.getLabMeses() != null) { Iterator it = message.getLabMeses().iterator(); StringBuffer lab = new StringBuffer(); while (it.hasNext()) { if (lab.length() > 0) { lab.append(", "); } LabMes labMes = (LabMes) it.next(); lab.append(labMes.getId().getLabel().getLabName()); } if (lab.length() > 0) { obj.setLabel(lab.toString()); } else { } } obj.setBox(message.getMesBox()); obj.setMid(message.getMesName()); files.addElement(obj); } return files; } catch (Exception e) { throw new FilesException(e); } finally { GeneralOperations.closeHibernateSession(hsession); } }
From source file:com.whizzosoftware.hobson.scheduler.ical.ICalTaskProviderTest.java
@Test public void testMonthlyNextRun() throws Exception { TimeZone tz = TimeZone.getDefault(); // an event that runs every day at midnight String ical = "BEGIN:VCALENDAR\n" + "VERSION:2.0\n" + "BEGIN:VEVENT\n" + "UID:15dee4fe-a841-4cf6-8d7f-76c3ad5492b1\n" + "DTSTART:20140701T220000\n" + "RRULE:FREQ=MONTHLY\n" + "SUMMARY:My Task\n" + "COMMENT:[{'pluginId':'com.whizzosoftware.hobson.server-api','actionId':'log','name':'My Action','properties':{'message':'Test'}}]\n" + "END:VEVENT\n" + "END:VCALENDAR"; // start the scheduler when the task should have run MockScheduledTaskExecutor executor = new MockScheduledTaskExecutor(); MockActionManager actionManager = new MockActionManager(); ICalTaskProvider s = new ICalTaskProvider("pluginId", null, null, tz); s.setScheduleExecutor(executor);//from w w w. ja va2s .c om s.setActionManager(actionManager); s.loadICSStream(new ByteArrayInputStream(ical.getBytes()), DateHelper.getTime(tz, 2014, 7, 1, 23, 0, 0)); // verify task was created and its next run time assertEquals(1, s.getTasks().size()); ICalTask task = (ICalTask) s.getTasks().iterator().next(); assertEquals(1406952000000l, task.getProperties().get(ICalTask.PROP_NEXT_RUN_TIME)); }