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