Search in sources :

Example 51 with Error

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

the class InspectTable method inspectTable.

// Inspects the provided text.
public static void inspectTable(String projectId, Table tableToInspect) {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (DlpServiceClient dlp = DlpServiceClient.create()) {
        // Specify the table to be inspected.
        ContentItem item = ContentItem.newBuilder().setTable(tableToInspect).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("PHONE_NUMBER").build();
        // Construct the configuration for the Inspect request.
        InspectConfig config = InspectConfig.newBuilder().addInfoTypes(infoType).setIncludeQuote(true).build();
        // Construct the Inspect request to be sent by the client.
        InspectContentRequest request = InspectContentRequest.newBuilder().setParent(LocationName.of(projectId, "global").toString()).setItem(item).setInspectConfig(config).build();
        // Use the client to send the API request.
        InspectContentResponse response = dlp.inspectContent(request);
        // Parse the response and process results
        System.out.println("Findings: " + response.getResult().getFindingsCount());
        for (Finding f : response.getResult().getFindingsList()) {
            System.out.println("\tQuote: " + f.getQuote());
            System.out.println("\tInfo type: " + f.getInfoType().getName());
            System.out.println("\tLikelihood: " + f.getLikelihood());
        }
    } catch (Exception e) {
        System.out.println("Error during inspectString: \n" + e.toString());
    }
}
Also used : DlpServiceClient(com.google.cloud.dlp.v2.DlpServiceClient) InspectContentResponse(com.google.privacy.dlp.v2.InspectContentResponse) Finding(com.google.privacy.dlp.v2.Finding) InspectContentRequest(com.google.privacy.dlp.v2.InspectContentRequest) InfoType(com.google.privacy.dlp.v2.InfoType) InspectConfig(com.google.privacy.dlp.v2.InspectConfig) ContentItem(com.google.privacy.dlp.v2.ContentItem)

Example 52 with Error

use of com.google.privacy.dlp.v2.Error in project kie-wb-common by kiegroup.

the class EventDefinitionReaderTest method testErrorRefOfWithValue.

@Test
public void testErrorRefOfWithValue() {
    Error error = mock(Error.class);
    when(error.getErrorCode()).thenReturn(SOME_VALUE);
    testErrorRef(error, SOME_VALUE);
}
Also used : Error(org.eclipse.bpmn2.Error) Test(org.junit.Test)

Example 53 with Error

use of com.google.privacy.dlp.v2.Error in project kie-wb-common by kiegroup.

the class EventPropertyWriter method addError.

public void addError(ErrorRef errorRef) {
    Error error = bpmn2.createError();
    ErrorEventDefinition errorEventDefinition = bpmn2.createErrorEventDefinition();
    addEventDefinition(errorEventDefinition);
    String errorCode = errorRef.getValue();
    String errorId;
    if (StringUtils.nonEmpty(errorCode)) {
        error.setErrorCode(errorCode);
        CustomAttribute.errorName.of(errorEventDefinition).set(errorCode);
        errorId = errorCode;
    } else {
        errorId = UUID.uuid();
    }
    error.setId(errorId);
    errorEventDefinition.setErrorRef(error);
    addRootElement(error);
}
Also used : ErrorEventDefinition(org.eclipse.bpmn2.ErrorEventDefinition) Error(org.eclipse.bpmn2.Error)

Example 54 with Error

use of com.google.privacy.dlp.v2.Error in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method setThrowEventsInfo.

