Search in sources :

Example 46 with Error

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

the class DlpServiceClientTest method updateJobTriggerTest.

@Test
public void updateJobTriggerTest() throws Exception {
    JobTrigger expectedResponse = JobTrigger.newBuilder().setName(JobTriggerName.ofProjectJobTriggerName("[PROJECT]", "[JOB_TRIGGER]").toString()).setDisplayName("displayName1714148973").setDescription("description-1724546052").addAllTriggers(new ArrayList<JobTrigger.Trigger>()).addAllErrors(new ArrayList<Error>()).setCreateTime(Timestamp.newBuilder().build()).setUpdateTime(Timestamp.newBuilder().build()).setLastRunTime(Timestamp.newBuilder().build()).build();
    mockDlpService.addResponse(expectedResponse);
    JobTriggerName name = JobTriggerName.ofProjectJobTriggerName("[PROJECT]", "[JOB_TRIGGER]");
    JobTrigger jobTrigger = JobTrigger.newBuilder().build();
    FieldMask updateMask = FieldMask.newBuilder().build();
    JobTrigger actualResponse = client.updateJobTrigger(name, jobTrigger, updateMask);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDlpService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    UpdateJobTriggerRequest actualRequest = ((UpdateJobTriggerRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertEquals(jobTrigger, actualRequest.getJobTrigger());
    Assert.assertEquals(updateMask, actualRequest.getUpdateMask());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) UpdateJobTriggerRequest(com.google.privacy.dlp.v2.UpdateJobTriggerRequest) ArrayList(java.util.ArrayList) Error(com.google.privacy.dlp.v2.Error) JobTriggerName(com.google.privacy.dlp.v2.JobTriggerName) JobTrigger(com.google.privacy.dlp.v2.JobTrigger) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 47 with Error

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

the class DlpServiceClientTest method createDlpJobTest3.

@Test
public void createDlpJobTest3() throws Exception {
    DlpJob expectedResponse = DlpJob.newBuilder().setName(DlpJobName.ofProjectDlpJobName("[PROJECT]", "[DLP_JOB]").toString()).setType(DlpJobType.forNumber(0)).setCreateTime(Timestamp.newBuilder().build()).setStartTime(Timestamp.newBuilder().build()).setEndTime(Timestamp.newBuilder().build()).setJobTriggerName("jobTriggerName494333030").addAllErrors(new ArrayList<Error>()).build();
    mockDlpService.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    InspectJobConfig inspectJob = InspectJobConfig.newBuilder().build();
    DlpJob actualResponse = client.createDlpJob(parent, inspectJob);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDlpService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateDlpJobRequest actualRequest = ((CreateDlpJobRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(inspectJob, actualRequest.getInspectJob());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ProjectName(com.google.privacy.dlp.v2.ProjectName) ArrayList(java.util.ArrayList) DlpJob(com.google.privacy.dlp.v2.DlpJob) CreateDlpJobRequest(com.google.privacy.dlp.v2.CreateDlpJobRequest) InspectJobConfig(com.google.privacy.dlp.v2.InspectJobConfig) Test(org.junit.Test)

Example 48 with Error

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

the class DlpServiceClientTest method activateJobTriggerTest.

@Test
public void activateJobTriggerTest() throws Exception {
    DlpJob expectedResponse = DlpJob.newBuilder().setName(DlpJobName.ofProjectDlpJobName("[PROJECT]", "[DLP_JOB]").toString()).setType(DlpJobType.forNumber(0)).setCreateTime(Timestamp.newBuilder().build()).setStartTime(Timestamp.newBuilder().build()).setEndTime(Timestamp.newBuilder().build()).setJobTriggerName("jobTriggerName494333030").addAllErrors(new ArrayList<Error>()).build();
    mockDlpService.addResponse(expectedResponse);
    ActivateJobTriggerRequest request = ActivateJobTriggerRequest.newBuilder().setName(JobTriggerName.ofProjectJobTriggerName("[PROJECT]", "[JOB_TRIGGER]").toString()).build();
    DlpJob actualResponse = client.activateJobTrigger(request);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDlpService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ActivateJobTriggerRequest actualRequest = ((ActivateJobTriggerRequest) actualRequests.get(0));
    Assert.assertEquals(request.getName(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) ActivateJobTriggerRequest(com.google.privacy.dlp.v2.ActivateJobTriggerRequest) DlpJob(com.google.privacy.dlp.v2.DlpJob) Test(org.junit.Test)

Example 49 with Error

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

the class DeIdentifyWithRedaction method deIdentifyWithRedaction.

// Inspects the provided text.
public static void deIdentifyWithRedaction(String projectId, String textToRedact) {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (DlpServiceClient dlp = DlpServiceClient.create()) {
        // Specify the content to be inspected.
        ContentItem item = ContentItem.newBuilder().setValue(textToRedact).build();
        // Specify the type of info the inspection will look for.
        // See https://cloud.google.com/dlp/docs/infotypes-reference for complete list of info types
        InfoType infoType = InfoType.newBuilder().setName("EMAIL_ADDRESS").build();
        InspectConfig inspectConfig = InspectConfig.newBuilder().addInfoTypes(infoType).build();
        // Define type of deidentification.
        PrimitiveTransformation primitiveTransformation = PrimitiveTransformation.newBuilder().setRedactConfig(RedactConfig.getDefaultInstance()).build();
        // Associate deidentification type with info type.
        InfoTypeTransformation transformation = InfoTypeTransformation.newBuilder().addInfoTypes(infoType).setPrimitiveTransformation(primitiveTransformation).build();
        // Construct the configuration for the Redact request and list all desired transformations.
        DeidentifyConfig redactConfig = DeidentifyConfig.newBuilder().setInfoTypeTransformations(InfoTypeTransformations.newBuilder().addTransformations(transformation)).build();
        // Construct the Redact request to be sent by the client.
        DeidentifyContentRequest request = DeidentifyContentRequest.newBuilder().setParent(LocationName.of(projectId, "global").toString()).setItem(item).setDeidentifyConfig(redactConfig).setInspectConfig(inspectConfig).build();
        // Use the client to send the API request.
        DeidentifyContentResponse response = dlp.deidentifyContent(request);
        // Parse the response and process results
        System.out.println("Text after redaction: " + response.getItem().getValue());
    } catch (Exception e) {
        System.out.println("Error during inspectString: \n" + e.toString());
    }
}
Also used : DeidentifyContentRequest(com.google.privacy.dlp.v2.DeidentifyContentRequest) PrimitiveTransformation(com.google.privacy.dlp.v2.PrimitiveTransformation) DlpServiceClient(com.google.cloud.dlp.v2.DlpServiceClient) DeidentifyConfig(com.google.privacy.dlp.v2.DeidentifyConfig) InfoTypeTransformation(com.google.privacy.dlp.v2.InfoTypeTransformations.InfoTypeTransformation) InfoType(com.google.privacy.dlp.v2.InfoType) InspectConfig(com.google.privacy.dlp.v2.InspectConfig) ContentItem(com.google.privacy.dlp.v2.ContentItem) DeidentifyContentResponse(com.google.privacy.dlp.v2.DeidentifyContentResponse)

Example 50 with Error

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

the class DeIdentifyWithReplacement method deIdentifyWithReplacement.

// Inspects the provided text.
public static void deIdentifyWithReplacement(String projectId, String textToRedact) {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (DlpServiceClient dlp = DlpServiceClient.create()) {
        // Specify the content to be inspected.
        ContentItem item = ContentItem.newBuilder().setValue(textToRedact).build();
        // Specify the type of info the inspection will look for.
        // See https://cloud.google.com/dlp/docs/infotypes-reference for complete list of info types
        InfoType infoType = InfoType.newBuilder().setName("EMAIL_ADDRESS").build();
        InspectConfig inspectConfig = InspectConfig.newBuilder().addInfoTypes(infoType).build();
        // Specify replacement string to be used for the finding.
        ReplaceValueConfig replaceValueConfig = ReplaceValueConfig.newBuilder().setNewValue(Value.newBuilder().setStringValue("[email-address]").build()).build();
        // Define type of deidentification as replacement.
        PrimitiveTransformation primitiveTransformation = PrimitiveTransformation.newBuilder().setReplaceConfig(replaceValueConfig).build();
        // Associate deidentification type with info type.
        InfoTypeTransformation transformation = InfoTypeTransformation.newBuilder().addInfoTypes(infoType).setPrimitiveTransformation(primitiveTransformation).build();
        // Construct the configuration for the Redact request and list all desired transformations.
        DeidentifyConfig redactConfig = DeidentifyConfig.newBuilder().setInfoTypeTransformations(InfoTypeTransformations.newBuilder().addTransformations(transformation)).build();
        // Construct the Redact request to be sent by the client.
        DeidentifyContentRequest request = DeidentifyContentRequest.newBuilder().setParent(LocationName.of(projectId, "global").toString()).setItem(item).setDeidentifyConfig(redactConfig).setInspectConfig(inspectConfig).build();
        // Use the client to send the API request.
        DeidentifyContentResponse response = dlp.deidentifyContent(request);
        // Parse the response and process results
        System.out.println("Text after redaction: " + response.getItem().getValue());
    } catch (Exception e) {
        System.out.println("Error during inspectString: \n" + e.toString());
    }
}
Also used : DeidentifyContentRequest(com.google.privacy.dlp.v2.DeidentifyContentRequest) PrimitiveTransformation(com.google.privacy.dlp.v2.PrimitiveTransformation) DlpServiceClient(com.google.cloud.dlp.v2.DlpServiceClient) DeidentifyConfig(com.google.privacy.dlp.v2.DeidentifyConfig) ReplaceValueConfig(com.google.privacy.dlp.v2.ReplaceValueConfig) InfoTypeTransformation(com.google.privacy.dlp.v2.InfoTypeTransformations.InfoTypeTransformation) InfoType(com.google.privacy.dlp.v2.InfoType) InspectConfig(com.google.privacy.dlp.v2.InspectConfig) ContentItem(com.google.privacy.dlp.v2.ContentItem) DeidentifyContentResponse(com.google.privacy.dlp.v2.DeidentifyContentResponse)

Aggregations

ArrayList (java.util.ArrayList)28 DlpServiceClient (com.google.cloud.dlp.v2.DlpServiceClient)23 Test (org.junit.Test)23 ParseException (org.apache.commons.cli.ParseException)18 AbstractMessage (com.google.protobuf.AbstractMessage)16 DlpJob (com.google.privacy.dlp.v2.DlpJob)15 InfoType (com.google.privacy.dlp.v2.InfoType)13 CreateDlpJobRequest (com.google.privacy.dlp.v2.CreateDlpJobRequest)12 ByteString (com.google.protobuf.ByteString)12 Error (dev.hawala.xns.level2.Error)12 Error (org.ovirt.engine.sdk4.Error)12 InspectConfig (com.google.privacy.dlp.v2.InspectConfig)11 Error (org.eclipse.bpmn2.Error)11 ContentItem (com.google.privacy.dlp.v2.ContentItem)10 ProjectName (com.google.privacy.dlp.v2.ProjectName)9 Iterator (java.util.Iterator)9 JobTrigger (com.google.privacy.dlp.v2.JobTrigger)8 RootElement (org.eclipse.bpmn2.RootElement)8 Error (com.google.privacy.dlp.v2.Error)7 ServiceOptions (com.google.cloud.ServiceOptions)6