Search in sources :

Example 1 with ParamsGetLead

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

Aggregations

ArrayOfLeadKey (com.marketo.mktows.ArrayOfLeadKey)1 ArrayOfString (com.marketo.mktows.ArrayOfString)1 LeadKey (com.marketo.mktows.LeadKey)1 ParamsGetLead (com.marketo.mktows.ParamsGetLead)1 SuccessGetLead (com.marketo.mktows.SuccessGetLead)1 MalformedURLException (java.net.MalformedURLException)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ParseException (java.text.ParseException)1 JAXBException (javax.xml.bind.JAXBException)1 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)1 WebServiceException (javax.xml.ws.WebServiceException)1 Schema (org.apache.avro.Schema)1 IndexedRecord (org.apache.avro.generic.IndexedRecord)1 ComponentException (org.talend.components.api.exception.ComponentException)1 MarketoError (org.talend.components.marketo.runtime.client.type.MarketoError)1 MarketoException (org.talend.components.marketo.runtime.client.type.MarketoException)1 MarketoRecordResult (org.talend.components.marketo.runtime.client.type.MarketoRecordResult)1