View Javadoc

1   /**
2    * Copyright 2004-2012 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.json.simple.JSONValue;
19  
20  import java.math.BigDecimal;
21  import java.util.ArrayList;
22  import java.util.HashMap;
23  import java.util.List;
24  import java.util.Map;
25  
26  public class TimeSummary {
27  	private List<String> summaryHeader = new ArrayList<String>();
28  	private List<EarnGroupSection> sections = new ArrayList<EarnGroupSection>();
29  	
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  
53          List<Map<String, Object>> earnCodeSections = new ArrayList<Map<String, Object>>();
54  
55          for (EarnGroupSection earnGroupSection : this.sections) {
56              for (EarnCodeSection earnCodeSection : earnGroupSection.getEarnCodeSections()) {
57                  Map<String, Object> ecs = new HashMap<String, Object>();
58  
59  
60                  ecs.put("earnCode", earnCodeSection.getEarnCode());
61                  ecs.put("desc", earnCodeSection.getDescription());
62                  ecs.put("totals", earnCodeSection.getTotals());
63                  ecs.put("isAmountEarnCode", earnCodeSection.getIsAmountEarnCode());
64  
65                  List<Map<String, Object>> assignmentRows = new ArrayList<Map<String, Object>>();
66                  for (AssignmentRow assignmentRow : earnCodeSection.getAssignmentsRows()) {
67  
68                      Map<String, Object> ar = new HashMap<String, Object>();
69  
70                      ar.put("assignmentKey", assignmentRow.getAssignmentKey());
71                      ar.put("descr", assignmentRow.getDescr());
72                      ar.put("cssClass", assignmentRow.getCssClass());
73                      ar.put("amount", assignmentRow.getAmount());
74                      ar.put("total", assignmentRow.getTotal());
75                      ar.put("amount", assignmentRow.getAmount());
76  
77                      assignmentRows.add(ar);
78                  }
79  
80                  ecs.put("assignmentRows", assignmentRows);
81                  ecs.put("earnGroup", earnGroupSection.getEarnGroup());
82                  ecs.put("totals", earnGroupSection.getTotals());
83  
84                  earnCodeSections.add(ecs);
85              }
86  
87          }
88  
89          return JSONValue.toJSONString(earnCodeSections);
90      }
91  
92  }