Skip to content

Commit 750a115

Browse files
feat(discov2): add methods for new batches api
1 parent 254428b commit 750a115

17 files changed

+1228
-11
lines changed

discovery/src/main/java/com/ibm/watson/discovery/v2/Discovery.java

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
import com.ibm.watson.discovery.v2.model.GetProjectOptions;
7373
import com.ibm.watson.discovery.v2.model.GetStopwordListOptions;
7474
import com.ibm.watson.discovery.v2.model.GetTrainingQueryOptions;
75+
import com.ibm.watson.discovery.v2.model.ListBatchesOptions;
76+
import com.ibm.watson.discovery.v2.model.ListBatchesResponse;
7577
import com.ibm.watson.discovery.v2.model.ListCollectionsOptions;
7678
import com.ibm.watson.discovery.v2.model.ListCollectionsResponse;
7779
import com.ibm.watson.discovery.v2.model.ListDocumentClassifierModelsOptions;
@@ -86,6 +88,9 @@
8688
import com.ibm.watson.discovery.v2.model.ListProjectsResponse;
8789
import com.ibm.watson.discovery.v2.model.ListTrainingQueriesOptions;
8890
import com.ibm.watson.discovery.v2.model.ProjectDetails;
91+
import com.ibm.watson.discovery.v2.model.PullBatchesOptions;
92+
import com.ibm.watson.discovery.v2.model.PullBatchesResponse;
93+
import com.ibm.watson.discovery.v2.model.PushBatchesOptions;
8994
import com.ibm.watson.discovery.v2.model.QueryCollectionNoticesOptions;
9095
import com.ibm.watson.discovery.v2.model.QueryNoticesOptions;
9196
import com.ibm.watson.discovery.v2.model.QueryNoticesResponse;
@@ -1794,6 +1799,129 @@ public ServiceCall<Void> deleteEnrichment(DeleteEnrichmentOptions deleteEnrichme
17941799
return createServiceCall(builder.build(), responseConverter);
17951800
}
17961801

