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;
}
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());
}
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());
}
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);
}
}
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));
}
}
Aggregations