use of com.google.cloud.videointelligence.v1p2beta1.Entity in project WildChests by BG-Software-LLC.
the class NMSAdapter_v1_16_R3 method getNearbyItems.
@Override
public Stream<Item> getNearbyItems(Location location, int range, boolean onlyChunk, KeySet blacklisted, KeySet whitelisted) {
World world = ((CraftWorld) location.getWorld()).getHandle();
List<Entity> entityList = new ArrayList<>();
if (onlyChunk) {
Chunk chunk = ((CraftChunk) location.getChunk()).getHandle();
for (int i = 0; i < chunk.entitySlices.length; i++) entityList.addAll(chunk.entitySlices[i]);
entityList = entityList.stream().filter(entity -> entity instanceof EntityItem).collect(Collectors.toList());
} else {
AxisAlignedBB boundingBox = new AxisAlignedBB(location.getX() + range, location.getY() + range, location.getZ() + range, location.getX() - range, location.getY() - range, location.getZ() - range);
entityList = world.getEntities(null, boundingBox, entity -> entity instanceof EntityItem);
}
return entityList.stream().map(entity -> (Item) entity.getBukkitEntity()).filter(item -> !blacklisted.contains(item.getItemStack()) && (whitelisted.isEmpty() || whitelisted.contains(item.getItemStack())));
}
use of com.google.cloud.videointelligence.v1p2beta1.Entity in project entity-service by hypertrace.
the class EntityDataServiceTest method testCreateWithIdentifyingAttributes.
@Test
public void testCreateWithIdentifyingAttributes() {
AttributeValue randomUUIDAttrValue = generateRandomUUIDAttrValue();
Entity entity = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.K8S_POD.name()).setEntityName("Some Service").putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_EXTERNAL_ID), randomUUIDAttrValue).build();
Entity createdEntity = entityDataServiceClient.upsert(entity);
assertNotNull(createdEntity.getEntityId());
Entity entity1 = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.K8S_POD.name()).setEntityName("Some Service 1").putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_EXTERNAL_ID), randomUUIDAttrValue).build();
Entity createdEntity1 = entityDataServiceClient.upsert(entity1);
// Should be same entity since identifying attributes are the same
assertEquals(createdEntity.getEntityId(), createdEntity1.getEntityId());
}
use of com.google.cloud.videointelligence.v1p2beta1.Entity in project entity-service by hypertrace.
the class EntityDataServiceTest method testEntityQueryAttributeWithExistsFiltering.
@Test
public void testEntityQueryAttributeWithExistsFiltering() {
String stringRandomizer1 = UUID.randomUUID().toString();
Entity entity1 = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.K8S_POD.name()).setEntityName("Some Service").putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_EXTERNAL_ID), AttributeValue.newBuilder().setValue(Value.newBuilder().setString("value1").build()).build()).putAttributes("simpleValue1" + "-" + stringRandomizer1, AttributeValue.newBuilder().setValue(Value.newBuilder().setString("StringValue1").build()).build()).build();
Entity createdEntity1 = entityDataServiceClient.upsert(entity1);
assertNotNull(createdEntity1.getEntityId());
String stringRandomizer2 = UUID.randomUUID().toString();
Entity entity2 = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.K8S_POD.name()).setEntityName("Some Service").putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_EXTERNAL_ID), AttributeValue.newBuilder().setValue(Value.newBuilder().setString("value2").build()).build()).putAttributes("simpleValue2" + "-" + stringRandomizer2, AttributeValue.newBuilder().setValue(Value.newBuilder().setString("StringValue2").build()).build()).putAttributes("test" + "-" + stringRandomizer2, AttributeValue.newBuilder().setValue(Value.newBuilder().setString("test").build()).build()).build();
Entity createdEntity2 = entityDataServiceClient.upsert(entity2);
assertNotNull(createdEntity2.getEntityId());
// test for exists operator
AttributeFilter existsFilter = AttributeFilter.newBuilder().setName(EntityConstants.attributeMapPathFor("simpleValue1" + "-" + stringRandomizer1)).setOperator(Operator.EXISTS).build();
List<Entity> entities = entityDataServiceClient.query(TENANT_ID, Query.newBuilder().setFilter(existsFilter).build());
assertEquals(1, entities.size());
assertEquals(createdEntity1, entities.get(0));
// test for not-exists operator
AttributeFilter notExistsFilter = AttributeFilter.newBuilder().setName(EntityConstants.attributeMapPathFor("simpleValue3")).setOperator(Operator.NOT_EXISTS).build();
entities = entityDataServiceClient.query(TENANT_ID, Query.newBuilder().setFilter(notExistsFilter).build());
assertTrue(entities.size() > 0);
// test with AND operator
AttributeFilter eqFilter = AttributeFilter.newBuilder().setName(EntityConstants.attributeMapPathFor("test" + "-" + stringRandomizer2)).setOperator(Operator.EQ).setAttributeValue(AttributeValue.newBuilder().setValue(Value.newBuilder().setString("test").build()).build()).build();
existsFilter = AttributeFilter.newBuilder().setName(EntityConstants.attributeMapPathFor("simpleValue2" + "-" + stringRandomizer2)).setOperator(Operator.EXISTS).build();
AttributeFilter andFilter = AttributeFilter.newBuilder().setOperator(Operator.AND).addChildFilter(eqFilter).addChildFilter(existsFilter).build();
entities = entityDataServiceClient.query(TENANT_ID, Query.newBuilder().setFilter(andFilter).build());
assertEquals(1, entities.size());
assertEquals(createdEntity2, entities.get(0));
// exists with attribute value - discard the value
existsFilter = AttributeFilter.newBuilder().setName(EntityConstants.attributeMapPathFor("simpleValue1" + "-" + stringRandomizer1)).setOperator(Operator.EXISTS).setAttributeValue(AttributeValue.newBuilder().setValue(Value.newBuilder().setString("StringValue").build()).build()).build();
entities = entityDataServiceClient.query(TENANT_ID, Query.newBuilder().setFilter(existsFilter).build());
assertEquals(1, entities.size());
assertEquals(createdEntity1, entities.get(0));
}
use of com.google.cloud.videointelligence.v1p2beta1.Entity in project entity-service by hypertrace.
the class EntityDataServiceTest method testCreateV2EntityTypeWithoutIdentifyingAttributes.
@Test
public void testCreateV2EntityTypeWithoutIdentifyingAttributes() {
Entity firstInputEntity = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(TEST_ENTITY_TYPE_V2).setEntityId(UUID.randomUUID().toString()).setEntityName("Test entity v2").putAttributes("foo", AttributeValue.newBuilder().setValue(Value.newBuilder().setString("foo1")).build()).build();
Entity firstCreatedEntity = entityDataServiceClient.upsert(firstInputEntity);
assertNotSame(firstInputEntity, firstCreatedEntity);
assertEntityEquals(firstInputEntity, firstCreatedEntity);
Entity secondInputEntity = firstInputEntity.toBuilder().clearAttributes().build();
Entity secondCreatedEntity = entityDataServiceClient.upsert(secondInputEntity);
assertEntityEquals(firstCreatedEntity, secondCreatedEntity);
}
use of com.google.cloud.videointelligence.v1p2beta1.Entity in project entity-service by hypertrace.
the class EntityDataServiceTest method testEntityQueryAttributeFiltering.
@Test
public void testEntityQueryAttributeFiltering() {
long timeBeforeQuery = System.currentTimeMillis();
String stringRandomizer = UUID.randomUUID().toString();
Entity entity = Entity.newBuilder().setTenantId(TENANT_ID).setEntityType(EntityType.K8S_POD.name()).setEntityName("Some Service").putIdentifyingAttributes(EntityConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_EXTERNAL_ID), AttributeValue.newBuilder().setValue(Value.newBuilder().setString("value1").build()).build()).putAttributes("simpleValue" + "-" + stringRandomizer, AttributeValue.newBuilder().setValue(Value.newBuilder().setString("StringValue").build()).build()).putAttributes("listValue" + "-" + stringRandomizer, AttributeValue.newBuilder().setValueList(AttributeValueList.newBuilder().addValues(AttributeValue.newBuilder().setValue(Value.newBuilder().setString("item1").build()).build()).addValues(AttributeValue.newBuilder().setValue(Value.newBuilder().setString("item2").build()).build()).build()).build()).putAttributes("mapValue" + "-" + stringRandomizer, AttributeValue.newBuilder().setValueMap(AttributeValueMap.newBuilder().putValues("nestedKey", AttributeValue.newBuilder().setValue(Value.newBuilder().setString("nestedValue").build()).build()).build()).build()).build();
Entity createdEntity = entityDataServiceClient.upsert(entity);
assertNotNull(createdEntity.getEntityId());
AttributeFilter stringFilter = AttributeFilter.newBuilder().setName(EntityConstants.attributeMapPathFor("simpleValue" + "-" + stringRandomizer)).setOperator(Operator.EQ).setAttributeValue(AttributeValue.newBuilder().setValue(Value.newBuilder().setString("StringValue").build()).build()).build();
List<Entity> entities1 = entityDataServiceClient.query(TENANT_ID, Query.newBuilder().setFilter(stringFilter).build());
Entity foundEntity1 = entities1.get(0);
assertEquals(createdEntity, foundEntity1);
// filter by createdTime, which is treated as attribute filtering because it should be able
// to support different operations like regular attribtues
AttributeFilter createTimeFilter = AttributeFilter.newBuilder().setName(EntityServiceConstants.ENTITY_CREATED_TIME).setOperator(Operator.GT).setAttributeValue(AttributeValue.newBuilder().setValue(Value.newBuilder().setLong(timeBeforeQuery).build()).build()).build();
List<Entity> entities11 = entityDataServiceClient.query(TENANT_ID, Query.newBuilder().setFilter(createTimeFilter).build());
Entity foundEntity11 = entities11.get(0);
assertEquals(createdEntity, foundEntity11);
AttributeFilter nestedFilter = AttributeFilter.newBuilder().setName(EntityConstants.attributeMapPathFor("mapValue" + "-" + stringRandomizer)).setOperator(Operator.EQ).setAttributeValue(AttributeValue.newBuilder().setValueMap(AttributeValueMap.newBuilder().putValues("nestedKey", AttributeValue.newBuilder().setValue(Value.newBuilder().setString("nestedValue").build()).build()).build()).build()).build();
List<Entity> entities2 = entityDataServiceClient.query(TENANT_ID, Query.newBuilder().setFilter(nestedFilter).build());
Entity foundEntity2 = entities2.get(0);
assertEquals(createdEntity, foundEntity2);
AttributeFilter listFilter = AttributeFilter.newBuilder().setName(EntityConstants.attributeMapPathFor("listValue" + "-" + stringRandomizer)).setOperator(Operator.EQ).setAttributeValue(AttributeValue.newBuilder().setValueList(AttributeValueList.newBuilder().addValues(AttributeValue.newBuilder().setValue(Value.newBuilder().setString("item1").build()).build()).addValues(AttributeValue.newBuilder().setValue(Value.newBuilder().setString("item2").build()).build()).build()).build()).build();
List<Entity> entities3 = entityDataServiceClient.query(TENANT_ID, Query.newBuilder().setFilter(listFilter).build());
Entity foundEntity3 = entities3.get(0);
assertEquals(createdEntity, foundEntity3);
AttributeFilter listInFilter = AttributeFilter.newBuilder().setName(EntityConstants.attributeMapPathFor("listValue" + "-" + stringRandomizer)).setOperator(Operator.CONTAINS).setAttributeValue(AttributeValue.newBuilder().setValueList(AttributeValueList.newBuilder().addValues(AttributeValue.newBuilder().setValue(Value.newBuilder().setString("item1").build()).build()).build()).build()).build();
List<Entity> entities4 = entityDataServiceClient.query(TENANT_ID, Query.newBuilder().setFilter(listInFilter).build());
Entity foundEntity4 = entities4.get(0);
assertEquals(createdEntity, foundEntity4);
}
Aggregations