|
| 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 | +} |
0 commit comments