Coverage Report - org.kuali.rice.kew.api.peopleflow.PeopleFlowMember
 
Classes in this File Line Coverage Branch Coverage Complexity
PeopleFlowMember
100%
24/24
N/A
1.417
PeopleFlowMember$1
N/A
N/A
1.417
PeopleFlowMember$Builder
100%
43/43
100%
12/12
1.417
PeopleFlowMember$Constants
0%
0/1
N/A
1.417
PeopleFlowMember$Elements
0%
0/1
N/A
1.417
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kew.api.peopleflow;
 17  
 
 18  
 import org.apache.commons.collections.CollectionUtils;
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.kuali.rice.core.api.CoreConstants;
 21  
 import org.kuali.rice.core.api.membership.MemberType;
 22  
 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
 23  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 24  
 import org.kuali.rice.core.api.mo.ModelObjectUtils;
 25  
 import org.kuali.rice.kew.api.action.ActionRequestPolicy;
 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.List;
 39  
 
 40  
 @XmlRootElement(name = PeopleFlowMember.Constants.ROOT_ELEMENT_NAME)
 41  
 @XmlAccessorType(XmlAccessType.NONE)
 42  
 @XmlType(name = PeopleFlowMember.Constants.TYPE_NAME, propOrder = {
 43  
         PeopleFlowMember.Elements.MEMBER_ID,
 44  
         PeopleFlowMember.Elements.MEMBER_TYPE,
 45  
         PeopleFlowMember.Elements.ACTION_REQUEST_POLICY,
 46  
         PeopleFlowMember.Elements.RESPONSIBILITY_ID,
 47  
         PeopleFlowMember.Elements.PRIORITY,
 48  
         PeopleFlowMember.Elements.DELEGATES,
 49  
         CoreConstants.CommonElements.FUTURE_ELEMENTS
 50  
 })
 51  12
 public final class PeopleFlowMember extends AbstractDataTransferObject implements PeopleFlowMemberContract {
 52  
 
 53  
     private static final int STARTING_PRIORITY = 1;
 54  
 
 55  
     @XmlElement(name = Elements.MEMBER_ID, required = true)
 56  
     private final String memberId;
 57  
 
 58  
     @XmlElement(name = Elements.MEMBER_TYPE, required = true)
 59  
     private final MemberType memberType;
 60  
 
 61  
     @XmlElement(name = Elements.ACTION_REQUEST_POLICY, required = false)
 62  
     private final ActionRequestPolicy actionRequestPolicy;
 63  
 
 64  
     @XmlElement(name = Elements.RESPONSIBILITY_ID, required = false)
 65  
     private final String responsibilityId;
 66  
 
 67  
     @XmlElement(name = Elements.PRIORITY, required = true)
 68  
     private final int priority;
 69  
 
 70  
     @XmlElementWrapper(name = Elements.DELEGATES, required = false)
 71  
     @XmlElement(name = Elements.DELEGATE, required = false)
 72  
     private final List<PeopleFlowDelegate> delegates;
 73  
 
 74  20
     @SuppressWarnings("unused")
 75  
     @XmlAnyElement
 76  
     private final Collection<Element> _futureElements = null;
 77  
 
 78  
     /**
 79  
      * Private constructor used only by JAXB.
 80  
      */
 81  8
     private PeopleFlowMember() {
 82  8
         this.memberId = null;
 83  8
         this.memberType = null;
 84  8
         this.actionRequestPolicy = null;
 85  8
         this.responsibilityId = null;
 86  8
         this.priority = STARTING_PRIORITY;
 87  8
         this.delegates = null;
 88  8
     }
 89  
 
 90  12
     private PeopleFlowMember(Builder builder) {
 91  12
         this.memberId = builder.getMemberId();
 92  12
         this.memberType = builder.getMemberType();
 93  12
         this.actionRequestPolicy = builder.getActionRequestPolicy();
 94  12
         this.responsibilityId = builder.getResponsibilityId();
 95  12
         this.priority = builder.getPriority();
 96  12
         this.delegates = ModelObjectUtils.buildImmutableCopy(builder.getDelegates());
 97  12
     }
 98  
 
 99  
     @Override
 100  
     public String getMemberId() {
 101  6
         return this.memberId;
 102  
     }
 103  
 
 104  
     @Override
 105  
     public MemberType getMemberType() {
 106  6
         return this.memberType;
 107  
     }
 108  
 
 109  
     @Override
 110  
     public ActionRequestPolicy getActionRequestPolicy() {
 111  3
         return this.actionRequestPolicy;
 112  
     }
 113  
 
 114  
     @Override
 115  
     public String getResponsibilityId() {
 116  3
         return this.responsibilityId;
 117  
     }
 118  
 
 119  
     @Override
 120  
     public int getPriority() {
 121  5
         return this.priority;
 122  
     }
 123  
 
 124  
     @Override
 125  
     public List<PeopleFlowDelegate> getDelegates() {
 126  11
         return this.delegates;
 127  
     }
 128  
 
 129  
     /**
 130  
      * A builder which can be used to construct {@link PeopleFlowMember} instances.  Enforces the constraints of the
 131  
      * {@link PeopleFlowMemberContract}.
 132  
      */
 133  12
     public final static class Builder implements Serializable, ModelBuilder, PeopleFlowMemberContract {
 134  
 
 135  
         private String memberId;
 136  
         private MemberType memberType;
 137  
         private ActionRequestPolicy actionRequestPolicy;
 138  
         private String responsibilityId;
 139  
         private int priority;
 140  
         private List<PeopleFlowDelegate.Builder> delegates;
 141  
 
 142  15
         private Builder(String memberId, MemberType memberType) {
 143  15
             setMemberId(memberId);
 144  14
             setMemberType(memberType);
 145  13
             setPriority(STARTING_PRIORITY);
 146  13
             setDelegates(new ArrayList<PeopleFlowDelegate.Builder>());
 147  13
         }
 148  
 
 149  
         public static Builder create(String memberId, MemberType memberType) {
 150  15
             return new Builder(memberId, memberType);
 151  
         }
 152  
 
 153  
         public static Builder create(PeopleFlowMemberContract contract) {
 154  3
             if (contract == null) {
 155  1
                 throw new IllegalArgumentException("contract was null");
 156  
             }
 157  2
             Builder builder = create(contract.getMemberId(), contract.getMemberType());
 158  2
             builder.setActionRequestPolicy(contract.getActionRequestPolicy());
 159  2
             builder.setResponsibilityId(contract.getResponsibilityId());
 160  2
             builder.setPriority(contract.getPriority());
 161  2
             if (CollectionUtils.isNotEmpty(contract.getDelegates())) {
 162  1
                 for (PeopleFlowDelegateContract delegate : contract.getDelegates()) {
 163  2
                     builder.getDelegates().add(PeopleFlowDelegate.Builder.create(delegate));
 164  
                 }
 165  
             }
 166  2
             return builder;
 167  
         }
 168  
 
 169  
         public PeopleFlowMember build() {
 170  12
             return new PeopleFlowMember(this);
 171  
         }
 172  
 
 173  
         @Override
 174  
         public String getMemberId() {
 175  13
             return this.memberId;
 176  
         }
 177  
 
 178  
         @Override
 179  
         public MemberType getMemberType() {
 180  13
             return this.memberType;
 181  
         }
 182  
 
 183  
         @Override
 184  
         public ActionRequestPolicy getActionRequestPolicy() {
 185  12
             return this.actionRequestPolicy;
 186  
         }
 187  
 
 188  
         @Override
 189  
         public String getResponsibilityId() {
 190  12
             return this.responsibilityId;
 191  
         }
 192  
 
 193  
         @Override
 194  
         public int getPriority() {
 195  13
             return this.priority;
 196  
         }
 197  
 
 198  
         @Override
 199  
         public List<PeopleFlowDelegate.Builder> getDelegates() {
 200  27
             return delegates;
 201  
         }
 202  
 
 203  
         public void setMemberId(String memberId) {
 204  15
             if (StringUtils.isBlank(memberId)) {
 205  1
                 throw new IllegalArgumentException("memberId was null or blank");
 206  
             }
 207  14
             this.memberId = memberId;
 208  14
         }
 209  
 
 210  
         public void setMemberType(MemberType memberType) {
 211  14
             if (memberType == null) {
 212  1
                 throw new IllegalArgumentException("memberType was null");
 213  
             }
 214  13
             this.memberType = memberType;
 215  13
         }
 216  
 
 217  
         public void setActionRequestPolicy(ActionRequestPolicy actionRequestPolicy) {
 218  4
             this.actionRequestPolicy = actionRequestPolicy;
 219  4
         }
 220  
 
 221  
         public void setResponsibilityId(String responsibilityId) {
 222  4
             this.responsibilityId = responsibilityId;
 223  4
         }
 224  
 
 225  
         public void setPriority(int priority) {
 226  21
             if (priority < STARTING_PRIORITY) {
 227  1
                 throw new IllegalArgumentException("Given priority was smaller than the minimum prior value of " + STARTING_PRIORITY);
 228  
             }
 229  20
             this.priority = priority;
 230  20
         }
 231  
 
 232  
         public void setDelegates(List<PeopleFlowDelegate.Builder> delegates) {
 233  13
             this.delegates = delegates;
 234  13
         }
 235  
     }
 236  
 
 237  
     /**
 238  
      * Defines some internal constants used on this class.
 239  
      */
 240  0
     static class Constants {
 241  
         final static String ROOT_ELEMENT_NAME = "peopleFlowMember";
 242  
         final static String TYPE_NAME = "PeopleFlowMemberType";
 243  
     }
 244  
 
 245  
     /**
 246  
      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
 247  
      */
 248  0
     static class Elements {
 249  
         final static String MEMBER_ID = "memberId";
 250  
         final static String MEMBER_TYPE = "memberType";
 251  
         final static String ACTION_REQUEST_POLICY = "actionRequestPolicy";
 252  
         final static String RESPONSIBILITY_ID = "responsibilityId";
 253  
         final static String PRIORITY = "priority";
 254  
         final static String DELEGATES = "delegates";
 255  
         final static String DELEGATE = "delegate";
 256  
     }
 257  
 
 258  
 }