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