|
72 | 72 | import com.ibm.watson.discovery.v2.model.GetProjectOptions;
|
73 | 73 | import com.ibm.watson.discovery.v2.model.GetStopwordListOptions;
|
74 | 74 | 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; |
75 | 77 | import com.ibm.watson.discovery.v2.model.ListCollectionsOptions;
|
76 | 78 | import com.ibm.watson.discovery.v2.model.ListCollectionsResponse;
|
77 | 79 | import com.ibm.watson.discovery.v2.model.ListDocumentClassifierModelsOptions;
|
|
86 | 88 | import com.ibm.watson.discovery.v2.model.ListProjectsResponse;
|
87 | 89 | import com.ibm.watson.discovery.v2.model.ListTrainingQueriesOptions;
|
88 | 90 | 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; |
89 | 94 | import com.ibm.watson.discovery.v2.model.QueryCollectionNoticesOptions;
|
90 | 95 | import com.ibm.watson.discovery.v2.model.QueryNoticesOptions;
|
91 | 96 | import com.ibm.watson.discovery.v2.model.QueryNoticesResponse;
|
@@ -1794,6 +1799,129 @@ public ServiceCall<Void> deleteEnrichment(DeleteEnrichmentOptions deleteEnrichme
|
1794 | 1799 | return createServiceCall(builder.build(), responseConverter);
|
1795 | 1800 | }
|
1796 | 1801 |
|
| 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 | + |
1797 | 1925 | /**
|
1798 | 1926 | * List document classifiers.
|
1799 | 1927 | *
|
|
0 commit comments