-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTask.bbj
222 lines (181 loc) · 7.75 KB
/
Task.bbj
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
REM /**
REM * Task.bbj
REM * @author gosteen, ndecker
REM *
REM */
REM package TaskApp
REM Test program that creates a task and prints out its details
declare auto Task t!
t! = new Task()
t!.setTitle("My first task")
t!.printDetails()
end
REM /**
REM * Defines the data structure for a task in the TaskApp
REM */
class public Task
REM Public Fields
REM ========================================
REM /** The title of the task. */
field public BBjString Title!
REM /** The description of the task. */
field public BBjString Description!
REM /** Boolean indicating whether the task is complete. */
field public BBjNumber Complete! = 0
REM /** Boolean indicating whether the task is deleted. */
field public BBjNumber Deleted! = 0
REM /** The priority of the task is a numeric that goes from 1 to 6, where 1 = highest priority and 6 = no priority. */
field public BBjNumber Priority!
REM /** The due date for the task as a Julian number.
REM * A value of -1 indicates an undefined due date.
REM */
field public BBjNumber DueDate!
REM Protected Fields
REM ========================================
REM /** The unique auto-generated ID for the task that may be used to distinguish between instances of the class. */
field protected BBjString Uuid!
REM /** The instant in time that the user created the task, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS) */
field protected BBjString Created!
REM Constants
REM ========================================
REM /** A constant value that represents the highest allowed priority */
method public static BBjNumber PRIORITY_HIGH()
methodret 1
methodend
REM /** A constant value that represents the lowest allowed priority */
method public static BBjNumber PRIORITY_LOW()
methodret 6
methodend
REM Constructors
REM ========================================
REM /**
REM * A Task item's constructor that sets all parameters to their default values.
REM */
method public Task()
#init()
methodend
REM /**
REM * A Task item's constructor that takes a JsonObject instead of individual parameters
REM *
REM * @param JsonObject json! The JSON representation of the Task object
REM */
method public Task(JsonObject json!)
#init()
if (json!.has("title")) then #Title! = json!.get("title").getAsString()
if (json!.has("description")) then #Description! = json!.get("description").getAsString()
if (json!.has("uuid")) then #Uuid! = json!.get("uuid").getAsString()
if (json!.has("priority")) then #Priority! = json!.get("priority").getAsInt()
if (json!.has("duedate")) then #DueDate! = json!.get("duedate").getAsInt()
if (json!.has("created")) then #Created! = json!.get("created").getAsString()
if (json!.has("complete")) then #Complete! = json!.get("complete").getAsInt()
REM Ensure that Priority is within allowed range
if (#Priority! < #PRIORITY_HIGH() or #Priority! > #PRIORITY_LOW()) then
#Priority! = #PRIORITY_LOW()
endif
methodend
REM /**
REM * Initializes a Task item and assigns defaults to its properties.
REM * This method is called by the other constructors to initialize all the properties.
REM */
method protected void init()
#Title! = ""
#Description! = ""
#Uuid! = java.util.UUID.randomUUID().toString()
#Priority! = Task.PRIORITY_LOW()
#Complete! = 0
#Deleted! = 0
#DueDate! = -1
#Created! = date(jul(date(0)), tim, "%Yz-%Mz-%DzT%hz:%mz")
methodend
REM Setters
REM ========================================
REM /**
REM * Sets the priority of the Task to the provided value
REM * @param BBjNumber priority! The task's priority
REM */
method public void setPriority(BBjNumber priority!)
if priority! < #PRIORITY_HIGH() then
priority! = #PRIORITY_HIGH()
endif
if priority! > #PRIORITY_LOW() then
priority! = #PRIORITY_LOW()
endif
#Priority! = priority!
methodend
REM Getters
REM ========================================
REM /**
REM * Gets the uuid of the Task as a BBjString
REM * @return BBjString The Task's uuid
REM */
method public BBjString getUuid()
methodret #Uuid!
methodend
REM Misc utility methods
REM ========================================
REM /**
REM * Prints the details of this Task object
REM */
method public void printDetails()
? "Title: ", #Title!
? "Description: ", #Description!
? "Complete: ", #Complete!
? "Priority: ", #Priority!
? "Due Date: ", #DueDate!
? "UUID: ", #Uuid!
? "Creation Timestamp: ", #Created!
?
? "getAsJsonObject(): "
? #getAsJsonObject()
?
? "getAsFormattedString(): "
? #getAsFormattedString()
methodend
REM /**
REM * Returns the Task object as a JSON object that may be serialized
REM * @return JsonObject A JsonObject version of the Task
REM */
method public JsonObject getAsJsonObject()
declare JsonObject json!
json! = new JsonObject()
json!.addProperty("uuid", #getUuid())
json!.addProperty("title", iff(#getTitle() <> null(), #getTitle(), ""))
json!.addProperty("description", iff(#getDescription() <> null(), #getDescription(), ""))
json!.addProperty("complete", iff(#getComplete() <> null(), str(#getComplete()), ""))
json!.addProperty("priority", iff(#getPriority() <> null(), str(#getPriority()), ""))
json!.addProperty("duedate", iff(#getDueDate() <> null(), str(#getDueDate()), ""))
json!.addProperty("created", #getCreated().toString())
methodret json!
methodend
REM /**
REM * Returns the Task object as a stringified JSON object that may be serialized
REM * @return BBjString A stringified JsonObject version of the Task
REM */
method public BBjString getAsString()
methodret #getAsJsonObject().toString()
methodend
REM /**
REM * Returns the Task object as a nicely-formatted stringified JSON object that may be serialized
REM * @return BBjString A stringified JsonObject version of the Task
REM */
method public BBjString getAsFormattedString()
declare auto TreeMap map!
json! = #getAsJsonObject()
if (json! = null()) then methodret ""
gson! = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create()
map! = gson!.fromJson(json!, TreeMap.class)
methodret gson!.toJson(map!)
methodend
classend
REM BBj USE Statements
use ::TaskListView.bbj::TaskListView
use ::Utils.bbj::Utils
REM Java USE Statements
use java.util.UUID; REM https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/UUID.html
use java.util.TreeMap; REM https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/TreeMap.html
use java.sql.Timestamp; REM https://docs.oracle.com/en/java/javase/17/docs/api/java.sql/java/sql/Timestamp.html
REM Google's Gson for JSON, which is included with BBj
use com.google.gson.Gson; REM https://javadoc.io/static/com.google.code.gson/gson/2.10.1/com.google.gson/com/google/gson/Gson.html
use com.google.gson.GsonBuilder; REM https://javadoc.io/doc/com.google.code.gson/gson/latest/com.google.gson/com/google/gson/GsonBuilder.html
use com.google.gson.JsonObject; REM https://javadoc.io/static/com.google.code.gson/gson/2.10.1/com.google.gson/com/google/gson/JsonObject.html
use com.google.gson.JsonArray; REM https://javadoc.io/static/com.google.code.gson/gson/2.10.1/com.google.gson/com/google/gson/JsonArray.html