| 1 | |
package org.codeforamerica.open311.facade.data; |
| 2 | |
|
| 3 | |
import java.io.Serializable; |
| 4 | |
import java.util.Map; |
| 5 | |
import java.util.Map.Entry; |
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
public class AttributeInfo implements Serializable { |
| 14 | |
|
| 15 | |
private static final long serialVersionUID = -6704474615491645869L; |
| 16 | |
private Boolean variable; |
| 17 | |
private String code; |
| 18 | |
private Datatype datatype; |
| 19 | |
private Boolean required; |
| 20 | |
private String datatypeDescription; |
| 21 | |
private Integer order; |
| 22 | |
private String description; |
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
private Map<String, String> values; |
| 29 | |
|
| 30 | |
public AttributeInfo(Boolean variable, String code, Datatype datatype, |
| 31 | |
Boolean required, String datatypeDescription, Integer order, |
| 32 | |
String description, Map<String, String> values) { |
| 33 | 5 | super(); |
| 34 | 5 | this.variable = variable; |
| 35 | 5 | this.code = code; |
| 36 | 5 | this.datatype = datatype; |
| 37 | 5 | this.required = required; |
| 38 | 5 | this.datatypeDescription = datatypeDescription; |
| 39 | 5 | this.order = order; |
| 40 | 5 | this.description = description; |
| 41 | 5 | this.values = values; |
| 42 | 5 | } |
| 43 | |
|
| 44 | |
public Boolean isVariable() { |
| 45 | 3 | return variable; |
| 46 | |
} |
| 47 | |
|
| 48 | |
public String getCode() { |
| 49 | 3 | return code; |
| 50 | |
} |
| 51 | |
|
| 52 | |
public Datatype getDatatype() { |
| 53 | 3 | return datatype; |
| 54 | |
} |
| 55 | |
|
| 56 | |
public Integer getOrder() { |
| 57 | 3 | return order; |
| 58 | |
} |
| 59 | |
|
| 60 | |
public String getDescription() { |
| 61 | 3 | return description; |
| 62 | |
} |
| 63 | |
|
| 64 | |
public Map<String, String> getValues() { |
| 65 | 6 | return values; |
| 66 | |
} |
| 67 | |
|
| 68 | |
public Boolean isRequired() { |
| 69 | 3 | return required; |
| 70 | |
} |
| 71 | |
|
| 72 | |
public String getDatatypeDescription() { |
| 73 | 3 | return datatypeDescription; |
| 74 | |
} |
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
public String toString() { |
| 81 | 0 | StringBuilder strBuilder = new StringBuilder("code: " + code + "\n"); |
| 82 | 0 | strBuilder.append("values: "); |
| 83 | 0 | for (Entry<String, String> pair : values.entrySet()) { |
| 84 | 0 | strBuilder.append("\n"); |
| 85 | 0 | strBuilder.append("\t" + pair.getKey() + " -> " + pair.getValue()); |
| 86 | |
} |
| 87 | 0 | return strBuilder.toString(); |
| 88 | |
} |
| 89 | |
|
| 90 | 8 | public static enum Datatype { |
| 91 | 1 | STRING, NUMBER, DATETIME, TEXT, SINGLEVALUELIST, MULTIVALUELIST; |
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
public static Datatype getFromString(String datatype) { |
| 102 | 25 | if (datatype.toLowerCase().equals("string")) { |
| 103 | 4 | return STRING; |
| 104 | |
} |
| 105 | 21 | if (datatype.toLowerCase().equals("number")) { |
| 106 | 4 | return NUMBER; |
| 107 | |
} |
| 108 | 17 | if (datatype.toLowerCase().equals("datetime")) { |
| 109 | 4 | return DATETIME; |
| 110 | |
} |
| 111 | 13 | if (datatype.toLowerCase().equals("text")) { |
| 112 | 2 | return TEXT; |
| 113 | |
} |
| 114 | 11 | if (datatype.toLowerCase().equals("singlevaluelist")) { |
| 115 | 7 | return SINGLEVALUELIST; |
| 116 | |
} |
| 117 | 4 | if (datatype.toLowerCase().equals("multivaluelist")) { |
| 118 | 2 | return MULTIVALUELIST; |
| 119 | |
} |
| 120 | 2 | return null; |
| 121 | |
} |
| 122 | |
} |
| 123 | |
} |