Search in sources :

Example 1 with Label

use of com.ibm.watson.compare_comply.v1.model.Label in project manifoldcf by apache.

the class ConfluenceClient method getPage.

/**
 * <p>
 * Get a Confluence page identified by its id
 * </p>
 *
 * @param pageId
 *          the page id
 * @return the Confluence page
 * @throws Exception
 */
public Page getPage(final String pageId) throws Exception {
    String url = String.format(Locale.ROOT, "%s://%s:%s%s%s/%s?%s", protocol, host, port, path, CONTENT_PATH, pageId, EXPANDABLE_PARAMETERS);
    url = sanitizeUrl(url);
    logger.debug("[Processing] Hitting url for getting document content : {}", url);
    final HttpGet httpGet = createGetRequest(url);
    try (CloseableHttpResponse response = executeRequest(httpGet)) {
        final HttpEntity entity = response.getEntity();
        final MutablePage page = pageFromHttpEntity(entity);
        EntityUtils.consume(entity);
        final List<Label> labels = getLabels(pageId);
        page.setLabels(labels);
        return page;
    } catch (final Exception e) {
        logger.error("[Processing] Failed to get page {}. Error: {}", url, e.getMessage());
        throw e;
    }
}
Also used : HttpEntity(org.apache.http.HttpEntity) MutablePage(org.apache.manifoldcf.crawler.connectors.confluence.v6.model.MutablePage) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Label(org.apache.manifoldcf.crawler.connectors.confluence.v6.model.Label) ManifoldCFException(org.apache.manifoldcf.core.interfaces.ManifoldCFException) ConfluenceException(org.apache.manifoldcf.crawler.connectors.confluence.v6.exception.ConfluenceException) IOException(java.io.IOException)

Example 2 with Label

use of com.ibm.watson.compare_comply.v1.model.Label in project java-sdk by watson-developer-cloud.

the class CompareComplyTest method testGetFeedbackWOptions.

@Test
public void testGetFeedbackWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"feedback_id\": \"feedbackId\", \"created\": \"2019-01-01T12:00:00.000Z\", \"comment\": \"comment\", \"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 getFeedbackPath = "/v1/feedback/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the GetFeedbackOptions model
    GetFeedbackOptions getFeedbackOptionsModel = new GetFeedbackOptions.Builder().feedbackId("testString").model("contracts").build();
    // Invoke operation with valid options model (positive test)
    Response<GetFeedback> response = compareComplyService.getFeedback(getFeedbackOptionsModel).execute();
    assertNotNull(response);
    GetFeedback responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "GET");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    // Get query params
    assertEquals(query.get("version"), "testString");
    assertEquals(query.get("model"), "contracts");
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getFeedbackPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetFeedback(com.ibm.watson.compare_comply.v1.model.GetFeedback) GetFeedbackOptions(com.ibm.watson.compare_comply.v1.model.GetFeedbackOptions) Test(org.testng.annotations.Test)

Example 3 with Label

use of com.ibm.watson.compare_comply.v1.model.Label in project java-sdk by watson-developer-cloud.

the class CompareComplyTest method testCompareDocumentsWOptions.

@Test
public void testCompareDocumentsWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"model_id\": \"modelId\", \"model_version\": \"modelVersion\", \"documents\": [{\"title\": \"title\", \"html\": \"html\", \"hash\": \"hash\", \"label\": \"label\"}], \"aligned_elements\": [{\"element_pair\": [{\"document_label\": \"documentLabel\", \"text\": \"text\", \"location\": {\"begin\": 5, \"end\": 3}, \"types\": [{\"label\": {\"nature\": \"nature\", \"party\": \"party\"}}], \"categories\": [{\"label\": \"Amendments\"}], \"attributes\": [{\"type\": \"Currency\", \"text\": \"text\", \"location\": {\"begin\": 5, \"end\": 3}}]}], \"identical_text\": false, \"provenance_ids\": [\"provenanceIds\"], \"significant_elements\": false}], \"unaligned_elements\": [{\"document_label\": \"documentLabel\", \"location\": {\"begin\": 5, \"end\": 3}, \"text\": \"text\", \"types\": [{\"label\": {\"nature\": \"nature\", \"party\": \"party\"}}], \"categories\": [{\"label\": \"Amendments\"}], \"attributes\": [{\"type\": \"Currency\", \"text\": \"text\", \"location\": {\"begin\": 5, \"end\": 3}}]}]}";
    String compareDocumentsPath = "/v1/comparison";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the CompareDocumentsOptions model
    CompareDocumentsOptions compareDocumentsOptionsModel = new CompareDocumentsOptions.Builder().file1(TestUtilities.createMockStream("This is a mock file.")).file2(TestUtilities.createMockStream("This is a mock file.")).file1ContentType("application/pdf").file2ContentType("application/pdf").file1Label("file_1").file2Label("file_2").model("contracts").build();
    // Invoke operation with valid options model (positive test)
    Response<CompareReturn> response = compareComplyService.compareDocuments(compareDocumentsOptionsModel).execute();
    assertNotNull(response);
    CompareReturn 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");
    assertEquals(query.get("file_1_label"), "file_1");
    assertEquals(query.get("file_2_label"), "file_2");
    assertEquals(query.get("model"), "contracts");
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, compareDocumentsPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) CompareDocumentsOptions(com.ibm.watson.compare_comply.v1.model.CompareDocumentsOptions) CompareReturn(com.ibm.watson.compare_comply.v1.model.CompareReturn) Test(org.testng.annotations.Test)

