| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.rice.kim.api.common.assignee; |
| 18 | |
|
| 19 | |
import org.apache.commons.collections.CollectionUtils; |
| 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.kim.api.common.delegate.DelegateType; |
| 25 | |
import org.kuali.rice.kim.api.common.delegate.DelegateTypeContract; |
| 26 | |
import org.w3c.dom.Element; |
| 27 | |
|
| 28 | |
import javax.xml.bind.annotation.XmlAccessType; |
| 29 | |
import javax.xml.bind.annotation.XmlAccessorType; |
| 30 | |
import javax.xml.bind.annotation.XmlAnyElement; |
| 31 | |
import javax.xml.bind.annotation.XmlElement; |
| 32 | |
import javax.xml.bind.annotation.XmlElementWrapper; |
| 33 | |
import javax.xml.bind.annotation.XmlRootElement; |
| 34 | |
import javax.xml.bind.annotation.XmlType; |
| 35 | |
import java.io.Serializable; |
| 36 | |
import java.util.ArrayList; |
| 37 | |
import java.util.Collection; |
| 38 | |
import java.util.Collections; |
| 39 | |
import java.util.List; |
| 40 | |
|
| 41 | |
|
| 42 | |
@XmlRootElement(name = Assignee.Constants.ROOT_ELEMENT_NAME) |
| 43 | |
@XmlAccessorType(XmlAccessType.NONE) |
| 44 | |
@XmlType(name = Assignee.Constants.TYPE_NAME, propOrder = { |
| 45 | |
Assignee.Elements.PRINCIPAL_ID, |
| 46 | |
Assignee.Elements.GROUP_ID, |
| 47 | |
Assignee.Elements.DELEGATES, |
| 48 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
| 49 | |
}) |
| 50 | |
public class Assignee extends AbstractDataTransferObject implements AssigneeContract { |
| 51 | |
@XmlElement(name = Elements.PRINCIPAL_ID, required = false) |
| 52 | |
private final String principalId; |
| 53 | |
|
| 54 | |
@XmlElement(name = Elements.GROUP_ID, required = true) |
| 55 | |
private final String groupId; |
| 56 | |
|
| 57 | |
@XmlElementWrapper(name = Elements.DELEGATES, required = false) |
| 58 | |
@XmlElement(name = Elements.DELEGATE, required = false) |
| 59 | |
private final List<DelegateType> delegates; |
| 60 | |
|
| 61 | 0 | @SuppressWarnings("unused") |
| 62 | |
@XmlAnyElement |
| 63 | |
private final Collection<Element> _futureElements = null; |
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | 0 | private Assignee() { |
| 70 | 0 | this.principalId = null; |
| 71 | 0 | this.groupId = null; |
| 72 | 0 | this.delegates = null; |
| 73 | 0 | } |
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | 0 | public Assignee(Builder builder) { |
| 81 | 0 | this.principalId = builder.getPrincipalId(); |
| 82 | 0 | this.groupId = builder.getGroupId(); |
| 83 | 0 | final List<DelegateType> temp = new ArrayList<DelegateType>(); |
| 84 | 0 | if (!CollectionUtils.isEmpty(builder.getDelegates())) { |
| 85 | 0 | for (DelegateType.Builder delegate: builder.getDelegates()) { |
| 86 | 0 | temp.add(delegate.build()); |
| 87 | |
} |
| 88 | |
} |
| 89 | 0 | this.delegates = Collections.unmodifiableList(temp); |
| 90 | 0 | } |
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
@Override |
| 96 | |
public String getPrincipalId() { |
| 97 | 0 | return this.principalId; |
| 98 | |
} |
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
@Override |
| 104 | |
public String getGroupId() { |
| 105 | 0 | return this.groupId; |
| 106 | |
} |
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
@Override |
| 112 | |
public List<DelegateType> getDelegates() { |
| 113 | 0 | return this.delegates; |
| 114 | |
} |
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | 0 | public static final class Builder implements AssigneeContract, ModelBuilder, Serializable { |
| 120 | |
private String principalId; |
| 121 | |
private String groupId; |
| 122 | |
private List<DelegateType.Builder> delegates; |
| 123 | |
|
| 124 | 0 | private Builder(String principalId, String groupId, List<DelegateType.Builder> delegates) { |
| 125 | 0 | setPrincipalId(principalId); |
| 126 | 0 | setGroupId(groupId); |
| 127 | 0 | setDelegates(delegates); |
| 128 | 0 | } |
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
public static Builder create(String principalId, String groupId, List<DelegateType.Builder> delegates) { |
| 134 | 0 | return new Builder(principalId, groupId, delegates); |
| 135 | |
} |
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
public static Builder create(AssigneeContract contract) { |
| 141 | 0 | final List<DelegateType.Builder> builders = new ArrayList<DelegateType.Builder>(); |
| 142 | 0 | for (DelegateTypeContract d : contract.getDelegates()) { |
| 143 | 0 | builders.add(DelegateType.Builder.create(d)); |
| 144 | |
} |
| 145 | |
|
| 146 | 0 | Builder builder = new Builder(contract.getPrincipalId(), contract.getGroupId(), builders); |
| 147 | 0 | return builder; |
| 148 | |
} |
| 149 | |
|
| 150 | |
@Override |
| 151 | |
public String getPrincipalId() { |
| 152 | 0 | return principalId; |
| 153 | |
} |
| 154 | |
|
| 155 | |
public void setPrincipalId(final String principalId) { |
| 156 | 0 | if (StringUtils.isBlank(principalId)) { |
| 157 | 0 | throw new IllegalArgumentException("principalId is blank"); |
| 158 | |
} |
| 159 | 0 | this.principalId = principalId; |
| 160 | 0 | } |
| 161 | |
|
| 162 | |
@Override |
| 163 | |
public String getGroupId() { |
| 164 | 0 | return groupId; |
| 165 | |
} |
| 166 | |
|
| 167 | |
public void setGroupId(final String groupId) { |
| 168 | 0 | if (StringUtils.isBlank(groupId)) { |
| 169 | 0 | throw new IllegalArgumentException("groupId is blank"); |
| 170 | |
} |
| 171 | 0 | this.groupId = groupId; |
| 172 | 0 | } |
| 173 | |
|
| 174 | |
@Override |
| 175 | |
public List<DelegateType.Builder> getDelegates() { |
| 176 | 0 | return delegates; |
| 177 | |
} |
| 178 | |
|
| 179 | |
public void setDelegates(final List<DelegateType.Builder> delegates) { |
| 180 | 0 | if (delegates == null || delegates.isEmpty()) { |
| 181 | 0 | throw new IllegalArgumentException("delegates is null or empty"); |
| 182 | |
} |
| 183 | 0 | this.delegates = Collections.unmodifiableList(new ArrayList<DelegateType.Builder>(delegates)); |
| 184 | 0 | } |
| 185 | |
|
| 186 | |
@Override |
| 187 | |
public Assignee build() { |
| 188 | 0 | return new Assignee(this); |
| 189 | |
} |
| 190 | |
|
| 191 | |
} |
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | 0 | static class Constants { |
| 197 | |
final static String ROOT_ELEMENT_NAME = "assignee"; |
| 198 | |
final static String TYPE_NAME = "assigneeType"; |
| 199 | |
} |
| 200 | |
|
| 201 | |
|
| 202 | |
|
| 203 | |
|
| 204 | |
|
| 205 | 0 | static class Elements { |
| 206 | |
final static String PRINCIPAL_ID = "principalId"; |
| 207 | |
final static String GROUP_ID = "groupId"; |
| 208 | |
final static String DELEGATES = "delegates"; |
| 209 | |
final static String DELEGATE = "delegate"; |
| 210 | |
} |
| 211 | |
} |