Search in sources :

Example 1 with SuccessGetLead

use of com.marketo.mktows.SuccessGetLead in project components by Talend.

the class MarketoSOAPClient method getLead.

@Override
public MarketoRecordResult getLead(TMarketoInputProperties parameters, String offset) {
    LOG.debug("MarketoSOAPClient.getLead with selector:{} key:{} value:{}.", parameters.leadSelectorSOAP.getValue(), parameters.leadKeyTypeSOAP.getValue(), parameters.leadKeyValue.getValue());
    String leadKeyType = parameters.leadKeyTypeSOAP.getValue().toString();
    String leadKeyValue = parameters.leadKeyValue.getValue();
    Schema schema = parameters.schemaInput.schema.getValue();
    Map<String, String> mappings = parameters.mappingInput.getNameMappingsForMarketo();
    // Create Request
    ParamsGetLead request = new ParamsGetLead();
    LeadKey key = new LeadKey();
    key.setKeyType(valueOf(leadKeyType));
    key.setKeyValue(leadKeyValue);
    request.setLeadKey(key);
    // 
    SuccessGetLead result = null;
    MarketoRecordResult mkto = new MarketoRecordResult();
    try {
        result = getPort().getLead(request, header);
    } catch (Exception e) {
        LOG.error("Lead not found : {}.", e.getMessage());
        mkto.setSuccess(false);
        mkto.setRecordCount(0);
        mkto.setRemainCount(0);
        mkto.setErrors(Collections.singletonList(new MarketoError(SOAP, e.getMessage())));
        return mkto;
    }
    if (result == null || result.getResult().getCount() == 0) {
        LOG.debug(MESSAGE_REQUEST_RETURNED_0_MATCHING_LEADS);
        mkto.setErrors(Collections.singletonList(new MarketoError(SOAP, MESSAGE_NO_LEADS_FOUND)));
        mkto.setSuccess(true);
    } else {
        int counted = result.getResult().getCount();
        List<IndexedRecord> results = convertLeadRecords(result.getResult().getLeadRecordList().getValue().getLeadRecords(), schema, mappings);
        mkto.setRecordCount(counted);
        mkto.setRemainCount(0);
        mkto.setSuccess(true);
        mkto.setRecords(results);
    }
    return mkto;
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) SuccessGetLead(com.marketo.mktows.SuccessGetLead) ArrayOfString(com.marketo.mktows.ArrayOfString) LeadKey(com.marketo.mktows.LeadKey) ArrayOfLeadKey(com.marketo.mktows.ArrayOfLeadKey) ParamsGetLead(com.marketo.mktows.ParamsGetLead) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) WebServiceException(javax.xml.ws.WebServiceException) MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) ParseException(java.text.ParseException) JAXBException(javax.xml.bind.JAXBException) ComponentException(org.talend.components.api.exception.ComponentException) MalformedURLException(java.net.MalformedURLException) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) MarketoError(org.talend.components.marketo.runtime.client.type.MarketoError)

Example 2 with SuccessGetLead

use of com.marketo.mktows.SuccessGetLead 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

SuccessGetLead (com.marketo.mktows.SuccessGetLead)2 ArrayOfAttribute (com.marketo.mktows.ArrayOfAttribute)1 ArrayOfLeadKey (com.marketo.mktows.ArrayOfLeadKey)1 ArrayOfLeadRecord (com.marketo.mktows.ArrayOfLeadRecord)1 ArrayOfString (com.marketo.mktows.ArrayOfString)1 Attribute (com.marketo.mktows.Attribute)1 LeadKey (com.marketo.mktows.LeadKey)1 LeadRecord (com.marketo.mktows.LeadRecord)1 ParamsGetLead (com.marketo.mktows.ParamsGetLead)1 ResultGetLead (com.marketo.mktows.ResultGetLead)1 MalformedURLException (java.net.MalformedURLException)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ParseException (java.text.ParseException)1 JAXBElement (javax.xml.bind.JAXBElement)1 JAXBException (javax.xml.bind.JAXBException)1 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)1 QName (javax.xml.namespace.QName)1 WebServiceException (javax.xml.ws.WebServiceException)1 Schema (org.apache.avro.Schema)1