View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.hr.time.timesummary;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.json.simple.JSONValue;
20  import org.kuali.hr.lm.leaveSummary.LeaveSummaryRow;
21  
22  import java.io.Serializable;
23  import java.math.BigDecimal;
24  import java.util.*;
25  
26  public class TimeSummary implements Serializable {
27  	private List<String> summaryHeader = new ArrayList<String>();
28  	private List<EarnGroupSection> sections = new ArrayList<EarnGroupSection>();
29  	private List<LeaveSummaryRow> maxedLeaveRows = new ArrayList<LeaveSummaryRow>();
30  	private List<BigDecimal> workedHours = new ArrayList<BigDecimal>();
31  
32  	public List<String> getSummaryHeader() {
33  		return summaryHeader;
34  	}
35  	public void setSummaryHeader(List<String> summaryHeader) {
36  		this.summaryHeader = summaryHeader;
37  	}
38  	public List<EarnGroupSection> getSections() {
39  		return sections;
40  	}
41  	public void setSections(List<EarnGroupSection> sections) {
42  		this.sections = sections;
43  	}
44  	public List<BigDecimal> getWorkedHours() {
45  		return workedHours;
46  	}
47  	public void setWorkedHours(List<BigDecimal> workedHours) {
48  		this.workedHours = workedHours;
49  	}
50  
51      public String toJsonString() {
52          List<Map<String, Object>> earnGroupSections = new ArrayList<Map<String, Object>>();
53  
54          //Lets add a fake EarnGroupSection for worked hours!!!
55          Map<String, Object> workedHours = new HashMap<String, Object>();
56          workedHours.put("totals", getWorkedHours());
57          workedHours.put("earnGroup", "Worked Hours");
58          workedHours.put("earnCodeSections", new HashMap<String, Object>());
59  
60          //Map<String, Object> workedHoursECS = new HashMap<String, Object>();
61          //workedHoursECS.put("earnCode", "");
62          ///workedHoursECS.put("desc", "Worked Hours");
63          //workedHoursECS.put("totals", getWorkedHours());
64          //workedHoursECS.put("isAmountEarnCode", earnCodeSection.getIsAmountEarnCode());
65  
66          for (EarnGroupSection earnGroupSection : this.sections) {
67              List<Map<String, Object>> earnCodeSections = new ArrayList<Map<String, Object>>();
68              Map<String, Object> egs = new TreeMap<String, Object>();
69              egs.put("earnGroup", earnGroupSection.getEarnGroup());
70              egs.put("totals", earnGroupSection.getTotals());
71  
72              for (EarnCodeSection earnCodeSection : earnGroupSection.getEarnCodeSections()) {
73                  Map<String, Object> ecs = new TreeMap<String, Object>();
74  
75                  ecs.put("earnCode", earnCodeSection.getEarnCode());
76                  ecs.put("desc", earnCodeSection.getDescription());
77                  ecs.put("totals", earnCodeSection.getTotals());
78                  ecs.put("isAmountEarnCode", earnCodeSection.getIsAmountEarnCode());
79  
80                  List<Map<String, Object>> assignmentRows = new ArrayList<Map<String, Object>>();
81                  for (AssignmentRow assignmentRow : earnCodeSection.getAssignmentsRows()) {
82                      Map<String, Object> ar = new TreeMap<String, Object>();
83  
84                      ar.put("descr", assignmentRow.getDescr());
85                      ar.put("assignmentKey", assignmentRow.getAssignmentKey());
86                      ar.put("cssClass", assignmentRow.getCssClass());
87                      ar.put("earnCode", earnCodeSection.getEarnCode());
88                      ecs.put("earnGroup", earnGroupSection.getEarnGroup());
89                      ecs.put("totals", earnGroupSection.getTotals());
90                      
91                      List<Map<String, Object>> assignmentColumns = new ArrayList<Map<String, Object>>();
92                      for (AssignmentColumn assignmentColumn : assignmentRow.getAssignmentColumns()) {
93                      	Map<String, Object> ac = new TreeMap<String, Object>();
94                      	
95                      	ac.put("cssClass", assignmentColumn.getCssClass());
96                      	ac.put("amount", assignmentColumn.getAmount());
97                      	ac.put("total", assignmentColumn.getTotal());
98                      	ac.put("isWeeklyTotal", assignmentColumn.isWeeklyTotal());
99                      	
100                     	assignmentColumns.add(ac);
101                     }
102                     ar.put("assignmentColumns", assignmentColumns);
103 
104                     assignmentRows.add(ar);
105                 }
106                 ecs.put("assignmentRows", assignmentRows);
107 
108                 earnCodeSections.add(ecs);
109             }
110             egs.put("earnCodeSections", earnCodeSections);
111             earnGroupSections.add(egs);
112         }
113         earnGroupSections.add(workedHours);
114 
115         return JSONValue.toJSONString(earnGroupSections);
116     }
117 	public List<LeaveSummaryRow> getMaxedLeaveRows() {
118 		return maxedLeaveRows;
119 	}
120 	public void setMaxedLeaveRows(List<LeaveSummaryRow> maxedLeaveRows) {
121 		this.maxedLeaveRows = maxedLeaveRows;
122 	}
123 
124 }