Skip to content

Commit 3ddcdf7

Browse files
authored
Merge pull request #562 from gooddata/jmi-warn
Introduce support for ExecutionResult's warnings
2 parents 85a4a59 + d0e51ac commit 3ddcdf7

6 files changed

Lines changed: 178 additions & 9 deletions

File tree

src/main/java/com/gooddata/executeafm/result/ExecutionResult.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,9 @@
1313
import com.gooddata.util.GoodDataToStringBuilder;
1414

1515
import java.util.ArrayList;
16-
import java.util.Arrays;
1716
import java.util.List;
1817

1918
import static com.gooddata.util.Validate.notNull;
20-
import static java.util.Arrays.asList;
21-
import static java.util.Arrays.stream;
22-
import static java.util.stream.Collectors.toList;
23-
import static org.apache.commons.lang3.ArrayUtils.toObject;
2419

2520
/**
2621
* Data result of the {@link com.gooddata.executeafm.Execution}.
@@ -35,6 +30,7 @@ public class ExecutionResult {
3530

3631
private List<List<List<ResultHeaderItem>>> headerItems;
3732
private List<List<List<String>>> totals;
33+
private List<Warning> warnings;
3834

3935
/**
4036
* Creates new result
@@ -65,13 +61,15 @@ public ExecutionResult(final String[][] data, final Paging paging) {
6561
*/
6662
@JsonCreator
6763
ExecutionResult(@JsonProperty("data") final DataList data,
68-
@JsonProperty("paging") final Paging paging,
69-
@JsonProperty("headerItems") final List<List<List<ResultHeaderItem>>> headerItems,
70-
@JsonProperty("totals") final List<List<List<String>>> totals) {
64+
@JsonProperty("paging") final Paging paging,
65+
@JsonProperty("headerItems") final List<List<List<ResultHeaderItem>>> headerItems,
66+
@JsonProperty("totals") final List<List<List<String>>> totals,
67+
@JsonProperty("warnings") final List<Warning> warnings) {
7168
this.data = data;
7269
this.paging = paging;
7370
this.headerItems = headerItems;
7471
this.totals = totals;
72+
this.warnings = warnings;
7573
}
7674

7775
/**
@@ -129,6 +127,21 @@ public void setTotals(final List<List<List<String>>> totals) {
129127
this.totals = totals;
130128
}
131129

130+
/**
131+
* @return result's warnings
132+
*/
133+
public List<Warning> getWarnings() {
134+
return warnings;
135+
}
136+
137+
/**
138+
* Sets warnings for this result
139+
* @param warnings result's warning
140+
*/
141+
public void setWarnings(final List<Warning> warnings) {
142+
this.warnings = warnings;
143+
}
144+
132145
@Override
133146
public String toString() {
134147
return GoodDataToStringBuilder.defaultToString(this);
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright (C) 2007-2017, GoodData(R) Corporation. All rights reserved.
3+
* This source code is licensed under the BSD-style license found in the
4+
* LICENSE.txt file in the root directory of this source tree.
5+
*/
6+
package com.gooddata.executeafm.result;
7+
8+
import com.fasterxml.jackson.annotation.JsonCreator;
9+
import com.fasterxml.jackson.annotation.JsonProperty;
10+
import com.gooddata.util.GoodDataToStringBuilder;
11+
12+
import java.util.List;
13+
14+
import static com.gooddata.util.Validate.notEmpty;
15+
import static com.gooddata.util.Validate.notNull;
16+
import static java.util.Collections.emptyList;
17+
18+
/**
19+
* {@link ExecutionResult}'s warning.
20+
*/
21+
public class Warning {
22+
private final String warningCode;
23+
private final String message;
24+
private final List<Object> parameters;
25+
26+
/**
27+
* Creates new instance
28+
* @param warningCode error code
29+
* @param message message
30+
*/
31+
public Warning(final String warningCode, final String message) {
32+
this(warningCode, message, emptyList());
33+
}
34+
35+
/**
36+
* Creates new instance
37+
* @param warningCode error code
38+
* @param message message
39+
* @param parameters message's parameters
40+
*/
41+
@JsonCreator
42+
public Warning(@JsonProperty("warningCode") final String warningCode,
43+
@JsonProperty("message") final String message,
44+
@JsonProperty("parameters") final List<Object> parameters) {
45+
this.warningCode = notEmpty(warningCode, "warningCode");
46+
this.message = notEmpty(message, "message");
47+
this.parameters = notNull(parameters, "parameters");
48+
}
49+
50+
/**
51+
* @return warning's error code
52+
*/
53+
public String getWarningCode() {
54+
return warningCode;
55+
}
56+
57+
/**
58+
* @return warning's message
59+
*/
60+
public String getMessage() {
61+
return message;
62+
}
63+
64+
/**
65+
* @return message's parameters
66+
*/
67+
public List<Object> getParameters() {
68+
return parameters;
69+
}
70+
71+
@Override
72+
public boolean equals(Object o) {
73+
if (this == o) return true;
74+
if (o == null || getClass() != o.getClass()) return false;
75+
76+
Warning warning = (Warning) o;
77+
78+
if (warningCode != null ? !warningCode.equals(warning.warningCode) : warning.warningCode != null) return false;
79+
if (message != null ? !message.equals(warning.message) : warning.message != null) return false;
80+
return parameters != null ? parameters.equals(warning.parameters) : warning.parameters == null;
81+
}
82+
83+
@Override
84+
public int hashCode() {
85+
int result = warningCode != null ? warningCode.hashCode() : 0;
86+
result = 31 * result + (message != null ? message.hashCode() : 0);
87+
result = 31 * result + (parameters != null ? parameters.hashCode() : 0);
88+
return result;
89+
}
90+
91+
@Override
92+
public String toString() {
93+
return GoodDataToStringBuilder.defaultToString(this);
94+
}
95+
}

src/test/groovy/com/gooddata/executeafm/result/ExecutionResultTest.groovy

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class ExecutionResultTest extends Specification {
4343
[[[
4444
new AttributeHeaderItem('Cost of Goods Sold', '/gdc/md/FoodMartDemo/obj/124/elements?id=3200'),
4545
new AttributeHeaderItem('Salaries', '/gdc/md/FoodMartDemo/obj/124/elements?id=6000')]]],
46-
[[['25']]]),
46+
[[['25']]],
47+
[new Warning('gdc123', 'Some msg %s %s %s', ['bum', 1, null])]),
4748
jsonEquals(resource(EXECUTION_RESULT_FULL_JSON))
4849
}
4950

