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);
}
}
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));
}
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;
}
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;
}
Aggregations