-
Notifications
You must be signed in to change notification settings - Fork 7
/
GiteaTask.java
154 lines (128 loc) · 4.15 KB
/
GiteaTask.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* Copyright © 2019 by elfuego.biz
*/
package biz.elfuego.idea.issues.gitea.model;
import biz.elfuego.idea.issues.gitea.util.Consts.TaskFields;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.apache.http.util.TextUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static biz.elfuego.idea.issues.gitea.util.Utils.*;
/**
* @author Roman Pedchenko <elfuego@elfuego.biz>
* @date 2018.06.30
*/
public class GiteaTask {
private String project;
private String id;
private String title;
private String description;
private Date createdAt;
private Date updatedAt;
private String state;
private GiteaUser assignee;
private List<GiteaUser> assignees;
public GiteaTask(String project, JsonObject json) throws Exception {
this.project = project;
this.fromJson(json);
}
public String getProject() {
return project;
}
@SuppressWarnings("unused")
public void setProject(String project) {
this.project = project;
}
public String getId() {
return id;
}
@SuppressWarnings("WeakerAccess")
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
@SuppressWarnings("WeakerAccess")
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
@SuppressWarnings("WeakerAccess")
public void setDescription(String description) {
this.description = description;
}
public Date getCreatedAt() {
return createdAt;
}
@SuppressWarnings("WeakerAccess")
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
@SuppressWarnings("WeakerAccess")
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
@SuppressWarnings("unused")
public GiteaUser getAssignee() {
return assignee;
}
@SuppressWarnings("WeakerAccess")
public void setAssignee(GiteaUser assignee) {
this.assignee = assignee;
}
public List<GiteaUser> getAssignees() {
return assignees;
}
public void setAssignees(List<GiteaUser> assignees) {
this.assignees = assignees;
}
public boolean isValid() {
return !(TextUtils.isEmpty(id) ||
TextUtils.isEmpty(title) ||
(createdAt == null) ||
(updatedAt == null) ||
TextUtils.isEmpty(state));
}
public boolean isAssignedTo(String login) {
if (assignee != null && assignee.getLogin().equals(login))
return true;
if (assignees != null)
for (GiteaUser u : assignees)
if (u.getLogin().equals(login))
return true;
return false;
}
private void fromJson(JsonObject current) throws Exception {
this.setId(getString(current, TaskFields.NUMBER, ""));
this.setTitle(getString(current, TaskFields.TITLE, ""));
this.setDescription(getString(current, TaskFields.DESCRIPTION, ""));
this.setCreatedAt(getDate(current, TaskFields.CREATEDAT));
this.setUpdatedAt(getDate(current, TaskFields.UPDATEDAT));
this.setState(getString(current, TaskFields.STATE, ""));
if (current.has(TaskFields.ASSIGNEE) && current.get(TaskFields.ASSIGNEE).isJsonObject())
this.setAssignee(new GiteaUser(getObject(current, TaskFields.ASSIGNEE)));
if (current.has(TaskFields.ASSIGNEES) && current.get(TaskFields.ASSIGNEES).isJsonArray()) {
JsonArray arr = getArray(current.get(TaskFields.ASSIGNEES));
List<GiteaUser> assignees1 = new ArrayList<>();
for (JsonElement el : arr)
if (el.isJsonObject())
assignees1.add(new GiteaUser(getObject(el)));
this.setAssignees(assignees1);
}
}
}