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());
}
}
}
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);
}
}
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);
}
}
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());
}
}
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());
}
}
}
Aggregations