Search in sources :

Example 16 with SyncStatus

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

the class MarketoRESTClientTestIT method testAddToList.

/*
     * 
     * 
     * ListOperations
     *
     */
@Test
public void testAddToList() 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(10) });
    // 
    // first make sure to remove lead
    MarketoSyncResult result = client.removeFromList(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 add it
    result = client.addToList(parms);
    LOG.debug("result = {}.", result);
    changes = result.getRecords();
    assertTrue(changes.size() > 0);
    for (SyncStatus r : changes) {
        assertNotNull(r);
        assertNotNull(r.getId());
        assertEquals("added", 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 17 with SyncStatus

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

the class MarketoRESTClientTestIT method testDeleteLeads.

/*
     *
     * management func
     *
     */
@Test
public void testDeleteLeads() throws Exception {
    MarketoSource source = new MarketoSource();
    source.initialize(null, outProperties);
    MarketoRESTClient client = (MarketoRESTClient) source.getClientService(null);
    // 
    Integer[] ids = { 0, 1, 2, 2 };
    MarketoSyncResult result = client.deleteLeads(ids);
    LOG.debug("result = {}.", result);
    List<SyncStatus> changes = result.getRecords();
    assertTrue(changes.size() > 0);
    for (SyncStatus r : changes) {
        assertNotNull(r);
        assertNotNull(r.getId());
        assertEquals("skipped", r.getStatus());
        LOG.debug("r = {}.", r);
    }
    // writer
    outProperties.outputOperation.setValue(OutputOperation.deleteLeads);
    outProperties.afterOutputOperation();
    List<IndexedRecord> leads = new ArrayList<>();
    Schema s = outProperties.schemaInput.schema.getValue();
    IndexedRecord record;
    for (int i = 0; i < 10; i++) {
        record = new GenericData.Record(s);
        record.put(0, createdLeads.get(i));
        leads.add(record);
    }
    // Non existing lead
    record = new GenericData.Record(s);
    record.put(0, 123);
    leads.add(record);
    MarketoSyncResult rs = client.deleteLeads(leads);
    for (SyncStatus sync : rs.getRecords()) {
        assertNotNull(sync);
        LOG.debug("sync = {}.", sync);
        if (sync.getId().equals(123)) {
            assertEquals("skipped", sync.getStatus());
            assertEquals("[1004] Lead not found.", sync.getAvailableReason());
        } else {
            assertEquals("deleted", sync.getStatus());
        }
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) ArrayList(java.util.ArrayList) GenericData(org.apache.avro.generic.GenericData) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) MarketoSource(org.talend.components.marketo.runtime.MarketoSource) Test(org.junit.Test)

Example 18 with SyncStatus

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

the class MarketoOutputWriter method processResult.

public 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);
        }
    }
    int idx = 0;
    for (SyncStatus status : mktoResult.getRecords()) {
        IndexedRecord statusRecord = recordsToProcess.get(idx);
        idx++;
        boolean isSuccess = Arrays.asList("created", "updated", "deleted", "scheduled", "triggered").contains(status.getStatus().toLowerCase());
        if (isBatchMode) {
            if (!isSuccess && dieOnError) {
                throw new MarketoRuntimeException(status.getAvailableReason());
            }
            // in batchmode we have only 0 or 1 connector only
            handleSuccess(fillRecord(status, flowSchema, statusRecord));
            if (!isSuccess) {
                // readjust counts
                result.successCount--;
                result.rejectCount++;
            }
        } else {
            if (isSuccess) {
                handleSuccess(fillRecord(status, flowSchema, statusRecord));
            } else {
                if (dieOnError) {
                    throw new MarketoRuntimeException(status.getAvailableReason());
                }
                handleReject(fillRecord(status, rejectSchema, statusRecord));
            }
        }
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus)

Example 19 with SyncStatus

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

the class MarketoClientCustomObjectsTestIT method testDeleteCustomObjectsFailWithWrongFields.

@Test
public void testDeleteCustomObjectsFailWithWrongFields() throws Exception {
    MarketoSyncResult rs = createCustomObjectRecords("");
    assertTrue(rs.isSuccess());
    // 
    oprops.customObjectName.setValue(TEST_CO_NAME_SMARTPHONE);
    Schema s = // 
    SchemaBuilder.record("sn").fields().name(FIELD_CO_SMARTPHONE_BRAND).type().stringType().noDefault().name(FIELD_CO_SMARTPHONE_MODEL).type().stringType().noDefault().name(FIELD_CO_SMARTPHONE_CUSTOMER_ID).type().intType().noDefault().endRecord();
    List<IndexedRecord> records = new ArrayList<>();
    IndexedRecord r1;
    for (String m : TEST_SMARTPHONE_MODELS) {
        r1 = new Record(s);
        r1.put(0, TEST_SMARTPHONE_BRAND_SAMSUNG);
        r1.put(1, m);
        r1.put(2, 3113479);
        records.add(r1);
    }
    MarketoSource source = new MarketoSource();
    source.initialize(null, irProps);
    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_SKIPPED, r.getStatus());
    }
}
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)

Example 20 with SyncStatus

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

the class MarketoClientCustomObjectsTestIT method testSyncCustomObjects.

@Test
public void testSyncCustomObjects() throws Exception {
    MarketoSyncResult rs = createCustomObjectRecords("");
    assertTrue(rs.isSuccess());
    List<SyncStatus> changes = rs.getRecords();
    assertEquals(TEST_SMARTPHONE_MODELS.length, changes.size());
    for (SyncStatus r : changes) {
        assertNotNull(r);
        assertNotNull(r.getSeq());
        assertNotNull(r.getMarketoGUID());
        assertTrue(r.getStatus().equals(STATUS_UPDATED) || r.getStatus().equals(STATUS_CREATED));
    }
}
Also used : SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) 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