Skip to content

Commit 85a4a59

Browse files
authored
Merge pull request gooddata#561 from gooddata/jmi-exec
Introduce AttributeHeader.formOf
2 parents c6fc641 + 20096f4 commit 85a4a59

11 files changed

Lines changed: 200 additions & 13 deletions

File tree

src/main/java/com/gooddata/executeafm/response/AttributeHeader.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,26 @@ public class AttributeHeader implements Header, LocallyIdentifiable {
2929
private final String localIdentifier;
3030
private final String uri;
3131
private final String identifier;
32+
private final AttributeInHeader formOf;
3233

3334
private List<TotalHeaderItem> totalItems;
3435

3536
/**
3637
* Creates new header
38+
* @deprecated use the constructor with {@link AttributeInHeader}
39+
*
3740
* @param name name
3841
* @param localIdentifier local identifier
3942
* @param uri uri
4043
* @param identifier identifier
4144
*/
45+
@Deprecated
4246
public AttributeHeader(final String name, final String localIdentifier, final String uri, final String identifier) {
43-
this.name = name;
44-
this.localIdentifier = localIdentifier;
45-
this.uri = uri;
46-
this.identifier = identifier;
47+
this.name = notEmpty(name, "name");
48+
this.localIdentifier = notEmpty(localIdentifier, "localIdentifier");
49+
this.uri = notEmpty(uri, "uri");
50+
this.identifier = notEmpty(identifier, "identifier");
51+
this.formOf = null;
4752
}
4853

4954
/**
@@ -52,18 +57,33 @@ public AttributeHeader(final String name, final String localIdentifier, final St
5257
* @param localIdentifier local identifier
5358
* @param uri uri
5459
* @param identifier identifier
60+
* @param formOf info about attribute which this header's display form is form of
61+
*/
62+
public AttributeHeader(final String name, final String localIdentifier, final String uri, final String identifier, final AttributeInHeader formOf) {
63+
this(name, localIdentifier, uri, identifier, formOf, null);
64+
}
65+
66+
/**
67+
* Creates new header
68+
* @param name name
69+
* @param localIdentifier local identifier
70+
* @param uri uri
71+
* @param identifier identifier
72+
* @param formOf info about attribute which this header's display form is form of
5573
* @param totalHeaderItems total header items
5674
*/
5775
@JsonCreator
5876
public AttributeHeader(@JsonProperty("name") final String name,
5977
@JsonProperty("localIdentifier") final String localIdentifier,
6078
@JsonProperty("uri") final String uri,
6179
@JsonProperty("identifier") final String identifier,
80+
@JsonProperty("formOf") final AttributeInHeader formOf,
6281
@JsonProperty("totalItems") final List<TotalHeaderItem> totalHeaderItems) {
6382
this.name = notEmpty(name, "name");
6483
this.localIdentifier = notEmpty(localIdentifier, "localIdentifier");
6584
this.uri = notEmpty(uri, "uri");
6685
this.identifier = notEmpty(identifier, "identifier");
86+
this.formOf = notNull(formOf, "formOf");
6787
this.totalItems = totalHeaderItems;
6888
}
6989

@@ -101,6 +121,10 @@ public String getIdentifier() {
101121
return identifier;
102122
}
103123

124+
public AttributeInHeader getFormOf() {
125+
return formOf;
126+
}
127+
104128
/**
105129
* Totals' headers belonging to the same level as this header.
106130
* @return lists of totals' header
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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.response;
7+
8+
import com.fasterxml.jackson.annotation.JsonCreator;
9+
import com.fasterxml.jackson.annotation.JsonInclude;
10+
import com.fasterxml.jackson.annotation.JsonProperty;
11+
import com.gooddata.util.GoodDataToStringBuilder;
12+
13+
import static com.gooddata.util.Validate.notEmpty;
14+
15+
/**
16+
* Represents attribute in {@link AttributeHeader}
17+
*/
18+
@JsonInclude(JsonInclude.Include.NON_NULL)
19+
public class AttributeInHeader {
20+
private final String name;
21+
private final String uri;
22+
private final String identifier;
23+
24+
/**
25+
* Creates new instance
26+
* @param name attribute's title
27+
* @param uri attribute's uri
28+
* @param identifier attribute's identifier
29+
*/
30+
@JsonCreator
31+
public AttributeInHeader(@JsonProperty("name") final String name,
32+
@JsonProperty("uri") final String uri,
33+
@JsonProperty("identifier") final String identifier) {
34+
this.name = notEmpty(name, "name");
35+
this.uri = notEmpty(uri, "uri");
36+
this.identifier = notEmpty(identifier, "identifier");
37+
}
38+
39+
/**
40+
* @return attribute's title
41+
*/
42+
public String getName() {
43+
return name;
44+
}
45+
46+
/**
47+
* @return attribute's uri
48+
*/
49+
public String getUri() {
50+
return uri;
51+
}
52+
53+
/**
54+
* @return attribute's identifier
55+
*/
56+
public String getIdentifier() {
57+
return identifier;
58+
}
59+
60+
@Override
61+
public boolean equals(Object o) {
62+
if (this == o) return true;
63+
if (o == null || getClass() != o.getClass()) return false;
64+
65+
AttributeInHeader attributeInHeader = (AttributeInHeader) o;
66+
67+
if (name != null ? !name.equals(attributeInHeader.name) : attributeInHeader.name != null) return false;
68+
if (uri != null ? !uri.equals(attributeInHeader.uri) : attributeInHeader.uri != null) return false;
69+
return identifier != null ? identifier.equals(attributeInHeader.identifier) : attributeInHeader.identifier == null;
70+
}
71+
72+
@Override
73+
public int hashCode() {
74+
int result = name != null ? name.hashCode() : 0;
75+
result = 31 * result + (uri != null ? uri.hashCode() : 0);
76+
result = 31 * result + (identifier != null ? identifier.hashCode() : 0);
77+
return result;
78+
}
79+
80+
@Override
81+
public String toString() {
82+
return GoodDataToStringBuilder.defaultToString(this);
83+
}
84+
}

src/test/groovy/com/gooddata/executeafm/response/AttributeHeaderTest.groovy

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ class AttributeHeaderTest extends Specification {
1717
private static final String ATTRIBUTE_HEADER_JSON = 'executeafm/response/attributeHeader.json'
1818
private static final String ATTRIBUTE_HEADER_FULL_JSON = 'executeafm/response/attributeHeaderFull.json'
1919

20+
private static final AttributeInHeader FORM_OF = new AttributeInHeader('Some attr', '/gdc/md/project_id/obj/567', 'attr.some.id')
21+
2022
def "should serialize full"() {
2123
expect:
22-
that new AttributeHeader('Name', 'a1', '/gdc/md/project_id/obj/123', 'attr.dataset.name', [new TotalHeaderItem('sum')]),
24+
that new AttributeHeader('Name', 'a1', '/gdc/md/project_id/obj/123', 'attr.dataset.name', FORM_OF, [new TotalHeaderItem('sum')]),
2325
jsonEquals(resource(ATTRIBUTE_HEADER_FULL_JSON))
2426
}
2527

2628
def "should serialize"() {
2729
expect:
28-
that new AttributeHeader('Name', 'a1', '/gdc/md/project_id/obj/123', 'attr.dataset.name'),
30+
that new AttributeHeader('Name', 'a1', '/gdc/md/project_id/obj/123', 'attr.dataset.name', FORM_OF),
2931
jsonEquals(resource(ATTRIBUTE_HEADER_JSON))
3032
}
3133

@@ -38,6 +40,7 @@ class AttributeHeaderTest extends Specification {
3840
header.localIdentifier == 'a1'
3941
header.uri == '/gdc/md/project_id/obj/123'
4042
header.identifier == 'attr.dataset.name'
43+
header.formOf == FORM_OF
4144
}
4245

4346
def "should deserialize full"() {
@@ -49,6 +52,7 @@ class AttributeHeaderTest extends Specification {
4952
header.localIdentifier == 'a1'
5053
header.uri == '/gdc/md/project_id/obj/123'
5154
header.identifier == 'attr.dataset.name'
55+
header.formOf == FORM_OF
5256
header.totalItems.size() == 1
5357
header.totalItems.first().name == 'sum'
5458
header.toString()
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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.response
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+
class AttributeInHeaderTest extends Specification {
17+
18+
private static final String ATTRIBUTE_IN_HEADER_JSON = 'executeafm/response/attributeInHeader.json'
19+
20+
def "should serialize"() {
21+
expect:
22+
that new AttributeInHeader('Some attr', '/gdc/md/project_id/obj/567', 'attr.some.id'),
23+
jsonEquals(resource(ATTRIBUTE_IN_HEADER_JSON))
24+
}
25+
26+
def "should deserialize"() {
27+
when:
28+
AttributeInHeader attributeInHeader = readObjectFromResource("/$ATTRIBUTE_IN_HEADER_JSON", AttributeInHeader)
29+
30+
then:
31+
attributeInHeader.name == 'Some attr'
32+
attributeInHeader.uri == '/gdc/md/project_id/obj/567'
33+
attributeInHeader.identifier == 'attr.some.id'
34+
attributeInHeader.toString()
35+
}
36+
37+
def "should verify equals"() {
38+
expect:
39+
EqualsVerifier.forClass(AttributeInHeader).usingGetClass().verify()
40+
}
41+
}

src/test/groovy/com/gooddata/executeafm/response/ExecutionResponseTest.groovy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ class ExecutionResponseTest extends Specification {
1616

1717
private static final String EXECUTION_RESPONSE_JSON = 'executeafm/response/executionResponse.json'
1818

19+
private static final AttributeInHeader FORM_OF = new AttributeInHeader('Some attr', '/gdc/md/project_id/obj/567', 'attr.some.id')
20+
1921
def "should serialize"() {
2022
expect:
2123
that new ExecutionResponse(
2224
[
2325
new ResultDimension(
24-
new AttributeHeader('Account', 'account', '/gdc/md/FoodMartDemo/obj/124', 'attr.account'),
25-
new AttributeHeader('Account Type', 'accountType', '/gdc/md/FoodMartDemo/obj/113', 'attr.accountType'),
26+
new AttributeHeader('Account', 'account', '/gdc/md/FoodMartDemo/obj/124', 'attr.account', FORM_OF),
27+
new AttributeHeader('Account Type', 'accountType', '/gdc/md/FoodMartDemo/obj/113', 'attr.accountType', FORM_OF),
2628
new MeasureGroupHeader([
2729
new MeasureHeaderItem('Accounting Amount [Sum]', 'format1', 'sum', '/gdc/md/FoodMartDemo/obj/114', 'metric.sum'),
2830
new MeasureHeaderItem('Accounting Amount [Avg]', 'format2', 'avg', '/gdc/md/FoodMartDemo/obj/115', 'metric.avg')

src/test/groovy/com/gooddata/executeafm/response/ResultDimensionTest.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ class ResultDimensionTest extends Specification {
1717

1818
private static final String RESULT_DIMENSION_JSON = 'executeafm/response/resultDimension.json'
1919

20+
private static final AttributeInHeader FORM_OF = new AttributeInHeader('Some attr', '/gdc/md/project_id/obj/567', 'attr.some.id')
21+
2022
def "should serialize"() {
2123
expect:
2224
that new ResultDimension(
23-
new AttributeHeader('Name', 'a1', '/gdc/md/project_id/obj/123', 'attr.dataset.name'),
25+
new AttributeHeader('Name', 'a1', '/gdc/md/project_id/obj/123', 'attr.dataset.name', FORM_OF),
2426
new MeasureGroupHeader([new MeasureHeaderItem('Name', '#,##0.00', 'm1')])),
2527
jsonEquals(resource(RESULT_DIMENSION_JSON))
2628
}

src/test/resources/executeafm/response/attributeHeader.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
"name": "Name",
44
"localIdentifier": "a1",
55
"uri": "/gdc/md/project_id/obj/123",
6-
"identifier": "attr.dataset.name"
6+
"identifier": "attr.dataset.name",
7+
"formOf": {
8+
"name": "Some attr",
9+
"uri": "/gdc/md/project_id/obj/567",
10+
"identifier": "attr.some.id"
11+
}
712
}
813
}

src/test/resources/executeafm/response/attributeHeaderFull.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
"localIdentifier": "a1",
55
"uri": "/gdc/md/project_id/obj/123",
66
"identifier": "attr.dataset.name",
7+
"formOf": {
8+
"name": "Some attr",
9+
"uri": "/gdc/md/project_id/obj/567",
10+
"identifier": "attr.some.id"
11+
},
712
"totalItems": [
813
{
914
"totalHeaderItem": {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Some attr",
3+
"uri": "/gdc/md/project_id/obj/567",
4+
"identifier": "attr.some.id"
5+
}

src/test/resources/executeafm/response/executionResponse.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,25 @@
1111
"uri": "/gdc/md/FoodMartDemo/obj/124",
1212
"identifier": "attr.account",
1313
"name": "Account",
14-
"localIdentifier": "account"
14+
"localIdentifier": "account",
15+
"formOf": {
16+
"name": "Some attr",
17+
"uri": "/gdc/md/project_id/obj/567",
18+
"identifier": "attr.some.id"
19+
}
1520
}
1621
},
1722
{
1823
"attributeHeader": {
1924
"uri": "/gdc/md/FoodMartDemo/obj/113",
2025
"identifier": "attr.accountType",
2126
"name": "Account Type",
22-
"localIdentifier": "accountType"
27+
"localIdentifier": "accountType",
28+
"formOf": {
29+
"name": "Some attr",
30+
"uri": "/gdc/md/project_id/obj/567",
31+
"identifier": "attr.some.id"
32+
}
2333
}
2434
},
2535
{

0 commit comments

Comments
 (0)