Search in sources :

Example 6 with TMarketoOutputProperties

use of org.talend.components.marketo.tmarketooutput.TMarketoOutputProperties in project components by Talend.

the class MarketoBaseTestIT method createDatasets.

public static void createDatasets(int numberOfLeads) throws Exception {
    LOG.info("Creating test leads");
    TMarketoOutputProperties p = initClient();
    if (numberOfLeads < 5) {
        numberOfLeads = 5;
    }
    // create leads for tests
    // test attributes
    List<Field> fields = new ArrayList<>();
    Field field = new Schema.Field("accountType", Schema.create(Schema.Type.STRING), null, (Object) null);
    fields.add(field);
    field = new Schema.Field("linkedInId", Schema.create(Type.INT), null, (Object) null);
    fields.add(field);
    field = new Schema.Field("sfdcAccountId", Schema.create(Type.STRING), null, (Object) null);
    fields.add(field);
    field = new Schema.Field("company", Schema.create(Type.STRING), null, (Object) null);
    fields.add(field);
    Schema s = MarketoUtils.newSchema(p.schemaInput.schema.getValue(), "leadAttribute", fields);
    p.schemaInput.schema.setValue(s);
    p.updateOutputSchemas();
    // 
    List<IndexedRecord> leads = new ArrayList<>();
    // 
    for (int i = 0; i < numberOfLeads; i++) {
        IndexedRecord record = new GenericData.Record(s);
        record.put(0, null);
        record.put(1, String.format("%s%02d%s", EMAIL_PREFIX, i, EMAIL_DOMAIN));
        record.put(2, String.format("firstName%02d", i));
        record.put(3, String.format("lastName%02d", i));
        record.put(4, String.format("Account Type %02d", i));
        // all the same linkedInId.
        record.put(5, COMMON_LINKEDIN_ID);
        // all the same SalesforceId.
        record.put(6, COMMON_SFDC_ACCOUNT_ID);
        // all the same SalesforceId.
        record.put(7, "Retail-Dev");
        leads.add(record);
    }
    // /
    MarketoSyncResult result = datasetsClient.syncMultipleLeads(p, leads);
    LOG.debug("result = {}.", result);
    List<SyncStatus> changes = result.getRecords();
    assertTrue(changes.size() > 0);
    for (SyncStatus r : changes) {
        assertNotNull(r);
        assertNotNull(r.getId());
        createdLeads.add(r.getId());
    }
    LOG.info("Created {} leads for tests. Now adding 5 leads to {} list.", createdLeads.size(), UNDX_TEST_LIST_SMALL);
    // adding 5 members to test list
    ListOperationParameters parms = new ListOperationParameters();
    parms.setApiMode(REST.name());
    parms.setListId(UNDX_TEST_LIST_SMALL_ID);
    parms.setLeadIds(new Integer[] { createdLeads.get(0), createdLeads.get(1), createdLeads.get(2), createdLeads.get(3), createdLeads.get(4) });
    // 
    result = datasetsClient.addToList(parms);
    LOG.debug("result = {}.", result);
    LOG.info("Test Dataset created successfully.");
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) ListOperationParameters(org.talend.components.marketo.runtime.client.type.ListOperationParameters) ArrayList(java.util.ArrayList) SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) Field(org.apache.avro.Schema.Field) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) Field(org.apache.avro.Schema.Field) TMarketoOutputProperties(org.talend.components.marketo.tmarketooutput.TMarketoOutputProperties) IndexedRecord(org.apache.avro.generic.IndexedRecord)

Example 7 with TMarketoOutputProperties

use of org.talend.components.marketo.tmarketooutput.TMarketoOutputProperties in project components by Talend.

the class MarketoSOAPClientTestIT method setUp.

