001package org.kuali.kpme.edo.api.checklist;
002
003import java.io.Serializable;
004import java.util.Collection;
005import java.util.Collections;
006import java.util.List;
007import javax.xml.bind.annotation.XmlAccessType;
008import javax.xml.bind.annotation.XmlAccessorType;
009import javax.xml.bind.annotation.XmlAnyElement;
010import javax.xml.bind.annotation.XmlElement;
011import javax.xml.bind.annotation.XmlRootElement;
012import javax.xml.bind.annotation.XmlType;
013
014import org.apache.commons.collections.CollectionUtils;
015import org.kuali.rice.core.api.CoreConstants;
016import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
017import org.kuali.rice.core.api.mo.ModelBuilder;
018import org.kuali.rice.core.api.mo.ModelObjectUtils;
019import org.w3c.dom.Element;
020
021@XmlRootElement(name = EdoChecklistSection.Constants.ROOT_ELEMENT_NAME)
022@XmlAccessorType(XmlAccessType.NONE)
023@XmlType(name = EdoChecklistSection.Constants.TYPE_NAME, propOrder = {
024    EdoChecklistSection.Elements.CHECKLIST_ITEMS,
025    EdoChecklistSection.Elements.CHECKLIST_SECTION_ORDINAL,
026    EdoChecklistSection.Elements.EDO_CHECKLIST_SECTION_ID,
027    EdoChecklistSection.Elements.EDO_CHECKLIST_ID,
028    EdoChecklistSection.Elements.DESCRIPTION,
029    EdoChecklistSection.Elements.CHECKLIST_SECTION_NAME,
030    CoreConstants.CommonElements.VERSION_NUMBER,
031    CoreConstants.CommonElements.OBJECT_ID,
032    CoreConstants.CommonElements.FUTURE_ELEMENTS
033})
034public final class EdoChecklistSection
035    extends AbstractDataTransferObject
036    implements EdoChecklistSectionContract
037{
038
039    @XmlElement(name = Elements.CHECKLIST_ITEMS, required = false)
040    private final List<EdoChecklistItem> checklistItems;
041    @XmlElement(name = Elements.CHECKLIST_SECTION_ORDINAL, required = false)
042    private final int checklistSectionOrdinal;
043    @XmlElement(name = Elements.EDO_CHECKLIST_SECTION_ID, required = false)
044    private final String edoChecklistSectionId;
045    @XmlElement(name = Elements.EDO_CHECKLIST_ID, required = false)
046    private final String edoChecklistId;
047    @XmlElement(name = Elements.DESCRIPTION, required = false)
048    private final String description;
049    @XmlElement(name = Elements.CHECKLIST_SECTION_NAME, required = false)
050    private final String checklistSectionName;
051    @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
052    private final Long versionNumber;
053    @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
054    private final String objectId;
055    @SuppressWarnings("unused")
056    @XmlAnyElement
057    private final Collection<Element> _futureElements = null;
058
059    /**
060     * Private constructor used only by JAXB.
061     * 
062     */
063    private EdoChecklistSection() {
064        this.checklistItems = null;
065        this.checklistSectionOrdinal = 0;
066        this.edoChecklistSectionId = null;
067        this.edoChecklistId = null;
068        this.description = null;
069        this.checklistSectionName = null;
070        this.versionNumber = null;
071        this.objectId = null;
072    }
073
074    private EdoChecklistSection(Builder builder) {
075        this.checklistItems = ModelObjectUtils.<EdoChecklistItem>buildImmutableCopy(builder.getChecklistItems());
076        this.checklistSectionOrdinal = builder.getChecklistSectionOrdinal();
077        this.edoChecklistSectionId = builder.getEdoChecklistSectionId();
078        this.edoChecklistId = builder.getEdoChecklistId();
079        this.description = builder.getDescription();
080        this.checklistSectionName = builder.getChecklistSectionName();
081        this.versionNumber = builder.getVersionNumber();
082        this.objectId = builder.getObjectId();
083    }
084
085    @Override
086    public List<EdoChecklistItem> getChecklistItems() {
087        return this.checklistItems;
088    }
089
090    @Override
091    public int getChecklistSectionOrdinal() {
092        return this.checklistSectionOrdinal;
093    }
094
095    @Override
096    public String getEdoChecklistSectionId() {
097        return this.edoChecklistSectionId;
098    }
099
100    @Override
101    public String getEdoChecklistId() {
102        return this.edoChecklistId;
103    }
104
105    @Override
106    public String getDescription() {
107        return this.description;
108    }
109
110    @Override
111    public String getChecklistSectionName() {
112        return this.checklistSectionName;
113    }
114
115    @Override
116    public Long getVersionNumber() {
117        return this.versionNumber;
118    }
119
120    @Override
121    public String getObjectId() {
122        return this.objectId;
123    }
124
125
126    /**
127     * A builder which can be used to construct {@link EdoChecklistSection} instances.  Enforces the constraints of the {@link EdoChecklistSectionContract}.
128     * 
129     */
130    public final static class Builder
131        implements Serializable, EdoChecklistSectionContract, ModelBuilder
132    {
133
134        private List<EdoChecklistItem.Builder> checklistItems;
135        private int checklistSectionOrdinal;
136        private String edoChecklistSectionId;
137        private String edoChecklistId;
138        private String description;
139        private String checklistSectionName;
140        private Long versionNumber;
141        private String objectId;
142        private static final ModelObjectUtils.Transformer<EdoChecklistItemContract, EdoChecklistItem.Builder> toChecklistItemBuilder =
143                new ModelObjectUtils.Transformer<EdoChecklistItemContract, EdoChecklistItem.Builder>() {
144                    public EdoChecklistItem.Builder transform(EdoChecklistItemContract input) {
145                        return EdoChecklistItem.Builder.create(input);
146                    }
147                };
148
149        private Builder() {
150            // TODO modify this constructor as needed to pass any required values and invoke the appropriate 'setter' methods
151        }
152
153        public static Builder create() {
154            // TODO modify as needed to pass any required values and add them to the signature of the 'create' method
155            return new Builder();
156        }
157
158        public static Builder create(EdoChecklistSectionContract contract) {
159            if (contract == null) {
160                throw new IllegalArgumentException("contract was null");
161            }
162            // TODO if create() is modified to accept required parameters, this will need to be modified
163            Builder builder = create();
164            if (CollectionUtils.isEmpty(contract.getChecklistItems())) {
165                builder.setChecklistItems(Collections.<EdoChecklistItem.Builder>emptyList());
166            } else {
167                builder.setChecklistItems(ModelObjectUtils.transform(contract.getChecklistItems(), toChecklistItemBuilder));
168            }
169            builder.setChecklistSectionOrdinal(contract.getChecklistSectionOrdinal());
170            builder.setEdoChecklistSectionId(contract.getEdoChecklistSectionId());
171            builder.setEdoChecklistId(contract.getEdoChecklistId());
172            builder.setDescription(contract.getDescription());
173            builder.setChecklistSectionName(contract.getChecklistSectionName());
174            builder.setVersionNumber(contract.getVersionNumber());
175            builder.setObjectId(contract.getObjectId());
176            return builder;
177        }
178
179        public EdoChecklistSection build() {
180            return new EdoChecklistSection(this);
181        }
182
183        @Override
184        public List<EdoChecklistItem.Builder> getChecklistItems() {
185            return this.checklistItems;
186        }
187
188        @Override
189        public int getChecklistSectionOrdinal() {
190            return this.checklistSectionOrdinal;
191        }
192
193        @Override
194        public String getEdoChecklistSectionId() {
195            return this.edoChecklistSectionId;
196        }
197
198        @Override
199        public String getEdoChecklistId() {
200            return this.edoChecklistId;
201        }
202
203        @Override
204        public String getDescription() {
205            return this.description;
206        }
207
208        @Override
209        public String getChecklistSectionName() {
210            return this.checklistSectionName;
211        }
212
213        @Override
214        public Long getVersionNumber() {
215            return this.versionNumber;
216        }
217
218        @Override
219        public String getObjectId() {
220            return this.objectId;
221        }
222
223        public void setChecklistItems(List<EdoChecklistItem.Builder> checklistItems) {
224            // TODO add validation of input value if required and throw IllegalArgumentException if needed
225            this.checklistItems = checklistItems;
226        }
227
228        public void setChecklistSectionOrdinal(int checklistSectionOrdinal) {
229            // TODO add validation of input value if required and throw IllegalArgumentException if needed
230            this.checklistSectionOrdinal = checklistSectionOrdinal;
231        }
232
233        public void setEdoChecklistSectionId(String edoChecklistSectionId) {
234            // TODO add validation of input value if required and throw IllegalArgumentException if needed
235            this.edoChecklistSectionId = edoChecklistSectionId;
236        }
237
238        public void setEdoChecklistId(String edoChecklistId) {
239            // TODO add validation of input value if required and throw IllegalArgumentException if needed
240            this.edoChecklistId = edoChecklistId;
241        }
242
243        public void setDescription(String description) {
244            // TODO add validation of input value if required and throw IllegalArgumentException if needed
245            this.description = description;
246        }
247
248        public void setChecklistSectionName(String checklistSectionName) {
249            // TODO add validation of input value if required and throw IllegalArgumentException if needed
250            this.checklistSectionName = checklistSectionName;
251        }
252
253        public void setVersionNumber(Long versionNumber) {
254            // TODO add validation of input value if required and throw IllegalArgumentException if needed
255            this.versionNumber = versionNumber;
256        }
257
258        public void setObjectId(String objectId) {
259            // TODO add validation of input value if required and throw IllegalArgumentException if needed
260            this.objectId = objectId;
261        }
262
263    }
264
265
266    /**
267     * Defines some internal constants used on this class.
268     * 
269     */
270    static class Constants {
271
272        final static String ROOT_ELEMENT_NAME = "edoChecklistSection";
273        final static String TYPE_NAME = "EdoChecklistSectionType";
274
275    }
276
277
278    /**
279     * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
280     * 
281     */
282    static class Elements {
283
284        final static String CHECKLIST_ITEMS = "checklistItems";
285        final static String CHECKLIST_SECTION_ORDINAL = "checklistSectionOrdinal";
286        final static String EDO_CHECKLIST_SECTION_ID = "edoChecklistSectionId";
287        final static String EDO_CHECKLIST_ID = "edoChecklistId";
288        final static String DESCRIPTION = "description";
289        final static String CHECKLIST_SECTION_NAME = "checklistSectionName";
290
291    }
292
293}
294