001package org.kuali.ole.deliver.bo;
002
003
004import org.apache.commons.collections.CollectionUtils;
005import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
006import org.kuali.rice.core.api.mo.ModelBuilder;
007
008import javax.xml.bind.annotation.*;
009import java.io.Serializable;
010import java.util.ArrayList;
011import java.util.List;
012
013
014@XmlRootElement(name = OlePatronLoanDocuments.Constants.ROOT_ELEMENT_NAME)
015@XmlAccessorType(XmlAccessType.NONE)
016@XmlType(name = "PatronLoan", propOrder = {
017        OlePatronLoanDocuments.Elements.OLE_PATRON_LOAN_ITM
018})
019public class OlePatronLoanDocuments extends AbstractDataTransferObject implements OlePatronLoanDocumentsContract {
020
021    private static final long serialVersionUID = 1L;
022
023    @XmlElement(name = Elements.OLE_PATRON_LOAN_ITM, required = false)
024    private final List<OlePatronLoanDocument> olePatronLoanItem;
025
026
027    public OlePatronLoanDocuments() {
028        this.olePatronLoanItem = null;
029    }
030
031    public OlePatronLoanDocuments(Builder builder) {
032
033        this.olePatronLoanItem = new ArrayList<OlePatronLoanDocument>();
034        if (!CollectionUtils.isEmpty(builder.getOlePatronLoanDocuments())) {
035            for (OlePatronLoanDocument.Builder olePatronLoanDocument : builder.getOlePatronLoanDocuments()) {
036                this.olePatronLoanItem.add(olePatronLoanDocument.build());
037            }
038        }
039    }
040
041    /**
042     * This method converts the PersistableBusinessObjectBase OlePatronDocument into immutable object OlePatronDefinition
043     *
044     * @param bo
045     * @return OlePatronDefinition
046     */
047    public static OlePatronLoanDocument to(OleRenewalLoanDocument bo) {
048        if (bo == null) {
049            return null;
050        }
051        return OlePatronLoanDocument.Builder.create(bo).build();
052    }
053
054
055    @Override
056    public String getId() {
057        return null;
058    }
059
060    @Override
061    public Long getVersionNumber() {
062        return null;
063    }
064
065
066    @Override
067    public List<? extends OlePatronLoanDocumentContract> getOlePatronLoanDocuments() {
068        return olePatronLoanItem;
069    }
070
071    public static class Builder
072            implements Serializable, ModelBuilder, OlePatronLoanDocumentsContract {
073        private List<OlePatronLoanDocument.Builder> olePatronLoanDocuments;
074        private Long versionNumber;
075        private String objectId;
076
077        public void setVersionNumber(Long versionNumber) {
078            this.versionNumber = versionNumber;
079        }
080
081        public String getObjectId() {
082            return objectId;
083        }
084
085        public void setObjectId(String objectId) {
086            this.objectId = objectId;
087        }
088
089        private Builder() {
090        }
091
092        public static Builder create() {
093            return new Builder();
094        }
095
096        public static Builder create(OlePatronLoanDocumentsContract contract) {
097
098            if (contract == null) {
099                throw new IllegalArgumentException("contract was null");
100            }
101            Builder builder = create();
102
103            builder.olePatronLoanDocuments = new ArrayList<OlePatronLoanDocument.Builder>();
104            if (!CollectionUtils.isEmpty(contract.getOlePatronLoanDocuments())) {
105                for (OlePatronLoanDocumentContract olePatronLoanDocumentContract : contract.getOlePatronLoanDocuments()) {
106                    builder.olePatronLoanDocuments.add(OlePatronLoanDocument.Builder.create(olePatronLoanDocumentContract));
107                }
108            }
109
110            builder.setVersionNumber(contract.getVersionNumber());
111
112            //builder.setId(contract.getId());
113
114            return builder;
115        }
116
117
118        public OlePatronLoanDocuments build() {
119            return new OlePatronLoanDocuments(this);
120        }
121
122        @Override
123        public String getId() {
124            return null;
125        }
126
127        @Override
128        public Long getVersionNumber() {
129            return null;
130        }
131
132        @Override
133        public List<OlePatronLoanDocument.Builder> getOlePatronLoanDocuments() {
134            return olePatronLoanDocuments;
135        }
136
137        public void setOlePatronLoanDocuments(List<OlePatronLoanDocumentContract> OlePatronLoanDocumentContract) {
138            this.olePatronLoanDocuments = olePatronLoanDocuments;
139        }
140
141
142    }
143
144
145    static class Constants {
146
147        final static String ROOT_ELEMENT_NAME = "olePatronLoanItems";
148    }
149
150    static class Elements {
151        //final static String OLE_PATRON_LOAN_ITMS = "olePatronLoanItems";
152        final static String OLE_PATRON_LOAN_ITM = "olePatronLoanItem";
153
154    }
155
156}