Skip to content

Commit dd47fed

Browse files
change to use a GsonSingleton and added missing javadoc
1 parent b3d364f commit dd47fed

File tree

78 files changed

+308
-279
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+308
-279
lines changed

src/main/java/com/ibm/watson/developer_cloud/concept_expansion/v1/ConceptExpansion.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.ibm.watson.developer_cloud.concept_expansion.v1.model.Job.Status;
3636
import com.ibm.watson.developer_cloud.service.Request;
3737
import com.ibm.watson.developer_cloud.service.WatsonService;
38+
import com.ibm.watson.developer_cloud.util.GsonSingleton;
3839
import com.ibm.watson.developer_cloud.util.ResponseUtil;
3940

4041
/**
@@ -49,10 +50,13 @@
4950
*/
5051
public class ConceptExpansion extends WatsonService {
5152

53+
/** The Constant SEEDS. */
5254
public static final String SEEDS = "seeds";
5355

56+
/** The Constant DATASET. */
5457
public static final String DATASET = "dataset";
5558

59+
/** The Constant LABEL. */
5660
public static final String LABEL = "label";
5761

5862
/** The Constant PARAM_STATE. */
@@ -140,7 +144,7 @@ public Job createJob(final String label, final String[] seeds) {
140144

141145
HttpResponse response = execute(request);
142146
String jsonJob = ResponseUtil.getString(response);
143-
return getGson().fromJson(jsonJob,Job.class);
147+
return GsonSingleton.getGson().fromJson(jsonJob,Job.class);
144148
} catch (IOException e) {
145149
throw new RuntimeException(e);
146150
}

src/main/java/com/ibm/watson/developer_cloud/concept_expansion/v1/model/Concept.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package com.ibm.watson.developer_cloud.concept_expansion.v1.model;
1818

19-
import com.google.gson.GsonBuilder;
2019
import com.ibm.watson.developer_cloud.concept_expansion.v1.ConceptExpansion;
20+
import com.ibm.watson.developer_cloud.util.GsonSingleton;
2121

2222
/**
2323
* This class map a Concept returned by {@link ConceptExpansion}.
@@ -74,7 +74,7 @@ public Double getPrevalence() {
7474
@Override
7575
public String toString() {
7676
return getClass().getName() + " "
77-
+ new GsonBuilder().setPrettyPrinting().create().toJson(this);
77+
+ GsonSingleton.getGson().toJson(this);
7878
}
7979

8080
}

src/main/java/com/ibm/watson/developer_cloud/concept_expansion/v1/model/ConceptExpansionDataset.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616
package com.ibm.watson.developer_cloud.concept_expansion.v1.model;
1717

18-
import com.google.gson.GsonBuilder;
1918
import com.ibm.watson.developer_cloud.concept_expansion.v1.ConceptExpansion;
19+
import com.ibm.watson.developer_cloud.util.GsonSingleton;
2020

2121
/**
2222
* Dataset used by the {@link ConceptExpansion} service.
@@ -76,6 +76,6 @@ public String getName() {
7676
@Override
7777
public String toString() {
7878
return getClass().getName() + " "
79-
+ new GsonBuilder().setPrettyPrinting().create().toJson(this);
79+
+ GsonSingleton.getGson().toJson(this);
8080
}
8181
}

src/main/java/com/ibm/watson/developer_cloud/concept_expansion/v1/model/Job.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616
package com.ibm.watson.developer_cloud.concept_expansion.v1.model;
1717

18-
import com.google.gson.GsonBuilder;
1918
import com.google.gson.annotations.SerializedName;
2019
import com.ibm.watson.developer_cloud.concept_expansion.v1.ConceptExpansion;
20+
import com.ibm.watson.developer_cloud.util.GsonSingleton;
2121

2222
/**
2323
* Job created by the {@link ConceptExpansion} service. It contains and id and a
@@ -170,7 +170,7 @@ public void setStatus(Status status) {
170170
@Override
171171
public String toString() {
172172
return getClass().getName() + " "
173-
+ new GsonBuilder().setPrettyPrinting().create().toJson(this);
173+
+ GsonSingleton.getGson().toJson(this);
174174
}
175175

176176
}

src/main/java/com/ibm/watson/developer_cloud/dialog/v1/DialogService.java

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@
3131
import org.apache.http.entity.mime.content.FileBody;
3232
import org.apache.http.entity.mime.content.StringBody;
3333

34-
import com.google.gson.Gson;
3534
import com.google.gson.JsonObject;
3635
import com.google.gson.reflect.TypeToken;
3736
import com.ibm.watson.developer_cloud.dialog.v1.model.Conversation;
37+
import com.ibm.watson.developer_cloud.dialog.v1.model.ConversationData;
3838
import com.ibm.watson.developer_cloud.dialog.v1.model.Dialog;
3939
import com.ibm.watson.developer_cloud.dialog.v1.model.DialogContent;
4040
import com.ibm.watson.developer_cloud.dialog.v1.model.NameValue;
41-
import com.ibm.watson.developer_cloud.dialog.v1.model.ConversationData;
4241
import com.ibm.watson.developer_cloud.service.Request;
4342
import com.ibm.watson.developer_cloud.service.WatsonService;
43+
import com.ibm.watson.developer_cloud.util.GsonSingleton;
4444
import com.ibm.watson.developer_cloud.util.ResponseUtil;
4545

4646
/**
@@ -59,15 +59,31 @@
5959
*/
6060
public class DialogService extends WatsonService {
6161

62-
// parameters
62+
/** The Constant CLIENT_ID. */
6363
public static final String CLIENT_ID = "client_id";
64+
65+
/** The Constant CONVERSATION_ID. */
6466
public static final String CONVERSATION_ID = "conversation_id";
67+
68+
/** The Constant DIALOG_ID. */
6569
public static final String DIALOG_ID = "dialog_id";
70+
71+
/** The Constant INPUT. */
6672
public static final String INPUT = "input";
73+
74+
/** The Constant DATE_FROM. */
6775
public static final String DATE_FROM = "date_from";
76+
77+
/** The Constant DATE_TO. */
6878
public static final String DATE_TO = "date_to";
79+
80+
/** The Constant LIMIT. */
6981
public static final String LIMIT = "limit";
82+
83+
/** The Constant OFFSET. */
7084
public static final String OFFSET = "offset";
85+
86+
/** The Constant NAME_VALUES. */
7187
public static final String NAME_VALUES = "name_values";
7288

7389
/** The list dialog content type. */
@@ -83,35 +99,28 @@ public class DialogService extends WatsonService {
8399
/** The list conversation data type. */
84100
private static final Type listConversationDataType = new TypeToken<List<ConversationData>>() {}.getType();
85101

102+
/** The Constant log. */
86103
private static final Logger log = Logger.getLogger(DialogService.class.getName());
87104

105+
/** The Constant sdfDate. */
88106
private static final SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
89107

108+
/** The Constant URL. */
90109
private static final String URL = "https://gateway.watsonplatform.net/dialog-experimental/api";
91110

92111

93112
/**
94-
* Instantiates a new Dialog service with the default url
113+
* Instantiates a new Dialog service with the default url.
95114
*/
96115
public DialogService() {
97116
setEndPoint(URL);
98117
}
99118

100119
/**
101120
* Starts or continue conversations.
102-
*
103-
* @param dialog_id
104-
* Dialog identifier
105-
* @param client_id
106-
* A client id number generated by the Dialog service. If not
107-
* specified a new client id will be issued.
108-
* @param conversation_id
109-
* the conversation id. If not specified, a new conversation will
110-
* be started.
111-
* @param input
112-
* the user input message
121+
*
122+
* @param params the params
113123
* @return the {@link Conversation} with the response
114-
*
115124
*/
116125
public Conversation converse(final Map<String, Object> params) {
117126

@@ -142,7 +151,7 @@ public Conversation converse(final Map<String, Object> params) {
142151
try {
143152
HttpResponse response = execute(request);
144153
String conversationAsJson = ResponseUtil.getString(response);
145-
Conversation conversation = getGson().fromJson(conversationAsJson, Conversation.class);
154+
Conversation conversation = GsonSingleton.getGson().fromJson(conversationAsJson, Conversation.class);
146155
return conversation;
147156
} catch (IOException e) {
148157
throw new RuntimeException(e);
@@ -188,7 +197,7 @@ public Dialog createDialog(final String name, final File dialogFile) {
188197

189198
HttpResponse response = execute(request);
190199
String DialogAsJson = ResponseUtil.getString(response);
191-
Dialog dialog = getGson().fromJson(DialogAsJson, Dialog.class);
200+
Dialog dialog = GsonSingleton.getGson().fromJson(DialogAsJson, Dialog.class);
192201
return dialog;
193202
} catch (IOException e) {
194203
throw new RuntimeException(e);
@@ -229,7 +238,7 @@ public List<DialogContent> getContent(final String dialogId) {
229238
try {
230239
HttpResponse response = execute(request);
231240
JsonObject jsonObject = ResponseUtil.getJsonObject(response);
232-
List<DialogContent> content = new Gson().fromJson(
241+
List<DialogContent> content = GsonSingleton.getGson().fromJson(
233242
jsonObject.get("items"), listDialogContentType);
234243
return content;
235244
} catch (IOException e) {
@@ -248,7 +257,7 @@ public List<Dialog> getDialogs() {
248257
try {
249258
HttpResponse response = execute(request);
250259
JsonObject jsonObject = ResponseUtil.getJsonObject(response);
251-
List<Dialog> dialogs = new Gson().fromJson(
260+
List<Dialog> dialogs = GsonSingleton.getGson().fromJson(
252261
jsonObject.get("dialogs"), listDialogType);
253262
return dialogs;
254263
} catch (IOException e) {
@@ -280,7 +289,7 @@ public List<NameValue> getProfile(String dialogId, Integer clientId) {
280289
try {
281290
HttpResponse response = execute(request);
282291
JsonObject jsonObject = ResponseUtil.getJsonObject(response);
283-
List<NameValue> content = new Gson().fromJson(
292+
List<NameValue> content = GsonSingleton.getGson().fromJson(
284293
jsonObject.get(NAME_VALUES), listNameValueType);
285294
return content;
286295
} catch (IOException e) {
@@ -290,17 +299,8 @@ public List<NameValue> getProfile(String dialogId, Integer clientId) {
290299

291300
/**
292301
* Returns chat session data dump for a given date rage.
293-
*
294-
* @param dialog_id
295-
* the dialog identifier
296-
* @param date_from
297-
* Date from where to start the data dump
298-
* @param date_to
299-
* Date to where to end the data dump
300-
* @param offset
301-
* the offset from where to return conversations
302-
* @param limit
303-
* the number of conversations to return
302+
*
303+
* @param params the params
304304
* @return A list of {@link ConversationData}
305305
*/
306306
public List<ConversationData> getConversationData(final Map<String, Object> params) {
@@ -342,7 +342,7 @@ public List<ConversationData> getConversationData(final Map<String, Object> para
342342
try {
343343
HttpResponse response = execute(request);
344344
JsonObject jsonObject = ResponseUtil.getJsonObject(response);
345-
List<ConversationData> conversationDataList = new Gson().fromJson(
345+
List<ConversationData> conversationDataList = GsonSingleton.getGson().fromJson(
346346
jsonObject.get("conversations"), listConversationDataType);
347347
return conversationDataList;
348348
} catch (IOException e) {
@@ -393,7 +393,7 @@ public Dialog updateDialog(final String dialogId, final File dialogFile) {
393393
}
394394

395395
/**
396-
* Updates a dialog profile with a list of {@link NaveValue} properties.
396+
* Updates a dialog profile with a list of {@link NameValue} properties.
397397
* If clientId is not specified a new clientId is generated.
398398
* Profile variables are case sensitive.
399399
*
@@ -421,7 +421,7 @@ public void updateProfile(final String dialogId, final Integer clientId, final L
421421
JsonObject contentJson = new JsonObject();
422422

423423
contentJson.addProperty(CLIENT_ID, clientId);
424-
contentJson.add(NAME_VALUES, getGson().toJsonTree(nameValues));
424+
contentJson.add(NAME_VALUES, GsonSingleton.getGson().toJsonTree(nameValues));
425425

426426
HttpRequestBase request = Request
427427
.Put("/v1/dialogs/" + dialogId + "/profile")

src/main/java/com/ibm/watson/developer_cloud/dialog/v1/model/Conversation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
import java.util.ArrayList;
1919
import java.util.List;
2020

21-
import com.google.gson.GsonBuilder;
2221
import com.google.gson.annotations.SerializedName;
2322
import com.ibm.watson.developer_cloud.dialog.v1.DialogService;
23+
import com.ibm.watson.developer_cloud.util.GsonSingleton;
2424

2525
/**
2626
* Conversation used by the {@link DialogService}.
@@ -210,6 +210,6 @@ public Conversation withResponse(final List<String> response) {
210210
@Override
211211
public String toString() {
212212
return getClass().getName() + " "
213-
+ new GsonBuilder().setPrettyPrinting().create().toJson(this);
213+
+ GsonSingleton.getGson().toJson(this);
214214
}
215215
}

src/main/java/com/ibm/watson/developer_cloud/dialog/v1/model/ConversationData.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import java.util.ArrayList;
1919
import java.util.List;
2020

21-
import com.google.gson.GsonBuilder;
2221
import com.google.gson.annotations.SerializedName;
22+
import com.ibm.watson.developer_cloud.util.GsonSingleton;
2323

2424
/**
2525
* Conversation data stores information about a conversation.
@@ -216,6 +216,6 @@ public ConversationData withConversationId(final Integer conversationId) {
216216
@Override
217217
public String toString() {
218218
return getClass().getName() + " "
219-
+ new GsonBuilder().setPrettyPrinting().create().toJson(this);
219+
+ GsonSingleton.getGson().toJson(this);
220220
}
221221
}

src/main/java/com/ibm/watson/developer_cloud/dialog/v1/model/Dialog.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616
package com.ibm.watson.developer_cloud.dialog.v1.model;
1717

18-
import com.google.gson.GsonBuilder;
1918
import com.google.gson.annotations.SerializedName;
2019
import com.ibm.watson.developer_cloud.dialog.v1.DialogService;
20+
import com.ibm.watson.developer_cloud.util.GsonSingleton;
2121

2222
/**
2323
* Dialog used by the {@link DialogService}.
@@ -102,6 +102,6 @@ public Dialog withName(final String name) {
102102
@Override
103103
public String toString() {
104104
return getClass().getName() + " "
105-
+ new GsonBuilder().setPrettyPrinting().create().toJson(this);
105+
+ GsonSingleton.getGson().toJson(this);
106106
}
107107
}

src/main/java/com/ibm/watson/developer_cloud/dialog/v1/model/DialogContent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.ibm.watson.developer_cloud.dialog.v1.model;
22

3-
import com.google.gson.GsonBuilder;
43
import com.ibm.watson.developer_cloud.dialog.v1.DialogService;
4+
import com.ibm.watson.developer_cloud.util.GsonSingleton;
55

66
/**
77
* Dialog content used by the {@link DialogService}.
@@ -82,6 +82,6 @@ public DialogContent withContent(final String content) {
8282
@Override
8383
public String toString() {
8484
return getClass().getName() + " "
85-
+ new GsonBuilder().setPrettyPrinting().create().toJson(this);
85+
+ GsonSingleton.getGson().toJson(this);
8686
}
8787
}

src/main/java/com/ibm/watson/developer_cloud/dialog/v1/model/HitNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package com.ibm.watson.developer_cloud.dialog.v1.model;
1818

19-
import com.google.gson.GsonBuilder;
2019
import com.google.gson.annotations.SerializedName;
20+
import com.ibm.watson.developer_cloud.util.GsonSingleton;
2121

2222
/**
2323
* The Class HitNode.
@@ -171,6 +171,6 @@ public HitNode withNodeId(final int nodeId) {
171171
@Override
172172
public String toString() {
173173
return getClass().getName() + " "
174-
+ new GsonBuilder().setPrettyPrinting().create().toJson(this);
174+
+ GsonSingleton.getGson().toJson(this);
175175
}
176176
}

0 commit comments

Comments
 (0)