public Metadata encodeMetadata() { Metadata meta = new Metadata(); meta.put(FN_START, mStart.getDateTimePartString(false)); if (mHasEnd) meta.put(FN_END, mEnd.getDateTimePartString(false)); else meta.put(FN_DURATION, mDuration); return meta; }
private static String getEncodedMetadata(ScheduledTask task) { boolean hasProperties = false; Metadata metadata = new Metadata(); Set<String> keys = task.getPropertyNames(); for (String key : keys) { hasProperties = true; metadata.put(key, task.getProperty(key)); } if (!hasProperties) { return null; } return metadata.toString(); }
private static void setProperties(ScheduledTask task, String encodedMetadata) throws ServiceException { if (StringUtil.isNullOrEmpty(encodedMetadata)) { return; } Metadata metadata = new Metadata(encodedMetadata); Map<String, ?> map = metadata.asMap(); for (Map.Entry<String, ?> entry : map.entrySet()) { if (entry.getValue() instanceof String) { task.setProperty(entry.getKey(), (String) entry.getValue()); } } }
public static Period decodeMetadata(Metadata meta, ICalTimeZone tz, TimeZoneMap tzmap) throws ServiceException { String start = meta.get(FN_START); ParsedDateTime startTime; try { startTime = ParsedDateTime.parse(start, tzmap, tz, tzmap.getLocalTimeZone()); } catch (ParseException e) { throw ServiceException.INVALID_REQUEST( "Invalid PERIOD start time in metadata: " + meta.toString(), e); } String end = meta.get(FN_END, null); if (end != null) { ParsedDateTime endTime; try { endTime = ParsedDateTime.parse(end, tzmap, tz, tzmap.getLocalTimeZone()); } catch (ParseException e) { throw ServiceException.INVALID_REQUEST( "Invalid PERIOD end time in metadata: " + meta.toString(), e); } return new Period(startTime, endTime); } else { String durStr = meta.get(FN_DURATION, null); if (durStr == null) throw ServiceException.INVALID_REQUEST( "PERIOD in metadata missing both end time and duration: " + meta.toString(), null); ParsedDuration duration = ParsedDuration.parse(durStr); return new Period(startTime, duration); } }