View Javadoc

1   /**
2    * Copyright 2004-2014 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.kpme.tklm.time.timeblock.web;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.joda.time.LocalDate;
23  import org.kuali.kpme.core.service.HrServiceLocator;
24  import org.kuali.kpme.core.task.Task;
25  import org.kuali.kpme.core.util.HrConstants;
26  import org.kuali.kpme.core.workarea.WorkArea;
27  import org.kuali.kpme.tklm.api.time.timeblock.web.TimeBlockRendererContract;
28  import org.kuali.kpme.tklm.common.TkConstants;
29  import org.kuali.kpme.tklm.time.timeblock.TimeBlock;
30  import org.kuali.kpme.tklm.time.timehourdetail.TimeHourDetail;
31  import org.kuali.kpme.tklm.time.timehourdetail.TimeHourDetailRenderer;
32  
33  /**
34   * Render helper to handle timeblock and time hour details display
35   */
36  public class TimeBlockRenderer implements TimeBlockRendererContract {
37  
38      private TimeBlock timeBlock;
39      private List<TimeHourDetailRenderer> detailRenderers = new ArrayList<TimeHourDetailRenderer>();
40      private String assignmentClass;
41      private String lunchLabel;
42      private String lunchLabelId;
43  
44      public TimeBlockRenderer(TimeBlock b) {
45          this.timeBlock = b;
46          for (TimeHourDetail detail : timeBlock.getTimeHourDetails()) {
47              detailRenderers.add(new TimeHourDetailRenderer(detail));
48          }
49      }
50  
51      public List<TimeHourDetailRenderer> getDetailRenderers() {
52          return detailRenderers;
53      }
54  
55      public TimeBlock getTimeBlock() {
56          return timeBlock;
57      }
58  
59      public String getTimeRange() {
60          StringBuilder b = new StringBuilder();
61          if(StringUtils.equals(timeBlock.getEarnCodeType(), HrConstants.EARN_CODE_TIME)) {
62              b.append(timeBlock.getBeginTimeDisplay().toString(TkConstants.DT_BASIC_TIME_FORMAT));
63              b.append(" - ");
64              b.append(timeBlock.getEndTimeDisplay().toString(TkConstants.DT_BASIC_TIME_FORMAT));
65          }
66  
67          return b.toString();
68      }
69  
70      public String getTitle() {
71          StringBuilder b = new StringBuilder();
72  
73          WorkArea wa = HrServiceLocator.getWorkAreaService().getWorkAreaWithoutRoles(timeBlock.getWorkArea(), LocalDate.now());
74          if(wa != null) {
75          	b.append(wa.getDescription());
76          }
77          Task task = HrServiceLocator.getTaskService().getTask(timeBlock.getTask(), timeBlock.getBeginDateTime().toLocalDate());
78          if(task != null) {
79          	// do not display task description if the task is the default one
80          	// default task is created in getTask() of TaskService
81          	if(!task.getDescription().equals(HrConstants.TASK_DEFAULT_DESP)) {
82          		b.append("-" + task.getDescription());
83          	}
84          }
85          return b.toString();
86      }
87  
88      public String getAmount() {
89      	if(StringUtils.equals(timeBlock.getEarnCodeType(), HrConstants.EARN_CODE_AMOUNT)) {
90      		if(timeBlock.getAmount() != null) {
91      			return timeBlock.getEarnCode() + ": $" + timeBlock.getAmount().toString();
92      		} else {
93      			return timeBlock.getEarnCode() + ": $0.00";
94      		}
95  	    }
96      	return "";
97      }
98  
99      public String getEarnCodeType() {
100     	return timeBlock.getEarnCodeType();
101     }
102 
103 	public String getAssignmentClass() {
104 		return assignmentClass;
105 	}
106 
107 	public void setAssignmentClass(String assignmentClass) {
108 		this.assignmentClass = assignmentClass;
109 	}
110 
111 	public String getLunchLabel() {
112 		return lunchLabel;
113 	}
114 
115 	public void setLunchLabel(String lunchLabel) {
116 		this.lunchLabel = lunchLabel;
117 	}
118 
119     public String getLunchLabelId() {
120         return lunchLabelId;
121     }
122 
123     public void setLunchLabelId(String lunchLabelId) {
124         this.lunchLabelId = lunchLabelId;
125     }
126 }