@Before
public void setUp() throws Exception {
    inputProperties = new TMarketoInputProperties("test");
    inputProperties.connection.setupProperties();
    inputProperties.connection.endpoint.setValue(ENDPOINT_SOAP);
    inputProperties.connection.clientAccessId.setValue(USERID_SOAP);
    inputProperties.connection.secretKey.setValue(SECRETKEY_SOAP);
    inputProperties.schemaInput.setupProperties();
    inputProperties.mappingInput.setupProperties();
    inputProperties.includeTypes.setupProperties();
    inputProperties.setupProperties();
    inputProperties.connection.apiMode.setValue(SOAP);
    inputProperties.includeTypes.type.setValue(new ArrayList<String>());
    inputProperties.excludeTypes.setupProperties();
    inputProperties.excludeTypes.type.setValue(new ArrayList<String>());
    inputProperties.connection.setupLayout();
    inputProperties.schemaInput.setupLayout();
    inputProperties.setupLayout();
    // 
    listProperties = new TMarketoListOperationProperties("test");
    listProperties.connection.setupProperties();
    listProperties.connection.endpoint.setValue(ENDPOINT_SOAP);
    listProperties.connection.clientAccessId.setValue(USERID_SOAP);
    listProperties.connection.secretKey.setValue(SECRETKEY_SOAP);
    listProperties.schemaInput.setupProperties();
    listProperties.setupProperties();
    listProperties.connection.apiMode.setValue(SOAP);
    listProperties.connection.setupLayout();
    listProperties.schemaInput.setupLayout();
    listProperties.setupLayout();
    // 
    outProperties = new TMarketoOutputProperties("test");
    outProperties.connection.setupProperties();
    outProperties.connection.endpoint.setValue(ENDPOINT_SOAP);
    outProperties.connection.clientAccessId.setValue(USERID_SOAP);
    outProperties.connection.secretKey.setValue(SECRETKEY_SOAP);
    outProperties.schemaInput.setupProperties();
    outProperties.setupProperties();
    outProperties.connection.apiMode.setValue(SOAP);
    outProperties.connection.setupLayout();
    outProperties.schemaInput.setupLayout();
    outProperties.setupLayout();
}
Also used : TMarketoOutputProperties(org.talend.components.marketo.tmarketooutput.TMarketoOutputProperties) TMarketoListOperationProperties(org.talend.components.marketo.tmarketolistoperation.TMarketoListOperationProperties) TMarketoInputProperties(org.talend.components.marketo.tmarketoinput.TMarketoInputProperties) Before(org.junit.Before)

Example 8 with TMarketoOutputProperties

use of org.talend.components.marketo.tmarketooutput.TMarketoOutputProperties in project components by Talend.

the class MarketoSink method validate.

@Override
public ValidationResult validate(RuntimeContainer container) {
    ValidationResultMutable vr = new ValidationResultMutable(super.validate(container));
    if (vr.getStatus().equals(Result.ERROR)) {
        return vr;
    }
    // output
    if (properties instanceof TMarketoOutputProperties) {
        switch(((TMarketoOutputProperties) properties).outputOperation.getValue()) {
            case syncLead:
                break;
            case syncMultipleLeads:
                break;
            case deleteLeads:
                break;
            case syncCustomObjects:
                if (StringUtils.isEmpty(((TMarketoOutputProperties) properties).customObjectName.getValue())) {
                    vr.setStatus(Result.ERROR);
                    vr.setMessage(messages.getMessage("error.validation.customobject.customobjectname"));
                    return vr;
                }
                if (StringUtils.isEmpty(((TMarketoOutputProperties) properties).customObjectDedupeBy.getValue())) {
                // TODO check API if required. Not sure...
                }
                break;
            case deleteCustomObjects:
                if (StringUtils.isEmpty(((TMarketoOutputProperties) properties).customObjectName.getValue())) {
                    vr.setStatus(Result.ERROR);
                    vr.setMessage(messages.getMessage("error.validation.customobject.customobjectname"));
                    return vr;
                }
                break;
        }
    }
    // check list operations
    if (properties instanceof TMarketoListOperationProperties) {
    // nothing to check for now.
    }
    // check getMultipleLeads with an input
    if (properties instanceof TMarketoInputProperties) {
        // operation must be getMultipleLeads
        if (!((TMarketoInputProperties) properties).inputOperation.getValue().equals(InputOperation.getMultipleLeads)) {
            vr.setStatus(Result.ERROR);
            vr.setMessage(messages.getMessage("error.validation.sink.getmultipleleads.only"));
            return vr;
        }
        // lead selector must be LeadKeySelector
        LeadSelector selector;
        if (APIMode.SOAP.equals(properties.getConnectionProperties().apiMode.getValue())) {
            selector = ((TMarketoInputProperties) properties).leadSelectorSOAP.getValue();
        } else {
            selector = ((TMarketoInputProperties) properties).leadSelectorREST.getValue();
        }
        if (!selector.equals(LeadSelector.LeadKeySelector)) {
            vr.setStatus(Result.ERROR);
            vr.setMessage(messages.getMessage("error.validation.sink.leadkeyselector.only"));
            return vr;
        }
        // lead key values must be defined
        if (StringUtils.isEmpty(((TMarketoInputProperties) properties).leadKeyValues.getValue())) {
            vr.setStatus(Result.ERROR);
            vr.setMessage(messages.getMessage("error.validation.leadkeyvalues"));
            return vr;
        }
    }
    return ValidationResult.OK;
}
Also used : TMarketoOutputProperties(org.talend.components.marketo.tmarketooutput.TMarketoOutputProperties) ValidationResultMutable(org.talend.daikon.properties.ValidationResultMutable) TMarketoListOperationProperties(org.talend.components.marketo.tmarketolistoperation.TMarketoListOperationProperties) TMarketoInputProperties(org.talend.components.marketo.tmarketoinput.TMarketoInputProperties) LeadSelector(org.talend.components.marketo.tmarketoinput.TMarketoInputProperties.LeadSelector)

