Search in sources :

Example 71 with LocationName

use of com.google.privacy.dlp.v2.LocationName in project java-translate by googleapis.

the class TranslateDocument method translateDocument.

// Translating Document
public static void translateDocument(String projectId, String filePath) throws IOException {
    // up any remaining background resources.
    try (TranslationServiceClient client = TranslationServiceClient.create()) {
        // The ``global`` location is not supported for batch translation
        LocationName parent = LocationName.of(projectId, "us-central1");
        // Supported file types: https://cloud.google.com/translate/docs/supported-formats
        ByteString content = ByteString.readFrom(new FileInputStream(filePath));
        DocumentInputConfig documentInputConfig = DocumentInputConfig.newBuilder().setContent(content).setMimeType("application/pdf").build();
        TranslateDocumentRequest request = TranslateDocumentRequest.newBuilder().setParent(parent.toString()).setTargetLanguageCode("fr-FR").setDocumentInputConfig(documentInputConfig).build();
        TranslateDocumentResponse response = client.translateDocument(request);
        // To view translated document, write `response.document_translation.byte_stream_outputs`
        // to file. If not provided in the TranslationRequest, the translated file will only be
        // returned through a byte-stream and its output mime type will be the same as the input
        // file's mime type
        System.out.println("Response: Detected Language Code - " + response.getDocumentTranslation().getDetectedLanguageCode());
    }
}
Also used : TranslationServiceClient(com.google.cloud.translate.v3beta1.TranslationServiceClient) ByteString(com.google.protobuf.ByteString) TranslateDocumentRequest(com.google.cloud.translate.v3beta1.TranslateDocumentRequest) TranslateDocumentResponse(com.google.cloud.translate.v3beta1.TranslateDocumentResponse) DocumentInputConfig(com.google.cloud.translate.v3beta1.DocumentInputConfig) FileInputStream(java.io.FileInputStream) LocationName(com.google.cloud.translate.v3beta1.LocationName)

Example 72 with LocationName

use of com.google.privacy.dlp.v2.LocationName in project java-kms by googleapis.

the class GenerateRandomBytes method generateRandomBytes.

// Create a new key for use with MacSign.
public void generateRandomBytes(String projectId, String locationId, int numBytes) throws IOException {
    // safely clean up any remaining background resources.
    try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) {
        // Build the parent name for the location.
        LocationName locationName = LocationName.of(projectId, locationId);
        // Generate the bytes.
        GenerateRandomBytesResponse response = client.generateRandomBytes(locationName.toString(), numBytes, ProtectionLevel.HSM);
        // The data comes back as raw bytes, which may include non-printable
        // characters. This base64-encodes the result so it can be printed below.
        String encodedData = Base64.getEncoder().encodeToString(response.getData().toByteArray());
        System.out.printf("Random bytes: %s", encodedData);
    }
}
Also used : GenerateRandomBytesResponse(com.google.cloud.kms.v1.GenerateRandomBytesResponse) KeyManagementServiceClient(com.google.cloud.kms.v1.KeyManagementServiceClient) LocationName(com.google.cloud.kms.v1.LocationName)

Example 73 with LocationName

use of com.google.privacy.dlp.v2.LocationName in project java-kms by googleapis.

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)

Example 74 with LocationName

use of com.google.privacy.dlp.v2.LocationName in project java-dlp by googleapis.

the class DlpServiceClientTest method listDeidentifyTemplatesExceptionTest.

@Test
public void listDeidentifyTemplatesExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockDlpService.addException(exception);
    try {
        LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
        client.listDeidentifyTemplates(parent);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) OrganizationLocationName(com.google.privacy.dlp.v2.OrganizationLocationName) LocationName(com.google.privacy.dlp.v2.LocationName) Test(org.junit.Test)

Example 75 with LocationName

use of com.google.privacy.dlp.v2.LocationName in project java-dlp by googleapis.

the class DlpServiceClientTest method listStoredInfoTypesExceptionTest.

@Test
public void listStoredInfoTypesExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockDlpService.addException(exception);
    try {
        LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
        client.listStoredInfoTypes(parent);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) OrganizationLocationName(com.google.privacy.dlp.v2.OrganizationLocationName) LocationName(com.google.privacy.dlp.v2.LocationName) Test(org.junit.Test)

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