use of org.apache.avro.generic.GenericData.Record in project components by Talend.
the class MarketoSOAPClient method convertLeadRecords.
public List<IndexedRecord> convertLeadRecords(List<LeadRecord> recordList, Schema schema, Map<String, String> mappings) {
List<IndexedRecord> results = new ArrayList<>();
for (LeadRecord input : recordList) {
IndexedRecord record = new Record(schema);
for (Field f : schema.getFields()) {
// find matching marketo column name
String col = mappings.get(f.name());
if (col == null) {
LOG.warn("[converLeadRecord] Couldn't find mapping for column {}.", f.name());
continue;
}
switch(col) {
case FIELD_ID:
record.put(f.pos(), input.getId() != null ? input.getId().getValue() : null);
break;
case FIELD_EMAIL:
record.put(f.pos(), input.getEmail() != null ? input.getEmail().getValue() : null);
break;
case FIELD_FOREIGN_SYS_PERSON_ID:
record.put(f.pos(), input.getForeignSysPersonId() != null ? input.getForeignSysPersonId().getValue() : null);
break;
case FIELD_FOREIGN_SYS_TYPE:
record.put(f.pos(), input.getForeignSysType() != null && input.getForeignSysType().getValue() != null ? input.getForeignSysType().getValue().value() : null);
break;
default:
if (!input.getLeadAttributeList().isNil()) {
for (Attribute attr : input.getLeadAttributeList().getValue().getAttributes()) {
if (attr.getAttrName().equals(col)) {
record.put(f.pos(), attr.getAttrValue());
}
}
}
}
}
results.add(record);
}
return results;
}
use of org.apache.avro.generic.GenericData.Record in project components by Talend.
the class MarketoClientCustomObjectsTestIT method createCustomObjectRecords.
public MarketoSyncResult createCustomObjectRecords(String dedupeBy) throws Exception {
oprops.customObjectName.setValue(TEST_CO_NAME_SMARTPHONE);
oprops.customObjectSyncAction.setValue(CustomObjectSyncAction.createOrUpdate);
oprops.customObjectDedupeBy.setValue(dedupeBy);
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);
MarketoSyncResult rs = client.syncCustomObjects(oprops, records);
return rs;
}
use of org.apache.avro.generic.GenericData.Record 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());
}
}
use of org.apache.avro.generic.GenericData.Record 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.apache.avro.generic.GenericData.Record in project components by Talend.
the class MarketoLeadClientTest method testSyncLead.
@Test
public void testSyncLead() throws Exception {
oprops.afterOutputOperation();
oprops.beforeMappingInput();
IndexedRecord record = new Record(MarketoConstants.getRESTOutputSchemaForSyncLead());
record.put(0, 12345);
record.put(1, "t@t.com");
//
doThrow(new MarketoException("REST", "error")).when(client).executePostRequest(eq(SyncResult.class), any(JsonObject.class));
mktoSR = client.syncLead(oprops, record);
assertFalse(mktoSR.isSuccess());
assertFalse(mktoSR.getErrorsString().isEmpty());
//
doReturn(new SyncResult()).when(client).executePostRequest(eq(SyncResult.class), any(JsonObject.class));
mktoSR = client.syncLead(oprops, record);
assertFalse(mktoSR.isSuccess());
//
SyncResult sr = new SyncResult();
sr.setSuccess(true);
List<SyncStatus> ssr = new ArrayList<>();
SyncStatus ss = new SyncStatus();
ss.setStatus("created");
ss.setMarketoGUID("mkto-123456");
ss.setSeq(0);
ss.setId(12345);
ss.setErrorMessage("");
ssr.add(ss);
sr.setResult(ssr);
doReturn(sr).when(client).executePostRequest(eq(SyncResult.class), any(JsonObject.class));
mktoSR = client.syncLead(oprops, record);
assertTrue(mktoSR.isSuccess());
assertTrue(mktoSR.getErrorsString().isEmpty());
}
Aggregations