use of com.marketo.mktows.LeadRecord in project components by Talend.
the class MarketoSOAPClientTest method getMultipleLeadResult.
public SuccessGetMultipleLeads getMultipleLeadResult() {
SuccessGetMultipleLeads result = new SuccessGetMultipleLeads();
ResultGetMultipleLeads res = new ResultGetMultipleLeads();
res.setReturnCount(1);
res.setRemainingCount(0);
ArrayOfLeadRecord leadrecords = new ArrayOfLeadRecord();
LeadRecord r = new LeadRecord();
r.setId(objectFactory.createLeadRecordId(12345));
r.setEmail(objectFactory.createLeadRecordEmail("t@t.com"));
r.setForeignSysPersonId(objectFactory.createLeadRecordForeignSysPersonId(""));
r.setForeignSysType(objectFactory.createLeadRecordForeignSysType(null));
leadrecords.getLeadRecords().add(r);
QName qname = new QName("http://www.marketo.com/mktows/", "leadAttributeList");
JAXBElement<ArrayOfLeadRecord> attrList = new JAXBElement(qname, LeadRecord.class, leadrecords);
res.setLeadRecordList(attrList);
result.setResult(res);
return result;
}
use of com.marketo.mktows.LeadRecord in project components by Talend.
the class MarketoSOAPClient method convertToLeadRecord.
/*
*
* SyncLeads operations
*
*/
public LeadRecord convertToLeadRecord(IndexedRecord record, Map<String, String> mappings) throws MarketoException {
// first, check if a mandatory field is in the schema
Boolean ok = Boolean.FALSE;
for (Entry<String, String> e : mappings.entrySet()) {
ok |= (e.getKey().equals(FIELD_ID) || e.getKey().equals(FIELD_EMAIL) || e.getKey().equals(FIELD_FOREIGN_SYS_PERSON_ID) || e.getValue().equals(FIELD_ID) || e.getValue().equals(FIELD_EMAIL) || e.getValue().equals(FIELD_FOREIGN_SYS_PERSON_ID)) && record.get(record.getSchema().getField(e.getKey()).pos()) != null;
}
if (!ok) {
MarketoException err = new MarketoException("SOAP", "syncLead error: Missing mandatory field for operation.");
LOG.error(err.toString());
throw err;
}
//
LeadRecord lead = new LeadRecord();
ArrayOfAttribute aoa = new ArrayOfAttribute();
for (Field f : record.getSchema().getFields()) {
// find matching marketo column name
String col = mappings.get(f.name());
if (col.equals(FIELD_ID)) {
final Integer id = (Integer) record.get(f.pos());
if (id != null) {
lead.setId(objectFactory.createLeadRecordId(id));
}
} else if (col.equals(FIELD_EMAIL)) {
final String email = (String) record.get(f.pos());
if (email != null) {
lead.setEmail(objectFactory.createLeadRecordEmail(email));
}
} else if (col.equals(FIELD_FOREIGN_SYS_PERSON_ID)) {
final String fspid = (String) record.get(f.pos());
if (fspid != null) {
lead.setForeignSysPersonId(objectFactory.createLeadRecordForeignSysPersonId(fspid));
}
} else if (col.equals(FIELD_FOREIGN_SYS_TYPE)) {
final String fst = (String) record.get(f.pos());
if (fst != null) {
lead.setForeignSysType(objectFactory.createLeadRecordForeignSysType(ForeignSysType.valueOf(fst)));
}
} else {
// skip status & error fields
if (FIELD_STATUS.equals(col) || FIELD_ERROR_MSG.equals(col)) {
continue;
}
Attribute attr = new Attribute();
Object value = record.get(f.pos());
attr.setAttrName(col);
if (MarketoClientUtils.isDateTypeField(f) && value != null) {
attr.setAttrValue(MarketoClientUtils.formatLongToDateString(Long.valueOf(String.valueOf(value))));
} else {
attr.setAttrValue(String.valueOf(value));
}
aoa.getAttributes().add(attr);
}
}
QName qname = new QName("http://www.marketo.com/mktows/", "leadAttributeList");
JAXBElement<ArrayOfAttribute> attrList = new JAXBElement(qname, ArrayOfAttribute.class, aoa);
lead.setLeadAttributeList(attrList);
return lead;
}
use of com.marketo.mktows.LeadRecord 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 com.marketo.mktows.LeadRecord in project components by Talend.
the class MarketoSOAPClientTestIT method testConvertToLeadRecord.
/*
*
* SyncLead Operations
*
*
*/
@Test
public void testConvertToLeadRecord() throws Exception {
outProperties.outputOperation.setValue(OutputOperation.syncLead);
outProperties.updateSchemaRelated();
outProperties.afterOutputOperation();
outProperties.beforeMappingInput();
MarketoSOAPClient client = new MarketoSOAPClient(outProperties.connection).connect();
IndexedRecord record = new GenericData.Record(outProperties.schemaInput.schema.getValue());
record.put(0, 10);
record.put(1, "undx@undx.net");
LeadRecord lr = client.convertToLeadRecord(record, outProperties.mappingInput.getNameMappingsForMarketo());
assertNotNull(lr);
assertEquals(new Integer(10), lr.getId().getValue());
assertEquals("undx@undx.net", lr.getEmail().getValue());
// test attributes
List<Field> fields = new ArrayList<>();
Field field = new Schema.Field("FirstName", Schema.create(Schema.Type.STRING), null, (Object) null);
fields.add(field);
field = new Schema.Field("LastName", Schema.create(Schema.Type.STRING), null, (Object) null);
fields.add(field);
Schema s = MarketoUtils.newSchema(outProperties.schemaInput.schema.getValue(), "leadAttribute", fields);
record = new GenericData.Record(s);
record.put(0, 10);
record.put(1, "undx@undx.net");
record.put(2, "ForeignPersonSysId");
// CUSTOM, SFDC, NETSUITE;
record.put(3, "SFDC");
record.put(5, "My firstName");
record.put(6, "My lastName");
outProperties.schemaInput.schema.setValue(s);
outProperties.beforeMappingInput();
lr = client.convertToLeadRecord(record, outProperties.mappingInput.getNameMappingsForMarketo());
assertNotNull(lr);
assertEquals(new Integer(10), lr.getId().getValue());
assertEquals("undx@undx.net", lr.getEmail().getValue());
assertEquals("ForeignPersonSysId", lr.getForeignSysPersonId().getValue());
assertEquals("SFDC", lr.getForeignSysType().getValue().toString());
assertEquals("My firstName", lr.getLeadAttributeList().getValue().getAttributes().get(0).getAttrValue().toString());
assertEquals("My lastName", lr.getLeadAttributeList().getValue().getAttributes().get(1).getAttrValue().toString());
// test mandatory field
record.put(0, 10);
record.put(1, null);
record.put(2, null);
lr = client.convertToLeadRecord(record, outProperties.mappingInput.getNameMappingsForMarketo());
assertNotNull(lr);
record.put(0, null);
record.put(1, "toto@toto.org");
record.put(2, null);
lr = client.convertToLeadRecord(record, outProperties.mappingInput.getNameMappingsForMarketo());
assertNotNull(lr);
assertNotNull(lr);
record.put(0, null);
record.put(1, null);
record.put(2, "SSDDSSDSD");
lr = client.convertToLeadRecord(record, outProperties.mappingInput.getNameMappingsForMarketo());
assertNotNull(lr);
record.put(0, null);
record.put(1, null);
record.put(2, null);
try {
lr = client.convertToLeadRecord(record, outProperties.mappingInput.getNameMappingsForMarketo());
assertNotNull(lr);
} catch (MarketoException e) {
assertEquals("syncLead error: Missing mandatory field for operation.", e.getMessage());
}
}
use of com.marketo.mktows.LeadRecord in project components by Talend.
the class MarketoSOAPClientTest method getGetLeadResult.
public SuccessGetLead getGetLeadResult() {
SuccessGetLead result = new SuccessGetLead();
ResultGetLead res = new ResultGetLead();
res.setCount(1);
ArrayOfLeadRecord leadrecords = new ArrayOfLeadRecord();
LeadRecord r = new LeadRecord();
r.setId(objectFactory.createLeadRecordId(12345));
r.setEmail(objectFactory.createLeadRecordEmail("email@email.com"));
r.setForeignSysPersonId(objectFactory.createLeadRecordForeignSysPersonId("foreignSysPersonId"));
r.setForeignSysType(objectFactory.createLeadRecordForeignSysType(ForeignSysType.SFDC));
ArrayOfAttribute aoa = objectFactory.createArrayOfAttribute();
Attribute attr = new Attribute();
attr.setAttrName("attrName");
attr.setAttrValue("attrValue");
aoa.getAttributes().add(attr);
r.setLeadAttributeList(objectFactory.createActivityRecordActivityAttributes(aoa));
leadrecords.getLeadRecords().add(r);
QName qname = new QName("http://www.marketo.com/mktows/", "leadAttributeList");
JAXBElement<ArrayOfLeadRecord> attrList = new JAXBElement(qname, LeadRecord.class, leadrecords);
res.setLeadRecordList(attrList);
result.setResult(res);
return result;
}
Aggregations