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