-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathPrintJob.java
More file actions
157 lines (141 loc) · 3.96 KB
/
PrintJob.java
File metadata and controls
157 lines (141 loc) · 3.96 KB
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
package com.printnode.api;
import com.google.gson.JsonObject;
import java.io.Serializable;
/**
* Object for a PrintJob.
* */
public class PrintJob implements Serializable {
/**
* The response body that made this PrintJob.
* */
private String json;
/**
* The ID of this PrintJob.
* */
private int id;
/**
* The Printer that relates to this PrintJob.
* */
private Printer printer;
/**
* The title of this PrintJob.
* */
private String title;
/**
* The Content type of this PrintJob.
* */
private String contentType;
/**
* The source of this PrintJob.
* */
private String source;
/**
* The time when this PrintJob will expire.
* */
private String expireAt;
/**
* The date of when this PrintJob was created.
* */
private String createTimestamp;
/**
* The state of this PrintJob.
* */
private String state;
/**
* Parses a JsonObject into PrintJob.
* Firstly, it begins iterating over the object.
* If the object we are converting is a solo JsonPrimitive, we map it directly to the variable.
* If the object we are converting is an array of JsonPrimitives,
* we firstly create an array of the same size as it.
* Then, iterate over it.
* If the object is a JsonObject with the same mappings each time, it is mapped to a HashMap.
* If the object is a JsonObject with different mappings, it is mapped to a Java Object.
* @param response JsonObject of the response.
* @see JsonObject
* @see com.google.gson.JsonArray
* @see com.google.gson.JsonPrimitive
* @see com.google.gson.JsonElement
* */
public PrintJob(final JsonObject response) {
if (!response.get("id").isJsonNull()) {
id = response.get("id").getAsInt();
}
if (!response.get("printer").isJsonNull()) {
printer = new Printer(response.get("printer").getAsJsonObject());
}
if (!response.get("title").isJsonNull()) {
title = response.get("title").getAsString();
}
if (!response.get("contentType").isJsonNull()) {
contentType = response.get("contentType").toString();
}
if (!response.get("source").isJsonNull()) {
source = response.get("source").getAsString();
}
if (!response.get("createTimestamp").isJsonNull()) {
createTimestamp = response.get("createTimestamp").getAsString();
}
if (!response.get("expireAt").isJsonNull()) {
expireAt = response.get("expireAt").getAsString();
}
if (!response.get("state").isJsonNull()) {
state = response.get("state").getAsString();
}
json = response.toString();
}
/**
* @return id of this PrintJob.
* */
public final int getId() {
return id;
}
/**
* @return Printer object relative to this PrintJob.
* @see Printer
* */
public final Printer getPrinter() {
return printer;
}
/**
* @return Title of this PrintJob.
* */
public final String getTitle() {
return title;
}
/**
* @return content type of this PrintJob.
* */
public final String getContentType() {
return contentType;
}
/**
* @return source of the PrintJob.
* */
public final String getSource() {
return source;
}
/**
* @return timestamp of when the PrintJob was created.
* */
public final String getCreateTimestamp() {
return createTimestamp;
}
/**
* @return time after timestamp when it expires.
* */
public final String getExpireAt() {
return expireAt;
}
/**
* @return state of the PrintJob.
* */
public final String getState() {
return state;
}
/**
* @return original response string.
* */
public final String toString() {
return json;
}
}