List of usage examples for org.joda.time DateTimeZone getID
@ToString public final String getID()
From source file:org.ohmage.query.impl.AnnotationQueries.java
License:Apache License
@Override public void createPromptResponseAnnotation(final UUID annotationId, final String client, final Long time, final DateTimeZone timezone, final String annotationText, Integer promptResponseId) throws DataAccessException { // Create the transaction. DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("Creating a new prompt response annotation."); try {//from w w w. j av a 2 s .c o m // Begin the transaction. PlatformTransactionManager transactionManager = new DataSourceTransactionManager(getDataSource()); TransactionStatus status = transactionManager.getTransaction(def); long id = 0; try { id = insertAnnotation(annotationId, time, timezone, client, annotationText); } catch (org.springframework.dao.DataAccessException e) { transactionManager.rollback(status); throw new DataAccessException("Error while executing SQL '" + SQL_INSERT_ANNOTATION + "' with parameters: " + annotationId + ", " + time + ", " + timezone.getID() + ", " + client + ", " + ((annotationText.length() > 25) ? annotationText.substring(0, 25) + "..." : annotationText), e); } try { // Insert the link between the prompt_response and its annotation getJdbcTemplate().update(SQL_INSERT_PROMPT_RESPONSE_ANNOTATION, promptResponseId, id); } catch (org.springframework.dao.DataAccessException e) { transactionManager.rollback(status); throw new DataAccessException("Error while executing SQL '" + SQL_INSERT_PROMPT_RESPONSE_ANNOTATION + "' with parameters: " + promptResponseId + ", " + id, e); } // Commit the transaction. try { transactionManager.commit(status); } catch (TransactionException e) { transactionManager.rollback(status); throw new DataAccessException("Error while committing the transaction.", e); } } catch (TransactionException e) { throw new DataAccessException("Error while attempting to rollback the transaction.", e); } }
From source file:org.ohmage.query.impl.AnnotationQueries.java
License:Apache License
/** * Helper method to insert an annotation and allow the other methods in * this class to do the work of linking the annotation to the appropriate * entity.//from ww w . j a v a 2 s . c o m * * @param annotationId a UUID to uniquely identify this annotation * @param time the epoch millis at which the annotation was created * @param timezone the timezone in which the annotation was created * @param client the software client that generated the annotation request * @param text the annotation text * @return the primary key of the newly created annotation * @throws org.springframework.dao.DataAccessException if an error occurs */ private long insertAnnotation(final UUID annotationId, final Long time, final DateTimeZone timezone, final String client, final String annotationText) throws org.springframework.dao.DataAccessException { final KeyHolder annotationIdKeyHolder = new GeneratedKeyHolder(); getJdbcTemplate().update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement(SQL_INSERT_ANNOTATION, new String[] { "id" }); ps.setString(1, annotationId.toString()); ps.setLong(2, time); ps.setString(3, timezone.getID()); ps.setString(4, client); ps.setString(5, annotationText); return ps; } }, annotationIdKeyHolder); return annotationIdKeyHolder.getKey().longValue(); }
From source file:org.ohmage.query.impl.AnnotationQueries.java
License:Apache License
@Override public void updateAnnotation(final UUID annotationId, final String annotationText, final String client, final long time, final DateTimeZone timezone) throws DataAccessException { // Create the transaction. DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("Updating an annotation."); try {/*from w w w . ja va2 s . com*/ // Begin the transaction. PlatformTransactionManager transactionManager = new DataSourceTransactionManager(getDataSource()); TransactionStatus status = transactionManager.getTransaction(def); try { getJdbcTemplate().update(SQL_UPDATE_ANNOTATION, time, timezone.getID(), client, annotationText, annotationId.toString()); } catch (org.springframework.dao.DataAccessException e) { transactionManager.rollback(status); throw new DataAccessException("Error executing SQL '" + SQL_UPDATE_ANNOTATION + "' with parameters: " + time + ", " + timezone.getID() + ", " + client + ", " + annotationText + ", " + annotationId.toString(), e); } // Commit the transaction. try { transactionManager.commit(status); } catch (TransactionException e) { transactionManager.rollback(status); throw new DataAccessException("Error while committing the transaction.", e); } } catch (TransactionException e) { throw new DataAccessException("Error while attempting to rollback the transaction.", e); } }
From source file:org.ohmage.request.event.EventReadChunkedRequest.java
License:Apache License
/** * Responds to the Mobility read chunked request. *///from w w w. j a v a2 s. c o m @Override public void respond(HttpServletRequest httpRequest, HttpServletResponse httpResponse) { LOGGER.info("Responding to the Mobility read chunked request."); Map<Long, List<MobilityPoint>> millisToPointMap = new HashMap<Long, List<MobilityPoint>>(); // Bucket the items preserving order in the bucket. for (MobilityPoint mobilityPoint : result) { long time = mobilityPoint.getTime(); // Get this point's bucket. time = (time / millisPerChunk) * millisPerChunk; List<MobilityPoint> bucket = millisToPointMap.get(time); if (bucket == null) { bucket = new LinkedList<MobilityPoint>(); millisToPointMap.put(time, bucket); } bucket.add(mobilityPoint); } JSONArray outputArray = new JSONArray(); // Process the buckets. try { for (Long time : millisToPointMap.keySet()) { Map<String, Integer> modeCountMap = new HashMap<String, Integer>(); String timestamp = null; DateTimeZone timezone = null; LocationStatus locationStatus = null; Location location = null; for (MobilityPoint mobilityPoint : millisToPointMap.get(time)) { // The first point sets the information. if (timestamp == null) { timestamp = DateTimeUtils.getIso8601DateString(mobilityPoint.getDate(), true); timezone = mobilityPoint.getTimezone(); locationStatus = mobilityPoint.getLocationStatus(); location = mobilityPoint.getLocation(); } // For all points, get the mode. String mode = mobilityPoint.getMode().toString().toLowerCase(); Integer count = modeCountMap.get(mode); if (count == null) { modeCountMap.put(mode, 1); } else { modeCountMap.put(mode, count + 1); } } JSONObject currResult = new JSONObject(); currResult.put(JSON_KEY_MODE_COUNT, modeCountMap); currResult.put(JSON_KEY_DURATION, millisPerChunk); currResult.put(JSON_KEY_TIMESTAMP, timestamp); currResult.put(JSON_KEY_TIMEZONE, timezone.getID()); currResult.put(JSON_KEY_LOCATION_STATUS, locationStatus.toString().toLowerCase()); try { currResult.put(JSON_KEY_LOCATION, ((location == null) ? null : location.toJson(true, LocationColumnKey.ALL_COLUMNS))); } catch (DomainException e) { LOGGER.error("Error creating the JSON.", e); setFailed(); } outputArray.put(currResult); } } catch (JSONException e) { LOGGER.error("Error building the response.", e); setFailed(); } super.respond(httpRequest, httpResponse, JSON_KEY_DATA, outputArray); }
From source file:org.openhab.io.caldav.internal.Util.java
License:Open Source License
public static Calendar createCalendar(CalDavEvent calDavEvent, DateTimeZone timeZone) { TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry(); TimeZone timezone = registry.getTimeZone(timeZone.getID()); Calendar calendar = new Calendar(); calendar.getProperties().add(Version.VERSION_2_0); calendar.getProperties().add(new ProdId("openHAB")); VEvent vEvent = new VEvent(); vEvent.getProperties().add(new Summary(calDavEvent.getName())); vEvent.getProperties().add(new Description(calDavEvent.getContent())); final DtStart dtStart = new DtStart(new net.fortuna.ical4j.model.DateTime(calDavEvent.getStart().toDate())); dtStart.setTimeZone(timezone);/*from ww w . j a va 2 s . c om*/ vEvent.getProperties().add(dtStart); final DtEnd dtEnd = new DtEnd(new net.fortuna.ical4j.model.DateTime(calDavEvent.getEnd().toDate())); dtEnd.setTimeZone(timezone); vEvent.getProperties().add(dtEnd); vEvent.getProperties().add(new Uid(calDavEvent.getId())); vEvent.getProperties().add(Clazz.PUBLIC); vEvent.getProperties().add( new LastModified(new net.fortuna.ical4j.model.DateTime(calDavEvent.getLastChanged().toDate()))); calendar.getComponents().add(vEvent); return calendar; }
From source file:org.teavm.classlib.impl.tz.ZoneInfoCompiler.java
License:Apache License
/** * @return false if error./*from w ww .ja v a 2 s.c om*/ */ static boolean test(String id, DateTimeZone tz) { if (!id.equals(tz.getID())) { return true; } // Test to ensure that reported transitions are not duplicated. long millis = ISOChronology.getInstanceUTC().year().set(0, 1850); long end = ISOChronology.getInstanceUTC().year().set(0, 2050); int offset = tz.getOffset(millis); List<Long> transitions = new ArrayList<>(); while (true) { long next = tz.nextTransition(millis); if (next == millis || next > end) { break; } millis = next; int nextOffset = tz.getOffset(millis); if (offset == nextOffset) { System.out.println( "*d* Error in " + tz.getID() + " " + new DateTime(millis, ISOChronology.getInstanceUTC())); return false; } transitions.add(Long.valueOf(millis)); offset = nextOffset; } // Now verify that reverse transitions match up. millis = ISOChronology.getInstanceUTC().year().set(0, 2050); end = ISOChronology.getInstanceUTC().year().set(0, 1850); for (int i = transitions.size(); --i >= 0;) { long prev = tz.previousTransition(millis); if (prev == millis || prev < end) { break; } millis = prev; long trans = transitions.get(i).longValue(); if (trans - 1 != millis) { System.out.println( "*r* Error in " + tz.getID() + " " + new DateTime(millis, ISOChronology.getInstanceUTC()) + " != " + new DateTime(trans - 1, ISOChronology.getInstanceUTC())); return false; } } return true; }
From source file:org.thelq.pircbotx.commands.NewYearsCommand.java
License:Open Source License
protected static String getExtendedNames(Collection<DateTimeZone> tzList) { if (tzList.isEmpty()) return null; //Prebuild long form of timezones long nowTime = System.currentTimeMillis(); Set<String> tzExtendedSet = Sets.newHashSet(); for (DateTimeZone curTz : tzList) { if (StringUtils.startsWithIgnoreCase(curTz.getID(), "Etc/")) continue; tzExtendedSet.add(curTz.getName(nowTime) + "(" + curTz.getShortName(nowTime) + ")"); }/*from w w w.j a va2 s .co m*/ return StringUtils.defaultIfBlank(StringUtils.join(tzExtendedSet, ", "), null); }
From source file:org.thelq.pircbotx.commands.NewYearsCommand.java
License:Open Source License
protected static String getShortNames(Collection<DateTimeZone> tzList) { //Prebuild long form of timezones long nowTime = System.currentTimeMillis(); Set<String> tzShortSet = Sets.newHashSet(); for (DateTimeZone curTz : tzList) { if (StringUtils.startsWithIgnoreCase(curTz.getID(), "Etc/")) continue; tzShortSet.add(curTz.getShortName(nowTime)); }//from ww w .j av a 2 s. c o m return StringUtils.defaultIfBlank(StringUtils.join(tzShortSet, ", "), null); }
From source file:org.unitime.timetable.server.ServerTimeZoneBackend.java
License:Open Source License
@Override public ServerTimeZoneResponse execute(ServerTimeZoneRequest request, SessionContext context) { Date first = null, last = null; for (Session session : SessionDAO.getInstance().findAll()) { if (first == null || first.after(session.getEventBeginDate())) first = session.getEventBeginDate(); if (last == null || last.before(session.getEventEndDate())) last = session.getEventEndDate(); }/*from w w w. j a v a 2 s.c o m*/ DateTimeZone zone = DateTimeZone.getDefault(); int offsetInMinutes = zone.getOffset(first.getTime()) / 60000; ServerTimeZoneResponse ret = new ServerTimeZoneResponse(); ret.setId(zone.getID()); ret.addName(zone.getName(new Date().getTime())); ret.setTimeZoneOffsetInMinutes(offsetInMinutes); long time = first.getTime(); long transition; while (time != (transition = zone.nextTransition(time)) && time < last.getTime()) { int adjustment = (zone.getOffset(transition) / 60000) - offsetInMinutes; ret.addTransition((int) (transition / 3600000), adjustment); time = transition; } return ret; }
From source file:rapture.kernel.ScheduleApiImpl.java
License:Open Source License
private RaptureJob createJob(CallingContext context, String jobURI, String description, String executableURI, String cronExpression, String timeZone, Map<String, String> jobParams, Boolean autoActivate, JobType type, int maxRuntimeMinutes, String appStatusNamePattern) { RaptureJob job = new RaptureJob(); job.setCronSpec(cronExpression);/*from w w w. ja v a 2 s . co m*/ // validate timezone DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(TimeZone.getTimeZone(timeZone)); if (!dateTimeZone.getID().equals(timeZone)) { throw RaptureExceptionFactory.create("Invalid TimeZone " + timeZone); } job.setTimeZone(timeZone); RaptureURI uri = new RaptureURI(jobURI, Scheme.JOB); job.setJobURI(uri.toString()); if (type == JobType.SCRIPT) { job.setScriptURI(executableURI); } else { job.setScriptURI(new RaptureURI(executableURI, Scheme.WORKFLOW).toString()); } job.setParams(jobParams); job.setDescription(description); job.setAutoActivate(autoActivate); if (autoActivate) { job.setActivated(true); } else { job.setActivated(false); } job.setJobType(type); job.setMaxRuntimeMinutes(maxRuntimeMinutes); if (appStatusNamePattern != null) { job.setAppStatusNamePattern(appStatusNamePattern); } RaptureJobStorage.add(uri, job, context.getUser(), Messages.getString("Schedule.createNew")); //$NON-NLS-1$ ScheduleManager.handleJobChanged(job, false, null, null); return job; }