|  1 |     | 
     | 
  |  2 |     | 
     | 
  |  3 |     | 
     | 
  |  4 |     | 
     | 
  |  5 |     | 
     | 
  |  6 |     | 
     | 
  |  7 |     | 
     | 
  |  8 |     | 
     | 
  |  9 |     | 
     | 
  |  10 |     | 
     | 
  |  11 |     | 
     | 
  |  12 |     | 
     | 
  |  13 |     | 
     | 
  |  14 |     | 
     | 
  |  15 |     | 
     | 
  |  16 |     | 
   package org.kuali.rice.kim.api.common.delegate;  | 
  |  17 |     | 
     | 
  |  18 |     | 
   import org.apache.commons.collections.CollectionUtils;  | 
  |  19 |     | 
   import org.apache.commons.lang.StringUtils;  | 
  |  20 |     | 
   import org.apache.commons.lang.builder.EqualsBuilder;  | 
  |  21 |     | 
   import org.apache.commons.lang.builder.HashCodeBuilder;  | 
  |  22 |     | 
   import org.apache.commons.lang.builder.ToStringBuilder;  | 
  |  23 |     | 
   import org.kuali.rice.core.api.CoreConstants;  | 
  |  24 |     | 
   import org.kuali.rice.core.api.mo.ModelBuilder;  | 
  |  25 |     | 
   import org.kuali.rice.core.api.mo.ModelObjectComplete;  | 
  |  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.XmlRootElement;  | 
  |  33 |     | 
   import javax.xml.bind.annotation.XmlType;  | 
  |  34 |     | 
   import java.util.ArrayList;  | 
  |  35 |     | 
   import java.util.Collection;  | 
  |  36 |     | 
   import java.util.Collections;  | 
  |  37 |     | 
   import java.util.List;  | 
  |  38 |     | 
     | 
  |  39 |     | 
     | 
  |  40 |     | 
   @XmlRootElement(name = DelegateType.Constants.ROOT_ELEMENT_NAME)  | 
  |  41 |     | 
   @XmlAccessorType(XmlAccessType.NONE)  | 
  |  42 |     | 
   @XmlType(name = DelegateType.Constants.TYPE_NAME, propOrder = { | 
  |  43 |     | 
           DelegateType.Elements.ROLE_ID,  | 
  |  44 |     | 
           DelegateType.Elements.DELEGATION_ID,  | 
  |  45 |     | 
           DelegateType.Elements.DELEGATION_TYPE_CODE,  | 
  |  46 |     | 
           DelegateType.Elements.KIM_TYPE_ID,  | 
  |  47 |     | 
           DelegateType.Elements.MEMBERS,  | 
  |  48 |     | 
           DelegateType.Elements.ACTIVE,  | 
  |  49 |     | 
           CoreConstants.CommonElements.FUTURE_ELEMENTS  | 
  |  50 |     | 
   })  | 
  |  51 |    5 |    public final class DelegateType implements DelegateTypeContract, ModelObjectComplete { | 
  |  52 |     | 
     | 
  |  53 |     | 
       private static final long serialVersionUID = 1L;  | 
  |  54 |     | 
     | 
  |  55 |     | 
       @XmlElement(name = Elements.ROLE_ID)  | 
  |  56 |     | 
       private final String roleId;  | 
  |  57 |     | 
     | 
  |  58 |     | 
       @XmlElement(name = Elements.DELEGATION_ID)  | 
  |  59 |     | 
       private final String delegationId;  | 
  |  60 |     | 
     | 
  |  61 |     | 
       @XmlElement(name = Elements.DELEGATION_TYPE_CODE)  | 
  |  62 |     | 
       private final String delegationTypeCode;  | 
  |  63 |     | 
     | 
  |  64 |     | 
       @XmlElement(name = Elements.KIM_TYPE_ID)  | 
  |  65 |     | 
       private final String kimTypeId;  | 
  |  66 |     | 
     | 
  |  67 |     | 
       @XmlElement(name = Elements.MEMBERS)  | 
  |  68 |     | 
       private final List<Delegate> members;  | 
  |  69 |     | 
     | 
  |  70 |     | 
       @XmlElement(name = Elements.ACTIVE)  | 
  |  71 |     | 
       private final boolean active;  | 
  |  72 |     | 
     | 
  |  73 |    8 |        @SuppressWarnings("unused") | 
  |  74 |     | 
       @XmlAnyElement  | 
  |  75 |     | 
       private final Collection<Element> _futureElements = null;  | 
  |  76 |     | 
     | 
  |  77 |     | 
         | 
  |  78 |     | 
     | 
  |  79 |     | 
     | 
  |  80 |     | 
       @SuppressWarnings("unused") | 
  |  81 |    3 |        private DelegateType() { | 
  |  82 |    3 |            roleId = null;  | 
  |  83 |    3 |            delegationId = null;  | 
  |  84 |    3 |            delegationTypeCode = null;  | 
  |  85 |    3 |            kimTypeId = null;  | 
  |  86 |    3 |            members = null;  | 
  |  87 |    3 |            active = false;  | 
  |  88 |    3 |        }  | 
  |  89 |     | 
     | 
  |  90 |    5 |        private DelegateType(Builder b) { | 
  |  91 |    5 |            roleId = b.getRoleId();  | 
  |  92 |    5 |            delegationId = b.getDelegationId();  | 
  |  93 |    5 |            delegationTypeCode = b.getDelegationTypeCode();  | 
  |  94 |    5 |            kimTypeId = b.getKimTypeId();  | 
  |  95 |    5 |            active = b.isActive();  | 
  |  96 |     | 
     | 
  |  97 |    5 |            List<Delegate> delegateMembers = new ArrayList<Delegate>();  | 
  |  98 |    5 |            if (!CollectionUtils.isEmpty(b.getMembers())) { | 
  |  99 |    5 |                for (Delegate.Builder delgateBuilder : b.getMembers()) { | 
  |  100 |    5 |                    delegateMembers.add(delgateBuilder.build());  | 
  |  101 |     | 
               }  | 
  |  102 |     | 
           }  | 
  |  103 |    5 |            members = delegateMembers;  | 
  |  104 |    5 |        }  | 
  |  105 |     | 
     | 
  |  106 |     | 
       @Override  | 
  |  107 |     | 
       public String getKimTypeId() { | 
  |  108 |    1 |            return this.kimTypeId;  | 
  |  109 |     | 
       }  | 
  |  110 |     | 
     | 
  |  111 |     | 
       @Override  | 
  |  112 |     | 
       public boolean isActive() { | 
  |  113 |    2 |            return this.active;  | 
  |  114 |     | 
       }  | 
  |  115 |     | 
     | 
  |  116 |     | 
       @Override  | 
  |  117 |     | 
       public String getDelegationTypeCode() { | 
  |  118 |    2 |            return this.delegationTypeCode;  | 
  |  119 |     | 
       }  | 
  |  120 |     | 
     | 
  |  121 |     | 
       @Override  | 
  |  122 |     | 
       public String getDelegationId() { | 
  |  123 |    2 |            return this.delegationId;  | 
  |  124 |     | 
       }  | 
  |  125 |     | 
     | 
  |  126 |     | 
       @Override  | 
  |  127 |     | 
       public String getRoleId() { | 
  |  128 |    2 |            return this.roleId;  | 
  |  129 |     | 
       }  | 
  |  130 |     | 
     | 
  |  131 |     | 
       @Override  | 
  |  132 |     | 
       public List<Delegate> getMembers() { | 
  |  133 |    3 |            return Collections.unmodifiableList(this.members);  | 
  |  134 |     | 
       }  | 
  |  135 |     | 
     | 
  |  136 |     | 
       @Override  | 
  |  137 |     | 
       public int hashCode() { | 
  |  138 |    0 |            return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);  | 
  |  139 |     | 
       }  | 
  |  140 |     | 
     | 
  |  141 |     | 
       @Override  | 
  |  142 |     | 
       public boolean equals(Object obj) { | 
  |  143 |    2 |            return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);  | 
  |  144 |     | 
       }  | 
  |  145 |     | 
     | 
  |  146 |     | 
       @Override  | 
  |  147 |     | 
       public String toString() { | 
  |  148 |    0 |            return ToStringBuilder.reflectionToString(this);  | 
  |  149 |     | 
       }  | 
  |  150 |     | 
     | 
  |  151 |     | 
     | 
  |  152 |    16 |        public static final class Builder implements DelegateTypeContract, ModelBuilder, ModelObjectComplete { | 
  |  153 |     | 
           private String roleId;  | 
  |  154 |     | 
           private String delegationId;  | 
  |  155 |     | 
           private String delegationTypeCode;  | 
  |  156 |     | 
           private String kimTypeId;  | 
  |  157 |     | 
           private List<Delegate.Builder> members;  | 
  |  158 |     | 
           private boolean active;  | 
  |  159 |     | 
     | 
  |  160 |     | 
           public static Builder create(DelegateTypeContract dtc) { | 
  |  161 |    1 |                Builder b = new Builder();  | 
  |  162 |    1 |                b.setRoleId(dtc.getRoleId());  | 
  |  163 |    1 |                b.setDelegationId(dtc.getDelegationId());  | 
  |  164 |    1 |                b.setDelegationTypeCode(dtc.getDelegationTypeCode());  | 
  |  165 |    1 |                b.setActive(dtc.isActive());  | 
  |  166 |     | 
     | 
  |  167 |    1 |                ArrayList<Delegate.Builder> delegateBuilders = new ArrayList<Delegate.Builder>();  | 
  |  168 |    1 |                for (DelegateContract delegate : dtc.getMembers()) { | 
  |  169 |    1 |                    delegateBuilders.add(Delegate.Builder.create(delegate));  | 
  |  170 |     | 
               }  | 
  |  171 |    1 |                b.setMembers(delegateBuilders);  | 
  |  172 |     | 
     | 
  |  173 |    1 |                return b;  | 
  |  174 |     | 
           }  | 
  |  175 |     | 
     | 
  |  176 |     | 
           public static Builder create(String roleId, String delegationId, String delegationTypeCode, List<Delegate.Builder> members) { | 
  |  177 |    10 |                Builder b = new Builder();  | 
  |  178 |    10 |                b.setRoleId(roleId);  | 
  |  179 |    10 |                b.setDelegationId(delegationId);  | 
  |  180 |    10 |                b.setDelegationTypeCode(delegationTypeCode);  | 
  |  181 |    10 |                b.setMembers(members);  | 
  |  182 |    10 |                b.setActive(true);  | 
  |  183 |     | 
     | 
  |  184 |    10 |                return b;  | 
  |  185 |     | 
           }  | 
  |  186 |     | 
     | 
  |  187 |     | 
           @Override  | 
  |  188 |     | 
           public DelegateType build() { | 
  |  189 |    5 |                return new DelegateType(this);  | 
  |  190 |     | 
           }  | 
  |  191 |     | 
     | 
  |  192 |     | 
           @Override  | 
  |  193 |     | 
           public String getRoleId() { | 
  |  194 |    5 |                return roleId;  | 
  |  195 |     | 
           }  | 
  |  196 |     | 
     | 
  |  197 |     | 
           public void setRoleId(String roleId) { | 
  |  198 |    13 |                if (StringUtils.isBlank(roleId)) { | 
  |  199 |    2 |                    throw new IllegalArgumentException("roleId cannot be null or blank"); | 
  |  200 |     | 
               }  | 
  |  201 |    11 |                this.roleId = roleId;  | 
  |  202 |    11 |            }  | 
  |  203 |     | 
     | 
  |  204 |     | 
           @Override  | 
  |  205 |     | 
           public String getDelegationId() { | 
  |  206 |    5 |                return delegationId;  | 
  |  207 |     | 
           }  | 
  |  208 |     | 
     | 
  |  209 |     | 
           public void setDelegationId(String delegationId) { | 
  |  210 |    13 |                if (StringUtils.isBlank(delegationId)) { | 
  |  211 |    2 |                    throw new IllegalArgumentException("delegationId cannot be null or blank"); | 
  |  212 |     | 
               }  | 
  |  213 |     | 
     | 
  |  214 |    11 |                this.delegationId = delegationId;  | 
  |  215 |    11 |            }  | 
  |  216 |     | 
     | 
  |  217 |     | 
           @Override  | 
  |  218 |     | 
           public String getDelegationTypeCode() { | 
  |  219 |    5 |                return delegationTypeCode;  | 
  |  220 |     | 
           }  | 
  |  221 |     | 
     | 
  |  222 |     | 
           public void setDelegationTypeCode(String delegationTypeCode) { | 
  |  223 |    13 |                if (StringUtils.isBlank(delegationTypeCode)) { | 
  |  224 |    2 |                    throw new IllegalArgumentException("delegationTypeCode cannot be null or blank"); | 
  |  225 |     | 
               }  | 
  |  226 |    11 |                this.delegationTypeCode = delegationTypeCode;  | 
  |  227 |    11 |            }  | 
  |  228 |     | 
     | 
  |  229 |     | 
           @Override  | 
  |  230 |     | 
           public String getKimTypeId() { | 
  |  231 |    5 |                return kimTypeId;  | 
  |  232 |     | 
           }  | 
  |  233 |     | 
     | 
  |  234 |     | 
           public void setKimTypeId(String kimTypeId) { | 
  |  235 |    1 |                this.kimTypeId = kimTypeId;  | 
  |  236 |    1 |            }  | 
  |  237 |     | 
     | 
  |  238 |     | 
           @Override  | 
  |  239 |     | 
           public List<Delegate.Builder> getMembers() { | 
  |  240 |    10 |                return members;  | 
  |  241 |     | 
           }  | 
  |  242 |     | 
     | 
  |  243 |     | 
           public void setMembers(List<Delegate.Builder> members) { | 
  |  244 |    11 |                this.members = members;  | 
  |  245 |    11 |            }  | 
  |  246 |     | 
     | 
  |  247 |     | 
           @Override  | 
  |  248 |     | 
           public boolean isActive() { | 
  |  249 |    5 |                return active;  | 
  |  250 |     | 
           }  | 
  |  251 |     | 
     | 
  |  252 |     | 
           public void setActive(Boolean active) { | 
  |  253 |    11 |                this.active = active;  | 
  |  254 |    11 |            }  | 
  |  255 |     | 
     | 
  |  256 |     | 
           @Override  | 
  |  257 |     | 
           public int hashCode() { | 
  |  258 |    0 |                return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);  | 
  |  259 |     | 
           }  | 
  |  260 |     | 
     | 
  |  261 |     | 
           @Override  | 
  |  262 |     | 
           public boolean equals(Object obj) { | 
  |  263 |    0 |                return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);  | 
  |  264 |     | 
           }  | 
  |  265 |     | 
     | 
  |  266 |     | 
           @Override  | 
  |  267 |     | 
           public String toString() { | 
  |  268 |    0 |                return ToStringBuilder.reflectionToString(this);  | 
  |  269 |     | 
           }  | 
  |  270 |     | 
       }  | 
  |  271 |     | 
     | 
  |  272 |     | 
     | 
  |  273 |     | 
         | 
  |  274 |     | 
     | 
  |  275 |     | 
     | 
  |  276 |     | 
     | 
  |  277 |    0 |        static class Elements { | 
  |  278 |     | 
           static final String ROLE_ID = "roleId";  | 
  |  279 |     | 
           static final String DELEGATION_ID = "delegationId";  | 
  |  280 |     | 
           static final String DELEGATION_TYPE_CODE = "delegationTypeCode";  | 
  |  281 |     | 
           static final String KIM_TYPE_ID = "kimTypeId";  | 
  |  282 |     | 
           static final String MEMBERS = "members";  | 
  |  283 |     | 
           static final String ACTIVE = "active";  | 
  |  284 |     | 
       }  | 
  |  285 |     | 
     | 
  |  286 |     | 
         | 
  |  287 |     | 
     | 
  |  288 |     | 
     | 
  |  289 |    0 |        static class Constants { | 
  |  290 |     | 
           final static String ROOT_ELEMENT_NAME = "delegateType";  | 
  |  291 |     | 
           final static String TYPE_NAME = "DelegateTypeType";  | 
  |  292 |    1 |            final static String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS}; | 
  |  293 |     | 
       }  | 
  |  294 |     | 
   }  |