Search in sources :

Example 21 with EntityType

use of org.openstreetmap.osmosis.core.domain.v0_6.EntityType in project osmosis by openstreetmap.

the class FastXmlParser method readRelationMember.

private RelationMember readRelationMember() throws Exception {
    long id;
    EntityType type;
    String role;
    id = Long.parseLong(reader.getAttributeValue(null, ATTRIBUTE_NAME_REF));
    type = memberTypeParser.parse(reader.getAttributeValue(null, ATTRIBUTE_NAME_TYPE));
    role = reader.getAttributeValue(null, ATTRIBUTE_NAME_ROLE);
    RelationMember relationMember = new RelationMember(id, type, role);
    reader.nextTag();
    reader.nextTag();
    return relationMember;
}
Also used : EntityType(org.openstreetmap.osmosis.core.domain.v0_6.EntityType) RelationMember(org.openstreetmap.osmosis.core.domain.v0_6.RelationMember)

Example 22 with EntityType

use of org.openstreetmap.osmosis.core.domain.v0_6.EntityType in project entity-service by hypertrace.

the class EntityTypeDocumentTest method testProtoConversion.

@Test
public void testProtoConversion() {
    EntityType entityType = EntityType.newBuilder().setName("API").setAttributeScope("API").setIdAttributeKey("id").setNameAttributeKey("name").setTimestampAttributeKey("timestamp").addRequiredConditions(EntityFormationCondition.newBuilder().setRequiredKey("other")).build();
    Assertions.assertEquals(entityType, EntityTypeDocument.fromProto("testTenant", entityType).toProto());
}
Also used : EntityType(org.hypertrace.entity.type.service.v2.EntityType) Test(org.junit.jupiter.api.Test)

Example 23 with EntityType

use of org.openstreetmap.osmosis.core.domain.v0_6.EntityType in project entity-service by hypertrace.

the class EntityTypeDocumentTest method testFromJsonMissingField.

@Test
public void testFromJsonMissingField() throws InvalidProtocolBufferException, JsonProcessingException {
    EntityType entityType = EntityType.newBuilder().setName("API").setAttributeScope("API").setIdAttributeKey("id").setNameAttributeKey("name").build();
    String entityTypeJson = JsonFormat.printer().print(entityType);
    Assertions.assertEquals(entityType, EntityTypeDocument.fromJson(entityTypeJson).toProto());
}
Also used : EntityType(org.hypertrace.entity.type.service.v2.EntityType) Test(org.junit.jupiter.api.Test)

Example 24 with EntityType

use of org.openstreetmap.osmosis.core.domain.v0_6.EntityType in project entity-service by hypertrace.

the class EntityTypeServiceImpl method deleteEntityTypes.

@Override
public void deleteEntityTypes(EntityTypeFilter request, StreamObserver<Empty> responseObserver) {
    Optional<String> tenantId = RequestContext.CURRENT.get().getTenantId();
    if (tenantId.isEmpty()) {
        responseObserver.onError(new ServiceException("Tenant id is missing in the request."));
        return;
    }
    try {
        Iterator<Document> documents = entityTypeCol.search(transform(tenantId.get(), request, false));
        StreamSupport.stream(Spliterators.spliteratorUnknownSize(documents, 0), false).map(document -> {
            try {
                EntityType.Builder builder = EntityType.newBuilder();
                PARSER.merge(document.toJson(), builder);
                return builder;
            } catch (InvalidProtocolBufferException e) {
                LOG.warn(String.format("Error processing entityType: %s", document.toJson()), e);
                return null;
            }
        }).filter(Objects::nonNull).forEach(entityTypeBuilder -> entityTypeCol.delete(new SingleValueKey(tenantId.get(), entityTypeBuilder.getName())));
        responseObserver.onNext(Empty.newBuilder().build());
        responseObserver.onCompleted();
    } catch (Exception ex) {
        LOG.error("Error deleting entity types matching filter:{}", request);
        responseObserver.onError(ex);
    }
}
Also used : EntityType(org.hypertrace.entity.type.service.v1.EntityType) SingleValueKey(org.hypertrace.core.documentstore.SingleValueKey) ServiceException(com.google.protobuf.ServiceException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Document(org.hypertrace.core.documentstore.Document) JSONDocument(org.hypertrace.core.documentstore.JSONDocument) ServiceException(com.google.protobuf.ServiceException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) IOException(java.io.IOException)

Example 25 with EntityType

use of org.openstreetmap.osmosis.core.domain.v0_6.EntityType in project entity-service by hypertrace.

the class EntityTypeServiceImpl method upsertEntityType.

@Override
public void upsertEntityType(EntityType request, StreamObserver<EntityType> responseObserver) {
    Optional<String> tenantId = RequestContext.CURRENT.get().getTenantId();
    if (tenantId.isEmpty()) {
        responseObserver.onError(new ServiceException("Tenant id is missing in the request."));
        return;
    }
    try {
        // TODO: Since we currently use the same object that's received in the request while
        // persisting in the doc store, we need to add tenantId explicitly here.
        // We need to split these objects later.
        EntityType newRequest = EntityType.newBuilder(request).setTenantId(tenantId.get()).build();
        entityTypeCol.upsert(new SingleValueKey(tenantId.get(), request.getName()), new JSONDocument(PROTO_PRINTER.print(newRequest)));
        responseObserver.onNext(newRequest);
        responseObserver.onCompleted();
    } catch (IOException ioe) {
        responseObserver.onError(new RuntimeException("Error upserting EntityType:" + request, ioe));
    }
}
Also used : EntityType(org.hypertrace.entity.type.service.v1.EntityType) SingleValueKey(org.hypertrace.core.documentstore.SingleValueKey) ServiceException(com.google.protobuf.ServiceException) JSONDocument(org.hypertrace.core.documentstore.JSONDocument) IOException(java.io.IOException)

Aggregations

EntityType (org.openstreetmap.osmosis.core.domain.v0_6.EntityType)12 RelationMember (org.openstreetmap.osmosis.core.domain.v0_6.RelationMember)9 Test (org.junit.Test)5 EntityType (com.google.cloud.dialogflow.cx.v3beta1.EntityType)4 EntityType (org.hypertrace.entity.type.service.v1.EntityType)4 Test (org.junit.jupiter.api.Test)4 EntityType (com.google.cloud.dialogflow.v2.EntityType)3 ServiceException (com.google.protobuf.ServiceException)3 JSONDocument (org.hypertrace.core.documentstore.JSONDocument)3 EntityType (org.hypertrace.entity.type.service.v2.EntityType)3 Relation (org.openstreetmap.osmosis.core.domain.v0_6.Relation)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 Osmformat (crosby.binary.Osmformat)2 IOException (java.io.IOException)2 Document (org.hypertrace.core.documentstore.Document)2 SingleValueKey (org.hypertrace.core.documentstore.SingleValueKey)2 BeforeClass (org.junit.BeforeClass)2 Agent (com.google.cloud.dialogflow.cx.v3beta1.Agent)1 CreateEntityTypeRequest (com.google.cloud.dialogflow.cx.v3beta1.CreateEntityTypeRequest)1 CreateFlowRequest (com.google.cloud.dialogflow.cx.v3beta1.CreateFlowRequest)1