Example 4 with Label

use of com.ibm.watson.compare_comply.v1.model.Label 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);
}
Also used : GetFeedback(com.ibm.watson.compare_comply.v1.model.GetFeedback) Category(com.ibm.watson.compare_comply.v1.model.Category) FeedbackDataInput(com.ibm.watson.compare_comply.v1.model.FeedbackDataInput) Label(com.ibm.watson.compare_comply.v1.model.Label) TypeLabel(com.ibm.watson.compare_comply.v1.model.TypeLabel) ArrayList(java.util.ArrayList) FeedbackList(com.ibm.watson.compare_comply.v1.model.FeedbackList) ShortDoc(com.ibm.watson.compare_comply.v1.model.ShortDoc) OriginalLabelsIn(com.ibm.watson.compare_comply.v1.model.OriginalLabelsIn) GetFeedbackOptions(com.ibm.watson.compare_comply.v1.model.GetFeedbackOptions) FeedbackReturn(com.ibm.watson.compare_comply.v1.model.FeedbackReturn) TypeLabel(com.ibm.watson.compare_comply.v1.model.TypeLabel) AddFeedbackOptions(com.ibm.watson.compare_comply.v1.model.AddFeedbackOptions) UpdatedLabelsIn(com.ibm.watson.compare_comply.v1.model.UpdatedLabelsIn) DeleteFeedbackOptions(com.ibm.watson.compare_comply.v1.model.DeleteFeedbackOptions) Location(com.ibm.watson.compare_comply.v1.model.Location) Test(org.junit.Test)

Example 5 with Label

use of com.ibm.watson.compare_comply.v1.model.Label 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);
}
Also used : Category(com.ibm.watson.compare_comply.v1.model.Category) FeedbackDataInput(com.ibm.watson.compare_comply.v1.model.FeedbackDataInput) Label(com.ibm.watson.compare_comply.v1.model.Label) TypeLabel(com.ibm.watson.compare_comply.v1.model.TypeLabel) ShortDoc(com.ibm.watson.compare_comply.v1.model.ShortDoc) OriginalLabelsIn(com.ibm.watson.compare_comply.v1.model.OriginalLabelsIn) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) FeedbackReturn(com.ibm.watson.compare_comply.v1.model.FeedbackReturn) TypeLabel(com.ibm.watson.compare_comply.v1.model.TypeLabel) AddFeedbackOptions(com.ibm.watson.compare_comply.v1.model.AddFeedbackOptions) UpdatedLabelsIn(com.ibm.watson.compare_comply.v1.model.UpdatedLabelsIn) Location(com.ibm.watson.compare_comply.v1.model.Location) Test(org.testng.annotations.Test)

Aggregations

MockResponse (okhttp3.mockwebserver.MockResponse)5 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)5 Test (org.testng.annotations.Test)5 AddFeedbackOptions (com.ibm.watson.compare_comply.v1.model.AddFeedbackOptions)2 Category (com.ibm.watson.compare_comply.v1.model.Category)2 FeedbackDataInput (com.ibm.watson.compare_comply.v1.model.FeedbackDataInput)2 FeedbackList (com.ibm.watson.compare_comply.v1.model.FeedbackList)2 FeedbackReturn (com.ibm.watson.compare_comply.v1.model.FeedbackReturn)2 GetFeedback (com.ibm.watson.compare_comply.v1.model.GetFeedback)2 GetFeedbackOptions (com.ibm.watson.compare_comply.v1.model.GetFeedbackOptions)2 Label (com.ibm.watson.compare_comply.v1.model.Label)2 Location (com.ibm.watson.compare_comply.v1.model.Location)2 OriginalLabelsIn (com.ibm.watson.compare_comply.v1.model.OriginalLabelsIn)2 ShortDoc (com.ibm.watson.compare_comply.v1.model.ShortDoc)2 TypeLabel (com.ibm.watson.compare_comply.v1.model.TypeLabel)2 UpdatedLabelsIn (com.ibm.watson.compare_comply.v1.model.UpdatedLabelsIn)2 ClassifyElementsOptions (com.ibm.watson.compare_comply.v1.model.ClassifyElementsOptions)1 ClassifyReturn (com.ibm.watson.compare_comply.v1.model.ClassifyReturn)1 CompareDocumentsOptions (com.ibm.watson.compare_comply.v1.model.CompareDocumentsOptions)1 CompareReturn (com.ibm.watson.compare_comply.v1.model.CompareReturn)1