public void setThrowEventsInfo(FlowElementsContainer container, Definitions def, List<RootElement> rootElements, List<Signal> toAddSignals, Set<Error> toAddErrors, Set<Escalation> toAddEscalations, Set<Message> toAddMessages, Set<ItemDefinition> toAddItemDefinitions) {
    List<FlowElement> flowElements = container.getFlowElements();
    for (FlowElement fe : flowElements) {
        if (fe instanceof ThrowEvent) {
            if (((ThrowEvent) fe).getEventDefinitions().size() > 0) {
                EventDefinition ed = ((ThrowEvent) fe).getEventDefinitions().get(0);
                if (ed instanceof SignalEventDefinition) {
                    SignalEventDefinition sed = (SignalEventDefinition) ed;
                    if (sed.getSignalRef() != null && sed.getSignalRef().length() > 0) {
                        String signalRef = sed.getSignalRef();
                        boolean shouldAddSignal = true;
                        for (RootElement re : rootElements) {
                            if (re instanceof Signal) {
                                if (((Signal) re).getName().equals(signalRef)) {
                                    shouldAddSignal = false;
                                    break;
                                }
                            }
                        }
                        if (toAddSignals != null) {
                            for (Signal s : toAddSignals) {
                                if (s.getName().equals(signalRef)) {
                                    shouldAddSignal = false;
                                    break;
                                }
                            }
                        }
                        if (shouldAddSignal) {
                            Signal signal = Bpmn2Factory.eINSTANCE.createSignal();
                            signal.setName(signalRef);
                            toAddSignals.add(signal);
                        }
                    }
                } else if (ed instanceof ErrorEventDefinition) {
                    String errorCode = null;
                    String errorId = null;
                    Iterator<FeatureMap.Entry> iter = ed.getAnyAttribute().iterator();
                    while (iter.hasNext()) {
                        FeatureMap.Entry entry = iter.next();
                        if (entry.getEStructuralFeature().getName().equals("erefname")) {
                            errorId = (String) entry.getValue();
                            errorCode = (String) entry.getValue();
                        }
                    }
                    Error err = this._errors.get(errorCode);
                    if (err == null) {
                        err = Bpmn2Factory.eINSTANCE.createError();
                        err.setId(errorId);
                        err.setErrorCode(errorCode);
                        this._errors.put(errorCode, err);
                    }
                    toAddErrors.add(err);
                    ((ErrorEventDefinition) ed).setErrorRef(err);
                } else if (ed instanceof EscalationEventDefinition) {
                    String escalationCode = null;
                    Iterator<FeatureMap.Entry> iter = ed.getAnyAttribute().iterator();
                    while (iter.hasNext()) {
                        FeatureMap.Entry entry = iter.next();
                        if (entry.getEStructuralFeature().getName().equals("esccode")) {
                            escalationCode = (String) entry.getValue();
                            break;
                        }
                    }
                    Escalation escalation = this._escalations.get(escalationCode);
                    if (escalation == null) {
                        escalation = Bpmn2Factory.eINSTANCE.createEscalation();
                        escalation.setEscalationCode(escalationCode);
                        this._escalations.put(escalationCode, escalation);
                    }
                    toAddEscalations.add(escalation);
                    ((EscalationEventDefinition) ed).setEscalationRef(escalation);
                } else if (ed instanceof MessageEventDefinition) {
                    ((MessageEventDefinition) ed).setMessageRef(extractMessage(ed, toAddMessages, toAddItemDefinitions));
                } else if (ed instanceof CompensateEventDefinition) {
                    Iterator<FeatureMap.Entry> iter = ed.getAnyAttribute().iterator();
                    while (iter.hasNext()) {
                        FeatureMap.Entry entry = iter.next();
                        if (entry.getEStructuralFeature().getName().equals("actrefname")) {
                            String activityNameRef = (String) entry.getValue();
                            // we have to iterate again through all flow
                            // elements
                            // in order to find our activity name
                            List<RootElement> re = def.getRootElements();
                            for (RootElement r : re) {
                                if (r instanceof Process) {
                                    Process p = (Process) r;
                                    List<FlowElement> fes = p.getFlowElements();
                                    for (FlowElement f : fes) {
                                        if (f instanceof Activity && ((Activity) f).getName().equals(activityNameRef)) {
                                            ((CompensateEventDefinition) ed).setActivityRef((Activity) f);
                                            ((Activity) f).setIsForCompensation(true);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } else if (fe instanceof FlowElementsContainer) {
            setThrowEventsInfo((FlowElementsContainer) fe, def, rootElements, toAddSignals, toAddErrors, toAddEscalations, toAddMessages, toAddItemDefinitions);
        }
    }
}
Also used : ThrowEvent(org.eclipse.bpmn2.ThrowEvent) Escalation(org.eclipse.bpmn2.Escalation) Error(org.eclipse.bpmn2.Error) Activity(org.eclipse.bpmn2.Activity) CallActivity(org.eclipse.bpmn2.CallActivity) FlowElementsContainer(org.eclipse.bpmn2.FlowElementsContainer) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Process(org.eclipse.bpmn2.Process) EventDefinition(org.eclipse.bpmn2.EventDefinition) ConditionalEventDefinition(org.eclipse.bpmn2.ConditionalEventDefinition) EscalationEventDefinition(org.eclipse.bpmn2.EscalationEventDefinition) MessageEventDefinition(org.eclipse.bpmn2.MessageEventDefinition) ErrorEventDefinition(org.eclipse.bpmn2.ErrorEventDefinition) SignalEventDefinition(org.eclipse.bpmn2.SignalEventDefinition) CompensateEventDefinition(org.eclipse.bpmn2.CompensateEventDefinition) TimerEventDefinition(org.eclipse.bpmn2.TimerEventDefinition) FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) Signal(org.eclipse.bpmn2.Signal) Entry(java.util.Map.Entry) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) RootElement(org.eclipse.bpmn2.RootElement) EscalationEventDefinition(org.eclipse.bpmn2.EscalationEventDefinition) FlowElement(org.eclipse.bpmn2.FlowElement) ErrorEventDefinition(org.eclipse.bpmn2.ErrorEventDefinition) Iterator(java.util.Iterator) SignalEventDefinition(org.eclipse.bpmn2.SignalEventDefinition) MessageEventDefinition(org.eclipse.bpmn2.MessageEventDefinition) CompensateEventDefinition(org.eclipse.bpmn2.CompensateEventDefinition)

Example 55 with Error

use of com.google.privacy.dlp.v2.Error in project java-docs-samples by GoogleCloudPlatform.

the class DeIdentification method reIdentifyWithFpe.

// [END dlp_deidentify_fpe]
// [START dlp_reidentify_fpe]
/**
 * Reidentify a string by encrypting sensitive information while preserving format.
 *
 * @param string The string to reidentify.
 * @param alphabet The set of characters used when encrypting the input. For more information, see
 *     cloud.google.com/dlp/docs/reference/rest/v2/content/deidentify
 * @param keyName The name of the Cloud KMS key to use when decrypting the wrapped key.
 * @param wrappedKey The encrypted (or "wrapped") AES-256 encryption key.
 * @param projectId ID of Google Cloud project to run the API under.
 * @param surrogateType The name of the surrogate custom info type to used during the encryption
 *     process.
 */
private static void reIdentifyWithFpe(String string, FfxCommonNativeAlphabet alphabet, String keyName, String wrappedKey, String projectId, String surrogateType) {
    // instantiate a client
    try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
        ContentItem contentItem = ContentItem.newBuilder().setValue(string).build();
        InfoType surrogateTypeObject = InfoType.newBuilder().setName(surrogateType).build();
        // Create the format-preserving encryption (FPE) configuration
        KmsWrappedCryptoKey kmsWrappedCryptoKey = KmsWrappedCryptoKey.newBuilder().setWrappedKey(ByteString.copyFrom(BaseEncoding.base64().decode(wrappedKey))).setCryptoKeyName(keyName).build();
        CryptoKey cryptoKey = CryptoKey.newBuilder().setKmsWrapped(kmsWrappedCryptoKey).build();
        CryptoReplaceFfxFpeConfig cryptoReplaceFfxFpeConfig = CryptoReplaceFfxFpeConfig.newBuilder().setCryptoKey(cryptoKey).setCommonAlphabet(alphabet).setSurrogateInfoType(surrogateTypeObject).build();
        // Create the deidentification transformation configuration
        PrimitiveTransformation primitiveTransformation = PrimitiveTransformation.newBuilder().setCryptoReplaceFfxFpeConfig(cryptoReplaceFfxFpeConfig).build();
        InfoTypeTransformation infoTypeTransformationObject = InfoTypeTransformation.newBuilder().setPrimitiveTransformation(primitiveTransformation).addInfoTypes(surrogateTypeObject).build();
        InfoTypeTransformations infoTypeTransformationArray = InfoTypeTransformations.newBuilder().addTransformations(infoTypeTransformationObject).build();
        // Create the inspection config
        CustomInfoType customInfoType = CustomInfoType.newBuilder().setInfoType(surrogateTypeObject).setSurrogateType(SurrogateType.newBuilder().build()).build();
        InspectConfig inspectConfig = InspectConfig.newBuilder().addCustomInfoTypes(customInfoType).build();
        // Create the reidentification request object
        DeidentifyConfig reidentifyConfig = DeidentifyConfig.newBuilder().setInfoTypeTransformations(infoTypeTransformationArray).build();
        ReidentifyContentRequest request = ReidentifyContentRequest.newBuilder().setParent(ProjectName.of(projectId).toString()).setReidentifyConfig(reidentifyConfig).setInspectConfig(inspectConfig).setItem(contentItem).build();
        // Execute the deidentification request
        ReidentifyContentResponse response = dlpServiceClient.reidentifyContent(request);
        // Print the reidentified input value
        // e.g. "My SSN is 7261298621" --> "My SSN is 123456789"
        String result = response.getItem().getValue();
        System.out.println(result);
    } catch (Exception e) {
        System.out.println("Error in reidentifyWithFpe: " + e.getMessage());
    }
}
Also used : InfoTypeTransformations(com.google.privacy.dlp.v2.InfoTypeTransformations) ReidentifyContentRequest(com.google.privacy.dlp.v2.ReidentifyContentRequest) PrimitiveTransformation(com.google.privacy.dlp.v2.PrimitiveTransformation) CryptoKey(com.google.privacy.dlp.v2.CryptoKey) KmsWrappedCryptoKey(com.google.privacy.dlp.v2.KmsWrappedCryptoKey) ByteString(com.google.protobuf.ByteString) ReidentifyContentResponse(com.google.privacy.dlp.v2.ReidentifyContentResponse) InspectConfig(com.google.privacy.dlp.v2.InspectConfig) DateTimeParseException(java.time.format.DateTimeParseException) ParseException(org.apache.commons.cli.ParseException) CustomInfoType(com.google.privacy.dlp.v2.CustomInfoType) CryptoReplaceFfxFpeConfig(com.google.privacy.dlp.v2.CryptoReplaceFfxFpeConfig) DlpServiceClient(com.google.cloud.dlp.v2.DlpServiceClient) DeidentifyConfig(com.google.privacy.dlp.v2.DeidentifyConfig) KmsWrappedCryptoKey(com.google.privacy.dlp.v2.KmsWrappedCryptoKey) InfoTypeTransformation(com.google.privacy.dlp.v2.InfoTypeTransformations.InfoTypeTransformation) InfoType(com.google.privacy.dlp.v2.InfoType) CustomInfoType(com.google.privacy.dlp.v2.CustomInfoType) ContentItem(com.google.privacy.dlp.v2.ContentItem)

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