Search in sources :

Example 26 with MarketoSyncResult

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

the class MarketoClientCustomObjectsTestIT method testDeleteCustomObjectsByDedupeFields.

@Test
public void testDeleteCustomObjectsByDedupeFields() 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_MODEL).type().stringType().noDefault().endRecord();
    List<IndexedRecord> records = new ArrayList<>();
    IndexedRecord r1;
    for (String m : TEST_SMARTPHONE_MODELS) {
        r1 = new Record(s);
        r1.put(0, m);
        records.add(r1);
    }
    MarketoSource source = new MarketoSource();
    oprops.customObjectDeleteBy.setValue(CustomObjectDeleteBy.dedupeFields);
    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)

Example 27 with MarketoSyncResult

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

the class MarketoClientCustomObjectsTestIT method testGetCustomObjectsPagination.

@Test
public void testGetCustomObjectsPagination() throws Exception {
    MarketoSyncResult rs = createCustomObjectRecords("");
    MarketoSource source = new MarketoSource();
    source.initialize(null, irProps);
    MarketoRESTClient client = (MarketoRESTClient) source.getClientService(null);
    irProps.customObjectName.setValue(TEST_CO_NAME_SMARTPHONE);
    irProps.batchSize.setValue(1);
    irProps.schemaInput.schema.setValue(MarketoConstants.getCustomObjectRecordSchema());
    irProps.customObjectFilterType.setValue(FIELD_CO_SMARTPHONE_MODEL);
    irProps.customObjectFilterValues.setValue(MarketoRESTClient.csvString(TEST_SMARTPHONE_MODELS));
    MarketoRecordResult result = client.getCustomObjects(irProps, null);
    assertNotNull(result.getRecords());
    assertTrue(result.getRemainCount() > 0);
    assertEquals(1, result.getRecords().size());
    LOG.debug("result = {}.", result.getRecords().get(0));
    result = client.getCustomObjects(irProps, result.getStreamPosition());
    assertNotNull(result.getRecords());
    assertEquals(1, result.getRecords().size());
    checkCustomObjectRecord(result.getRecords().get(0));
}
Also used : MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) Test(org.junit.Test)

Example 28 with MarketoSyncResult

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

the class MarketoBaseRESTClient method getSyncResultFromRequest.

/**
 * Execute POST or GET request and feed the MarketoSyncResult to return
 *
 * @param paramPOSTJson
 * @return
 */
public MarketoSyncResult getSyncResultFromRequest(boolean sendPOST, JsonObject paramPOSTJson) {
    MarketoSyncResult mkto = new MarketoSyncResult();
    try {
        SyncResult rs;
        if (sendPOST) {
            rs = (SyncResult) executePostRequest(SyncResult.class, paramPOSTJson);
        } else {
            rs = (SyncResult) executeGetRequest(SyncResult.class);
        }
        // 
        mkto.setRequestId(REST + "::" + rs.getRequestId());
        mkto.setStreamPosition(rs.getNextPageToken());
        mkto.setSuccess(rs.isSuccess());
        if (mkto.isSuccess()) {
            mkto.setRecordCount(rs.getResult().size());
            mkto.setRemainCount(0);
            mkto.setRecords(rs.getResult());
            if (rs.isMoreResult()) {
                // cannot know how many remain...
                mkto.setRemainCount(mkto.getRecordCount());
                mkto.setStreamPosition(rs.getNextPageToken());
            }
        // 
        } else {
            mkto.setRecordCount(0);
            mkto.setErrors(rs.getErrors());
        }
        LOG.debug("rs = {}.", rs);
    } catch (MarketoException e) {
        mkto.setSuccess(false);
        mkto.setErrors(Collections.singletonList(e.toMarketoError()));
    }
    return mkto;
}
Also used : MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) SyncResult(org.talend.components.marketo.runtime.client.rest.response.SyncResult) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult)

Example 29 with MarketoSyncResult

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

the class MarketoRuntimeTestBase method getFailedSyncResult.

public MarketoSyncResult getFailedSyncResult(boolean withSyncRecord) {
    MarketoSyncResult mkto = new MarketoSyncResult();
    mkto.setSuccess(false);
    mkto.setErrors(Arrays.asList(new MarketoError("REST", "error")));
    if (withSyncRecord) {
        SyncStatus sts1 = new SyncStatus();
        sts1.setId(12345);
        sts1.setStatus("failed");
        sts1.setMarketoGUID("mktoGUID");
        sts1.setSeq(0);
        List<SyncStatus> stl = new ArrayList<>();
        stl.add(sts1);
        mkto.setRecords(stl);
    }
    return mkto;
}
Also used : SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) ArrayList(java.util.ArrayList) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) MarketoError(org.talend.components.marketo.runtime.client.type.MarketoError)

Aggregations

MarketoSyncResult (org.talend.components.marketo.runtime.client.type.MarketoSyncResult)29 SyncStatus (org.talend.components.marketo.runtime.client.rest.type.SyncStatus)20 Test (org.junit.Test)18 MarketoSource (org.talend.components.marketo.runtime.MarketoSource)17 ArrayList (java.util.ArrayList)13 IndexedRecord (org.apache.avro.generic.IndexedRecord)10 Schema (org.apache.avro.Schema)9 ListOperationParameters (org.talend.components.marketo.runtime.client.type.ListOperationParameters)8 MarketoError (org.talend.components.marketo.runtime.client.type.MarketoError)5 Field (org.apache.avro.Schema.Field)4 Record (org.apache.avro.generic.GenericData.Record)4 MarketoException (org.talend.components.marketo.runtime.client.type.MarketoException)4 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