src/main/kotlin/de/uapcore/lightpit/entities/Issue.kt

changeset 150
822b7e3d064d
child 167
3f30adba1c63
equal deleted inserted replaced
149:30b840ed8c0e 150:822b7e3d064d
1 /*
2 * Copyright 2020 Mike Becker. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 package de.uapcore.lightpit.entities
27
28 import java.sql.Date
29 import java.sql.Timestamp
30 import java.time.Instant
31 import kotlin.math.roundToInt
32
33 data class IssueStatusPhase(val number: Int) {
34 companion object {
35 val Open = IssueStatusPhase(0)
36 val WorkInProgress = IssueStatusPhase(1)
37 val Done = IssueStatusPhase(2)
38 }
39 }
40
41 enum class IssueStatus(val phase: IssueStatusPhase) {
42 InSpecification(IssueStatusPhase.Open),
43 ToDo(IssueStatusPhase.Open),
44 Scheduled(IssueStatusPhase.Open),
45 InProgress(IssueStatusPhase.WorkInProgress),
46 InReview(IssueStatusPhase.WorkInProgress),
47 Done(IssueStatusPhase.Done),
48 Rejected(IssueStatusPhase.Done),
49 Withdrawn(IssueStatusPhase.Done),
50 Duplicate(IssueStatusPhase.Done);
51 }
52
53 enum class IssueCategory {
54 Feature, Improvement, Bug, Task, Test
55 }
56
57 data class Issue(var id: Int) {
58
59 var project: Project? = null
60 var component: Component? = null
61
62 var status = IssueStatus.InSpecification
63 var category = IssueCategory.Feature
64
65 var subject: String? = null
66 var description: String? = null
67 var assignee: User? = null
68
69 var affectedVersions = emptyList<Version>()
70 var resolvedVersions = emptyList<Version>()
71
72 var created: Timestamp = Timestamp.from(Instant.now())
73 var updated: Timestamp = Timestamp.from(Instant.now())
74 var eta: Date? = null
75
76 /**
77 * An issue is overdue, if it is not done and the ETA is before the current time.
78 */
79 val overdue get() = status.phase != IssueStatusPhase.Done && eta?.before(Date(System.currentTimeMillis())) ?: false
80 }
81
82 class IssueSummary {
83 var open = 0
84 var active = 0
85 var done = 0
86
87 val total get() = open + active + done
88
89 val openPercent get() = 100 - activePercent - donePercent
90 val activePercent get() = if (total > 0) (100f * active / total).roundToInt() else 0
91 val donePercent get() = if (total > 0) (100f * done / total).roundToInt() else 100
92
93 /**
94 * Adds the specified issue to the summary by incrementing the respective counter.
95 * @param issue the issue
96 */
97 fun add(issue: Issue) {
98 when (issue.status.phase) {
99 IssueStatusPhase.Open -> open++
100 IssueStatusPhase.WorkInProgress -> active++
101 IssueStatusPhase.Done -> done++
102 }
103 }
104 }
105

mercurial