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