Example 9 with TMarketoOutputProperties

use of org.talend.components.marketo.tmarketooutput.TMarketoOutputProperties in project components by Talend.

the class MarketoOutputWriterTestIT method getSOAPProperties.

public TMarketoOutputProperties getSOAPProperties() {
    TMarketoOutputProperties props = new TMarketoOutputProperties("test");
    props.setupProperties();
    props.connection.setupProperties();
    props.connection.endpoint.setValue(ENDPOINT_SOAP);
    props.connection.clientAccessId.setValue(USERID_SOAP);
    props.connection.secretKey.setValue(SECRETKEY_SOAP);
    props.connection.setupLayout();
    props.schemaInput.setupProperties();
    props.schemaInput.setupLayout();
    props.setupLayout();
    props.connection.apiMode.setValue(APIMode.SOAP);
    props.schemaInput.schema.setValue(MarketoConstants.getSOAPOutputSchemaForSyncLead());
    props.schemaListener.afterSchema();
    return props;
}
Also used : TMarketoOutputProperties(org.talend.components.marketo.tmarketooutput.TMarketoOutputProperties)

Example 10 with TMarketoOutputProperties

use of org.talend.components.marketo.tmarketooutput.TMarketoOutputProperties in project components by Talend.

the class MarketoOutputWriterTestIT method getRESTProperties.

public TMarketoOutputProperties getRESTProperties() {
    TMarketoOutputProperties props = new TMarketoOutputProperties("test");
    props.setupProperties();
    props.connection.setupProperties();
    props.connection.endpoint.setValue(ENDPOINT_REST);
    props.connection.clientAccessId.setValue(USERID_REST);
    props.connection.secretKey.setValue(SECRETKEY_REST);
    props.connection.setupLayout();
    props.schemaInput.setupProperties();
    props.schemaInput.setupLayout();
    props.setupLayout();
    props.connection.apiMode.setValue(REST);
    props.schemaInput.schema.setValue(MarketoConstants.getRESTOutputSchemaForSyncLead());
    props.schemaListener.afterSchema();
    return props;
}
Also used : TMarketoOutputProperties(org.talend.components.marketo.tmarketooutput.TMarketoOutputProperties)

Aggregations

TMarketoOutputProperties (org.talend.components.marketo.tmarketooutput.TMarketoOutputProperties)17 Before (org.junit.Before)9 TMarketoInputProperties (org.talend.components.marketo.tmarketoinput.TMarketoInputProperties)9 TMarketoListOperationProperties (org.talend.components.marketo.tmarketolistoperation.TMarketoListOperationProperties)7 Test (org.junit.Test)3 AuthenticationHeader (com.marketo.mktows.AuthenticationHeader)1 MktowsPort (com.marketo.mktows.MktowsPort)1 ObjectFactory (com.marketo.mktows.ObjectFactory)1 ParamsListMObjects (com.marketo.mktows.ParamsListMObjects)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 Schema (org.apache.avro.Schema)1 Field (org.apache.avro.Schema.Field)1 IndexedRecord (org.apache.avro.generic.IndexedRecord)1 RuntimeContainer (org.talend.components.api.container.RuntimeContainer)1 MarketoProvideConnectionProperties (org.talend.components.marketo.MarketoProvideConnectionProperties)1 SyncStatus (org.talend.components.marketo.runtime.client.rest.type.SyncStatus)1 ListOperationParameters (org.talend.components.marketo.runtime.client.type.ListOperationParameters)1 MarketoSyncResult (org.talend.components.marketo.runtime.client.type.MarketoSyncResult)1