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