use of com.google.storage.onestore.v3.OnestoreEntity.EntityProto in project appengine-java-standard by GoogleCloudPlatform.
the class PropertyPseudoKind method addPropertyEntitiesToSchema.
/**
* Build __property__ entities from results of scanning entities, and add them to the schema
*/
private static void addPropertyEntitiesToSchema(List<EntityProto> schema, String kind, SortedSetMultimap<String, String> allProps, String app, String namespace, boolean keysOnly) {
// {@link SortedSet}s so the results will be ordered.
for (String prop : allProps.keySet()) {
// Create schema entity and set its key based on the kind
EntityProto propEntity = new EntityProto();
schema.add(propEntity);
Path path = new Path();
path.addElement().setType(KIND_METADATA_KIND).setName(kind);
path.addElement().setType(PROPERTY_METADATA_KIND).setName(prop);
Reference key = new Reference().setApp(app).setPath(path);
if (namespace.length() > 0) {
key.setNameSpace(namespace);
}
propEntity.setKey(key);
// EntityProto.entity_group is a required PB field.
propEntity.getMutableEntityGroup().addElement(path.getElement(0));
if (!keysOnly) {
for (String rep : allProps.get(prop)) {
PropertyValue repValue = new PropertyValue().setStringValue(rep);
propEntity.addProperty().setName("property_representation").setValue(repValue).setMultiple(true);
}
}
}
}
use of com.google.storage.onestore.v3.OnestoreEntity.EntityProto in project appengine-java-standard by GoogleCloudPlatform.
the class EntityTest method testUnindexedValue.
@Test
public void testUnindexedValue() {
Entity entity = new Entity("foo");
entity.setProperty("indexed", "foo");
entity.setUnindexedProperty("unindexed", "bar");
entity.setProperty("text", new Text("hello"));
entity.setProperty("blob", new Blob(new byte[] { 1, 2, 3 }));
entity.setProperty("entity", new EmbeddedEntity());
assertThat(entity.hasProperty("indexed")).isTrue();
assertThat(entity.getProperty("indexed")).isEqualTo("foo");
assertThat(entity.isUnindexedProperty("indexed")).isFalse();
assertWithMessage("isUnindexed for text").that(entity.isUnindexedProperty("text")).isTrue();
assertWithMessage("isUnindexed for blob").that(entity.isUnindexedProperty("blob")).isTrue();
assertWithMessage("isUnindexed for embedded entity").that(entity.isUnindexedProperty("entity")).isTrue();
assertThat(entity.hasProperty("unindexed")).isTrue();
assertThat(entity.getProperty("unindexed")).isEqualTo("bar");
assertThat(entity.isUnindexedProperty("unindexed")).isTrue();
assertThat(entity.getProperties()).containsExactly("indexed", "foo", "unindexed", "bar", "text", new Text("hello"), "blob", new Blob(new byte[] { 1, 2, 3 }), "entity", new EmbeddedEntity());
assertThat(entity.getPropertyMap()).containsExactly("indexed", "foo", "unindexed", new Entity.UnindexedValue("bar"), "text", new Text("hello"), "blob", new Blob(new byte[] { 1, 2, 3 }), "entity", new EmbeddedEntity());
EntityProto proto = EntityTranslator.convertToPb(entity);
assertThat(proto.propertySize()).isEqualTo(1);
assertThat(proto.rawPropertySize()).isEqualTo(4);
}
use of com.google.storage.onestore.v3.OnestoreEntity.EntityProto in project nomulus by google.
the class RecordAccumulator method getEntityWrapperSet.
/**
* Creates an {@link EntityWrapper} set from the current set of raw records.
*/
ImmutableSet<EntityWrapper> getEntityWrapperSet() {
ImmutableSet.Builder<EntityWrapper> builder = new ImmutableSet.Builder<>();
for (byte[] rawRecord : records) {
// Parse the entity proto and create an Entity object from it.
EntityProto proto = new EntityProto();
proto.parseFrom(rawRecord);
EntityWrapper entity = new EntityWrapper(EntityTranslator.createFromPb(proto));
builder.add(entity);
}
return builder.build();
}
use of com.google.storage.onestore.v3.OnestoreEntity.EntityProto in project nomulus by google.
the class EntityImports method fixProperty.
private static void fixProperty(OnestoreEntity.Property property, String appId) {
OnestoreEntity.PropertyValue value = property.getMutableValue();
if (value.hasReferenceValue()) {
fixKey(value.getMutableReferenceValue(), appId);
return;
}
if (property.getMeaningEnum().equals(Meaning.ENTITY_PROTO)) {
EntityProto embeddedProto = bytesToEntityProto(value.getStringValueAsBytes());
fixEntity(embeddedProto, appId);
value.setStringValueAsBytes(embeddedProto.toByteArray());
}
}
use of com.google.storage.onestore.v3.OnestoreEntity.EntityProto in project nomulus by google.
the class EntityImportsTest method loadEntityProtos.
private static ImmutableList<EntityProto> loadEntityProtos(InputStream inputStream) {
ImmutableList.Builder<EntityProto> protosBuilder = new ImmutableList.Builder<>();
while (true) {
EntityProto proto = new EntityProto();
boolean parsed = proto.parseDelimitedFrom(inputStream);
if (parsed && proto.isInitialized()) {
protosBuilder.add(proto);
} else {
break;
}
}
return protosBuilder.build();
}
Aggregations