Skip to content

Commit a5824da

Browse files
authored
Add description field and add tests (#266)
1 parent cca0f96 commit a5824da

File tree

7 files changed

+154
-38
lines changed

7 files changed

+154
-38
lines changed

graphmdl-base/src/main/java/io/graphmdl/base/dto/Column.java

+21-5
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,26 @@ public class Column
3030
private final boolean notNull;
3131
private final String relationship;
3232
private final String expression;
33+
private final String description;
3334

3435
public static Column column(String name, String type, String relationship, boolean notNull)
3536
{
36-
return new Column(name, type, relationship, notNull, null);
37+
return column(name, type, relationship, notNull, null, null);
3738
}
3839

3940
public static Column column(String name, String type, String relationship, boolean notNull, String expression)
4041
{
41-
return new Column(name, type, relationship, notNull, expression);
42+
return column(name, type, relationship, notNull, expression, null);
43+
}
44+
45+
public static Column column(String name, String type, String relationship, boolean notNull, String expression, String description)
46+
{
47+
return new Column(name, type, relationship, notNull, expression, description);
4248
}
4349

4450
public static Column relationshipColumn(String name, String type, String relationship)
4551
{
46-
return new Column(name, type, relationship, false, null);
52+
return new Column(name, type, relationship, false, null, null);
4753
}
4854

4955
@JsonCreator
@@ -52,13 +58,15 @@ public Column(
5258
@JsonProperty("type") String type,
5359
@JsonProperty("relationship") String relationship,
5460
@JsonProperty("notNull") boolean notNull,
55-
@JsonProperty("expression") String expression)
61+
@JsonProperty("expression") String expression,
62+
@JsonProperty("description") String description)
5663
{
5764
this.name = requireNonNull(name, "name is null");
5865
this.type = requireNonNull(type, "type is null");
5966
this.relationship = relationship;
6067
this.notNull = notNull;
6168
this.expression = expression;
69+
this.description = description;
6270
}
6371

6472
@JsonProperty
@@ -85,6 +93,12 @@ public boolean isNotNull()
8593
return notNull;
8694
}
8795

96+
@JsonProperty
97+
public String getDescription()
98+
{
99+
return description;
100+
}
101+
88102
@JsonProperty
89103
public Optional<String> getExpression()
90104
{
@@ -118,7 +132,8 @@ public boolean equals(Object obj)
118132
&& Objects.equals(name, that.name)
119133
&& Objects.equals(type, that.type)
120134
&& Objects.equals(relationship, that.relationship)
121-
&& Objects.equals(expression, that.expression);
135+
&& Objects.equals(expression, that.expression)
136+
&& Objects.equals(description, that.description);
122137
}
123138

124139
@Override
@@ -136,6 +151,7 @@ public String toString()
136151
", notNull=" + notNull +
137152
", relationship='" + relationship + '\'' +
138153
", expression='" + expression + '\'' +
154+
", description='" + description + '\'' +
139155
'}';
140156
}
141157
}

graphmdl-base/src/main/java/io/graphmdl/base/dto/EnumDefinition.java

+24-4
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,27 @@ public class EnumDefinition
2727
{
2828
public static EnumDefinition enumDefinition(String name, List<EnumValue> values)
2929
{
30-
return new EnumDefinition(name, values);
30+
return enumDefinition(name, values, null);
31+
}
32+
33+
public static EnumDefinition enumDefinition(String name, List<EnumValue> values, String description)
34+
{
35+
return new EnumDefinition(name, values, description);
3136
}
3237

3338
private final String name;
3439
private final List<EnumValue> values;
40+
private final String description;
3541

3642
@JsonCreator
3743
public EnumDefinition(
3844
@JsonProperty("name") String name,
39-
@JsonProperty("values") List<EnumValue> values)
45+
@JsonProperty("values") List<EnumValue> values,
46+
@JsonProperty("description") String description)
4047
{
4148
this.name = requireNonNull(name);
4249
this.values = requireNonNull(values);
50+
this.description = description;
4351
}
4452

