private static Map<String, Object> getProperties(Entity entity) throws IOException, ClassNotFoundException { if (entity == null) { return null; } ImmutableMap.Builder<String, Object> builder = new ImmutableMap.Builder<>(); for (String property : entity.getNames()) { // builder.put(property, entity.getValue(property)); if (entity.getValue(property) instanceof StringValue) { builder.put(property, (String) entity.getString(property)); } else if (entity.getValue(property) instanceof LongValue) { // This conversion is safe because of integer to long conversion above builder.put(property, new Long(entity.getLong(property)).intValue()); } else if (entity.getValue(property) instanceof DoubleValue) { builder.put(property, (Double) entity.getDouble(property)); } else if (entity.getValue(property) instanceof BooleanValue) { builder.put(property, (Boolean) entity.getBoolean(property)); } else if (entity.getValue(property) instanceof TimestampValue) { builder.put(property, (Timestamp) entity.getTimestamp(property)); } else { Blob blob = entity.getBlob(property); Object obj = null; try (ObjectInputStream in = new ObjectInputStream(blob.asInputStream())) { obj = in.readObject(); } builder.put(property, obj); // BlobValue } } return builder.build(); }
while (results.hasNext()) { Entity result = results.next(); sortedComments.put(result.getTimestamp("timestamp"), result.getString("content")); resultCount++;
/** * Converts a list of task entities to a list of formatted task strings. * * @param tasks An iterator over task entities * @return A list of tasks strings, one per entity */ static List<String> formatTasks(Iterator<Entity> tasks) { List<String> strings = new ArrayList<>(); while (tasks.hasNext()) { Entity task = tasks.next(); if (task.getBoolean("done")) { strings.add( String.format("%d : %s (done)", task.getKey().getId(), task.getString("description"))); } else { strings.add(String.format("%d : %s (created %s)", task.getKey().getId(), task.getString("description"), task.getTimestamp("created"))); } } return strings; }
/** * Optionally get an {@link Instant} value for an {@link Entity}'s property. * * @return an optional containing the property value if it existed, empty otherwise. */ static Optional<Instant> getOptInstantProperty(Optional<Entity> entity, String property) { return entity .filter(w -> w.contains(property)) .map(workflow -> timestampToInstant(workflow.getTimestamp(property))); }
Instant instant = timestampToInstant(entity.getTimestamp(PROPERTY_NEXT_NATURAL_TRIGGER)); final Instant triggerInstant; triggerInstant = timestampToInstant(entity.getTimestamp(PROPERTY_NEXT_NATURAL_OFFSET_TRIGGER));
static Backfill entityToBackfill(Entity entity) throws IOException { final WorkflowId workflowId = WorkflowId.create(entity.getString(PROPERTY_COMPONENT), entity.getString(PROPERTY_WORKFLOW)); final BackfillBuilder builder = Backfill.newBuilder() .id(entity.getKey().getName()) .start(timestampToInstant(entity.getTimestamp(PROPERTY_START))) .end(timestampToInstant(entity.getTimestamp(PROPERTY_END))) .workflowId(workflowId) .concurrency((int) entity.getLong(PROPERTY_CONCURRENCY)) .nextTrigger(timestampToInstant(entity.getTimestamp(PROPERTY_NEXT_TRIGGER))) .schedule(Schedule.parse(entity.getString(PROPERTY_SCHEDULE))) .allTriggered(entity.getBoolean(PROPERTY_ALL_TRIGGERED)) .halted(entity.getBoolean(PROPERTY_HALTED)) .reverse(read(entity, PROPERTY_REVERSE, Boolean.FALSE)); if (entity.contains(PROPERTY_DESCRIPTION)) { builder.description(entity.getString(PROPERTY_DESCRIPTION)); } if (entity.contains(PROPERTY_TRIGGER_PARAMETERS)) { builder.triggerParameters(OBJECT_MAPPER.readValue( entity.getString(PROPERTY_TRIGGER_PARAMETERS), TriggerParameters.class)); } return builder.build(); }