Skip navigation links

Package com.veeva.vault.sdk.api.integration

This package provides interfaces to build Vault to Vault integrations which require data mapping.

See: Description

Package com.veeva.vault.sdk.api.integration Description

This package provides interfaces to build Vault to Vault integrations which require data mapping.

Spark Integration Rules

Spark Integration Rules allow developers to use configurable rules for mapping object and document fields for Vault to Vault integrations. Users must first set up Integrationrule components, which are configurable rule sets for field mapping, reference lookup, and field defaulting. Once configured, you can evaluate integration rules within a MessageProcessor using the services in this package.

Example

The following is a simple example of mapping data. The source vault retrieves data through HTTP Callout and maps it to the desired format in the target vault.
      // Locate service
      IntegrationRuleService integrationRuleService = ServiceLocator.locate(IntegrationRuleService.class);

       // Get integration rule for this connection
       GetIntegrationRulesRequest getIntegrationRulesRequest = integrationRuleService.newGetIntegrationRulesRequestBuilder()
           .withConnectionId(connectionId).build();
      GetIntegrationRulesResponse getIntegrationRulesResponse = integrationRuleService.getIntegrationRules(getIntegrationRulesRequest);


      IntegrationRule integrationRule = getIntegrationRulesResponse.getIntegrationRules().iterator().next();

      // Create a callback query
      CallbackQueryRequest callbackQueryRequest = integrationRule.newCallbackQueryRequestBuilder()
          .withApiVersion("v20.2")
          .withFilterClauseToken("id_value)", "12345")
          .build();
      String callbackQuery = integrationRule.buildCallbackQuery(callbackQueryRequest);


      // Create and send HTTP Callout request filter results with the filter criteria
      HttpRequest request = httpService.newHttpRequest("connectionName");
      request.setMethod(HttpMethod.POST);
      request.appendPath("/api/v19.1/query");
      request.setHeader("Content-Type", "application/x-www-form-urlencoded");
      request.setHeader("X-VaultAPI-DescribeQuery", "true");
      request.setBodyParam("q", callbackQuery);

      httpService.send(request, HttpResponseBodyValueType.JSONDATA).onSuccess(httpResponse -> {
          JsonData response = httpResponse.getResponseBody();
          if (response.isValidJson()) {
              String responseStatus = response.getJsonObject().getValue("responseStatus", JsonValueType.STRING);
              if (responseStatus.equals("SUCCESS")) {
                  JsonArray data = response.getJsonObject().getValue("data", JsonValueType.ARRAY);
                  JsonObject queryDescribe = response.getJsonObject().getValue("queryDescribe", JsonValueType.OBJECT);

                  if (!getIntegrationRulesResponse.hasError()){
                      IntegrationRule integrationRule = getIntegrationRulesResponse.getIntegrationRules().iterator().next();
                      for (int i = 0; i < data.getSize();i++) {
                          JsonObject queryRecord = data.getValue(i, JsonValueType.OBJECT);

                          // Get the resulting values for a row based on the evaluation of the rule against a json query response record
                          EvaluateFieldRulesRequest evaluateFieldRulesRequest = integrationRuleService.newEvaluateFieldRulesRequestBuilder()
                              .withIntegrationRule(integrationRule)
                              .withTargetName("target_name__c")
                              .withQueryDescribe(queryDescribe)
                              .withQueryData(queryRecord)
                              .build();
                          EvaluateFieldRulesResponse evaluateFieldRulesResponse = integrationRuleService.evaluateFieldRules(evaluateFieldRulesRequest);
                          Collection<FieldRuleResult> fieldRuleResults = evaluateFieldRulesResponse.getFieldRuleResults();
                          // Create new record in target vault using values in "fieldRuleResults"
                          Record r = recordService.newRecord("targetName__c")
                          for (Iterator<FieldRuleResult> iterator = fieldRuleResults.iterator(); iterator.hasNext();) {
                              FieldRuleResult fieldRuleResult = iterator.next();
                              if (!fieldRuleResult.hasError()){
                                  r.setValue(fieldRuleResult.getTargetField(), fieldRuleResult.getValue());
                              } else {
                                  FieldRuleError error = fieldRuleResult.getError();
                                  ItemErrorType errorType = error.getType();
                                  String errorMessage = error.getMessage();
                                  // do handling based on error type and message
                              }
                          }
                      }
                  } else {
                      IntegrationRuleError error = getIntegrationRulesResponse.getError();
                      MessageErrorType errorType = error.getType();
                      String errorMessage = error.getMessage();
                      // do handling based on error type and message
                  }
              }
          }
      }

 
 
Skip navigation links

Copyright © Veeva Systems 2017–2020. All rights reserved.