Skip to content

Commit 199486c

Browse files
author
kamaleshnneerasa
committed
Adding color, description in labels graphql apis
1 parent 1ec3bd0 commit 199486c

File tree

6 files changed

+82
-7
lines changed

6 files changed

+82
-7
lines changed
Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.hypertrace.graphql.label.dao;
22

3+
import java.util.Objects;
34
import org.hypertrace.graphql.label.request.LabelCreateRequest;
45
import org.hypertrace.graphql.label.request.LabelUpdateRequest;
56
import org.hypertrace.label.config.service.v1.CreateLabelRequest;
@@ -8,15 +9,27 @@
89

910
public class LabelRequestConverter {
1011
CreateLabelRequest convertCreationRequest(LabelCreateRequest creationRequest) {
11-
return CreateLabelRequest.newBuilder()
12-
.setData(LabelData.newBuilder().setKey(creationRequest.label().key()).build())
13-
.build();
12+
LabelData.Builder dataBuilder = LabelData.newBuilder().setKey(creationRequest.label().key());
13+
if (Objects.nonNull(creationRequest.label().color())) {
14+
dataBuilder.setColor(Objects.requireNonNull(creationRequest.label().color()));
15+
}
16+
if (Objects.nonNull(creationRequest.label().description())) {
17+
dataBuilder.setDescription(Objects.requireNonNull(creationRequest.label().description()));
18+
}
19+
return CreateLabelRequest.newBuilder().setData(dataBuilder.build()).build();
1420
}
1521

1622
UpdateLabelRequest convertUpdateRequest(LabelUpdateRequest updateRequest) {
23+
LabelData.Builder dataBuilder = LabelData.newBuilder().setKey(updateRequest.label().key());
24+
if (Objects.nonNull(updateRequest.label().color())) {
25+
dataBuilder.setColor(Objects.requireNonNull(updateRequest.label().color()));
26+
}
27+
if (Objects.nonNull(updateRequest.label().description())) {
28+
dataBuilder.setDescription(Objects.requireNonNull(updateRequest.label().description()));
29+
}
1730
return UpdateLabelRequest.newBuilder()
1831
.setId(updateRequest.label().id())
19-
.setData(LabelData.newBuilder().setKey(updateRequest.label().key()).build())
32+
.setData(dataBuilder.build())
2033
.build();
2134
}
2235
}

hypertrace-graphql-labels-schema/src/main/java/org/hypertrace/graphql/label/dao/LabelResponseConverter.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,40 @@ Single<LabelResultSet> convert(GetLabelsResponse response) {
2525
Single<List<Label>> convertToLabelList(GetLabelsResponse response) {
2626
return Single.just(
2727
response.getLabelsList().stream()
28-
.map(label -> new DefaultLabel(label.getId(), label.getData().getKey()))
28+
.map(
29+
label ->
30+
new DefaultLabel(
31+
label.getId(),
32+
label.getData().getKey(),
33+
label.getData().hasColor() ? label.getData().getColor() : null,
34+
label.getData().hasDescription() ? label.getData().getDescription() : null))
2935
.collect(Collectors.toUnmodifiableList()));
3036
}
3137

3238
Single<Label> convertLabel(CreateLabelResponse response) {
3339
return Single.just(
34-
new DefaultLabel(response.getLabel().getId(), response.getLabel().getData().getKey()));
40+
new DefaultLabel(
41+
response.getLabel().getId(),
42+
response.getLabel().getData().getKey(),
43+
response.getLabel().getData().hasColor()
44+
? response.getLabel().getData().getColor()
45+
: null,
46+
response.getLabel().getData().hasDescription()
47+
? response.getLabel().getData().getDescription()
48+
: null));
3549
}
3650

