| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.student.core.assembly.data; |
| 17 | |
|
| 18 | |
import java.io.Serializable; |
| 19 | |
import java.util.ArrayList; |
| 20 | |
import java.util.HashMap; |
| 21 | |
import java.util.LinkedHashMap; |
| 22 | |
import java.util.List; |
| 23 | |
import java.util.Map; |
| 24 | |
import java.util.Map.Entry; |
| 25 | |
|
| 26 | |
public class Metadata implements Serializable { |
| 27 | |
|
| 28 | |
private static final long serialVersionUID = 1L; |
| 29 | |
|
| 30 | 205 | public enum WriteAccess { |
| 31 | 3 | ON_CREATE, |
| 32 | 3 | ALWAYS, NEVER, WHEN_NULL, REQUIRED |
| 33 | |
} |
| 34 | |
|
| 35 | |
private String name; |
| 36 | |
private String labelKey; |
| 37 | |
private WriteAccess writeAccess; |
| 38 | |
|
| 39 | 566 | private boolean canUnmask = false; |
| 40 | 566 | private boolean canView = true; |
| 41 | 566 | private boolean canEdit = true; |
| 42 | 566 | private boolean dynamic = false; |
| 43 | |
|
| 44 | |
protected String partialMaskFormatter; |
| 45 | |
protected String maskFormatter; |
| 46 | |
|
| 47 | |
private boolean onChangeRefreshMetadata; |
| 48 | |
|
| 49 | |
private Data.DataType dataType; |
| 50 | |
|
| 51 | |
private Data.Value defaultValue; |
| 52 | |
|
| 53 | |
private String defaultValuePath; |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
private List<ConstraintMetadata> constraints; |
| 58 | |
|
| 59 | |
private LookupMetadata initialLookup; |
| 60 | |
|
| 61 | |
private String lookupContextPath; |
| 62 | |
|
| 63 | |
private List<LookupMetadata> additionalLookups; |
| 64 | |
|
| 65 | |
private Map<String, Metadata> childProperties; |
| 66 | |
|
| 67 | 260 | public Metadata() { |
| 68 | |
|
| 69 | 260 | } |
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | 306 | public Metadata(Metadata toClone) { |
| 78 | 306 | this.additionalLookups = toClone.additionalLookups; |
| 79 | 306 | this.constraints = toClone.constraints; |
| 80 | 306 | this.dataType = toClone.dataType; |
| 81 | 306 | this.defaultValue = toClone.defaultValue; |
| 82 | 306 | this.defaultValuePath = toClone.defaultValuePath; |
| 83 | 306 | this.lookupContextPath = toClone.lookupContextPath; |
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | 306 | this.initialLookup = toClone.initialLookup; |
| 88 | 306 | this.onChangeRefreshMetadata = toClone.onChangeRefreshMetadata; |
| 89 | 306 | this.name = toClone.name; |
| 90 | 306 | this.writeAccess = toClone.writeAccess; |
| 91 | 306 | this.canEdit = toClone.canEdit; |
| 92 | 306 | this.canView = toClone.canView; |
| 93 | 306 | this.canUnmask = toClone.canUnmask; |
| 94 | 306 | if(toClone.childProperties != null) { |
| 95 | 88 | this.childProperties = new HashMap<String, Metadata>(); |
| 96 | 88 | for(Map.Entry<String, Metadata> childProperty : toClone.childProperties.entrySet()) { |
| 97 | 304 | this.childProperties.put(childProperty.getKey(), new Metadata(childProperty.getValue())); |
| 98 | |
} |
| 99 | |
|
| 100 | |
} |
| 101 | 306 | } |
| 102 | |
|
| 103 | |
@Override |
| 104 | |
public String toString() { |
| 105 | 0 | StringBuilder sb = new StringBuilder(); |
| 106 | 0 | _toString(sb); |
| 107 | 0 | return sb.toString(); |
| 108 | |
} |
| 109 | |
|
| 110 | |
protected void _toString(StringBuilder sb) { |
| 111 | 0 | Data.DataType type = (dataType == null) ? Data.DataType.DATA : dataType; |
| 112 | 0 | sb.append("Type: "); |
| 113 | 0 | sb.append(type.toString()); |
| 114 | 0 | sb.append(", Default: "); |
| 115 | 0 | sb.append(", canEdit: " + canEdit); |
| 116 | 0 | sb.append(", canView: " + canView); |
| 117 | 0 | sb.append(defaultValue == null ? "null" : defaultValue.toString()); |
| 118 | 0 | sb.append(", Properties: {"); |
| 119 | 0 | if (childProperties != null) { |
| 120 | 0 | for (Entry<String, Metadata> e : childProperties.entrySet()) { |
| 121 | 0 | sb.append("("); |
| 122 | 0 | sb.append(e.getKey()); |
| 123 | 0 | sb.append(" = "); |
| 124 | 0 | Metadata m = e.getValue(); |
| 125 | 0 | if (m == null) { |
| 126 | 0 | sb.append("null"); |
| 127 | |
} else { |
| 128 | 0 | m._toString(sb); |
| 129 | |
} |
| 130 | 0 | sb.append(");"); |
| 131 | 0 | } |
| 132 | |
} |
| 133 | 0 | sb.append("}"); |
| 134 | |
|
| 135 | 0 | } |
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
public List<ConstraintMetadata> getConstraints() { |
| 140 | 184 | if (constraints == null) { |
| 141 | 0 | constraints = new ArrayList<ConstraintMetadata>(); |
| 142 | |
} |
| 143 | 184 | return constraints; |
| 144 | |
} |
| 145 | |
|
| 146 | |
public void setConstraints(List<ConstraintMetadata> constraints) { |
| 147 | 74 | this.constraints = constraints; |
| 148 | 74 | } |
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
public void setNonServerConstraints(List<ConstraintMetadata> constraints) { |
| 156 | 149 | if (constraints != null){ |
| 157 | 148 | List<ConstraintMetadata> metadataConstraints = new ArrayList<ConstraintMetadata>(); |
| 158 | 148 | for (ConstraintMetadata constraint:constraints){ |
| 159 | 508 | if (!"single".equals(constraint.getId()) && |
| 160 | |
!"optional".equals(constraint.getId()) && |
| 161 | |
!constraint.isServerSide()){ |
| 162 | 193 | metadataConstraints.add(constraint); |
| 163 | |
} |
| 164 | |
} |
| 165 | 148 | this.constraints = metadataConstraints; |
| 166 | |
} |
| 167 | 149 | } |
| 168 | |
|
| 169 | |
public Data.DataType getDataType() { |
| 170 | 330 | return dataType; |
| 171 | |
} |
| 172 | |
|
| 173 | |
public void setDataType(Data.DataType dataType) { |
| 174 | 278 | this.dataType = dataType; |
| 175 | 278 | } |
| 176 | |
|
| 177 | |
public Data.Value getDefaultValue() { |
| 178 | 22 | return defaultValue; |
| 179 | |
} |
| 180 | |
|
| 181 | |
public void setDefaultValue(Data.Value defaultValue) { |
| 182 | 219 | this.defaultValue = defaultValue; |
| 183 | 219 | } |
| 184 | |
|
| 185 | |
public String getDefaultValuePath() { |
| 186 | 0 | return defaultValuePath; |
| 187 | |
} |
| 188 | |
|
| 189 | |
public void setDefaultValuePath(String defaultValuePath) { |
| 190 | 0 | this.defaultValuePath = defaultValuePath; |
| 191 | 0 | } |
| 192 | |
|
| 193 | |
public LookupMetadata getInitialLookup() { |
| 194 | 48 | return initialLookup; |
| 195 | |
} |
| 196 | |
|
| 197 | |
public void setInitialLookup(LookupMetadata initialLookup) { |
| 198 | 150 | this.initialLookup = initialLookup; |
| 199 | 150 | } |
| 200 | |
|
| 201 | |
public String getLookupContextPath() { |
| 202 | 0 | return lookupContextPath; |
| 203 | |
} |
| 204 | |
|
| 205 | |
public void setLookupContextPath(String lookupContextPath) { |
| 206 | 145 | this.lookupContextPath = lookupContextPath; |
| 207 | 145 | } |
| 208 | |
|
| 209 | |
public List<LookupMetadata> getAdditionalLookups() { |
| 210 | 66 | if (additionalLookups == null) { |
| 211 | 22 | additionalLookups = new ArrayList<LookupMetadata>(); |
| 212 | |
} |
| 213 | 66 | return additionalLookups; |
| 214 | |
} |
| 215 | |
|
| 216 | |
public void setAdditionalLookups(List<LookupMetadata> additionalLookups) { |
| 217 | 145 | this.additionalLookups = additionalLookups; |
| 218 | 145 | } |
| 219 | |
|
| 220 | |
public Map<String, Metadata> getProperties() { |
| 221 | 65 | if (childProperties == null) { |
| 222 | 11 | childProperties = new LinkedHashMap<String, Metadata>(); |
| 223 | |
} |
| 224 | 65 | return childProperties; |
| 225 | |
} |
| 226 | |
|
| 227 | |
public void setProperties(Map<String, Metadata> properties) { |
| 228 | 76 | this.childProperties = properties; |
| 229 | 76 | } |
| 230 | |
|
| 231 | |
public WriteAccess getWriteAccess() { |
| 232 | 0 | return writeAccess; |
| 233 | |
} |
| 234 | |
|
| 235 | |
public void setWriteAccess(WriteAccess writeAccess) { |
| 236 | 259 | this.writeAccess = writeAccess; |
| 237 | 259 | } |
| 238 | |
|
| 239 | |
|
| 240 | |
public boolean isOnChangeRefreshMetadata() { |
| 241 | 0 | return onChangeRefreshMetadata; |
| 242 | |
} |
| 243 | |
|
| 244 | |
public void setOnChangeRefreshMetadata(boolean onChangeRefereshMetadata) { |
| 245 | 21 | this.onChangeRefreshMetadata = onChangeRefereshMetadata; |
| 246 | 21 | } |
| 247 | |
|
| 248 | |
public boolean isCanUnmask() { |
| 249 | 22 | return canUnmask; |
| 250 | |
} |
| 251 | |
|
| 252 | |
public void setCanUnmask(boolean canUnmask) { |
| 253 | 219 | this.canUnmask = canUnmask; |
| 254 | 219 | } |
| 255 | |
|
| 256 | |
public boolean isCanView() { |
| 257 | 22 | return canView; |
| 258 | |
} |
| 259 | |
|
| 260 | |
public void setCanView(boolean canView) { |
| 261 | 219 | this.canView = canView; |
| 262 | 219 | } |
| 263 | |
|
| 264 | |
public boolean isCanEdit() { |
| 265 | 42 | return canEdit; |
| 266 | |
} |
| 267 | |
|
| 268 | |
public void setCanEdit(boolean canEdit) { |
| 269 | 226 | this.canEdit = canEdit; |
| 270 | 226 | } |
| 271 | |
|
| 272 | |
public String getName() { |
| 273 | 0 | return name; |
| 274 | |
} |
| 275 | |
|
| 276 | |
public void setName(String name) { |
| 277 | 145 | this.name = name; |
| 278 | 145 | } |
| 279 | |
|
| 280 | |
public boolean isDynamic() { |
| 281 | 22 | return dynamic; |
| 282 | |
} |
| 283 | |
|
| 284 | |
public void setDynamic(boolean dynamic) { |
| 285 | 74 | this.dynamic = dynamic; |
| 286 | 74 | } |
| 287 | |
|
| 288 | |
public String getLabelKey() { |
| 289 | 22 | return labelKey; |
| 290 | |
} |
| 291 | |
|
| 292 | |
public void setLabelKey(String labelKey) { |
| 293 | 74 | this.labelKey = labelKey; |
| 294 | 74 | } |
| 295 | |
|
| 296 | |
public String getPartialMaskFormatter() { |
| 297 | 3 | return partialMaskFormatter; |
| 298 | |
} |
| 299 | |
|
| 300 | |
public void setPartialMaskFormatter(String partialMaskFormatter) { |
| 301 | 8 | this.partialMaskFormatter = partialMaskFormatter; |
| 302 | 8 | } |
| 303 | |
|
| 304 | |
public String getMaskFormatter() { |
| 305 | 4 | return maskFormatter; |
| 306 | |
} |
| 307 | |
|
| 308 | |
public void setMaskFormatter(String maskFormatter) { |
| 309 | 9 | this.maskFormatter = maskFormatter; |
| 310 | 9 | } |
| 311 | |
} |