001    /*
002     * Copyright 2011 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.kfs.gl.businessobject;
017    
018    import java.sql.Date;
019    import java.util.Comparator;
020    import java.util.LinkedHashMap;
021    
022    import org.kuali.rice.kns.bo.PersistableBusinessObjectBase;
023    
024    public class OriginEntryGroup extends PersistableBusinessObjectBase {
025    
026        private static final String VALID_STRING = "Valid-";
027        private static final String INVALID_STRING = "Error-";
028        private static final String PROCESSED_STRING = "Process-";
029        private static final String NOT_PROCESSED_STRING = "Don't Process-";
030        private static final String SCRUB_STRING = "Scrub";
031        private static final String NO_SCRUB_STRING = "Don't Scrub";
032    
033        private Integer id;
034        private Date date;
035        private String sourceCode;
036        private Boolean valid;
037        private Boolean process;
038        private Boolean scrub;
039    
040        // This does not normally get populated. It only gets populated if
041        // getAllOriginEntryGroup() is called
042        private Integer rows = new Integer(0);
043    
044        private OriginEntrySource source;
045    
046        /**
047         * 
048         */
049        public OriginEntryGroup() {
050            super();
051        }
052    
053        protected LinkedHashMap toStringMapper() {
054            LinkedHashMap map = new LinkedHashMap();
055            map.put("id", id);
056            return map;
057        }
058    
059        public String getName() {
060            StringBuffer sb = new StringBuffer(this.getSourceCode());
061            sb.append(" ");
062            sb.append(source.getName());
063            sb.append(" (");
064            sb.append(rows);
065            sb.append(") ");
066            sb.append(this.getId());
067            sb.append(" ");
068            sb.append(this.getDate().toString());
069            sb.append(" ");
070            sb.append(valid ? VALID_STRING : INVALID_STRING);
071            sb.append(process ? PROCESSED_STRING : NOT_PROCESSED_STRING);
072            sb.append(scrub ? SCRUB_STRING : NO_SCRUB_STRING);
073            return sb.toString();
074        }
075    
076        public Integer getRows() {
077            return rows;
078        }
079    
080        public void setRows(Integer rows) {
081            this.rows = rows;
082        }
083    
084        public OriginEntrySource getSource() {
085            return source;
086        }
087    
088        public void setSource(OriginEntrySource oes) {
089            source = oes;
090        }
091    
092        public Date getDate() {
093            return date;
094        }
095    
096        public void setDate(Date date) {
097            this.date = date;
098        }
099    
100        public Integer getId() {
101            return id;
102        }
103    
104        public void setId(Integer id) {
105            this.id = id;
106        }
107    
108        public Boolean getProcess() {
109            return process;
110        }
111    
112        public void setProcess(Boolean process) {
113            this.process = process;
114        }
115    
116        public Boolean getScrub() {
117            return scrub;
118        }
119    
120        public void setScrub(Boolean scrub) {
121            this.scrub = scrub;
122        }
123    
124        public String getSourceCode() {
125            return sourceCode;
126        }
127    
128        public void setSourceCode(String sourceCode) {
129            this.sourceCode = sourceCode;
130        }
131    
132        public Boolean getValid() {
133            return valid;
134        }
135    
136        public void setValid(Boolean valid) {
137            this.valid = valid;
138        }
139        
140        /**
141         * An implementation of Comparator which compares origin entry groups by their source attribute
142         */
143        public static class GroupTypeComparator implements Comparator {
144            /**
145             * Constructs a GroupTypeComparator instance
146             */
147            public GroupTypeComparator() {
148            }
149    
150            /**
151             * Compares origin entry groups based on the alphabeticality of their source attributes
152             * 
153             * @param c1 the first origin entry group to compare
154             * @param c2 the origin entry group compared to
155             * @return a negative if c1's source is less than c2's, 0 if they are equal, a positive if c1's source is greater than c2's
156             * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
157             */
158            public int compare(Object c1, Object c2) {
159    
160                OriginEntryGroup oeg1 = (OriginEntryGroup) c1;
161                OriginEntryGroup oeg2 = (OriginEntryGroup) c2;
162    
163                String sort1 = oeg1.getSourceCode();
164                String sort2 = oeg2.getSourceCode();
165    
166                int c = sort1.compareTo(sort2);
167                if (c != 0) {
168                    return c;
169                }
170                return oeg1.getId().compareTo(oeg2.getId());
171            }
172        }
173    
174    }