3751
Single<Label> convertUpdateLabel(UpdateLabelResponse response) {
3852
return Single.just(
39-
new DefaultLabel(response.getLabel().getId(), response.getLabel().getData().getKey()));
53+
new DefaultLabel(
54+
response.getLabel().getId(),
55+
response.getLabel().getData().getKey(),
56+
response.getLabel().getData().hasColor()
57+
? response.getLabel().getData().getColor()
58+
: null,
59+
response.getLabel().getData().hasDescription()
60+
? response.getLabel().getData().getDescription()
61+
: null));
4062
}
4163

4264
@Value
@@ -52,5 +74,7 @@ private static class DefaultLabelResultSet implements LabelResultSet {
5274
private static class DefaultLabel implements Label {
5375
String id;
5476
String key;
77+
String color;
78+
String description;
5579
}
5680
}

hypertrace-graphql-labels-schema/src/main/java/org/hypertrace/graphql/label/deserialization/CreateLabelDeserializationConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,11 @@ public List<Module> jacksonModules() {
3333
private static class CreateLabelArgument implements CreateLabel {
3434
@JsonProperty(KEY)
3535
String key;
36+
37+
@JsonProperty(COLOR_KEY)
38+
String color;
39+
40+
@JsonProperty(DESCRIPTION_KEY)
41+
String description;
3642
}
3743
}

hypertrace-graphql-labels-schema/src/main/java/org/hypertrace/graphql/label/deserialization/LabelDeserializationConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,11 @@ private static class LabelArgument implements Label {
3636

3737
@JsonProperty(KEY)
3838
String key;
39+
40+
@JsonProperty(COLOR_KEY)
41+
String color;
42+
43+
@JsonProperty(DESCRIPTION_KEY)
44+
String description;
3945
}
4046
}

hypertrace-graphql-labels-schema/src/main/java/org/hypertrace/graphql/label/schema/Label.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,29 @@
33
import graphql.annotations.annotationTypes.GraphQLField;
44
import graphql.annotations.annotationTypes.GraphQLName;
55
import graphql.annotations.annotationTypes.GraphQLNonNull;
6+
import javax.annotation.Nullable;
67
import org.hypertrace.core.graphql.common.schema.id.Identifiable;
78

89
@GraphQLName(Label.TYPE_NAME)
910
public interface Label extends Identifiable {
1011
String TYPE_NAME = "Label";
1112
String ARGUMENT_NAME = "label";
1213
String KEY = "key";
14+
String COLOR_KEY = "color";
15+
String DESCRIPTION_KEY = "description";
1316

1417
@GraphQLField
1518
@GraphQLNonNull
1619
@GraphQLName(KEY)
1720
String key();
21+
22+
@GraphQLField
23+
@Nullable
24+
@GraphQLName(COLOR_KEY)
25+
String color();
26+
27+
@GraphQLField
28+
@Nullable
29+
@GraphQLName(DESCRIPTION_KEY)
30+
String description();
1831
}

hypertrace-graphql-labels-schema/src/main/java/org/hypertrace/graphql/label/schema/mutation/CreateLabel.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,28 @@
33
import graphql.annotations.annotationTypes.GraphQLField;
44
import graphql.annotations.annotationTypes.GraphQLName;
55
import graphql.annotations.annotationTypes.GraphQLNonNull;
6+
import javax.annotation.Nullable;
67

78
@GraphQLName(CreateLabel.TYPE_NAME)
89
public interface CreateLabel {
910
String TYPE_NAME = "CreateLabel";
1011
String ARGUMENT_NAME = "label";
1112
String KEY = "key";
13+
String COLOR_KEY = "color";
14+
String DESCRIPTION_KEY = "description";
1215

1316
@GraphQLField
1417
@GraphQLNonNull
1518
@GraphQLName(KEY)
1619
String key();
20+
21+
@GraphQLField
22+
@Nullable
23+
@GraphQLName(COLOR_KEY)
24+
String color();
25+
26+
@GraphQLField
27+
@Nullable
28+
@GraphQLName(DESCRIPTION_KEY)
29+
String description();
1730
}

0 commit comments

Comments
 (0)