1802+
/**
1803+
* List batches.
1804+
*
1805+
* <p>A batch is a set of documents that are ready for enrichment by an external application.
1806+
* After you apply a webhook enrichment to a collection, and then process or upload documents to
1807+
* the collection, Discovery creates a batch with a unique **batch_id**.
1808+
*
1809+
* <p>To start, you must register your external application as a **webhook** type by using the
1810+
* [Create enrichment API](/apidocs/discovery-data#createenrichment) method.
1811+
*
1812+
* <p>Use the List batches API to get the following:
1813+
*
1814+
* <p>* Notified batches that are not yet pulled by the external enrichment application.
1815+
*
1816+
* <p>* Batches that are pulled, but not yet pushed to Discovery by the external enrichment
1817+
* application.
1818+
*
1819+
* @param listBatchesOptions the {@link ListBatchesOptions} containing the options for the call
1820+
* @return a {@link ServiceCall} with a result of type {@link ListBatchesResponse}
1821+
*/
1822+
public ServiceCall<ListBatchesResponse> listBatches(ListBatchesOptions listBatchesOptions) {
1823+
com.ibm.cloud.sdk.core.util.Validator.notNull(
1824+
listBatchesOptions, "listBatchesOptions cannot be null");
1825+
Map<String, String> pathParamsMap = new HashMap<String, String>();
1826+
pathParamsMap.put("project_id", listBatchesOptions.projectId());
1827+
pathParamsMap.put("collection_id", listBatchesOptions.collectionId());
1828+
RequestBuilder builder =
1829+
RequestBuilder.get(
1830+
RequestBuilder.resolveRequestUrl(
1831+
getServiceUrl(),
1832+
"/v2/projects/{project_id}/collections/{collection_id}/batches",
1833+
pathParamsMap));
1834+
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "listBatches");
1835+
for (Entry<String, String> header : sdkHeaders.entrySet()) {
1836+
builder.header(header.getKey(), header.getValue());
1837+
}
1838+
builder.header("Accept", "application/json");
1839+
builder.query("version", String.valueOf(this.version));
1840+
ResponseConverter<ListBatchesResponse> responseConverter =
1841+
ResponseConverterUtils.getValue(
1842+
new com.google.gson.reflect.TypeToken<ListBatchesResponse>() {}.getType());
1843+
return createServiceCall(builder.build(), responseConverter);
1844+
}
1845+
1846+
/**
1847+
* Pull batches.
1848+
*
1849+
* <p>Pull a batch of documents from Discovery for enrichment by an external application. Ensure
1850+
* to include the `Accept-Encoding: gzip` header in this method to get the file. You can also
1851+
* implement retry logic when calling this method to avoid any network errors.
1852+
*
1853+
* @param pullBatchesOptions the {@link PullBatchesOptions} containing the options for the call
1854+
* @return a {@link ServiceCall} with a result of type {@link PullBatchesResponse}
1855+
*/
1856+
public ServiceCall<PullBatchesResponse> pullBatches(PullBatchesOptions pullBatchesOptions) {
1857+
com.ibm.cloud.sdk.core.util.Validator.notNull(
1858+
pullBatchesOptions, "pullBatchesOptions cannot be null");
1859+
Map<String, String> pathParamsMap = new HashMap<String, String>();
1860+
pathParamsMap.put("project_id", pullBatchesOptions.projectId());
1861+
pathParamsMap.put("collection_id", pullBatchesOptions.collectionId());
1862+
pathParamsMap.put("batch_id", pullBatchesOptions.batchId());
1863+
RequestBuilder builder =
1864+
RequestBuilder.get(
1865+
RequestBuilder.resolveRequestUrl(
1866+
getServiceUrl(),
1867+
"/v2/projects/{project_id}/collections/{collection_id}/batches/{batch_id}",
1868+
pathParamsMap));
1869+
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "pullBatches");
1870+
for (Entry<String, String> header : sdkHeaders.entrySet()) {
1871+
builder.header(header.getKey(), header.getValue());
1872+
}
1873+
builder.header("Accept", "application/json");
1874+
builder.query("version", String.valueOf(this.version));
1875+
ResponseConverter<PullBatchesResponse> responseConverter =
1876+
ResponseConverterUtils.getValue(
1877+
new com.google.gson.reflect.TypeToken<PullBatchesResponse>() {}.getType());
1878+
return createServiceCall(builder.build(), responseConverter);
1879+
}
1880+
1881+
/**
1882+
* Push batches.
1883+
*
1884+
* <p>Push a batch of documents to Discovery after annotation by an external application. You can
1885+
* implement retry logic when calling this method to avoid any network errors.
1886+
*
1887+
* @param pushBatchesOptions the {@link PushBatchesOptions} containing the options for the call
1888+
* @return a {@link ServiceCall} with a result of type {@link Boolean}
1889+
*/
1890+
public ServiceCall<Boolean> pushBatches(PushBatchesOptions pushBatchesOptions) {
1891+
com.ibm.cloud.sdk.core.util.Validator.notNull(
1892+
pushBatchesOptions, "pushBatchesOptions cannot be null");
1893+
com.ibm.cloud.sdk.core.util.Validator.isTrue(
1894+
(pushBatchesOptions.file() != null), "At least one of or file must be supplied.");
1895+
Map<String, String> pathParamsMap = new HashMap<String, String>();
1896+
pathParamsMap.put("project_id", pushBatchesOptions.projectId());
1897+
pathParamsMap.put("collection_id", pushBatchesOptions.collectionId());
1898+
pathParamsMap.put("batch_id", pushBatchesOptions.batchId());
1899+
RequestBuilder builder =
1900+
RequestBuilder.post(
1901+
RequestBuilder.resolveRequestUrl(
1902+
getServiceUrl(),
1903+
"/v2/projects/{project_id}/collections/{collection_id}/batches/{batch_id}",
1904+
pathParamsMap));
1905+
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "pushBatches");
1906+
for (Entry<String, String> header : sdkHeaders.entrySet()) {
1907+
builder.header(header.getKey(), header.getValue());
1908+
}
1909+
builder.header("Accept", "application/json");
1910+
builder.query("version", String.valueOf(this.version));
1911+
MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
1912+
multipartBuilder.setType(MultipartBody.FORM);
1913+
if (pushBatchesOptions.file() != null) {
1914+
okhttp3.RequestBody fileBody =
1915+
RequestUtils.inputStreamBody(pushBatchesOptions.file(), "application/octet-stream");
1916+
multipartBuilder.addFormDataPart("file", pushBatchesOptions.filename(), fileBody);
1917+
}
1918+
builder.body(multipartBuilder.build());
1919+
ResponseConverter<Boolean> responseConverter =
1920+
ResponseConverterUtils.getValue(
1921+
new com.google.gson.reflect.TypeToken<Boolean>() {}.getType());
1922+
return createServiceCall(builder.build(), responseConverter);
1923+
}
1924+
17971925
/**
17981926
* List document classifiers.
17991927
*
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* (C) Copyright IBM Corp. 2024.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package com.ibm.watson.discovery.v2.model;
14+
15+
import com.google.gson.annotations.SerializedName;
16+
import com.ibm.cloud.sdk.core.service.model.GenericModel;
17+
import java.util.Date;
18+
19+
/**
20+
* A batch is a set of documents that are ready for enrichment by an external application. After you
21+
* apply a webhook enrichment to a collection, and then process or upload documents to the
22+
* collection, Discovery creates a batch with a unique **batch_id**.
23+
*/
24+
public class BatchDetails extends GenericModel {
25+
26+
@SerializedName("batch_id")
27+
protected String batchId;
28+
29+
protected Date created;
30+
31+
@SerializedName("enrichment_id")
32+
protected String enrichmentId;
33+
34+
protected BatchDetails() {}
35+
36+
/**
37+
* Gets the batchId.
38+
*
39+
* <p>The Universally Unique Identifier (UUID) for a batch of documents.
40+
*
41+
* @return the batchId
42+
*/
43+
public String getBatchId() {
44+
return batchId;
45+
}
46+
47+
/**
48+
* Gets the created.
49+
*
50+
* <p>The date and time (RFC3339) that the batch was created.
51+
*
52+
* @return the created
53+
*/
54+
public Date getCreated() {
55+
return created;
56+
}
57+
58+
/**
59+
* Gets the enrichmentId.
60+
*
61+
* <p>The Universally Unique Identifier (UUID) for the external enrichment.
62+
*
63+
* @return the enrichmentId
64+
*/
65+
public String getEnrichmentId() {
66+
return enrichmentId;
67+
}
68+
}

