use of com.marketo.mktows.Attribute in project components by Talend.
the class MarketoSOAPClientTest method getLeadActivityResult.
public SuccessGetLeadActivity getLeadActivityResult() throws Exception {
SuccessGetLeadActivity result = new SuccessGetLeadActivity();
LeadActivityList res = new LeadActivityList();
res.setReturnCount(1);
res.setRemainingCount(0);
StreamPosition sp = new StreamPosition();
sp.setOffset(objectFactory.createStreamPositionOffset(""));
res.setNewStartPosition(sp);
ArrayOfActivityRecord arecords = new ArrayOfActivityRecord();
//
ActivityRecord ar = new ActivityRecord();
ar.setId(objectFactory.createActivityRecordId(123456L));
ar.setMarketoGUID("ABC-123-DEF");
ar.setMktgAssetName("mktgAssetName");
ar.setActivityDateTime(factory.newXMLGregorianCalendar(gcDateTest));
ar.setActivityType("activityType");
ar.setCampaign(objectFactory.createActivityRecordCampaign("campaign"));
ar.setForeignSysId(objectFactory.createActivityRecordForeignSysId("foreignSysId"));
ar.setForeignSysOrgId(objectFactory.createActivityRecordForeignSysOrgId("foreignSysOrgId"));
ar.setMktPersonId("mktPersonId");
ar.setPersonName(objectFactory.createActivityRecordPersonName("personName"));
ar.setOrgName(objectFactory.createActivityRecordOrgName("orgName"));
ArrayOfAttribute aoa = objectFactory.createArrayOfAttribute();
Attribute attr = new Attribute();
attr.setAttrName("attrName");
attr.setAttrValue("attrValue");
aoa.getAttributes().add(attr);
ar.setActivityAttributes(objectFactory.createActivityRecordActivityAttributes(aoa));
//
arecords.getActivityRecords().add(ar);
res.setActivityRecordList(objectFactory.createLeadActivityListActivityRecordList(arecords));
result.setLeadActivityList(res);
return result;
}
use of com.marketo.mktows.Attribute 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.Attribute in project components by Talend.
the class MarketoSOAPClient method convertLeadChangeRecords.
private List<IndexedRecord> convertLeadChangeRecords(List<LeadChangeRecord> value, Schema schema, Map<String, String> mappings) {
List<IndexedRecord> results = new ArrayList<>();
for (LeadChangeRecord input : value) {
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("[convertLeadChangeRecords] Couldn't find mapping for column {}.", f.name());
continue;
}
switch(col) {
case FIELD_ID:
record.put(f.pos(), input.getId().getValue());
break;
case FIELD_MARKETO_GUID:
record.put(f.pos(), input.getMarketoGUID());
break;
case FIELD_ACTIVITY_DATE_TIME:
record.put(f.pos(), input.getActivityDateTime() != null ? input.getActivityDateTime().toGregorianCalendar().getTimeInMillis() : null);
break;
case FIELD_ACTIVITY_TYPE:
record.put(f.pos(), input.getActivityType());
break;
case FIELD_MKTG_ASSET_NAME:
record.put(f.pos(), input.getMktgAssetName() != null ? input.getMktgAssetName().getValue() : null);
break;
case FIELD_MKT_PERSON_ID:
record.put(f.pos(), input.getMktPersonId());
break;
case FIELD_CAMPAIGN:
record.put(f.pos(), input.getCampaign());
break;
default:
if (!input.getActivityAttributes().isNil()) {
for (Attribute attr : input.getActivityAttributes().getValue().getAttributes()) {
if (attr.getAttrName().equals(col)) {
record.put(f.pos(), attr.getAttrValue());
}
}
}
}
}
results.add(record);
}
return results;
}
use of com.marketo.mktows.Attribute in project components by Talend.
the class MarketoSOAPClient method convertLeadActivityRecords.
private List<IndexedRecord> convertLeadActivityRecords(List<ActivityRecord> activityRecords, Schema schema, Map<String, String> mappings) {
List<IndexedRecord> results = new ArrayList<>();
for (ActivityRecord input : activityRecords) {
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("[convertLeadActivityRecords] 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_MARKETO_GUID:
record.put(f.pos(), input.getMarketoGUID());
break;
case FIELD_ACTIVITY_DATE_TIME:
record.put(f.pos(), input.getActivityDateTime() != null ? input.getActivityDateTime().toGregorianCalendar().getTimeInMillis() : null);
break;
case FIELD_ACTIVITY_TYPE:
record.put(f.pos(), input.getActivityType());
break;
case FIELD_MKTG_ASSET_NAME:
record.put(f.pos(), input.getMktgAssetName());
break;
case FIELD_MKT_PERSON_ID:
record.put(f.pos(), input.getMktPersonId());
break;
case FIELD_CAMPAIGN:
record.put(f.pos(), input.getCampaign() != null ? input.getCampaign().getValue() : null);
break;
case FIELD_FOREIGN_SYS_ID:
record.put(f.pos(), input.getForeignSysId() != null ? input.getForeignSysId().getValue() : null);
break;
case FIELD_PERSON_NAME:
record.put(f.pos(), input.getPersonName() != null ? input.getPersonName().getValue() : null);
break;
case FIELD_ORG_NAME:
record.put(f.pos(), input.getOrgName() != null ? input.getOrgName().getValue() : null);
break;
case FIELD_FOREIGN_SYS_ORG_ID:
record.put(f.pos(), input.getForeignSysOrgId() != null ? input.getForeignSysOrgId().getValue() : null);
break;
default:
if (!input.getActivityAttributes().isNil()) {
for (Attribute attr : input.getActivityAttributes().getValue().getAttributes()) {
if (attr.getAttrName().equals(col)) {
record.put(f.pos(), attr.getAttrValue());
}
}
}
}
}
results.add(record);
}
return results;
}
use of com.marketo.mktows.Attribute 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;
}
Aggregations