001 /** 002 * Copyright 2005-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.kew.api.peopleflow; 017 018 import org.apache.commons.lang.StringUtils; 019 import org.kuali.rice.core.api.CoreConstants; 020 import org.kuali.rice.core.api.delegation.DelegationType; 021 import org.kuali.rice.core.api.membership.MemberType; 022 import org.kuali.rice.core.api.mo.AbstractDataTransferObject; 023 import org.kuali.rice.core.api.mo.ModelBuilder; 024 import org.kuali.rice.kew.api.action.ActionRequestPolicy; 025 import org.w3c.dom.Element; 026 027 import javax.xml.bind.annotation.XmlAccessType; 028 import javax.xml.bind.annotation.XmlAccessorType; 029 import javax.xml.bind.annotation.XmlAnyElement; 030 import javax.xml.bind.annotation.XmlElement; 031 import javax.xml.bind.annotation.XmlRootElement; 032 import javax.xml.bind.annotation.XmlType; 033 import java.io.Serializable; 034 import java.util.Collection; 035 036 @XmlRootElement(name = PeopleFlowDelegate.Constants.ROOT_ELEMENT_NAME) 037 @XmlAccessorType(XmlAccessType.NONE) 038 @XmlType(name = PeopleFlowDelegate.Constants.TYPE_NAME, propOrder = { 039 PeopleFlowDelegate.Elements.MEMBER_ID, 040 PeopleFlowDelegate.Elements.MEMBER_TYPE, 041 PeopleFlowDelegate.Elements.ACTION_REQUEST_POLICY, 042 PeopleFlowDelegate.Elements.DELEGATION_TYPE, 043 PeopleFlowDelegate.Elements.RESPONSIBILITY_ID, 044 CoreConstants.CommonElements.FUTURE_ELEMENTS 045 }) 046 public final class PeopleFlowDelegate extends AbstractDataTransferObject implements PeopleFlowDelegateContract { 047 048 @XmlElement(name = Elements.MEMBER_ID, required = true) 049 private final String memberId; 050 051 @XmlElement(name = Elements.MEMBER_TYPE, required = true) 052 private final MemberType memberType; 053 054 @XmlElement(name = Elements.ACTION_REQUEST_POLICY, required = false) 055 private final ActionRequestPolicy actionRequestPolicy; 056 057 @XmlElement(name = Elements.DELEGATION_TYPE, required = true) 058 private final DelegationType delegationType; 059 060 @XmlElement(name = Elements.RESPONSIBILITY_ID, required = false) 061 private final String responsibilityId; 062 063 @SuppressWarnings("unused") 064 @XmlAnyElement 065 private final Collection<Element> _futureElements = null; 066 067 /** 068 * Private constructor used only by JAXB. 069 */ 070 @SuppressWarnings("unused") 071 private PeopleFlowDelegate() { 072 this.memberId = null; 073 this.memberType = null; 074 this.actionRequestPolicy = null; 075 this.delegationType = null; 076 this.responsibilityId = null; 077 } 078 079 private PeopleFlowDelegate(Builder builder) { 080 this.memberId = builder.getMemberId(); 081 this.memberType = builder.getMemberType(); 082 this.actionRequestPolicy = builder.getActionRequestPolicy(); 083 this.delegationType = builder.getDelegationType(); 084 this.responsibilityId = builder.getResponsibilityId(); 085 } 086 087 @Override 088 public String getMemberId() { 089 return this.memberId; 090 } 091 092 @Override 093 public MemberType getMemberType() { 094 return this.memberType; 095 } 096 097 @Override 098 public ActionRequestPolicy getActionRequestPolicy() { 099 return actionRequestPolicy; 100 } 101 102 @Override 103 public DelegationType getDelegationType() { 104 return this.delegationType; 105 } 106 107 @Override 108 public String getResponsibilityId() { 109 return responsibilityId; 110 } 111 112 /** 113 * A builder which can be used to construct {@link PeopleFlowDelegate} instances. Enforces the constraints of the 114 * {@link PeopleFlowDelegateContract}. 115 * 116 */ 117 public final static class Builder implements Serializable, ModelBuilder, PeopleFlowDelegateContract { 118 119 private String memberId; 120 private MemberType memberType; 121 private ActionRequestPolicy actionRequestPolicy; 122 private DelegationType delegationType; 123 private String responsibilityId; 124 125 private Builder(String memberId, MemberType memberType) { 126 setMemberId(memberId); 127 setMemberType(memberType); 128 setDelegationType(DelegationType.SECONDARY); 129 } 130 131 public static Builder create(String memberId, MemberType memberType) { 132 return new Builder(memberId, memberType); 133 } 134 135 public static Builder create(PeopleFlowDelegateContract contract) { 136 if (contract == null) { 137 throw new IllegalArgumentException("contract was null"); 138 } 139 Builder builder = create(contract.getMemberId(), contract.getMemberType()); 140 builder.setActionRequestPolicy(contract.getActionRequestPolicy()); 141 builder.setDelegationType(contract.getDelegationType()); 142 builder.setResponsibilityId(contract.getResponsibilityId()); 143 return builder; 144 } 145 146 public PeopleFlowDelegate build() { 147 return new PeopleFlowDelegate(this); 148 } 149 150 @Override 151 public String getMemberId() { 152 return this.memberId; 153 } 154 155 @Override 156 public MemberType getMemberType() { 157 return this.memberType; 158 } 159 160 @Override 161 public ActionRequestPolicy getActionRequestPolicy() { 162 return actionRequestPolicy; 163 } 164 165 @Override 166 public DelegationType getDelegationType() { 167 return this.delegationType; 168 } 169 170 @Override 171 public String getResponsibilityId() { 172 return responsibilityId; 173 } 174 175 public void setMemberId(String memberId) { 176 if (StringUtils.isBlank(memberId)) { 177 throw new IllegalArgumentException("memberId was a null or blank value"); 178 } 179 this.memberId = memberId; 180 } 181 182 public void setMemberType(MemberType memberType) { 183 if (memberType == null) { 184 throw new IllegalArgumentException("memberType was null"); 185 } 186 this.memberType = memberType; 187 } 188 189 public void setActionRequestPolicy(ActionRequestPolicy actionRequestPolicy) { 190 this.actionRequestPolicy = actionRequestPolicy; 191 } 192 193 public void setDelegationType(DelegationType delegationType) { 194 if (delegationType == null) { 195 throw new IllegalArgumentException("delegationType was null"); 196 } 197 this.delegationType = delegationType; 198 } 199 200 public void setResponsibilityId(String responsibilityId) { 201 this.responsibilityId = responsibilityId; 202 } 203 204 } 205 206 /** 207 * Defines some internal constants used on this class. 208 */ 209 static class Constants { 210 final static String ROOT_ELEMENT_NAME = "peopleFlowDelegate"; 211 final static String TYPE_NAME = "PeopleFlowDelegateType"; 212 } 213 214 /** 215 * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML. 216 */ 217 static class Elements { 218 final static String MEMBER_ID = "memberId"; 219 final static String MEMBER_TYPE = "memberType"; 220 final static String ACTION_REQUEST_POLICY = "actionRequestPolicy"; 221 final static String DELEGATION_TYPE = "delegationType"; 222 final static String RESPONSIBILITY_ID = "responsibilityId"; 223 } 224 225 }