discovery/src/main/java/com/ibm/watson/discovery/v2/model/CreateEnrichment.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ public class CreateEnrichment extends GenericModel {
4444
* <p>* `watson_knowledge_studio_model`: Creates an enrichment from a Watson Knowledge Studio
4545
* machine learning model that is defined in a ZIP file.
4646
*
47-
* <p>* `webhook`: Connects to an external enrichment application by using a webhook. The feature
48-
* is available from IBM Cloud-managed instances only. The external enrichment feature is beta
49-
* functionality. Beta features are not supported by the SDKs.
47+
* <p>* `webhook`: Connects to an external enrichment application by using a webhook.
5048
*
5149
* <p>* `sentence_classifier`: Use sentence classifier to classify sentences in your documents.
5250
* This feature is available in IBM Cloud-managed instances only. The sentence classifier feature
@@ -221,9 +219,7 @@ public String description() {
221219
* <p>* `watson_knowledge_studio_model`: Creates an enrichment from a Watson Knowledge Studio
222220
* machine learning model that is defined in a ZIP file.
223221
*
224-
* <p>* `webhook`: Connects to an external enrichment application by using a webhook. The feature
225-
* is available from IBM Cloud-managed instances only. The external enrichment feature is beta
226-
* functionality. Beta features are not supported by the SDKs.
222+
* <p>* `webhook`: Connects to an external enrichment application by using a webhook.
227223
*
228224
* <p>* `sentence_classifier`: Use sentence classifier to classify sentences in your documents.
229225
* This feature is available in IBM Cloud-managed instances only. The sentence classifier feature
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
* (C) Copyright IBM Corp. 2024.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package com.ibm.watson.discovery.v2.model;
14+
15+
import com.ibm.cloud.sdk.core.service.model.GenericModel;
16+
17+
/** The listBatches options. */
18+
public class ListBatchesOptions extends GenericModel {
19+
20+
protected String projectId;
21+
protected String collectionId;
22+
23+
/** Builder. */
24+
public static class Builder {
25+
private String projectId;
26+
private String collectionId;
27+
28+
/**
29+
* Instantiates a new Builder from an existing ListBatchesOptions instance.
30+
*
31+
* @param listBatchesOptions the instance to initialize the Builder with
32+
*/
33+
private Builder(ListBatchesOptions listBatchesOptions) {
34+
this.projectId = listBatchesOptions.projectId;
35+
this.collectionId = listBatchesOptions.collectionId;
36+
}
37+
38+
/** Instantiates a new builder. */
39+
public Builder() {}
40+
41+
/**
42+
* Instantiates a new builder with required properties.
43+
*
44+
* @param projectId the projectId
45+
* @param collectionId the collectionId
46+
*/
47+
public Builder(String projectId, String collectionId) {
48+
this.projectId = projectId;
49+
this.collectionId = collectionId;
50+
}
51+
52+
/**
53+
* Builds a ListBatchesOptions.
54+
*
55+
* @return the new ListBatchesOptions instance
56+
*/
57+
public ListBatchesOptions build() {
58+
return new ListBatchesOptions(this);
59+
}
60+
61+
/**
62+
* Set the projectId.
63+
*
64+
* @param projectId the projectId
65+
* @return the ListBatchesOptions builder
66+
*/
67+
public Builder projectId(String projectId) {
68+
this.projectId = projectId;
69+
return this;
70+
}
71+
72+
/**
73+
* Set the collectionId.
74+
*
75+
* @param collectionId the collectionId
76+
* @return the ListBatchesOptions builder
77+
*/
78+
public Builder collectionId(String collectionId) {
79+
this.collectionId = collectionId;
80+
return this;
81+
}
82+
}
83+
84+
protected ListBatchesOptions() {}
85+
86+
protected ListBatchesOptions(Builder builder) {
87+
com.ibm.cloud.sdk.core.util.Validator.notEmpty(builder.projectId, "projectId cannot be empty");
88+
com.ibm.cloud.sdk.core.util.Validator.notEmpty(
89+
builder.collectionId, "collectionId cannot be empty");
90+
projectId = builder.projectId;
91+
collectionId = builder.collectionId;
92+
}
93+
94+
/**
95+
* New builder.
96+
*
97+
* @return a ListBatchesOptions builder
98+
*/
99+
public Builder newBuilder() {
100+
return new Builder(this);
101+
}
102+
103+
/**
104+
* Gets the projectId.
105+
*
106+
* <p>The Universally Unique Identifier (UUID) of the project. This information can be found from
107+
* the *Integrate and Deploy* page in Discovery.
108+
*
109+
* @return the projectId
110+
*/
111+
public String projectId() {
112+
return projectId;
113+
}
114+
115+
/**
116+
* Gets the collectionId.
117+
*
118+
* <p>The Universally Unique Identifier (UUID) of the collection.
119+
*
120+
* @return the collectionId
121+
*/
122+
public String collectionId() {
123+
return collectionId;
124+
}
125+
}

0 commit comments

Comments
 (0)