Search in sources :

Example 46 with LocationName

use of com.google.logging.v2.LocationName in project java-servicedirectory by googleapis.

the class Quickstart method quickstart.

public static void quickstart(String projectId, String locationId) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (RegistrationServiceClient client = RegistrationServiceClient.create()) {
        // The project and location that hold the namespace to list.
        LocationName parent = LocationName.of(projectId, locationId);
        // Call the API.
        ListNamespacesPagedResponse response = client.listNamespaces(parent);
        // Iterate over each namespace and print its name.
        System.out.println("Namespaces:");
        for (Namespace namespace : response.iterateAll()) {
            System.out.println(namespace.getName());
        }
    }
}
Also used : Namespace(com.google.cloud.servicedirectory.v1.Namespace) RegistrationServiceClient(com.google.cloud.servicedirectory.v1.RegistrationServiceClient) LocationName(com.google.cloud.servicedirectory.v1.LocationName) ListNamespacesPagedResponse(com.google.cloud.servicedirectory.v1.RegistrationServiceClient.ListNamespacesPagedResponse)

Example 47 with LocationName

use of com.google.logging.v2.LocationName in project google-cloud-java by GoogleCloudPlatform.

the class TranslateSnippetsBeta method createGlossary.

// [END translate_batch_translate_text_beta]
/**
 * Creates a glossary.
 *
 * @param projectId - Id of the project.
 * @param location - location name.
 * @param name - Glossary name.
 * @param gcsUri - Google Cloud Storage URI where glossary is stored in csv format.
 */
