Search in sources :

Example 1 with Entity

use of org.hypertrace.entity.data.service.v1.Entity in project Denizen-For-Bukkit by DenizenScript.

the class WorldHelper_v1_8_R3 method setWorldAccess.

@Override
public void setWorldAccess(World world, final WorldAccess worldAccess) {
    if (worldAccessMap.containsKey(world)) {
        removeWorldAccess(world);
    }
    IWorldAccess nmsWorldAccess = new IWorldAccess() {

        @Override
        public void a(BlockPosition blockPosition) {
        }

        @Override
        public void b(BlockPosition blockPosition) {
        }

        @Override
        public void a(int i, int i1, int i2, int i3, int i4, int i5) {
        }

        @Override
        public void a(String s, double v, double v1, double v2, float v3, float v4) {
        }

        @Override
        public void a(EntityHuman entityHuman, String s, double v, double v1, double v2, float v3, float v4) {
        }

        @Override
        public void a(int i, boolean b, double v, double v1, double v2, double v3, double v4, double v5, int... ints) {
        }

        @Override
        public void a(Entity entity) {
        }

        @Override
        public void b(Entity entity) {
            worldAccess.despawn(entity.getBukkitEntity());
        }

        @Override
        public void a(String s, BlockPosition blockPosition) {
        }

        @Override
        public void a(int i, BlockPosition blockPosition, int i1) {
        }

        @Override
        public void a(EntityHuman entityHuman, int i, BlockPosition blockPosition, int i1) {
        }

        @Override
        public void b(int i, BlockPosition blockPosition, int i1) {
        }
    };
    worldAccessMap.put(world, nmsWorldAccess);
    ((CraftWorld) world).getHandle().addIWorldAccess(nmsWorldAccess);
}
Also used : IWorldAccess(net.minecraft.server.v1_8_R3.IWorldAccess) EntityHuman(net.minecraft.server.v1_8_R3.EntityHuman) Entity(net.minecraft.server.v1_8_R3.Entity) BlockPosition(net.minecraft.server.v1_8_R3.BlockPosition)

Example 2 with Entity

use of org.hypertrace.entity.data.service.v1.Entity in project GeoGig by boundlessgeo.

the class OSMExport method getFeatures.

private Iterator<EntityContainer> getFeatures(String ref) {
    Optional<ObjectId> id = geogig.command(RevParse.class).setRefSpec(ref).call();
    if (!id.isPresent()) {
        return Iterators.emptyIterator();
    }
    LsTreeOp op = geogig.command(LsTreeOp.class).setStrategy(Strategy.DEPTHFIRST_ONLY_FEATURES).setReference(ref);
    if (bbox != null) {
        final Envelope env;
        try {
            env = new Envelope(Double.parseDouble(bbox.get(0)), Double.parseDouble(bbox.get(2)), Double.parseDouble(bbox.get(1)), Double.parseDouble(bbox.get(3)));
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("Wrong bbox definition");
        }
        Predicate<Bounded> filter = new Predicate<Bounded>() {

            @Override
            public boolean apply(final Bounded bounded) {
                boolean intersects = bounded.intersects(env);
                return intersects;
            }
        };
        op.setBoundsFilter(filter);
    }
    Iterator<NodeRef> iterator = op.call();
    final EntityConverter converter = new EntityConverter();
    Function<NodeRef, EntityContainer> function = new Function<NodeRef, EntityContainer>() {

        @Override
        @Nullable
        public EntityContainer apply(@Nullable NodeRef ref) {
            RevFeature revFeature = geogig.command(RevObjectParse.class).setObjectId(ref.objectId()).call(RevFeature.class).get();
            SimpleFeatureType featureType;
            if (ref.path().startsWith(OSMUtils.NODE_TYPE_NAME)) {
                featureType = OSMUtils.nodeType();
            } else {
                featureType = OSMUtils.wayType();
            }
            SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);
            RevFeatureType revFeatureType = RevFeatureTypeImpl.build(featureType);
            List<PropertyDescriptor> descriptors = revFeatureType.sortedDescriptors();
            ImmutableList<Optional<Object>> values = revFeature.getValues();
            for (int i = 0; i < descriptors.size(); i++) {
                PropertyDescriptor descriptor = descriptors.get(i);
                Optional<Object> value = values.get(i);
                featureBuilder.set(descriptor.getName(), value.orNull());
            }
            SimpleFeature feature = featureBuilder.buildFeature(ref.name());
            Entity entity = converter.toEntity(feature, null);
            EntityContainer container;
            if (entity instanceof Node) {
                container = new NodeContainer((Node) entity);
            } else {
                container = new WayContainer((Way) entity);
            }
            return container;
        }
    };
    return Iterators.transform(iterator, function);
}
Also used : EntityConverter(org.locationtech.geogig.osm.internal.EntityConverter) Entity(org.openstreetmap.osmosis.core.domain.v0_6.Entity) WayContainer(org.openstreetmap.osmosis.core.container.v0_6.WayContainer) Node(org.openstreetmap.osmosis.core.domain.v0_6.Node) EntityContainer(org.openstreetmap.osmosis.core.container.v0_6.EntityContainer) NodeContainer(org.openstreetmap.osmosis.core.container.v0_6.NodeContainer) Envelope(com.vividsolutions.jts.geom.Envelope) Way(org.openstreetmap.osmosis.core.domain.v0_6.Way) Predicate(com.google.common.base.Predicate) NodeRef(org.locationtech.geogig.api.NodeRef) Function(com.google.common.base.Function) Bounded(org.locationtech.geogig.api.Bounded) RevFeature(org.locationtech.geogig.api.RevFeature) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) Optional(com.google.common.base.Optional) ObjectId(org.locationtech.geogig.api.ObjectId) SimpleFeature(org.opengis.feature.simple.SimpleFeature) LsTreeOp(org.locationtech.geogig.api.plumbing.LsTreeOp) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) Nullable(javax.annotation.Nullable) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 3 with Entity

