Search in sources :

Example 1 with Attribute

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;
}
Also used : ArrayOfActivityRecord(com.marketo.mktows.ArrayOfActivityRecord) ArrayOfAttribute(com.marketo.mktows.ArrayOfAttribute) ArrayOfAttribute(com.marketo.mktows.ArrayOfAttribute) Attribute(com.marketo.mktows.Attribute) SuccessGetLeadActivity(com.marketo.mktows.SuccessGetLeadActivity) StreamPosition(com.marketo.mktows.StreamPosition) ArrayOfActivityRecord(com.marketo.mktows.ArrayOfActivityRecord) ActivityRecord(com.marketo.mktows.ActivityRecord) LeadActivityList(com.marketo.mktows.LeadActivityList)

Example 2 with Attribute

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;
}
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 Attribute

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;
}
Also used : Field(org.apache.avro.Schema.Field) IndexedRecord(org.apache.avro.generic.IndexedRecord) 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) LeadChangeRecord(com.marketo.mktows.LeadChangeRecord)

Example 4 with Attribute

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

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

Aggregations

ArrayOfAttribute (com.marketo.mktows.ArrayOfAttribute)7 Attribute (com.marketo.mktows.Attribute)7 ArrayOfLeadRecord (com.marketo.mktows.ArrayOfLeadRecord)5 LeadRecord (com.marketo.mktows.LeadRecord)5 ActivityRecord (com.marketo.mktows.ActivityRecord)4 ArrayOfString (com.marketo.mktows.ArrayOfString)4 LeadChangeRecord (com.marketo.mktows.LeadChangeRecord)4 Field (org.apache.avro.Schema.Field)4 ArrayList (java.util.ArrayList)3 Record (org.apache.avro.generic.GenericData.Record)3 IndexedRecord (org.apache.avro.generic.IndexedRecord)3 StreamPosition (com.marketo.mktows.StreamPosition)2 JAXBElement (javax.xml.bind.JAXBElement)2 QName (javax.xml.namespace.QName)2 ArrayOfActivityRecord (com.marketo.mktows.ArrayOfActivityRecord)1 ArrayOfLeadChangeRecord (com.marketo.mktows.ArrayOfLeadChangeRecord)1 LeadActivityList (com.marketo.mktows.LeadActivityList)1 ResultGetLead (com.marketo.mktows.ResultGetLead)1 ResultGetLeadChanges (com.marketo.mktows.ResultGetLeadChanges)1 SuccessGetLead (com.marketo.mktows.SuccessGetLead)1