// [START translate_create_glossary_beta]
static Glossary createGlossary(String projectId, String location, String name, String gcsUri) {
    try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
        LocationName locationName = LocationName.newBuilder().setProject(projectId).setLocation(location).build();
        LanguageCodesSet languageCodesSet = LanguageCodesSet.newBuilder().addLanguageCodes("en").addLanguageCodes("es").build();
        GcsSource gcsSource = GcsSource.newBuilder().setInputUri(gcsUri).build();
        GlossaryInputConfig glossaryInputConfig = GlossaryInputConfig.newBuilder().setGcsSource(gcsSource).build();
        GlossaryName glossaryName = GlossaryName.newBuilder().setProject(projectId).setLocation(location).setGlossary(name).build();
        Glossary glossary = Glossary.newBuilder().setLanguageCodesSet(languageCodesSet).setInputConfig(glossaryInputConfig).setName(glossaryName.toString()).build();
        CreateGlossaryRequest request = CreateGlossaryRequest.newBuilder().setParent(locationName.toString()).setGlossary(glossary).build();
        // Call the API
        Glossary response = translationServiceClient.createGlossaryAsync(request).get(300, TimeUnit.SECONDS);
        System.out.format("Created: %s\n", response.getName());
        System.out.format("Input Uri: %s\n", response.getInputConfig().getGcsSource());
        return response;
    } catch (Exception e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : LanguageCodesSet(com.google.cloud.translate.v3beta1.Glossary.LanguageCodesSet) TranslationServiceClient(com.google.cloud.translate.v3beta1.TranslationServiceClient) GcsSource(com.google.cloud.translate.v3beta1.GcsSource) CreateGlossaryRequest(com.google.cloud.translate.v3beta1.CreateGlossaryRequest) GlossaryInputConfig(com.google.cloud.translate.v3beta1.GlossaryInputConfig) Glossary(com.google.cloud.translate.v3beta1.Glossary) GlossaryName(com.google.cloud.translate.v3beta1.GlossaryName) LocationName(com.google.cloud.translate.v3beta1.LocationName)

Example 48 with LocationName

use of com.google.logging.v2.LocationName in project google-cloud-java by GoogleCloudPlatform.

the class TranslateSnippetsBeta method translateText.

// [END translate_detect_language_beta]
// [START translate_translate_text_beta]
/**
 * Translates a given text to a target language.
 *
 * @param projectId - Id of the project.
 * @param location - location name.
 * @param text - Text for translation.
 * @param sourceLanguageCode - Language code of text. e.g. "en"
 * @param targetLanguageCode - Language code for translation. e.g. "sr"
 */
static TranslateTextResponse translateText(String projectId, String location, String text, String sourceLanguageCode, String targetLanguageCode) {
    try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
        LocationName locationName = LocationName.newBuilder().setProject(projectId).setLocation(location).build();
        TranslateTextRequest translateTextRequest = TranslateTextRequest.newBuilder().setParent(locationName.toString()).setMimeType("text/plain").setSourceLanguageCode(sourceLanguageCode).setTargetLanguageCode(targetLanguageCode).addContents(text).build();
        // Call the API
        TranslateTextResponse response = translationServiceClient.translateText(translateTextRequest);
        System.out.format("Translated Text: %s", response.getTranslationsList().get(0).getTranslatedText());
        return response;
    } catch (Exception e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : TranslationServiceClient(com.google.cloud.translate.v3beta1.TranslationServiceClient) BatchTranslateTextRequest(com.google.cloud.translate.v3beta1.BatchTranslateTextRequest) TranslateTextRequest(com.google.cloud.translate.v3beta1.TranslateTextRequest) TranslateTextResponse(com.google.cloud.translate.v3beta1.TranslateTextResponse) LocationName(com.google.cloud.translate.v3beta1.LocationName)

Example 49 with LocationName

use of com.google.logging.v2.LocationName in project java-docs-samples by GoogleCloudPlatform.

the class CreateKeyRing method createKeyRing.

// Create a new key ring.
public void createKeyRing(String projectId, String locationId, String id) throws IOException {
    // safely clean up any remaining background resources.
    try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) {
        // Build the parent name from the project and location.
        LocationName locationName = LocationName.of(projectId, locationId);
        // Build the key ring to create.
        KeyRing keyRing = KeyRing.newBuilder().build();
        // Create the key ring.
        KeyRing createdKeyRing = client.createKeyRing(locationName, id, keyRing);
        System.out.printf("Created key ring %s%n", createdKeyRing.getName());
    }
}
Also used : KeyRing(com.google.cloud.kms.v1.KeyRing) KeyManagementServiceClient(com.google.cloud.kms.v1.KeyManagementServiceClient) LocationName(com.google.cloud.kms.v1.LocationName)

Example 50 with LocationName

use of com.google.logging.v2.LocationName in project java-docs-samples by GoogleCloudPlatform.

the class Quickstart method quickstart.

public void quickstart(String projectId, String locationId) throws IOException {
    // safely clean up any remaining background resources.
    try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) {
        // Build the parent from the project and location.
        LocationName parent = LocationName.of(projectId, locationId);
        // Call the API.
        ListKeyRingsPagedResponse response = client.listKeyRings(parent);
        // Iterate over each key ring and print its name.
        System.out.println("key rings:");
        for (KeyRing keyRing : response.iterateAll()) {
            System.out.printf("%s%n", keyRing.getName());
        }
    }
}
Also used : ListKeyRingsPagedResponse(com.google.cloud.kms.v1.KeyManagementServiceClient.ListKeyRingsPagedResponse) KeyRing(com.google.cloud.kms.v1.KeyRing) KeyManagementServiceClient(com.google.cloud.kms.v1.KeyManagementServiceClient) LocationName(com.google.cloud.kms.v1.LocationName)

Aggregations

Test (org.junit.Test)28 LocationName (com.google.privacy.dlp.v2.LocationName)22 OrganizationLocationName (com.google.privacy.dlp.v2.OrganizationLocationName)22 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)17 LocationName (com.google.cloud.automl.v1.LocationName)17 AbstractMessage (com.google.protobuf.AbstractMessage)14 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)13 LocationName (com.google.cloud.translate.v3.LocationName)13 TranslationServiceClient (com.google.cloud.translate.v3.TranslationServiceClient)13 StatusRuntimeException (io.grpc.StatusRuntimeException)13 OperationMetadata (com.google.cloud.automl.v1.OperationMetadata)12 AutoMlClient (com.google.cloud.automl.v1beta1.AutoMlClient)12 LocationName (com.google.cloud.automl.v1beta1.LocationName)12 LocationName (com.google.cloud.translate.v3beta1.LocationName)10 TranslationServiceClient (com.google.cloud.translate.v3beta1.TranslationServiceClient)10 Model (com.google.cloud.automl.v1.Model)8 Dataset (com.google.cloud.automl.v1.Dataset)7 Dataset (com.google.cloud.automl.v1beta1.Dataset)6 GcsSource (com.google.cloud.translate.v3.GcsSource)5 ArrayList (java.util.ArrayList)5