use of com.ibm.watson.compare_comply.v1.model.FeedbackReturn in project java-sdk by watson-developer-cloud.
the class CompareComplyServiceIT method testFeedbackOperations.
@Test
public void testFeedbackOperations() {
String userId = "lp_java";
String comment = "could be better";
String text = "1. IBM will provide a Senior Managing Consultant / expert resource, for up to 80 hours, to assist " + "Florida Power & Light (FPL) with the creation of an IT infrastructure unit cost model for existing " + "infrastructure.";
ShortDoc shortDoc = new ShortDoc.Builder().title("doc title").hash("").build();
Location location = new Location.Builder().begin(241).end(237).build();
OriginalLabelsIn.Builder originalLabelsInBuilder = new OriginalLabelsIn.Builder();
Label label1 = new Label.Builder().nature("Obligation").party("IBM").build();
List<String> ids1 = Arrays.asList("85f5981a-ba91-44f5-9efa-0bd22e64b7bc", "ce0480a1-5ef1-4c3e-9861-3743b5610795");
TypeLabel typeLabel1 = new TypeLabel.Builder().label(label1).provenanceIds(ids1).build();
Label label2 = new Label.Builder().nature("End User").party("Exclusion").build();
List<String> ids2 = Arrays.asList("85f5981a-ba91-44f5-9efa-0bd22e64b7bc", "ce0480a1-5ef1-4c3e-9861-3743b5610795");
TypeLabel typeLabel2 = new TypeLabel.Builder().label(label2).provenanceIds(ids2).build();
List<TypeLabel> types = Arrays.asList(typeLabel1, typeLabel2);
originalLabelsInBuilder.types(types);
Category category1 = new Category.Builder().label(Category.Label.RESPONSIBILITIES).provenanceIds(new ArrayList<String>()).build();
Category category2 = new Category.Builder().label(Category.Label.AMENDMENTS).provenanceIds(new ArrayList<String>()).build();
originalLabelsInBuilder.categories(Arrays.asList(category1, category2));
UpdatedLabelsIn.Builder updatedLabelsInBuilder = new UpdatedLabelsIn.Builder();
Label label3 = new Label.Builder().nature("Disclaimer").party("buyer").build();
TypeLabel typeLabel3 = new TypeLabel.Builder().label(label3).build();
updatedLabelsInBuilder.types(Arrays.asList(typeLabel1, typeLabel3));
updatedLabelsInBuilder.categories(Arrays.asList(category1, category2));
FeedbackDataInput feedbackDataInput = new FeedbackDataInput.Builder().document(shortDoc).location(location).text(text).originalLabels(originalLabelsInBuilder.build()).updatedLabels(updatedLabelsInBuilder.build()).feedbackType("element_classification").modelId("contracts").modelVersion("11.00").build();
AddFeedbackOptions addFeedbackOptions = new AddFeedbackOptions.Builder().userId(userId).comment(comment).feedbackData(feedbackDataInput).build();
FeedbackReturn feedbackReturn = service.addFeedback(addFeedbackOptions).execute().getResult();
String feedbackId = feedbackReturn.getFeedbackId();
GetFeedbackOptions getFeedbackOptions = new GetFeedbackOptions.Builder().feedbackId(feedbackId).build();
GetFeedback getFeedback = service.getFeedback(getFeedbackOptions).addHeader("x-watson-metadata", "customer_id=sdk-test-customer-id").execute().getResult();
assertEquals(text, getFeedback.getFeedbackData().getText());
DeleteFeedbackOptions deleteFeedbackOptions = new DeleteFeedbackOptions.Builder().feedbackId(feedbackId).build();
service.deleteFeedback(deleteFeedbackOptions).execute();
FeedbackList feedbackList = service.listFeedback().execute().getResult();
List<GetFeedback> allFeedback = feedbackList.getFeedback();
boolean successfullyDeleted = true;
for (GetFeedback feedback : allFeedback) {
if (feedback.getFeedbackId().equals(feedbackId)) {
successfullyDeleted = false;
break;
}
}
assertTrue(successfullyDeleted);
}
use of com.ibm.watson.compare_comply.v1.model.FeedbackReturn in project java-sdk by watson-developer-cloud.
the class CompareComplyTest method testAddFeedbackWOptions.
@Test
public void testAddFeedbackWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"feedback_id\": \"feedbackId\", \"user_id\": \"userId\", \"comment\": \"comment\", \"created\": \"2019-01-01T12:00:00.000Z\", \"feedback_data\": {\"feedback_type\": \"feedbackType\", \"document\": {\"title\": \"title\", \"hash\": \"hash\"}, \"model_id\": \"modelId\", \"model_version\": \"modelVersion\", \"location\": {\"begin\": 5, \"end\": 3}, \"text\": \"text\", \"original_labels\": {\"types\": [{\"label\": {\"nature\": \"nature\", \"party\": \"party\"}, \"provenance_ids\": [\"provenanceIds\"], \"modification\": \"added\"}], \"categories\": [{\"label\": \"Amendments\", \"provenance_ids\": [\"provenanceIds\"], \"modification\": \"added\"}]}, \"updated_labels\": {\"types\": [{\"label\": {\"nature\": \"nature\", \"party\": \"party\"}, \"provenance_ids\": [\"provenanceIds\"], \"modification\": \"added\"}], \"categories\": [{\"label\": \"Amendments\", \"provenance_ids\": [\"provenanceIds\"], \"modification\": \"added\"}]}, \"pagination\": {\"refresh_cursor\": \"refreshCursor\", \"next_cursor\": \"nextCursor\", \"refresh_url\": \"refreshUrl\", \"next_url\": \"nextUrl\", \"total\": 5}}}";
String addFeedbackPath = "/v1/feedback";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the ShortDoc model
ShortDoc shortDocModel = new ShortDoc.Builder().title("testString").hash("testString").build();
// Construct an instance of the Location model
Location locationModel = new Location.Builder().begin(Long.valueOf("26")).end(Long.valueOf("26")).build();
// Construct an instance of the Label model
Label labelModel = new Label.Builder().nature("testString").party("testString").build();
// Construct an instance of the TypeLabel model
TypeLabel typeLabelModel = new TypeLabel.Builder().label(labelModel).provenanceIds(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).modification("added").build();
// Construct an instance of the Category model
Category categoryModel = new Category.Builder().label("Amendments").provenanceIds(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).modification("added").build();
// Construct an instance of the OriginalLabelsIn model
OriginalLabelsIn originalLabelsInModel = new OriginalLabelsIn.Builder().types(new java.util.ArrayList<TypeLabel>(java.util.Arrays.asList(typeLabelModel))).categories(new java.util.ArrayList<Category>(java.util.Arrays.asList(categoryModel))).build();
// Construct an instance of the UpdatedLabelsIn model
UpdatedLabelsIn updatedLabelsInModel = new UpdatedLabelsIn.Builder().types(new java.util.ArrayList<TypeLabel>(java.util.Arrays.asList(typeLabelModel))).categories(new java.util.ArrayList<Category>(java.util.Arrays.asList(categoryModel))).build();
// Construct an instance of the FeedbackDataInput model
FeedbackDataInput feedbackDataInputModel = new FeedbackDataInput.Builder().feedbackType("testString").document(shortDocModel).modelId("testString").modelVersion("testString").location(locationModel).text("testString").originalLabels(originalLabelsInModel).updatedLabels(updatedLabelsInModel).build();
// Construct an instance of the AddFeedbackOptions model
AddFeedbackOptions addFeedbackOptionsModel = new AddFeedbackOptions.Builder().feedbackData(feedbackDataInputModel).userId("testString").comment("testString").build();
// Invoke operation with valid options model (positive test)
Response<FeedbackReturn> response = compareComplyService.addFeedback(addFeedbackOptionsModel).execute();
assertNotNull(response);
FeedbackReturn responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "POST");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
// Get query params
assertEquals(query.get("version"), "testString");
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, addFeedbackPath);
}
use of com.ibm.watson.compare_comply.v1.model.FeedbackReturn in project java-sdk by watson-developer-cloud.
the class CompareComply method addFeedback.
/**
* Add feedback.
*
* <p>Adds feedback in the form of _labels_ from a subject-matter expert (SME) to a governing
* document. **Important:** Feedback is not immediately incorporated into the training model, nor
* is it guaranteed to be incorporated at a later date. Instead, submitted feedback is used to
* suggest future updates to the training model.
*
* @param addFeedbackOptions the {@link AddFeedbackOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link FeedbackReturn}
*/
public ServiceCall<FeedbackReturn> addFeedback(AddFeedbackOptions addFeedbackOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(addFeedbackOptions, "addFeedbackOptions cannot be null");
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/feedback"));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("compare-comply", "v1", "addFeedback");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
builder.query("version", String.valueOf(this.version));
final JsonObject contentJson = new JsonObject();
contentJson.add("feedback_data", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(addFeedbackOptions.feedbackData()));
if (addFeedbackOptions.userId() != null) {
contentJson.addProperty("user_id", addFeedbackOptions.userId());
}
if (addFeedbackOptions.comment() != null) {
contentJson.addProperty("comment", addFeedbackOptions.comment());
}
builder.bodyJson(contentJson);
ResponseConverter<FeedbackReturn> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<FeedbackReturn>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations