salesforce-lib/src/main/java/com/streamsets/pipeline/stage/destination/salesforce/ForceTarget.java
@Override
  protected List<ConfigIssue> init() {
    // Validate configuration values and open any required resources.
    List<ConfigIssue> issues = super.init();
    Target.Context context = getContext();
    Optional
        .ofNullable(conf.init(context, CONF_PREFIX))
        .ifPresent(issues::addAll);

    errorRecordHandler = new DefaultErrorRecordHandler(context);

    sObjectNameVars = getContext().createELVars();
    sObjectNameEval = context.createELEval(SOBJECT_NAME);
    ELUtils.validateExpression(conf.sObjectNameTemplate,
        context,
        Groups.FORCE.getLabel(),
        SOBJECT_NAME,
        Errors.FORCE_12, issues
    );

    externalIdFieldVars = getContext().createELVars();
    externalIdFieldEval = context.createELEval(EXTERNAL_ID_NAME);
    ELUtils.validateExpression(conf.externalIdField,
        context,
        Groups.FORCE.getLabel(),
        EXTERNAL_ID_NAME,
        Errors.FORCE_24, issues
    );

    if (issues.isEmpty()) {
      fieldMappings = new TreeMap<>();
      for (ForceFieldMapping mapping : conf.fieldMapping) {
        // SDC-7446 Allow colon as well as period as field separator
        String salesforceField = conf.useBulkAPI
            ? mapping.salesforceField.replace(':', '.')
            : mapping.salesforceField;
        fieldMappings.put(salesforceField, mapping.sdcField);
      }

      try {
        ConnectorConfig partnerConfig = ForceUtils.getPartnerConfig(conf, new ForceSessionRenewer());
        partnerConnection = Connector.newConnection(partnerConfig);
        if (conf.mutualAuth.useMutualAuth) {
          ForceUtils.setupMutualAuth(partnerConfig, conf.mutualAuth);
        }
        bulkConnection = ForceUtils.getBulkConnection(partnerConfig, conf);
        LOG.info("Successfully authenticated as {}", conf.username);
      } catch (ConnectionException | AsyncApiException | StageException | URISyntaxException ce) {
        LOG.error("Can't connect to SalesForce", ce);
        issues.add(getContext().createConfigIssue(Groups.FORCE.name(),
            "connectorConfig",
            Errors.FORCE_00,
            ForceUtils.getExceptionCode(ce) + ", " + ForceUtils.getExceptionMessage(ce)
        ));
      }

      if (conf.useBulkAPI) {
        writer = new ForceBulkWriter(fieldMappings, bulkConnection, getContext());
      } else {
        writer = new ForceSoapWriter(fieldMappings, partnerConnection);
      }
    }

    // If issues is not empty, the UI will inform the user of each configuration issue in the list.
    return issues;
  }
@Override
  protected List<ConfigIssue> init() {
    // Validate configuration values and open any required resources.
    List<ConfigIssue> issues = super.init();
    Target.Context context = getContext();
    Optional
        .ofNullable(conf.init(context, CONF_PREFIX))
        .ifPresent(issues::addAll);

    errorRecordHandler = new DefaultErrorRecordHandler(context);

    sObjectNameVars = getContext().createELVars();
    sObjectNameEval = context.createELEval(SOBJECT_NAME);
    ELUtils.validateExpression(conf.sObjectNameTemplate,
        context,
        Groups.FORCE.getLabel(),
        SOBJECT_NAME,
        Errors.FORCE_12, issues
    );

    externalIdFieldVars = getContext().createELVars();
    externalIdFieldEval = context.createELEval(EXTERNAL_ID_NAME);
    ELUtils.validateExpression(conf.externalIdField,
        context,
        Groups.FORCE.getLabel(),
        EXTERNAL_ID_NAME,
        Errors.FORCE_24, issues
    );

    if (issues.isEmpty()) {
      fieldMappings = new TreeMap<>();
      for (ForceFieldMapping mapping : conf.fieldMapping) {
        // SDC-7446 Allow colon as well as period as field separator
        String salesforceField = conf.useBulkAPI
            ? mapping.salesforceField.replace(':', '.')
            : mapping.salesforceField;
        fieldMappings.put(salesforceField, mapping.sdcField);
      }

      try {
        ConnectorConfig partnerConfig = ForceUtils.getPartnerConfig(conf, new ForceSessionRenewer());
        partnerConnection = Connector.newConnection(partnerConfig);
        if (conf.mutualAuth.useMutualAuth) {
          ForceUtils.setupMutualAuth(partnerConfig, conf.mutualAuth);
        }
        bulkConnection = ForceUtils.getBulkConnection(partnerConfig, conf);
        LOG.info("Successfully authenticated as {}", conf.username);
      } catch (ConnectionException | AsyncApiException | StageException | URISyntaxException ce) {
        LOG.error("Can't connect to SalesForce", ce);
        issues.add(getContext().createConfigIssue(Groups.FORCE.name(),
            "connectorConfig",
            Errors.FORCE_00,
            ForceUtils.getExceptionCode(ce) + ", " + ForceUtils.getExceptionMessage(ce)
        ));
      }

      if (conf.useBulkAPI) {
        writer = new ForceBulkWriter(fieldMappings, bulkConnection, getContext());
      } else {
        writer = new ForceSoapWriter(fieldMappings, partnerConnection);
      }
    }

    // If issues is not empty, the UI will inform the user of each configuration issue in the list.
    return issues;
  }
