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