Search in sources :

Example 6 with SyncStatus

use of org.talend.components.marketo.runtime.client.rest.type.SyncStatus in project components by Talend.

the class MarketoListOperationWriter method processResult.

private void processResult(MarketoSyncResult mktoResult) {
    cleanWrites();
    if (!mktoResult.isSuccess()) {
        // build a SyncStatus for record which failed
        SyncStatus status = new SyncStatus();
        status.setStatus("failed");
        status.setErrorMessage(mktoResult.getErrorsString());
        if (mktoResult.getRecords().isEmpty()) {
            mktoResult.setRecords(Arrays.asList(status));
        } else {
            List<SyncStatus> tmp = mktoResult.getRecords();
            tmp.add(status);
            mktoResult.setRecords(tmp);
        }
    }
    for (SyncStatus status : mktoResult.getRecords()) {
        if (Arrays.asList("true", "added", "removed", "notmemberof", "memberof").contains(status.getStatus().toLowerCase()) || (properties.isApiSOAP() && !addTo.equals(operation))) {
            handleSuccess(fillRecord(status, flowSchema));
        } else {
            if (dieOnError) {
                throw new MarketoRuntimeException(status.getAvailableReason());
            }
            handleReject(fillRecord(status, rejectSchema));
        }
    }
}
Also used : SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus)

Example 7 with SyncStatus

use of org.talend.components.marketo.runtime.client.rest.type.SyncStatus in project components by Talend.

the class MarketoRESTClientTestIT method testIsMemberOfList.

@Test
public void testIsMemberOfList() throws Exception {
    MarketoSource source = new MarketoSource();
    source.initialize(null, listProperties);
    MarketoClientService client = source.getClientService(null);
    // 
    ListOperationParameters parms = new ListOperationParameters();
    parms.setApiMode(APIMode.REST.name());
    parms.setListId(UNDX_TEST_LIST_SMALL_ID);
    parms.setLeadIds(new Integer[] { createdLeads.get(0), createdLeads.get(1), createdLeads.get(2) });
    // 
    MarketoSyncResult result = client.isMemberOfList(parms);
    LOG.debug("result = {}.", result);
    List<SyncStatus> changes = result.getRecords();
    assertTrue(changes.size() > 0);
    for (SyncStatus r : changes) {
        assertNotNull(r);
        assertNotNull(r.getId());
        assertEquals("memberof", r.getStatus());
        LOG.debug("r = {}.", r);
    }
}
Also used : ListOperationParameters(org.talend.components.marketo.runtime.client.type.ListOperationParameters) SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) Test(org.junit.Test)

Example 8 with SyncStatus

use of org.talend.components.marketo.runtime.client.rest.type.SyncStatus in project components by Talend.

the class MarketoRESTClientTestIT method testRemoveFromList.

@Test
public void testRemoveFromList() throws Exception {
    MarketoSource source = new MarketoSource();
    source.initialize(null, listProperties);
    MarketoClientService client = source.getClientService(null);
    // 
    ListOperationParameters parms = new ListOperationParameters();
    parms.setApiMode(APIMode.REST.name());
    parms.setListId(UNDX_TEST_LIST_SMALL_ID);
    parms.setLeadIds(new Integer[] { createdLeads.get(20) });
    // 
    // first subscribe lead
    MarketoSyncResult result = client.addToList(parms);
    LOG.debug("result = {}.", result);
    List<SyncStatus> changes = result.getRecords();
    assertTrue(changes.size() > 0);
    for (SyncStatus r : changes) {
        assertNotNull(r);
        assertNotNull(r.getId());
        LOG.debug("r = {}.", r);
    }
    // then remove it
    result = client.removeFromList(parms);
    LOG.debug("result = {}.", result);
    changes = result.getRecords();
    assertTrue(changes.size() > 0);
    for (SyncStatus r : changes) {
        assertNotNull(r);
        assertNotNull(r.getId());
        assertEquals("removed", r.getStatus());
        LOG.debug("r = {}.", r);
    }
}
Also used : ListOperationParameters(org.talend.components.marketo.runtime.client.type.ListOperationParameters) SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) Test(org.junit.Test)

Example 9 with SyncStatus

use of org.talend.components.marketo.runtime.client.rest.type.SyncStatus 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 10 with SyncStatus

use of org.talend.components.marketo.runtime.client.rest.type.SyncStatus in project components by Talend.

the class MarketoClientCustomObjectsTestIT method testDeleteCustomObjectsByIdField.

@Test
public void testDeleteCustomObjectsByIdField() throws Exception {
    MarketoSyncResult rs = createCustomObjectRecords("");
    assertTrue(rs.isSuccess());
    List<String> mktoIds = new ArrayList<>();
    for (SyncStatus sr : rs.getRecords()) {
        mktoIds.add(sr.getMarketoGUID());
    }
    // 
    oprops.customObjectName.setValue(TEST_CO_NAME_SMARTPHONE);
    Schema s = // 
    SchemaBuilder.record("sn").fields().name(FIELD_CO_MARKETO_GUID).type().stringType().noDefault().endRecord();
    List<IndexedRecord> records = new ArrayList<>();
    IndexedRecord r1;
    for (String m : mktoIds) {
        r1 = new Record(s);
        r1.put(0, m);
        records.add(r1);
    }
    MarketoSource source = new MarketoSource();
    oprops.customObjectDeleteBy.setValue(CustomObjectDeleteBy.idField);
    source.initialize(null, oprops);
    MarketoRESTClient client = (MarketoRESTClient) source.getClientService(null);
    rs = client.deleteCustomObjects(oprops, records);
    assertTrue(rs.isSuccess());
    List<SyncStatus> changes = rs.getRecords();
    assertEquals(TEST_SMARTPHONE_MODELS.length, changes.size());
    for (SyncStatus r : changes) {
        assertNotNull(r);
        assertNotNull(r.getSeq());
        assertEquals(STATUS_DELETED, r.getStatus());
        LOG.debug("r = {}.", r);
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) Record(org.apache.avro.generic.GenericData.Record) IndexedRecord(org.apache.avro.generic.IndexedRecord) MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) Test(org.junit.Test)

Aggregations

SyncStatus (org.talend.components.marketo.runtime.client.rest.type.SyncStatus)25 MarketoSyncResult (org.talend.components.marketo.runtime.client.type.MarketoSyncResult)23 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)13 MarketoSource (org.talend.components.marketo.runtime.MarketoSource)13 IndexedRecord (org.apache.avro.generic.IndexedRecord)11 ListOperationParameters (org.talend.components.marketo.runtime.client.type.ListOperationParameters)8 Schema (org.apache.avro.Schema)7 Record (org.apache.avro.generic.GenericData.Record)5 MarketoError (org.talend.components.marketo.runtime.client.type.MarketoError)5 MarketoException (org.talend.components.marketo.runtime.client.type.MarketoException)5 MalformedURLException (java.net.MalformedURLException)3 InvalidKeyException (java.security.InvalidKeyException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 ParseException (java.text.ParseException)3 JAXBContext (javax.xml.bind.JAXBContext)3 JAXBException (javax.xml.bind.JAXBException)3 Marshaller (javax.xml.bind.Marshaller)3 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)3 WebServiceException (javax.xml.ws.WebServiceException)3