Skip to content

Commit dcf52e7

Browse files
committed
introduce support for dataLoadingColumn
1 parent 91ce6d3 commit dcf52e7

3 files changed

Lines changed: 252 additions & 0 deletions

File tree

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/*
2+
* Copyright (C) 2007-2016, GoodData(R) Corporation. All rights reserved.
3+
*/
4+
5+
package com.gooddata.md;
6+
7+
import com.fasterxml.jackson.annotation.JsonCreator;
8+
import com.fasterxml.jackson.annotation.JsonInclude;
9+
import com.fasterxml.jackson.annotation.JsonProperty;
10+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
11+
import com.fasterxml.jackson.annotation.JsonTypeName;
12+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
13+
import com.gooddata.gdc.UriResponse;
14+
import com.gooddata.util.BooleanIntegerDeserializer;
15+
16+
/**
17+
* Represents datasets' loading column.
18+
* Deserialization only.
19+
*/
20+
@JsonTypeName("dataLoadingColumn")
21+
@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME)
22+
@JsonInclude(JsonInclude.Include.NON_NULL)
23+
public class DataLoadingColumn extends AbstractObj implements Queryable {
24+
25+
private static final String INT = "INT";
26+
private static final String VARCHAR = "VARCHAR";
27+
28+
private final Content content;
29+
30+
@JsonCreator
31+
private DataLoadingColumn(@JsonProperty("meta") Meta meta, @JsonProperty("content") Content content) {
32+
super(meta);
33+
this.content = content;
34+
}
35+
36+
public UriResponse getColumnUri() {
37+
return content.getColumnUri();
38+
}
39+
40+
public String getName() {
41+
return content.getColumnName();
42+
}
43+
44+
public String getType() {
45+
return content.getColumnType();
46+
}
47+
48+
/**
49+
* @return true when the type is not null and equal to <code>VARCHAR</code>, false otherwise
50+
*/
51+
public boolean hasTypeVarchar() {
52+
return VARCHAR.equals(getType());
53+
}
54+
55+
/**
56+
* @return true when the type is not null and equal to <code>INT</code>, false otherwise
57+
*/
58+
public boolean hasTypeInt() {
59+
return INT.equals(getType());
60+
}
61+
62+
public Integer getLength() {
63+
return content.getColumnLength();
64+
}
65+
66+
public Integer getPrecision() {
67+
return content.getColumnPrecision();
68+
}
69+
70+
public boolean isUnique() {
71+
return content.isColumnUnique();
72+
}
73+
74+
public boolean isNullable() {
75+
return content.isColumnNull();
76+
}
77+
78+
public String getSynchronizeType() {
79+
return content.getColumnSynchronize() != null ? content.getColumnSynchronize().getType() : null;
80+
}
81+
82+
public Integer getSynchronizeLength() {
83+
return content.getColumnSynchronize() != null ? content.getColumnSynchronize().getLength() : null;
84+
}
85+
86+
public Integer getSynchronizePrecision() {
87+
return content.getColumnSynchronize() != null ? content.getColumnSynchronize().getPrecision() : null;
88+
}
89+
90+
private static class Content {
91+
92+
private final UriResponse columnUri;
93+
private final String columnName;
94+
private final String columnType;
95+
private final Integer columnLength;
96+
private final Integer columnPrecision;
97+
private final boolean columnUnique;
98+
private final boolean columnNull;
99+
private final ColumnSynchronize columnSynchronize;
100+
101+
private Content(@JsonProperty("column") UriResponse columnUri, @JsonProperty("columnName") String columnName, @JsonProperty("type") String columnType,
102+
@JsonProperty("length") Integer columnLength, @JsonProperty("precision") Integer columnPrecision,
103+
@JsonProperty("columnUnique") @JsonDeserialize(using = BooleanIntegerDeserializer.class) boolean columnUnique,
104+
@JsonProperty("columnNull") @JsonDeserialize(using = BooleanIntegerDeserializer.class) boolean columnNull,
105+
@JsonProperty("columnSynchronize") ColumnSynchronize columnSynchronize) {
106+
this.columnUri = columnUri;
107+
this.columnName = columnName;
108+
this.columnType = columnType;
109+
this.columnLength = columnLength;
110+
this.columnPrecision = columnPrecision;
111+
this.columnUnique = columnUnique;
112+
this.columnNull = columnNull;
113+
this.columnSynchronize = columnSynchronize;
114+
}
115+
116+
public UriResponse getColumnUri() {
117+
return columnUri;
118+
}
119+
120+
public String getColumnName() {
121+
return columnName;
122+
}
123+
124+
public String getColumnType() {
125+
return columnType;
126+
}
127+
128+
public Integer getColumnLength() {
129+
return columnLength;
130+
}
131+
132+
public Integer getColumnPrecision() {
133+
return columnPrecision;
134+
}
135+
136+
public boolean isColumnUnique() {
137+
return columnUnique;
138+
}
139+
140+
public boolean isColumnNull() {
141+
return columnNull;
142+
}
143+
144+
public ColumnSynchronize getColumnSynchronize() {
145+
return columnSynchronize;
146+
}
147+
}
148+
149+
private static class ColumnSynchronize {
150+
private final String type;
151+
private final Integer length;
152+
private final Integer precision;
153+
154+
@JsonCreator
155+
private ColumnSynchronize(@JsonProperty("columnType") String type, @JsonProperty("columnLength") Integer length,
156+
@JsonProperty("precision") Integer precision) {
157+
this.type = type;
158+
this.length = length;
159+
this.precision = precision;
160+
}
161+
162+
public String getType() {
163+
return type;
164+
}
165+
166+
public Integer getLength() {
167+
return length;
168+
}
169+
170+
public Integer getPrecision() {
171+
return precision;
172+
}
173+
}
174+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (C) 2007-2016, GoodData(R) Corporation. All rights reserved.
3+
*/
4+
5+
package com.gooddata.md;
6+
7+
import static org.hamcrest.CoreMatchers.is;
8+
import static org.hamcrest.CoreMatchers.notNullValue;
9+
import static org.hamcrest.CoreMatchers.nullValue;
10+
import static org.hamcrest.MatcherAssert.assertThat;
11+
12+
import com.fasterxml.jackson.databind.ObjectMapper;
13+
import org.testng.annotations.Test;
14+
15+
import java.io.InputStream;
16+
17+
public class DataLoadingColumnTest {
18+
19+
@Test
20+
public void shouldDeserialize() throws Exception {
21+
final InputStream stream = getClass().getResourceAsStream("/md/dataLoadingColumn.json");
22+
final DataLoadingColumn column = new ObjectMapper().readValue(stream, DataLoadingColumn.class);
23+
assertThat(column, is(notNullValue()));
24+
25+
assertThat(column.getColumnUri(), is(notNullValue()));
26+
assertThat(column.getColumnUri().getUri(), is("/gdc/md/PROJECT_ID/obj/COLUMN_ID"));
27+
28+
assertThat(column.getType(), is("INT"));
29+
assertThat(column.hasTypeInt(), is(true));
30+
assertThat(column.hasTypeVarchar(), is(false));
31+
32+
assertThat(column.getName(), is("COLUMN_NAME"));
33+
assertThat(column.getLength(), is(128));
34+
assertThat(column.getPrecision(), is(nullValue()));
35+
assertThat(column.isUnique(), is(false));
36+
assertThat(column.isNullable(), is(true));
37+
38+
assertThat(column.getSynchronizeType(), is("INT"));
39+
assertThat(column.getSynchronizeLength(), is(128));
40+
assertThat(column.getSynchronizePrecision(), is(0));
41+
}
42+
43+
44+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"dataLoadingColumn" : {
3+
"content" : {
4+
"columnName" : "COLUMN_NAME",
5+
"columnUnique" : 0,
6+
"columnPrecision" : null,
7+
"columnNull" : 1,
8+
"columnType" : "INT",
9+
"columnLength" : 128,
10+
"column" : {
11+
"uri" : "/gdc/md/PROJECT_ID/obj/COLUMN_ID"
12+
},
13+
"columnSynchronize" : {
14+
"columnType" : "INT",
15+
"columnLength" : 128,
16+
"precision" : 0
17+
}
18+
},
19+
"meta" : {
20+
"author" : "/gdc/account/profile/PROFILE_ID",
21+
"uri" : "/gdc/md/PROJECT_ID/obj/DATA_LOADING_COLUMN_ID",
22+
"tags" : "",
23+
"created" : "2016-02-29 13:24:37",
24+
"identifier" : "IDENTIFIER",
25+
"deprecated" : "0",
26+
"summary" : "",
27+
"isProduction" : 1,
28+
"title" : "TITLE",
29+
"category" : "dataLoadingColumn",
30+
"updated" : "2016-03-03 13:14:04",
31+
"contributor" : "/gdc/account/profile/PROFILE_ID"
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)