Search in sources :

Example 1 with LeadRecord

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;
}
Also used : ArrayOfLeadRecord(com.marketo.mktows.ArrayOfLeadRecord) ArrayOfLeadRecord(com.marketo.mktows.ArrayOfLeadRecord) LeadRecord(com.marketo.mktows.LeadRecord) QName(javax.xml.namespace.QName) SuccessGetMultipleLeads(com.marketo.mktows.SuccessGetMultipleLeads) JAXBElement(javax.xml.bind.JAXBElement) ResultGetMultipleLeads(com.marketo.mktows.ResultGetMultipleLeads)

Example 2 with LeadRecord

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;
}
Also used : ArrayOfAttribute(com.marketo.mktows.ArrayOfAttribute) ArrayOfAttribute(com.marketo.mktows.ArrayOfAttribute) Attribute(com.marketo.mktows.Attribute) QName(javax.xml.namespace.QName) MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) ArrayOfString(com.marketo.mktows.ArrayOfString) JAXBElement(javax.xml.bind.JAXBElement) Field(org.apache.avro.Schema.Field) ArrayOfLeadRecord(com.marketo.mktows.ArrayOfLeadRecord) LeadRecord(com.marketo.mktows.LeadRecord)

Example 3 with LeadRecord

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;
}
Also used : Field(org.apache.avro.Schema.Field) IndexedRecord(org.apache.avro.generic.IndexedRecord) ArrayOfLeadRecord(com.marketo.mktows.ArrayOfLeadRecord) LeadRecord(com.marketo.mktows.LeadRecord) ArrayOfAttribute(com.marketo.mktows.ArrayOfAttribute) Attribute(com.marketo.mktows.Attribute) ArrayList(java.util.ArrayList) Record(org.apache.avro.generic.GenericData.Record) ActivityRecord(com.marketo.mktows.ActivityRecord) LeadChangeRecord(com.marketo.mktows.LeadChangeRecord) ArrayOfLeadRecord(com.marketo.mktows.ArrayOfLeadRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) LeadRecord(com.marketo.mktows.LeadRecord) ArrayOfString(com.marketo.mktows.ArrayOfString)

Example 4 with LeadRecord

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());
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) ArrayList(java.util.ArrayList) Field(org.apache.avro.Schema.Field) GenericData(org.apache.avro.generic.GenericData) Field(org.apache.avro.Schema.Field) LeadRecord(com.marketo.mktows.LeadRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) LeadRecord(com.marketo.mktows.LeadRecord) Test(org.junit.Test)

Example 5 with LeadRecord

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;
}
Also used : ArrayOfLeadRecord(com.marketo.mktows.ArrayOfLeadRecord) ArrayOfAttribute(com.marketo.mktows.ArrayOfAttribute) ArrayOfLeadRecord(com.marketo.mktows.ArrayOfLeadRecord) LeadRecord(com.marketo.mktows.LeadRecord) ArrayOfAttribute(com.marketo.mktows.ArrayOfAttribute) Attribute(com.marketo.mktows.Attribute) QName(javax.xml.namespace.QName) SuccessGetLead(com.marketo.mktows.SuccessGetLead) ResultGetLead(com.marketo.mktows.ResultGetLead) JAXBElement(javax.xml.bind.JAXBElement)

Aggregations

LeadRecord (com.marketo.mktows.LeadRecord)6 ArrayOfLeadRecord (com.marketo.mktows.ArrayOfLeadRecord)5 ArrayOfAttribute (com.marketo.mktows.ArrayOfAttribute)3 Attribute (com.marketo.mktows.Attribute)3 JAXBElement (javax.xml.bind.JAXBElement)3 QName (javax.xml.namespace.QName)3 Field (org.apache.avro.Schema.Field)3 ArrayOfString (com.marketo.mktows.ArrayOfString)2 ArrayList (java.util.ArrayList)2 IndexedRecord (org.apache.avro.generic.IndexedRecord)2 MarketoException (org.talend.components.marketo.runtime.client.type.MarketoException)2 ActivityRecord (com.marketo.mktows.ActivityRecord)1 ArrayOfSyncStatus (com.marketo.mktows.ArrayOfSyncStatus)1 LeadChangeRecord (com.marketo.mktows.LeadChangeRecord)1 LeadSyncStatus (com.marketo.mktows.LeadSyncStatus)1 ResultGetLead (com.marketo.mktows.ResultGetLead)1 ResultGetMultipleLeads (com.marketo.mktows.ResultGetMultipleLeads)1 ResultSyncLead (com.marketo.mktows.ResultSyncLead)1 SuccessGetLead (com.marketo.mktows.SuccessGetLead)1 SuccessGetMultipleLeads (com.marketo.mktows.SuccessGetMultipleLeads)1