BrightSide Workbench Full Report + Source Code
TimeTracker.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2020 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.elephant.entities.db;
20 
21 import java.io.Serializable;
22 import java.time.Instant;
23 import java.time.LocalDateTime;
24 import java.time.ZoneId;
25 import java.time.ZonedDateTime;
26 import java.time.temporal.ChronoUnit;
27 import java.util.Date;
28 import javax.persistence.Entity;
29 import javax.persistence.Id;
30 import javax.persistence.IdClass;
31 import javax.persistence.Temporal;
32 import org.turro.string.Strings;
33 import org.turro.entities.Entities;
34 import org.turro.entities.IElephantEntity;
35 import org.turro.util.CompareUtil;
36 
41 @Entity
42 @IdClass(TimeTrackerPK.class)
43 public class TimeTracker implements Serializable, Comparable<TimeTracker> {
44 
45  @Id private String entityPath;
46  @Id private String trackedPath;
47 
48  @Temporal(value = javax.persistence.TemporalType.TIMESTAMP)
49  @Id private Date timeTrack;
50 
51  private TimeTrackerType trackType;
52 
53  private double hours;
54 
55  private boolean validated;
56 
57  public String getEntityPath() {
58  return entityPath;
59  }
60 
61  public void setEntityPath(String entityPath) {
62  this.entityPath = entityPath;
63  }
64 
65  public String getTrackedPath() {
66  return trackedPath;
67  }
68 
69  public void setTrackedPath(String trackedPath) {
70  this.trackedPath = trackedPath;
71  }
72 
73  public Date getTimeTrack() {
74  return timeTrack;
75  }
76 
77  public void setTimeTrack(Date timeTrack) {
78  this.timeTrack = timeTrack;
79  }
80 
82  return trackType;
83  }
84 
85  public void setTrackType(TimeTrackerType trackType) {
86  this.trackType = trackType;
87  }
88 
89  public double getHours() {
90  return hours;
91  }
92 
93  public void setHours(double hours) {
94  this.hours = hours;
95  }
96 
97  public boolean isValidated() {
98  return validated;
99  }
100 
101  public void setValidated(boolean validated) {
102  this.validated = validated;
103  }
104 
105  /* Helpers */
106 
107  public LocalDateTime getLocalDateTime() {
108  return LocalDateTime.from(timeTrack.toInstant().atZone(ZoneId.systemDefault()));
109  }
110 
111  public boolean isEmpty() {
112  return Strings.isBlank(entityPath) || timeTrack == null || trackType == null;
113  }
114 
115  public boolean isPreviousValid(TimeTracker previous) {
116  return previous == null || trackType.isPreviousValid(previous.getTrackType());
117  }
118 
119  public boolean isToday() {
120  return timeTrack.toInstant().truncatedTo(ChronoUnit.DAYS)
121  .equals(Instant.now().truncatedTo(ChronoUnit.DAYS));
122  }
123 
124  /* Entity */
125 
127  return Entities.getController(entityPath);
128  }
129 
131  return Entities.getController(trackedPath);
132  }
133 
134  /* Compare */
135 
136  @Override
137  public int compareTo(TimeTracker o) {
138  int result = CompareUtil.compare(entityPath, o.entityPath);
139  if(result == 0) {
140  result = CompareUtil.compare(trackedPath, o.trackedPath);
141  }
142  if(result == 0) {
143  result = CompareUtil.compare(timeTrack, o.timeTrack);
144  }
145  return result;
146  }
147 
148 }
void setTrackType(TimeTrackerType trackType)
boolean isPreviousValid(TimeTracker previous)
void setTrackedPath(String trackedPath)
static IElephantEntity getController(String path)
Definition: Entities.java:78
boolean isPreviousValid(TimeTrackerType previousType)