4553
@JsonProperty
@@ -54,6 +62,12 @@ public String getName()
5462
return name;
5563
}
5664

65+
@JsonProperty
66+
public String getDescription()
67+
{
68+
return description;
69+
}
70+
5771
public Optional<EnumValue> valueOf(String enumValueName)
5872
{
5973
return values.stream()
@@ -71,13 +85,18 @@ public boolean equals(Object obj)
7185
return false;
7286
}
7387
EnumDefinition that = (EnumDefinition) obj;
74-
return Objects.equals(name, that.name) && Objects.equals(values, that.values);
88+
return Objects.equals(name, that.name)
89+
&& Objects.equals(values, that.values)
90+
&& Objects.equals(description, that.description);
7591
}
7692

7793
@Override
7894
public int hashCode()
7995
{
80-
return Objects.hash(name, values);
96+
return Objects.hash(
97+
name,
98+
values,
99+
description);
81100
}
82101

83102
@Override
@@ -86,6 +105,7 @@ public String toString()
86105
return "EnumDefinition{" +
87106
"name='" + name + '\'' +
88107
", values=" + values +
108+
", description='" + description + '\'' +
89109
'}';
90110
}
91111
}

graphmdl-base/src/main/java/io/graphmdl/base/dto/Metric.java

+28-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class Metric
3535
private final List<TimeGrain> timeGrain;
3636
private final boolean preAggregated;
3737
private final Duration refreshTime;
38+
private final String description;
3839

3940
public static Metric metric(String name, String baseModel, List<Column> dimension, List<Column> measure, List<TimeGrain> timeGrain)
4041
{
@@ -43,7 +44,12 @@ public static Metric metric(String name, String baseModel, List<Column> dimensio
4344

4445
public static Metric metric(String name, String baseModel, List<Column> dimension, List<Column> measure, List<TimeGrain> timeGrain, boolean preAggregated)
4546
{
46-
return new Metric(name, baseModel, dimension, measure, timeGrain, preAggregated, null);
47+
return metric(name, baseModel, dimension, measure, timeGrain, preAggregated, null);
48+
}
49+
50+
public static Metric metric(String name, String baseModel, List<Column> dimension, List<Column> measure, List<TimeGrain> timeGrain, boolean preAggregated, String description)
51+
{
52+
return new Metric(name, baseModel, dimension, measure, timeGrain, preAggregated, null, description);
4753
}
4854

4955
@JsonCreator
@@ -54,7 +60,8 @@ public Metric(
5460
@JsonProperty("measure") List<Column> measure,
5561
@JsonProperty("timeGrain") List<TimeGrain> timeGrain,
5662
@JsonProperty("preAggregated") boolean preAggregated,
57-
@JsonProperty("refreshTime") Duration refreshTime)
63+
@JsonProperty("refreshTime") Duration refreshTime,
64+
@JsonProperty("description") String description)
5865
{
5966
this.name = requireNonNull(name, "name is null");
6067
this.baseModel = requireNonNull(baseModel, "baseModel is null");
@@ -64,6 +71,7 @@ public Metric(
6471
checkArgument(measure.size() > 0, "the number of measures should be one at least");
6572
this.timeGrain = requireNonNull(timeGrain, "timeGrain is null");
6673
this.refreshTime = refreshTime == null ? new Duration(30, MINUTES) : refreshTime;
74+
this.description = description;
6775
}
6876

6977
@JsonProperty
@@ -115,6 +123,12 @@ public Duration getRefreshTime()
115123
return refreshTime;
116124
}
117125

126+
@JsonProperty
127+
public String getDescription()
128+
{
129+
return description;
130+
}
131+
118132
@Override
119133
public boolean equals(Object obj)
120134
{
@@ -131,13 +145,22 @@ public boolean equals(Object obj)
131145
&& Objects.equals(dimension, that.dimension)
132146
&& Objects.equals(measure, that.measure)
133147
&& Objects.equals(timeGrain, that.timeGrain)
134-
&& Objects.equals(refreshTime, that.refreshTime);
148+
&& Objects.equals(refreshTime, that.refreshTime)
149+
&& Objects.equals(description, that.description);
135150
}
136151

137152
@Override
138153
public int hashCode()
139154
{
140-
return Objects.hash(name, baseModel, dimension, measure, timeGrain, preAggregated, refreshTime);
155+
return Objects.hash(
156+
name,
157+
baseModel,
158+
dimension,
159+
measure,
160+
timeGrain,
161+
preAggregated,
162+
refreshTime,
163+
description);
141164
}
142165

143166
@Override
@@ -151,6 +174,7 @@ public String toString()
151174
", timeGrain=" + timeGrain +
152175
", preAggregated=" + preAggregated +
153176
", refreshTime=" + refreshTime +
177+
", description='" + description + '\'' +
154178
'}';
155179
}
156180
}

