| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.rice.kim.api.type; |
| 18 | |
|
| 19 | |
import org.apache.commons.lang.StringUtils; |
| 20 | |
import org.kuali.rice.core.api.CoreConstants; |
| 21 | |
import org.kuali.rice.core.api.mo.AbstractDataTransferObject; |
| 22 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
| 23 | |
import org.w3c.dom.Element; |
| 24 | |
|
| 25 | |
import javax.xml.bind.annotation.XmlAccessType; |
| 26 | |
import javax.xml.bind.annotation.XmlAccessorType; |
| 27 | |
import javax.xml.bind.annotation.XmlAnyElement; |
| 28 | |
import javax.xml.bind.annotation.XmlElement; |
| 29 | |
import javax.xml.bind.annotation.XmlRootElement; |
| 30 | |
import javax.xml.bind.annotation.XmlType; |
| 31 | |
import java.io.Serializable; |
| 32 | |
import java.util.ArrayList; |
| 33 | |
import java.util.Collection; |
| 34 | |
import java.util.Collections; |
| 35 | |
import java.util.List; |
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
@XmlRootElement(name = KimType.Constants.ROOT_ELEMENT_NAME) |
| 45 | |
@XmlAccessorType(XmlAccessType.NONE) |
| 46 | |
@XmlType(name = KimType.Constants.TYPE_NAME, propOrder = { |
| 47 | |
KimType.Elements.ID, |
| 48 | |
KimType.Elements.SERVICE_NAME, |
| 49 | |
KimType.Elements.NAMESPACE_CODE, |
| 50 | |
KimType.Elements.NAME, |
| 51 | |
KimType.Elements.ATTRIBUTE_DEFNS, |
| 52 | |
KimType.Elements.ACTIVE, |
| 53 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
| 54 | |
CoreConstants.CommonElements.OBJECT_ID, |
| 55 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
| 56 | |
}) |
| 57 | 9 | public final class KimType extends AbstractDataTransferObject implements KimTypeContract { |
| 58 | |
private static final long serialVersionUID = 1L; |
| 59 | |
|
| 60 | |
@XmlElement(name = KimType.Elements.ID, required = false) |
| 61 | |
private final String id; |
| 62 | |
|
| 63 | |
@XmlElement(name = KimType.Elements.SERVICE_NAME, required = false) |
| 64 | |
private final String serviceName; |
| 65 | |
|
| 66 | |
@XmlElement(name = KimType.Elements.NAMESPACE_CODE, required = false) |
| 67 | |
private final String namespaceCode; |
| 68 | |
|
| 69 | |
@XmlElement(name = KimType.Elements.NAME, required = false) |
| 70 | |
private final String name; |
| 71 | |
|
| 72 | |
@XmlElement(name = KimType.Elements.ATTRIBUTE_DEFNS, required = false) |
| 73 | |
private final List<KimTypeAttribute> attributeDefinitions; |
| 74 | |
|
| 75 | |
@XmlElement(name = KimType.Elements.ACTIVE, required = false) |
| 76 | |
private final boolean active; |
| 77 | |
|
| 78 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
| 79 | |
private final Long versionNumber; |
| 80 | |
|
| 81 | |
@XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false) |
| 82 | |
private final String objectId; |
| 83 | |
|
| 84 | 14 | @SuppressWarnings("unused") |
| 85 | |
@XmlAnyElement |
| 86 | |
private final Collection<Element> _futureElements = null; |
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | 5 | private KimType() { |
| 92 | 5 | this.id = null; |
| 93 | 5 | this.serviceName = null; |
| 94 | 5 | this.namespaceCode = null; |
| 95 | 5 | this.name = null; |
| 96 | 5 | this.attributeDefinitions = Collections.<KimTypeAttribute>emptyList(); |
| 97 | 5 | this.active = false; |
| 98 | 5 | this.versionNumber = Long.valueOf(1L); |
| 99 | 5 | this.objectId = null; |
| 100 | 5 | } |
| 101 | |
|
| 102 | 9 | private KimType(Builder builder) { |
| 103 | 9 | this.id = builder.getId(); |
| 104 | 9 | this.serviceName = builder.getServiceName(); |
| 105 | 9 | this.namespaceCode = builder.getNamespaceCode(); |
| 106 | 9 | this.name = builder.getName(); |
| 107 | 9 | final List<KimTypeAttribute> temp = new ArrayList<KimTypeAttribute>(); |
| 108 | 9 | for (KimTypeAttribute.Builder attr : builder.getAttributeDefinitions()) { |
| 109 | |
|
| 110 | 0 | attr.setKimTypeId(this.id); |
| 111 | 0 | temp.add(attr.build()); |
| 112 | |
} |
| 113 | 9 | this.attributeDefinitions = Collections.unmodifiableList(temp); |
| 114 | |
|
| 115 | 9 | this.active = builder.isActive(); |
| 116 | 9 | this.versionNumber = builder.getVersionNumber(); |
| 117 | 9 | this.objectId = builder.getObjectId(); |
| 118 | 9 | } |
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
public KimTypeAttribute getAttributeDefinitionById(String id) { |
| 134 | 0 | if (StringUtils.isBlank(id)) { |
| 135 | 0 | throw new IllegalArgumentException("id is blank"); |
| 136 | |
} |
| 137 | |
|
| 138 | 0 | if (this.attributeDefinitions != null) { |
| 139 | 0 | for (KimTypeAttribute att : this.attributeDefinitions) { |
| 140 | 0 | if (att != null && att.getKimAttribute() != null |
| 141 | |
&& id.equals(att.getKimAttribute().getId())) { |
| 142 | 0 | return att; |
| 143 | |
} |
| 144 | |
} |
| 145 | |
} |
| 146 | 0 | return null; |
| 147 | |
} |
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
public KimTypeAttribute getAttributeDefinitionByName(String name) { |
| 163 | 0 | if (StringUtils.isBlank(name)) { |
| 164 | 0 | throw new IllegalArgumentException("name is blank"); |
| 165 | |
} |
| 166 | |
|
| 167 | 0 | if (this.attributeDefinitions != null) { |
| 168 | 0 | for (KimTypeAttribute att : this.attributeDefinitions) { |
| 169 | 0 | if (att != null && att.getKimAttribute() != null |
| 170 | |
&& name.equals(att.getKimAttribute().getAttributeName())) { |
| 171 | 0 | return att; |
| 172 | |
} |
| 173 | |
} |
| 174 | |
} |
| 175 | 0 | return null; |
| 176 | |
} |
| 177 | |
|
| 178 | |
@Override |
| 179 | |
public String getId() { |
| 180 | 5 | return id; |
| 181 | |
} |
| 182 | |
|
| 183 | |
@Override |
| 184 | |
public String getServiceName() { |
| 185 | 2 | return serviceName; |
| 186 | |
} |
| 187 | |
|
| 188 | |
@Override |
| 189 | |
public String getNamespaceCode() { |
| 190 | 2 | return namespaceCode; |
| 191 | |
} |
| 192 | |
|
| 193 | |
@Override |
| 194 | |
public String getName() { |
| 195 | 2 | return name; |
| 196 | |
} |
| 197 | |
|
| 198 | |
@Override |
| 199 | |
public List<KimTypeAttribute> getAttributeDefinitions() { |
| 200 | 4 | return attributeDefinitions; |
| 201 | |
} |
| 202 | |
|
| 203 | |
@Override |
| 204 | |
public boolean isActive() { |
| 205 | 2 | return active; |
| 206 | |
} |
| 207 | |
|
| 208 | |
@Override |
| 209 | |
public Long getVersionNumber() { |
| 210 | 2 | return versionNumber; |
| 211 | |
} |
| 212 | |
|
| 213 | |
@Override |
| 214 | |
public String getObjectId() { |
| 215 | 2 | return objectId; |
| 216 | |
} |
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | 8 | public static final class Builder implements KimTypeContract, ModelBuilder, Serializable { |
| 222 | |
private String id; |
| 223 | |
private String serviceName; |
| 224 | |
private String namespaceCode; |
| 225 | |
private String name; |
| 226 | 12 | private List<KimTypeAttribute.Builder> attributeDefinitions = new ArrayList<KimTypeAttribute.Builder>(); |
| 227 | |
private boolean active; |
| 228 | 12 | private Long versionNumber = 1L; |
| 229 | |
private String objectId; |
| 230 | |
|
| 231 | 12 | private Builder() { |
| 232 | 12 | } |
| 233 | |
|
| 234 | |
|
| 235 | |
|
| 236 | |
|
| 237 | |
public static Builder create() { |
| 238 | 9 | return new Builder(); |
| 239 | |
} |
| 240 | |
|
| 241 | |
|
| 242 | |
|
| 243 | |
|
| 244 | |
public static Builder create(KimTypeContract contract) { |
| 245 | 3 | if (contract == null) { |
| 246 | 0 | throw new IllegalArgumentException("contract was null"); |
| 247 | |
} |
| 248 | 3 | Builder builder = new Builder(); |
| 249 | 3 | builder.setId(contract.getId()); |
| 250 | 3 | builder.setServiceName(contract.getServiceName()); |
| 251 | 3 | builder.setNamespaceCode(contract.getNamespaceCode()); |
| 252 | 3 | builder.setName(contract.getName()); |
| 253 | |
|
| 254 | 3 | if (contract.getAttributeDefinitions() != null) { |
| 255 | 3 | final List<KimTypeAttribute.Builder> temp = new ArrayList<KimTypeAttribute.Builder>(); |
| 256 | 3 | for (KimTypeAttributeContract attr : contract.getAttributeDefinitions()) { |
| 257 | 0 | temp.add(KimTypeAttribute.Builder.create(attr)); |
| 258 | |
} |
| 259 | |
|
| 260 | 3 | builder.setAttributeDefinitions(Collections.unmodifiableList(temp)); |
| 261 | |
} |
| 262 | |
|
| 263 | 3 | builder.setActive(contract.isActive()); |
| 264 | 3 | builder.setVersionNumber(contract.getVersionNumber()); |
| 265 | 3 | builder.setObjectId(contract.getObjectId()); |
| 266 | 3 | return builder; |
| 267 | |
} |
| 268 | |
|
| 269 | |
@Override |
| 270 | |
public String getId() { |
| 271 | 9 | return id; |
| 272 | |
} |
| 273 | |
|
| 274 | |
public void setId(final String id) { |
| 275 | 9 | this.id = id; |
| 276 | 9 | } |
| 277 | |
|
| 278 | |
@Override |
| 279 | |
public String getServiceName() { |
| 280 | 9 | return serviceName; |
| 281 | |
} |
| 282 | |
|
| 283 | |
public void setServiceName(final String serviceName) { |
| 284 | 4 | this.serviceName = serviceName; |
| 285 | 4 | } |
| 286 | |
|
| 287 | |
@Override |
| 288 | |
public String getNamespaceCode() { |
| 289 | 9 | return namespaceCode; |
| 290 | |
} |
| 291 | |
|
| 292 | |
public void setNamespaceCode(final String namespaceCode) { |
| 293 | 6 | this.namespaceCode = namespaceCode; |
| 294 | 6 | } |
| 295 | |
|
| 296 | |
@Override |
| 297 | |
public String getName() { |
| 298 | 9 | return name; |
| 299 | |
} |
| 300 | |
|
| 301 | |
public void setName(final String name) { |
| 302 | 3 | this.name = name; |
| 303 | 3 | } |
| 304 | |
|
| 305 | |
@Override |
| 306 | |
public List<KimTypeAttribute.Builder> getAttributeDefinitions() { |
| 307 | 9 | return attributeDefinitions; |
| 308 | |
} |
| 309 | |
|
| 310 | |
public void setAttributeDefinitions(final List<KimTypeAttribute.Builder> attributeDefinitions) { |
| 311 | 3 | if (attributeDefinitions == null) { |
| 312 | 0 | throw new IllegalArgumentException("attributeDefinitions is null"); |
| 313 | |
} |
| 314 | |
|
| 315 | 3 | this.attributeDefinitions = attributeDefinitions; |
| 316 | 3 | } |
| 317 | |
|
| 318 | |
@Override |
| 319 | |
public boolean isActive() { |
| 320 | 9 | return active; |
| 321 | |
} |
| 322 | |
|
| 323 | |
public void setActive(final boolean active) { |
| 324 | 5 | this.active = active; |
| 325 | 5 | } |
| 326 | |
|
| 327 | |
@Override |
| 328 | |
public Long getVersionNumber() { |
| 329 | 9 | return versionNumber; |
| 330 | |
} |
| 331 | |
|
| 332 | |
public void setVersionNumber(final Long versionNumber) { |
| 333 | 7 | if (versionNumber != null && versionNumber <= 0) { |
| 334 | 2 | throw new IllegalArgumentException("versionNumber is invalid"); |
| 335 | |
} |
| 336 | |
|
| 337 | 5 | this.versionNumber = versionNumber; |
| 338 | 5 | } |
| 339 | |
|
| 340 | |
@Override |
| 341 | |
public String getObjectId() { |
| 342 | 9 | return objectId; |
| 343 | |
} |
| 344 | |
|
| 345 | |
public void setObjectId(final String objectId) { |
| 346 | 5 | this.objectId = objectId; |
| 347 | 5 | } |
| 348 | |
|
| 349 | |
@Override |
| 350 | |
public KimType build() { |
| 351 | 9 | return new KimType(this); |
| 352 | |
} |
| 353 | |
} |
| 354 | |
|
| 355 | |
|
| 356 | |
|
| 357 | |
|
| 358 | 0 | static class Constants { |
| 359 | |
static final String ROOT_ELEMENT_NAME = "kimType"; |
| 360 | |
static final String TYPE_NAME = "KimTypeType"; |
| 361 | |
} |
| 362 | |
|
| 363 | |
|
| 364 | |
|
| 365 | |
|
| 366 | |
|
| 367 | 0 | static class Elements { |
| 368 | |
static final String ID = "id"; |
| 369 | |
static final String SERVICE_NAME = "serviceName"; |
| 370 | |
static final String NAMESPACE_CODE = "namespaceCode"; |
| 371 | |
static final String NAME = "name"; |
| 372 | |
static final String ATTRIBUTE_DEFNS = "attributeDefinitions"; |
| 373 | |
static final String ACTIVE = "active"; |
| 374 | |
} |
| 375 | |
} |