Search in sources :

Example 1 with DeleteGlossaryResponse

use of com.google.cloud.translate.v3.DeleteGlossaryResponse in project java-translate by googleapis.

the class DeleteGlossary method deleteGlossary.

// Delete a specific glossary based on the glossary ID
public static void deleteGlossary(String projectId, String glossaryId) throws InterruptedException, ExecutionException, IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (TranslationServiceClient client = TranslationServiceClient.create()) {
        // Supported Locations: `global`, [glossary location], or [model location]
        // Glossaries must be hosted in `us-central1`
        // Custom Models must use the same location as your model. (us-central1)
        GlossaryName glossaryName = GlossaryName.of(projectId, "us-central1", glossaryId);
        DeleteGlossaryRequest request = DeleteGlossaryRequest.newBuilder().setName(glossaryName.toString()).build();
        // Start an asynchronous request
        OperationFuture<DeleteGlossaryResponse, DeleteGlossaryMetadata> future = client.deleteGlossaryAsync(request);
        System.out.println("Waiting for operation to complete...");
        DeleteGlossaryResponse response = future.get();
        System.out.format("Deleted Glossary: %s\n", response.getName());
    }
}
Also used : DeleteGlossaryRequest(com.google.cloud.translate.v3.DeleteGlossaryRequest) DeleteGlossaryResponse(com.google.cloud.translate.v3.DeleteGlossaryResponse) TranslationServiceClient(com.google.cloud.translate.v3.TranslationServiceClient) GlossaryName(com.google.cloud.translate.v3.GlossaryName) DeleteGlossaryMetadata(com.google.cloud.translate.v3.DeleteGlossaryMetadata)

Example 2 with DeleteGlossaryResponse

use of com.google.cloud.translate.v3.DeleteGlossaryResponse in project google-cloud-java by GoogleCloudPlatform.

the class TranslateSnippetsBeta method deleteGlossary.

// [END translate_translate_text_with_glossary_beta]
/**
 * Deletes a glossary.
 *
 * @param projectId - Id of the project.
 * @param location - location name.
 * @param name - Glossary name.
 */
// [START translate_delete_glossary_beta]
static DeleteGlossaryResponse deleteGlossary(String projectId, String location, String name) {
    try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
        GlossaryName glossaryName = GlossaryName.newBuilder().setProject(projectId).setLocation(location).setGlossary(name).build();
        // Call the API
        DeleteGlossaryResponse response = translationServiceClient.deleteGlossaryAsync(glossaryName.toString()).get(300, TimeUnit.SECONDS);
        System.out.format("Deleted: %s\n", response.getName());
        return response;
    } catch (Exception e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : DeleteGlossaryResponse(com.google.cloud.translate.v3beta1.DeleteGlossaryResponse) TranslationServiceClient(com.google.cloud.translate.v3beta1.TranslationServiceClient) GlossaryName(com.google.cloud.translate.v3beta1.GlossaryName)

Example 3 with DeleteGlossaryResponse

use of com.google.cloud.translate.v3.DeleteGlossaryResponse in project google-cloud-java by GoogleCloudPlatform.

the class ITTranslateSnippetsBeta method test3_testDeleteGlossary.

@Test
public void test3_testDeleteGlossary() {
    DeleteGlossaryResponse response = TranslateSnippetsBeta.deleteGlossary(projectId, "us-central1", "glossary-testing");
    assertTrue(response.toString(), response.toString().contains("glossary-testing"));
}
Also used : DeleteGlossaryResponse(com.google.cloud.translate.v3beta1.DeleteGlossaryResponse) Test(org.junit.Test)

Example 4 with DeleteGlossaryResponse

use of com.google.cloud.translate.v3.DeleteGlossaryResponse in project google-cloud-java by googleapis.

the class TranslateSnippetsBeta method deleteGlossary.

// [END translate_translate_text_with_glossary_beta]
/**
 * Deletes a glossary.
 *
 * @param projectId - Id of the project.
 * @param location - location name.
 * @param name - Glossary name.
 */
// [START translate_delete_glossary_beta]
static DeleteGlossaryResponse deleteGlossary(String projectId, String location, String name) {
    try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
        GlossaryName glossaryName = GlossaryName.newBuilder().setProject(projectId).setLocation(location).setGlossary(name).build();
        // Call the API
        DeleteGlossaryResponse response = translationServiceClient.deleteGlossaryAsync(glossaryName.toString()).get(300, TimeUnit.SECONDS);
        System.out.format("Deleted: %s\n", response.getName());
        return response;
    } catch (Exception e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : DeleteGlossaryResponse(com.google.cloud.translate.v3beta1.DeleteGlossaryResponse) TranslationServiceClient(com.google.cloud.translate.v3beta1.TranslationServiceClient) GlossaryName(com.google.cloud.translate.v3beta1.GlossaryName)

Example 5 with DeleteGlossaryResponse

use of com.google.cloud.translate.v3.DeleteGlossaryResponse in project google-cloud-java by googleapis.

the class ITTranslateSnippetsBeta method test3_testDeleteGlossary.

@Test
public void test3_testDeleteGlossary() {
    DeleteGlossaryResponse response = TranslateSnippetsBeta.deleteGlossary(projectId, "us-central1", "glossary-testing");
    assertTrue(response.toString(), response.toString().contains("glossary-testing"));
}
Also used : DeleteGlossaryResponse(com.google.cloud.translate.v3beta1.DeleteGlossaryResponse) Test(org.junit.Test)

Aggregations

DeleteGlossaryResponse (com.google.cloud.translate.v3beta1.DeleteGlossaryResponse)4 GlossaryName (com.google.cloud.translate.v3beta1.GlossaryName)2 TranslationServiceClient (com.google.cloud.translate.v3beta1.TranslationServiceClient)2 Test (org.junit.Test)2 DeleteGlossaryMetadata (com.google.cloud.translate.v3.DeleteGlossaryMetadata)1 DeleteGlossaryRequest (com.google.cloud.translate.v3.DeleteGlossaryRequest)1 DeleteGlossaryResponse (com.google.cloud.translate.v3.DeleteGlossaryResponse)1 GlossaryName (com.google.cloud.translate.v3.GlossaryName)1 TranslationServiceClient (com.google.cloud.translate.v3.TranslationServiceClient)1