@@ -65,6 +66,9 @@ class ExecutionResultTest extends Specification {
6566
def totals = result.totals
6667
totals[0][0][0] == '25'
6768

69+
def warnings = result.warnings
70+
warnings == [new Warning('gdc123', 'Some msg %s %s %s', ['bum', 1, null])]
71+
6872
result.toString()
6973
}
7074

@@ -73,11 +77,14 @@ class ExecutionResultTest extends Specification {
7377
ExecutionResult result = new ExecutionResult([1] as String[], new Paging())
7478
result.addHeaderItems([[new AttributeHeaderItem("n", "u")]])
7579
result.setTotals([[[1]]])
80+
result.setWarnings([new Warning('gdc123', 'Some msg %s %s %s', ['bum', 1, null])])
7681

7782
then:
7883
result.getHeaderItems()[0][0][0].name == "n"
7984
result.getHeaderItems()[0][0][0].uri == "u"
8085

8186
result.getTotals() == [[[1]]]
87+
88+
result.getWarnings() == [new Warning('gdc123', 'Some msg %s %s %s', ['bum', 1, null])]
8289
}
8390
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (C) 2007-2017, GoodData(R) Corporation. All rights reserved.
3+
* This source code is licensed under the BSD-style license found in the
4+
* LICENSE.txt file in the root directory of this source tree.
5+
*/
6+
package com.gooddata.executeafm.result
7+
8+
import nl.jqno.equalsverifier.EqualsVerifier
9+
import spock.lang.Specification
10+
11+
import static com.gooddata.util.ResourceUtils.readObjectFromResource
12+
import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals
13+
import static net.javacrumbs.jsonunit.core.util.ResourceUtils.resource
14+
import static spock.util.matcher.HamcrestSupport.that
15+
16+
17+
class WarningTest extends Specification {
18+
19+
private static final String WARNING_JSON = 'executeafm/result/warning.json'
20+
21+
def "should serialize"() {
22+
expect:
23+
that new Warning('gdc123', 'Some msg %s %s %s', ['bum', 1, null]),
24+
jsonEquals(resource(WARNING_JSON))
25+
}
26+
27+
def "should deserialize"() {
28+
when:
29+
Warning warning = readObjectFromResource("/$WARNING_JSON", Warning)
30+
31+
then:
32+
warning.warningCode == 'gdc123'
33+
warning.message == 'Some msg %s %s %s'
34+
warning.parameters == ['bum', 1, null]
35+
warning.toString()
36+
}
37+
38+
def "should verify equals"() {
39+
expect:
40+
EqualsVerifier.forClass(Warning).usingGetClass().verify()
41+
}
42+
}

src/test/resources/executeafm/result/executionResultFull.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@
4141
"25"
4242
]
4343
]
44+
],
45+
"warnings": [
46+
{
47+
"warningCode": "gdc123",
48+
"message": "Some msg %s %s %s",
49+
"parameters": ["bum", 1, null]
50+
}
4451
]
4552
}
4653
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"warningCode": "gdc123",
3+
"message": "Some msg %s %s %s",
4+
"parameters": ["bum", 1, null]
5+
}

0 commit comments

Comments
 (0)