Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public CreateEntity build() {
* Adds an values to values.
*
* @param values the new values
* @return the builder
*/
public Builder values(CreateValue values) {
if (this.values == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public CreateIntent build() {
* Adds an examples to examples.
*
* @param examples the new examples
* @return the builder
*/
public Builder examples(CreateExample examples) {
if (this.examples == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public CreateValue build() {
* Adds an synonyms to synonyms.
*
* @param synonyms the new synonyms
* @return the builder
*/
public Builder synonyms(String synonyms) {
if (this.synonyms == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public CreateWorkspace build() {
* Adds an intents to intents.
*
* @param intents the new intents
* @return the builder
*/
public Builder intents(CreateIntent intents) {
if (this.intents == null) {
Expand All @@ -97,6 +98,7 @@ public Builder intents(CreateIntent intents) {
* Adds an entities to entities.
*
* @param entities the new entities
* @return the builder
*/
public Builder entities(CreateEntity entities) {
if (this.entities == null) {
Expand All @@ -110,6 +112,7 @@ public Builder entities(CreateEntity entities) {
* Adds an dialogNodes to dialogNodes.
*
* @param dialogNodes the new dialogNodes
* @return the builder
*/
public Builder dialogNodes(CreateDialogNode dialogNodes) {
if (this.dialogNodes == null) {
Expand All @@ -123,6 +126,7 @@ public Builder dialogNodes(CreateDialogNode dialogNodes) {
* Adds an counterexamples to counterexamples.
*
* @param counterexamples the new counterexamples
* @return the builder
*/
public Builder counterexamples(CreateExample counterexamples) {
if (this.counterexamples == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
*/
package com.ibm.watson.developer_cloud.conversation.v1.model;

import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import com.ibm.watson.developer_cloud.conversation.v1.model.util.PaginationResponseTypeAdapter;
import com.ibm.watson.developer_cloud.service.model.GenericModel;

/**
* The pagination data for the returned objects.
*/
@JsonAdapter(PaginationResponseTypeAdapter.class)
public class PaginationResponse extends GenericModel {

/** The URL that will return the same page of results. */
Expand All @@ -31,6 +34,28 @@ public class PaginationResponse extends GenericModel {
/** Reserved for future use. */
private Long matched;

/** A token identifying the last value from the previous page of results. */
private String cursor;

/**
* Gets the cursor.
* A token identifying the last value from the previous page of results.
*
* @return the cursor
*/
public String getCursor() {
return cursor;
}

/**
* Sets the cursor.
*
* @param cursor the new cursor
*/
public void setCursor(String cursor) {
this.cursor = cursor;
}

/**
* Gets the refreshUrl.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public UpdateWorkspace build() {
* Adds an intents to intents.
*
* @param intents the new intents
* @return the builder
*/
public Builder intents(CreateIntent intents) {
if (this.intents == null) {
Expand All @@ -97,6 +98,7 @@ public Builder intents(CreateIntent intents) {
* Adds an entities to entities.
*
* @param entities the new entities
* @return the builder
*/
public Builder entities(CreateEntity entities) {
if (this.entities == null) {
Expand All @@ -110,6 +112,7 @@ public Builder entities(CreateEntity entities) {
* Adds an dialogNodes to dialogNodes.
*
* @param dialogNodes the new dialogNodes
* @return the builder
*/
public Builder dialogNodes(CreateDialogNode dialogNodes) {
if (this.dialogNodes == null) {
Expand All @@ -123,6 +126,7 @@ public Builder dialogNodes(CreateDialogNode dialogNodes) {
* Adds an counterexamples to counterexamples.
*
* @param counterexamples the new counterexamples
* @return the builder
*/
public Builder counterexamples(CreateExample counterexamples) {
if (this.counterexamples == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@
*/
public class WorkspaceExportResponse extends GenericModel {


/**
* Classifier Status.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be "Workspace Status".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😭

*/
public enum Status {

/** The available. */
@SerializedName("Available") AVAILABLE,

/** The failed. */
@SerializedName("Failed") FAILED,

/** The non existent. */
@SerializedName("Non Existent") NON_EXISTENT,

/** The training. */
@SerializedName("Training") TRAINING,

/** The unavailable. */
@SerializedName("Unavailable") UNAVAILABLE
}

/** The name of the workspace. */
private String name;
/** The description of the workspace. */
Expand All @@ -40,7 +62,7 @@ public class WorkspaceExportResponse extends GenericModel {
@SerializedName("workspace_id")
private String workspaceId;
/** The current status of the workspace (`Non Existent`, `Training`, `Failed`, `Available`, or `Unavailable`). */
private String status;
private Status status;
/** An array of intents. */
private List<IntentExportResponse> intents;
/** An array of entities. */
Expand Down Expand Up @@ -116,7 +138,7 @@ public String getWorkspaceId() {
*
* @return the status
*/
public String getStatus() {
public Status getStatus() {
return status;
}

Expand Down Expand Up @@ -215,7 +237,7 @@ public void setWorkspaceId(final String workspaceId) {
*
* @param status the new status
*/
public void setStatus(final String status) {
public void setStatus(final Status status) {
this.status = status;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright 2017 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.ibm.watson.developer_cloud.conversation.v1.model.util;

import java.io.IOException;

import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import com.ibm.watson.developer_cloud.conversation.v1.model.PaginationResponse;
import com.ibm.watson.developer_cloud.util.RequestUtils;

import okhttp3.HttpUrl;

/**
* Type adapter to transform JSON into a {@link PaginationResponse} and vice versa.
*/
public class PaginationResponseTypeAdapter extends TypeAdapter<PaginationResponse> {
private static final String MATCHED = "matched";
private static final String TOTAL = "total";
private static final String NEXT_URL = "next_url";
private static final String REFRESH_URL = "refresh_url";
private static final String CURSOR = "cursor";

/* (non-Javadoc)
* @see com.google.gson.TypeAdapter#write(com.google.gson.stream.JsonWriter, java.lang.Object)
*/
@Override
public void write(JsonWriter writer, PaginationResponse pagination) throws IOException {
writer.beginObject();
writer.name(REFRESH_URL).value(pagination.getRefreshUrl());
writer.name(NEXT_URL).value(pagination.getNextUrl());
writer.name(TOTAL).value(pagination.getTotal());
writer.name(MATCHED).value(pagination.getMatched());
writer.endObject();
writer.flush();
}

/* (non-Javadoc)
* @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
*/
@Override
public PaginationResponse read(JsonReader reader) throws IOException {
if (reader.peek() == JsonToken.NULL) {
reader.nextNull();
return null;
}
reader.beginObject();
PaginationResponse pagination = new PaginationResponse();
while (reader.hasNext()) {
String name = reader.nextName();
if (name.equals(REFRESH_URL)) {
pagination.setRefreshUrl(reader.nextString());
} else if (name.equals(NEXT_URL)) {
String nextUrl = reader.nextString();
HttpUrl url = HttpUrl.parse(RequestUtils.DEFAULT_ENDPOINT + nextUrl);
pagination.setCursor(url.queryParameter(CURSOR));
pagination.setNextUrl(nextUrl);
} else if (name.equals(TOTAL)) {
pagination.setTotal(reader.nextLong());
} else if (name.equals(MATCHED)) {
pagination.setMatched(reader.nextLong());
} else {
reader.skipValue();
}
}
reader.endObject();

return pagination;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void testDeleteCounterexample() {
service.deleteCounterexample(workspaceId, counterExampleText).execute();

try {
ExampleResponse response = service.getCounterexample(workspaceId, counterExampleText).execute();
service.getCounterexample(workspaceId, counterExampleText).execute();
fail("deleteCounterexample failed");
} catch (Exception ex) {
// Expected result
Expand Down Expand Up @@ -386,7 +386,7 @@ public void testDeleteExample() {
service.deleteExample(workspaceId, exampleIntent, exampleText).execute();

try {
ExampleResponse response = service.getExample(workspaceId, exampleIntent, exampleText).execute();
service.getExample(workspaceId, exampleIntent, exampleText).execute();
fail("deleteCounterexample failed");
} catch (Exception ex) {
// Expected result
Expand Down Expand Up @@ -587,7 +587,7 @@ public void testDeleteIntent() {
service.deleteIntent(workspaceId, intentName).execute();

try {
IntentExportResponse response = service.getIntent(workspaceId, intentName, false).execute();
service.getIntent(workspaceId, intentName, false).execute();
fail("deleteIntent failed");
} catch (Exception ex) {
// Expected result
Expand Down Expand Up @@ -931,7 +931,7 @@ public void testDeleteWorkspace() {

service.deleteWorkspace(workspaceId).execute();

WorkspaceExportResponse exResponse = service.getWorkspace(workspaceId, true).execute();
service.getWorkspace(workspaceId, true).execute();
} catch (Exception ex) {
// Expected result
assertTrue(ex instanceof NotFoundException);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2017 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.ibm.watson.developer_cloud.conversation.v1.model.util;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.io.FileNotFoundException;
import java.io.IOException;

import org.junit.Test;

import com.ibm.watson.developer_cloud.WatsonServiceUnitTest;
import com.ibm.watson.developer_cloud.conversation.v1.model.PaginationResponse;
import com.ibm.watson.developer_cloud.util.GsonSingleton;

/**
* The Class PaginationResponseTypeAdapterTest.
*/
public class PaginationResponseTypeAdapterTest extends WatsonServiceUnitTest {
private static final String FIXTURE = "src/test/resources/conversation/pagination.json";

/* (non-Javadoc)
* @see com.ibm.watson.developer_cloud.WatsonServiceUnitTest#setUp()
*/
@Override
public void setUp() throws Exception { }

/* (non-Javadoc)
* @see com.ibm.watson.developer_cloud.WatsonServiceUnitTest#tearDown()
*/
@Override
public void tearDown() throws IOException { }

/**
* Test parse type adapter.
*
* @throws FileNotFoundException the file not found exception
*/
@Test
public void testParseTypeAdapter() throws FileNotFoundException {
PaginationResponse pagination = loadFixture(FIXTURE, PaginationResponse.class);
assertEquals(pagination.getCursor(), "batman");
}

/**
* Test write type adapter.
*
* @throws FileNotFoundException the file not found exception
*/
@Test
public void testWriteTypeAdapter() throws FileNotFoundException {
PaginationResponse pagination = loadFixture(FIXTURE, PaginationResponse.class);
assertNotNull(GsonSingleton.getGson().toJson(pagination), pagination.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
"text": "I'd like to get insurance to for my home"
},
"context": {

},

"output": {
"text": ["Do you want to get a quote?"]
}
}
}
4 changes: 4 additions & 0 deletions conversation/src/test/resources/conversation/pagination.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"refresh_url": "/v1/workspaces/pizza_app-e0f3/counterexamples?version=2017-12-18&page_limit=2",
"next_url": "/v1/workspaces/pizza_app-e0f3/counterexamples?cursor=batman&version=2017-12-18&page_limit=2"
}
Loading