graphmdl-base/src/main/java/io/graphmdl/base/dto/Model.java

+21-5
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,36 @@ public class Model
2828
private final String refSql;
2929
private final List<Column> columns;
3030
private final String primaryKey;
31+
private final String description;
3132

3233
public static Model model(String name, String refSql, List<Column> columns)
3334
{
34-
return new Model(name, refSql, columns, null);
35+
return model(name, refSql, columns, null, null);
3536
}
3637

3738
public static Model model(String name, String refSql, List<Column> columns, String primaryKey)
3839
{
39-
return new Model(name, refSql, columns, primaryKey);
40+
return model(name, refSql, columns, primaryKey, null);
41+
}
42+
43+
public static Model model(String name, String refSql, List<Column> columns, String primaryKey, String description)
44+
{
45+
return new Model(name, refSql, columns, primaryKey, description);
4046
}
4147

4248
@JsonCreator
4349
public Model(
4450
@JsonProperty("name") String name,
4551
@JsonProperty("refSql") String refSql,
4652
@JsonProperty("columns") List<Column> columns,
47-
@JsonProperty("primaryKey") String primaryKey)
53+
@JsonProperty("primaryKey") String primaryKey,
54+
@JsonProperty("description") String description)
4855
{
4956
this.name = requireNonNull(name, "name is null");
5057
this.refSql = requireNonNull(refSql, "refSql is null");
5158
this.columns = columns == null ? List.of() : columns;
5259
this.primaryKey = primaryKey;
60+
this.description = description;
5361
}
5462

5563
@JsonProperty
@@ -76,6 +84,12 @@ public String getPrimaryKey()
7684
return primaryKey;
7785
}
7886

87+
@JsonProperty
88+
public String getDescription()
89+
{
90+
return description;
91+
}
92+
7993
@Override
8094
public boolean equals(Object obj)
8195
{
@@ -89,13 +103,14 @@ public boolean equals(Object obj)
89103
return Objects.equals(name, that.name)
90104
&& Objects.equals(refSql, that.refSql)
91105
&& Objects.equals(columns, that.columns)
92-
&& Objects.equals(primaryKey, that.primaryKey);
106+
&& Objects.equals(primaryKey, that.primaryKey)
107+
&& Objects.equals(description, that.description);
93108
}
94109

95110
@Override
96111
public int hashCode()
97112
{
98-
return Objects.hash(name, refSql, columns, primaryKey);
113+
return Objects.hash(name, refSql, columns, primaryKey, description);
99114
}
100115

101116
@Override
@@ -106,6 +121,7 @@ public String toString()
106121
", refSql='" + refSql + '\'' +
107122
", columns=" + columns +
108123
", primaryKey='" + primaryKey + '\'' +
124+
", description='" + description + '\'' +
109125
'}';
110126
}
111127
}

0 commit comments

Comments
 (0)