001/**
002 * Copyright 2005-2014 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 */
016package org.kuali.rice.krms.api.repository.agenda;
017
018import java.io.Serializable;
019import java.util.Collection;
020
021import javax.xml.bind.annotation.XmlAccessType;
022import javax.xml.bind.annotation.XmlAccessorType;
023import javax.xml.bind.annotation.XmlAnyElement;
024import javax.xml.bind.annotation.XmlElement;
025import javax.xml.bind.annotation.XmlRootElement;
026import javax.xml.bind.annotation.XmlType;
027
028import org.apache.commons.lang.StringUtils;
029import org.kuali.rice.core.api.CoreConstants;
030import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
031import org.kuali.rice.core.api.mo.ModelBuilder;
032
033/**
034 * Concrete model object implementation of KRMS AgendaTreeRuleEntry
035 * immutable.
036 * Instances of AgendaTreeRuleEntry can be (un)marshalled to and from XML.
037 * 
038 * @author Kuali Rice Team (rice.collab@kuali.org)
039 *
040 */
041@XmlRootElement(name = AgendaTreeRuleEntry.Constants.ROOT_ELEMENT_NAME)
042@XmlAccessorType(XmlAccessType.NONE)
043@XmlType(name = AgendaTreeRuleEntry.Constants.TYPE_NAME, propOrder = {
044                AgendaTreeRuleEntry.Elements.AGENDA_ITEM_ID,
045                AgendaTreeRuleEntry.Elements.RULE_ID,
046                AgendaTreeRuleEntry.Elements.IF_TRUE,
047                AgendaTreeRuleEntry.Elements.IF_FALSE,
048                CoreConstants.CommonElements.FUTURE_ELEMENTS
049})
050public final class AgendaTreeRuleEntry extends AbstractDataTransferObject implements AgendaTreeEntryDefinitionContract {
051
052        private static final long serialVersionUID = 8594116503548506936L;
053
054        @XmlElement(name = Elements.AGENDA_ITEM_ID, required = true)
055        private final String agendaItemId;
056        
057        @XmlElement(name = Elements.RULE_ID, required = true)
058        private final String ruleId;
059        
060        @XmlElement(name = Elements.IF_TRUE, required = false)
061        private final AgendaTreeDefinition ifTrue;
062        
063        @XmlElement(name = Elements.IF_FALSE, required = false)
064        private final AgendaTreeDefinition ifFalse;
065                
066        @SuppressWarnings("unused")
067    @XmlAnyElement
068    private final Collection<org.w3c.dom.Element> _futureElements = null;
069
070    /**
071     * This constructor should never be called.
072     * It is only present for use during JAXB unmarshalling.
073     */
074        private AgendaTreeRuleEntry() {
075                this.agendaItemId = null;
076                this.ruleId = null;
077                this.ifTrue = null;
078                this.ifFalse = null;
079        }
080
081    /**
082     * Constructs a AgendaTreeRuleEntry from the given builder.
083     * This constructor is private and should only ever be invoked from the builder.
084     *
085     * @param builder the Builder from which to construct the AgendaTreeRuleEntry
086     */
087        private AgendaTreeRuleEntry(Builder builder) {
088                this.agendaItemId = builder.getAgendaItemId();
089                this.ruleId = builder.getRuleId();
090                this.ifTrue = builder.getIfTrue() == null ? null : builder.getIfTrue().build();
091                this.ifFalse = builder.getIfFalse() == null ? null : builder.getIfFalse().build();
092        }
093        
094        @Override
095        public String getAgendaItemId() {
096                return agendaItemId;
097        }
098
099    /**
100     * Returns the rule id.
101     * @return ruleId of the AgendaTreeRuleEntry
102     */
103        public String getRuleId() {
104                return this.ruleId;
105        }
106
107    /**
108     * Returns the AgendaTreeDefinition for ifTrue.
109     * @return {@link AgendaTreeDefinition} for ifTrue
110     */
111        public AgendaTreeDefinition getIfTrue() {
112                return this.ifTrue;
113        }
114
115    /**
116     * Returns the AgendaTreeDefinition for ifFalse.
117     * @return {@link AgendaTreeDefinition} for ifFalse
118     */
119        public AgendaTreeDefinition getIfFalse() {
120                return this.ifFalse;
121        }
122
123    /**
124     * This builder is used to construct instances of AgendaTreeRuleEntry.
125     * It enforces the constraints of the {@link AgendaTreeEntryDefinitionContract}.
126     */
127        public static class Builder implements AgendaTreeEntryDefinitionContract, Serializable {
128        
129                private static final long serialVersionUID = 3548736700798501429L;
130                
131                private String agendaItemId;
132                private String ruleId;
133                private AgendaTreeDefinition.Builder ifTrue;
134                private AgendaTreeDefinition.Builder ifFalse;
135
136                /**
137                 * Private constructor for creating a builder with all of it's required attributes.
138         *
139         * @param agendaItemId the agendaItemId value to set, must not be null or blank
140         * @param ruleId the propId value to set, must not be null or blank
141         */
142        private Builder(String agendaItemId, String ruleId) {
143                setAgendaItemId(agendaItemId);
144                setRuleId(ruleId);
145        }
146
147        /**
148         * Create a builder using the given values
149         *
150         * @param agendaItemId the agendaItemId value to set, must not be null or blank
151         * @param ruleId the propId value to set, must not be null or blank
152         * @return Builder with the given values set
153         */
154        public static Builder create(String agendaItemId, String ruleId){
155                return new Builder(agendaItemId, ruleId);
156        }
157        
158        @Override
159        public String getAgendaItemId() {
160                        return this.agendaItemId;
161                }
162
163        /**
164         * Returns the rule id.
165         * @return ruleId of the AgendaTreeRuleEntry
166         */
167                public String getRuleId() {
168                        return this.ruleId;
169                }
170
171        /**
172         * Returns the AgendaTreeDefinition.Builder for ifTrue.
173         * @return {@link AgendaTreeDefinition.Builder} for ifTrue
174         */
175                public AgendaTreeDefinition.Builder getIfTrue() {
176                        return this.ifTrue;
177                }
178
179        /**
180         * Returns the AgendaTreeDefinition.Builder for ifFalse.
181         * @return {@link AgendaTreeDefinition.Builder} for ifFalse
182         */
183                public AgendaTreeDefinition.Builder getIfFalse() {
184                        return this.ifFalse;
185                }
186
187        /**
188         * Sets the agendaItemId, cannot be null or blank.
189         * @param agendaItemId the agendaItemId value to set, must not be null or blank
190         * @throws IllegalArgumentException if agendaItemId is null or blank.
191         */
192                public void setAgendaItemId(String agendaItemId) {
193                        if (StringUtils.isBlank(agendaItemId)) {
194                                throw new IllegalArgumentException("agendaItemId was null or blank");
195                        }
196                        this.agendaItemId = agendaItemId;
197                }
198
199        /**
200         * @param ruleId the propId value to set, must not be null or blank
201         * @throws IllegalArgumentException if ruleId is null or blank.
202         */
203                public void setRuleId(String ruleId) {
204                        if (StringUtils.isBlank(ruleId)) {
205                                throw new IllegalArgumentException("ruleId was null or blank");
206                        }
207                        this.ruleId = ruleId;
208                }
209
210        /**
211         * Set the ifTrue {@link AgendaTreeDefinition.Builder}
212         * @param ifTrue {@link AgendaTreeDefinition.Builder} for ifTrue
213         */
214                public void setIfTrue(AgendaTreeDefinition.Builder ifTrue) {
215                        this.ifTrue = ifTrue;
216                }
217
218        /**
219         * Set the ifFalse {@link AgendaTreeDefinition.Builder}
220         * @param ifFalse {@link AgendaTreeDefinition.Builder} for ifFalse
221         */
222                public void setIfFalse(AgendaTreeDefinition.Builder ifFalse) {
223                        this.ifFalse = ifFalse;
224                }
225
226        /**
227         * Build the {@link AgendaTreeRuleEntry} with the builders values
228         * @return {@link AgendaTreeRuleEntry} with the builders values
229         */
230        public AgendaTreeRuleEntry build() {
231            return new AgendaTreeRuleEntry(this);
232        }
233                
234    }
235        
236        /**
237         * Defines some internal constants used on this class.
238         */
239        static class Constants {
240                final static String ROOT_ELEMENT_NAME = "agendaTreeRuleEntry";
241                final static String TYPE_NAME = "AgendaTreeRuleEntryType";
242        }
243        
244        /**
245         * A private class which exposes constants which define the XML element names to use
246         * when this object is marshalled to XML.
247         */
248        static class Elements {
249                final static String AGENDA_ITEM_ID = "agendaItemId";
250                final static String RULE_ID = "ruleId";
251                final static String IF_TRUE = "ifTrue";
252                final static String IF_FALSE = "ifFalse";
253        }
254
255}