use of org.hypertrace.entity.data.service.v1.Entity in project beam by apache.

the class EntityToRowRowToEntityTest method testRowToEntityConverterWithoutKey.

@Test
public void testRowToEntityConverterWithoutKey() {
    Schema schemaWithoutKey = Schema.builder().addFields(SCHEMA.getFields().stream().filter(f -> !f.getName().equals("__key__")).collect(Collectors.toList())).build();
    Row rowWithoutKey = Row.withSchema(schemaWithoutKey).addValues(schemaWithoutKey.getFieldNames().stream().map(ROW::getValue).collect(Collectors.toList())).build();
    PCollection<Entity> result = pipeline.apply(Create.of(rowWithoutKey)).setRowSchema(schemaWithoutKey).apply(RowToEntity.createTest(UUID_VALUE, "__key__", KIND));
    PAssert.that(result).containsInAnyOrder(ENTITY);
    pipeline.run().waitUntilFinish();
}
Also used : Arrays(java.util.Arrays) RunWith(org.junit.runner.RunWith) DatastoreHelper.makeValue(com.google.datastore.v1.client.DatastoreHelper.makeValue) INT64(org.apache.beam.sdk.schemas.Schema.FieldType.INT64) DOUBLE(org.apache.beam.sdk.schemas.Schema.FieldType.DOUBLE) Key(com.google.datastore.v1.Key) Create(org.apache.beam.sdk.transforms.Create) DatastoreHelper.makeKey(com.google.datastore.v1.client.DatastoreHelper.makeKey) TestPipeline(org.apache.beam.sdk.testing.TestPipeline) Value(com.google.datastore.v1.Value) Row(org.apache.beam.sdk.values.Row) FieldType.array(org.apache.beam.sdk.schemas.Schema.FieldType.array) DateTimeFormat(org.joda.time.format.DateTimeFormat) PAssert(org.apache.beam.sdk.testing.PAssert) DateTime(org.joda.time.DateTime) FieldType(org.apache.beam.sdk.schemas.Schema.FieldType) Test(org.junit.Test) BYTES(org.apache.beam.sdk.schemas.Schema.FieldType.BYTES) UUID(java.util.UUID) JUnit4(org.junit.runners.JUnit4) DATETIME(org.apache.beam.sdk.schemas.Schema.FieldType.DATETIME) PCollection(org.apache.beam.sdk.values.PCollection) Collectors(java.util.stream.Collectors) Schema(org.apache.beam.sdk.schemas.Schema) StandardCharsets(java.nio.charset.StandardCharsets) Entity(com.google.datastore.v1.Entity) ByteString(com.google.protobuf.ByteString) BOOLEAN(org.apache.beam.sdk.schemas.Schema.FieldType.BOOLEAN) Rule(org.junit.Rule) STRING(org.apache.beam.sdk.schemas.Schema.FieldType.STRING) Collections(java.util.Collections) Entity(com.google.datastore.v1.Entity) Schema(org.apache.beam.sdk.schemas.Schema) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Example 4 with Entity

use of org.hypertrace.entity.data.service.v1.Entity in project beam by apache.

the class EntityToRowRowToEntityTest method testEntityToRowConverterWithoutKey.

