BrightSide Workbench Full Report + Source Code
XMLTimeControlUtil.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2012 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.erp.time;
20 
21 import java.util.ArrayList;
22 import java.util.Date;
23 import java.util.Iterator;
24 import java.util.List;
25 import org.amic.util.date.CheckDate;
26 import org.turro.elephant.context.IConstructor;
27 
32 public class XMLTimeControlUtil {
33 
34  private XMLHumanResource humanResource;
35  private IConstructor constructor;
36 
37  public XMLTimeControlUtil(IConstructor constructor) {
38  this.constructor = constructor;
39  }
40 
42  return humanResource;
43  }
44 
45  public void setHumanResource(XMLHumanResource humanResource) {
46  this.humanResource = humanResource;
47  }
48 
49  public List<XMLTimeControl> getPendingControl() {
50  ArrayList<XMLTimeControl> list = new ArrayList<XMLTimeControl>();
51  if(humanResource != null) {
52  XMLTimeControlSet xtcs = new XMLTimeControlSet(constructor);
53  for(XMLTimeControl tc : xtcs) {
54  if(tc.getHumanResourceId() == humanResource.getId() && tc.getEndTime() == null) {
55  list.add(tc);
56  }
57  }
58  }
59  return list;
60  }
61 
62  public XMLTimeControl start() {
63  return start(null);
64  }
65 
66  public synchronized XMLTimeControl start(Date date) {
67  XMLTimeControl tc = new XMLTimeControl();
68  tc.setHumanResourceId(humanResource.getId());
69  if(date == null) {
70  tc.setStartTime(new Date());
71  } else {
72  tc.setStartTime(date);
73  }
74  XMLTimeControlSet xtcs = new XMLTimeControlSet(constructor);
75  xtcs.add(tc);
76  xtcs.saveCollection();
77  return tc;
78  }
79 
81  return end(tc, null);
82  }
83 
84  public synchronized XMLTimeControl end(XMLTimeControl tc, Date date) {
85  XMLTimeControlSet xtcs = new XMLTimeControlSet(constructor);
86  for(XMLTimeControl xtc : xtcs) {
87  if(xtc.getHumanResourceId() == tc.getHumanResourceId() &&
88  xtc.getStartTime().equals(tc.getStartTime())) {
89  if(date == null) {
90  xtc.setEndTime(new Date());
91  } else {
92  xtc.setEndTime(date);
93  }
94  xtcs.saveCollection();
95  return xtc;
96  }
97  }
98  return null;
99  }
100 
101  public List<XMLTimeControl> getFromDate(Date date) {
102  CheckDate d = new CheckDate(date);
103  ArrayList<XMLTimeControl> list = new ArrayList<XMLTimeControl>();
104  XMLTimeControlSet xtcs = new XMLTimeControlSet(constructor);
105  for(XMLTimeControl tc : xtcs) {
106  if(d.compareDayMonthYear(tc.getStartTime()) == 0 ||
107  (tc.getEndTime() != null && d.compareDayMonthYear(tc.getEndTime()) == 0)) {
108  list.add(tc);
109  }
110  }
111  return list;
112  }
113 
114  void deleteCompleted() {
115  XMLTimeControlSet xtcs = new XMLTimeControlSet(constructor);
116  xtcs.createCopy();
117  Iterator<XMLTimeControl> it = xtcs.iterator();
118  while(it.hasNext()) {
119  if(it.next().getEndTime() != null) {
120  it.remove();
121  }
122  }
123  xtcs.saveCollection();
124  }
125 
126 }
127 
List< XMLTimeControl > getPendingControl()
synchronized XMLTimeControl end(XMLTimeControl tc, Date date)
XMLTimeControlUtil(IConstructor constructor)
List< XMLTimeControl > getFromDate(Date date)
XMLTimeControl end(XMLTimeControl tc)
synchronized XMLTimeControl start(Date date)
void setHumanResource(XMLHumanResource humanResource)
void setHumanResourceId(long humanResourceId)