@ Override protected List < ConfigIssue > init ( ) { // Validate configuration values and open any required resources. List < ConfigIssue > issues = super . init ( ) ; Target . Context context = getContext ( ) ; Optional . ofNullable ( conf . init ( context , CONF_PREFIX ) ) . ifPresent ( issues :: addAll ) ; errorRecordHandler = new DefaultErrorRecordHandler ( context ) ; sObjectNameVars = getContext ( ) . createELVars ( ) ; sObjectNameEval = context . createELEval ( SOBJECT_NAME ) ; ELUtils . validateExpression ( conf . sObjectNameTemplate , context , Groups . FORCE . getLabel ( ) , SOBJECT_NAME , Errors . FORCE_12 , issues ) ; externalIdFieldVars = getContext ( ) . createELVars ( ) ; externalIdFieldEval = context . createELEval ( EXTERNAL_ID_NAME ) ; ELUtils . validateExpression ( conf . externalIdField , context , Groups . FORCE . getLabel ( ) , EXTERNAL_ID_NAME , Errors . FORCE_24 , issues ) ; if ( issues . isEmpty ( ) ) { fieldMappings = new TreeMap <> ( ) ; for ( ForceFieldMapping mapping : conf . fieldMapping ) { // SDC-7446 Allow colon as well as period as field separator String salesforceField = conf . useBulkAPI ? mapping . salesforceField . replace ( ' ' , ' ' ) : mapping . salesforceField ; fieldMappings . put ( salesforceField , mapping . sdcField ) ; } try { ConnectorConfig partnerConfig = ForceUtils . getPartnerConfig ( conf , new ForceSessionRenewer ( ) ) ; partnerConnection = Connector . newConnection ( partnerConfig ) ; if ( conf . mutualAuth . useMutualAuth ) { ForceUtils . setupMutualAuth ( partnerConfig , conf . mutualAuth ) ; } bulkConnection = ForceUtils . getBulkConnection ( partnerConfig , conf ) ; LOG . info ( "Successfully authenticated as {}" , conf . username ) ; } catch ( ConnectionException | AsyncApiException | StageException | URISyntaxException ce ) { LOG . error ( "Can't connect to SalesForce" , ce ) ; issues . add ( getContext ( ) . createConfigIssue ( Groups . FORCE . name ( ) , "connectorConfig" , Errors . FORCE_00 , ForceUtils . getExceptionCode ( ce ) + ", " + ForceUtils . getExceptionMessage ( ce ) ) ) ; } if ( conf . useBulkAPI ) { writer = new ForceBulkWriter ( fieldMappings , bulkConnection , getContext ( ) ) ; } else { writer = new ForceSoapWriter ( fieldMappings , partnerConnection ) ; } } // If issues is not empty, the UI will inform the user of each configuration issue in the list. return issues ; }
{@inheritDoc}
{