@Test
public void testEntityToRowConverterWithoutKey() {
    Schema schemaWithoutKey = Schema.builder().addFields(SCHEMA.getFields().stream().filter(f -> !f.getName().equals("__key__")).collect(Collectors.toList())).build();
    Row rowWithoutKey = Row.withSchema(schemaWithoutKey).addValues(schemaWithoutKey.getFieldNames().stream().map(ROW::getValue).collect(Collectors.toList())).build();
    PCollection<Row> result = pipeline.apply(Create.of(ENTITY)).apply(EntityToRow.create(schemaWithoutKey, DEFAULT_KEY_FIELD));
    PAssert.that(result).containsInAnyOrder(rowWithoutKey);
    pipeline.run().waitUntilFinish();
}
Also used : Arrays(java.util.Arrays) RunWith(org.junit.runner.RunWith) DatastoreHelper.makeValue(com.google.datastore.v1.client.DatastoreHelper.makeValue) INT64(org.apache.beam.sdk.schemas.Schema.FieldType.INT64) DOUBLE(org.apache.beam.sdk.schemas.Schema.FieldType.DOUBLE) Key(com.google.datastore.v1.Key) Create(org.apache.beam.sdk.transforms.Create) DatastoreHelper.makeKey(com.google.datastore.v1.client.DatastoreHelper.makeKey) TestPipeline(org.apache.beam.sdk.testing.TestPipeline) Value(com.google.datastore.v1.Value) Row(org.apache.beam.sdk.values.Row) FieldType.array(org.apache.beam.sdk.schemas.Schema.FieldType.array) DateTimeFormat(org.joda.time.format.DateTimeFormat) PAssert(org.apache.beam.sdk.testing.PAssert) DateTime(org.joda.time.DateTime) FieldType(org.apache.beam.sdk.schemas.Schema.FieldType) Test(org.junit.Test) BYTES(org.apache.beam.sdk.schemas.Schema.FieldType.BYTES) UUID(java.util.UUID) JUnit4(org.junit.runners.JUnit4) DATETIME(org.apache.beam.sdk.schemas.Schema.FieldType.DATETIME) PCollection(org.apache.beam.sdk.values.PCollection) Collectors(java.util.stream.Collectors) Schema(org.apache.beam.sdk.schemas.Schema) StandardCharsets(java.nio.charset.StandardCharsets) Entity(com.google.datastore.v1.Entity) ByteString(com.google.protobuf.ByteString) BOOLEAN(org.apache.beam.sdk.schemas.Schema.FieldType.BOOLEAN) Rule(org.junit.Rule) STRING(org.apache.beam.sdk.schemas.Schema.FieldType.STRING) Collections(java.util.Collections) Schema(org.apache.beam.sdk.schemas.Schema) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Example 5 with Entity

use of org.hypertrace.entity.data.service.v1.Entity in project beam by apache.

the class DatastoreV1Test method testReadFnRetriesErrors.

/**
 * Tests that {@link ReadFn} retries after an error.
 */
@Test
public void testReadFnRetriesErrors() throws Exception {
    // An empty query to read entities.
    Query query = Query.newBuilder().setLimit(Int32Value.newBuilder().setValue(1)).build();
    // Use mockResponseForQuery to generate results.
    when(mockDatastore.runQuery(any(RunQueryRequest.class))).thenThrow(new DatastoreException("RunQuery", Code.DEADLINE_EXCEEDED, "", null)).thenAnswer(invocationOnMock -> {
        Query q = ((RunQueryRequest) invocationOnMock.getArguments()[0]).getQuery();
        return mockResponseForQuery(q);
    });
    ReadFn readFn = new ReadFn(V_1_OPTIONS, mockDatastoreFactory);
    DoFnTester<Query, Entity> doFnTester = DoFnTester.of(readFn);
    doFnTester.setCloningBehavior(CloningBehavior.DO_NOT_CLONE);
    doFnTester.processBundle(query);
    verifyMetricWasSet("BatchDatastoreRead", "ok", NAMESPACE, 1);
    verifyMetricWasSet("BatchDatastoreRead", "unknown", NAMESPACE, 1);
}
Also used : Entity(com.google.datastore.v1.Entity) DeleteEntity(org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteEntity) GqlQuery(com.google.datastore.v1.GqlQuery) Query(com.google.datastore.v1.Query) ReadFn(org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.Read.ReadFn) RunQueryRequest(com.google.datastore.v1.RunQueryRequest) DatastoreException(com.google.datastore.v1.client.DatastoreException) Test(org.junit.Test)

Aggregations

Entity (org.hypertrace.entity.data.service.v1.Entity)110 Test (org.junit.jupiter.api.Test)97 LivingEntity (org.bukkit.entity.LivingEntity)94 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)88 EnrichedEntity (org.hypertrace.entity.data.service.v1.EnrichedEntity)34 Entity (com.google.datastore.v1.Entity)33 ArrayList (java.util.ArrayList)32 net.minecraft.world.entity (net.minecraft.world.entity)32 org.bukkit.entity (org.bukkit.entity)32 Location (org.bukkit.Location)29 Event (org.hypertrace.core.datamodel.Event)27 AttributeValue (org.hypertrace.core.datamodel.AttributeValue)22 BackendInfo (org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo)21 Entity (net.minecraft.server.v1_16_R3.Entity)19 AttributeValue (org.hypertrace.entity.data.service.v1.AttributeValue)19 NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)18 AnnotateVideoProgress (com.google.cloud.videointelligence.v1.AnnotateVideoProgress)17 AnnotateVideoRequest (com.google.cloud.videointelligence.v1.AnnotateVideoRequest)17 AnnotateVideoResponse (com.google.cloud.videointelligence.v1.AnnotateVideoResponse)17 Entity (com.google.cloud.videointelligence.v1.Entity)17