Skip to content

Commit de98fa8

Browse files
authored
Added fetch attribute by id in Attribute Store (#171)
1 parent 4420bc3 commit de98fa8

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

hypertrace-core-graphql-attribute-store/src/main/java/org/hypertrace/core/graphql/attributes/AttributeStore.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public interface AttributeStore {
1313

1414
Single<AttributeModel> getIdAttribute(GraphQlRequestContext context, String scope);
1515

16+
Single<AttributeModel> getAttributeById(GraphQlRequestContext context, String attributeId);
17+
1618
Single<AttributeModel> getForeignIdAttribute(
1719
GraphQlRequestContext context, String scope, String foreignScope);
1820

hypertrace-core-graphql-attribute-store/src/main/java/org/hypertrace/core/graphql/attributes/CachingAttributeStore.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ public Single<AttributeModel> getForeignIdAttribute(
8686
.flatMap(key -> this.get(context, scope, key));
8787
}
8888

89+
@Override
90+
public Single<AttributeModel> getAttributeById(
91+
GraphQlRequestContext context, String attributeId) {
92+
return grpcContextBuilder
93+
.build(context)
94+
.call(() -> cachingAttributeClient.get(attributeId))
95+
.mapOptional(this.translator::translate)
96+
.switchIfEmpty(Single.error(this.buildErrorForMissingAttributeId(attributeId)));
97+
}
98+
8999
@Override
90100
public Completable create(
91101
final GraphQlRequestContext context, final List<AttributeMetadata> attributes) {
@@ -139,6 +149,11 @@ private NoSuchElementException buildErrorForMissingAttribute(String scope, Strin
139149
String.format("No attribute available for scope '%s' and key '%s'", scope, key));
140150
}
141151

152+
private NoSuchElementException buildErrorForMissingAttributeId(String attributeId) {
153+
return new NoSuchElementException(
154+
String.format("No attribute available for attribute id '%s'", attributeId));
155+
}
156+
142157
private NoSuchElementException buildErrorForMissingForeignScopeMapping(
143158
String scope, String foreignScope) {
144159
return new NoSuchElementException(

0 commit comments

Comments
 (0)