/** * Creates a new {@code Entity}. * * @return an immutable entity. */ public Entity build() { entity.getMutableProperties().clear(); entity.putAllProperties( properties .entrySet() .stream() .collect(Collectors.toMap( Map.Entry::getKey, e -> e.getValue().getPb().toBuilder().build()))); return new Entity(entity.build()); }
com.google.datastore.v1.Entity getPb(final String namespace) { final Map<String, com.google.datastore.v1.Value> propertiesLocal = entity.getProperties() .entrySet() .stream() .collect(Collectors.toMap( Map.Entry::getKey, e -> Value.builder(e.getValue()).build().getPb(namespace))); return com.google.datastore.v1.Entity .newBuilder() .putAllProperties(propertiesLocal) .setKey(getKey().getPb(namespace)) .build(); } }
@ProcessElement public void processElement(ProcessContext c) { Entity.Builder entityBuilder = Entity.newBuilder(); Key key = makeKey(makeKey(kind, ancestorKey).build(), kind, c.element().getKey()).build(); entityBuilder.setKey(key); List<Value> candidates = new ArrayList<>(); Map<String, Value> properties = new HashMap<>(); for (CompletionCandidate tag : c.element().getValue()) { Entity.Builder tagEntity = Entity.newBuilder(); properties.put("tag", makeValue(tag.value).build()); properties.put("count", makeValue(tag.count).build()); candidates.add(makeValue(tagEntity).build()); } properties.put("candidates", makeValue(candidates).build()); entityBuilder.putAllProperties(properties); c.output(entityBuilder.build()); } }