use of com.marketo.mktows.MktowsContextHeader in project components by Talend.
the class MarketoSOAPClient method syncLead.
/**
* Request<br/>
*
* Field Name <br/>
* <code>leadRecord->Id</code> Required – Only when Email or foreignSysPersonId is not present The Marketo Id of the
* lead record<br/>
* <code>leadRecord->Email</code> Required – Only when Id or foreignSysPersonId is not present The email address
* associated with the lead record<br/>
* <code>leadRecord->foreignSysPersonId</code> Required – Only when Id or Email is not present The foreign system id
* associated with the lead record<br/>
* <code>leadRecord->foreignSysType</code> Optional – Only required when foreignSysPersonId is present The type of
* foreign system. Possible values: CUSTOM, SFDC, NETSUITE<br/>
* <code>leadRecord->leadAttributeList->attribute->attrName</code> Required The name of the lead attribute you want to
* update the value of.<br/>
* <code>leadRecord->leadAttributeList->attribute->attrValue</code> Required The value you want to set to the lead
* attribute specificed in attrName. returnLead Required When true will return the complete updated lead record upon
* update.<br/>
* <code>marketoCookie</code> Optional The Munchkin javascript cookie<br/>
*/
@Override
public MarketoSyncResult syncLead(TMarketoOutputProperties parameters, IndexedRecord lead) {
MarketoSyncResult mkto = new MarketoSyncResult();
try {
ParamsSyncLead request = new ParamsSyncLead();
request.setReturnLead(false);
//
request.setLeadRecord(convertToLeadRecord(lead, parameters.mappingInput.getNameMappingsForMarketo()));
MktowsContextHeader headerContext = new MktowsContextHeader();
headerContext.setTargetWorkspace("default");
SuccessSyncLead result = getPort().syncLead(request, header, headerContext);
//
if (LOG.isDebugEnabled()) {
try {
JAXBContext context = JAXBContext.newInstance(SuccessSyncLead.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
m.marshal(result, System.out);
} catch (JAXBException e) {
LOG.error(e.getMessage());
}
}
//
com.marketo.mktows.SyncStatus status = result.getResult().getSyncStatus();
mkto.setSuccess(status.getError().isNil());
if (mkto.isSuccess()) {
mkto.setRecordCount(1);
SyncStatus resultStatus = new SyncStatus(status.getLeadId(), status.getStatus().value());
mkto.setRecords(Collections.singletonList(resultStatus));
} else {
mkto.setErrors(Collections.singletonList(new MarketoError(SOAP, status.getError().getValue())));
}
} catch (Exception e) {
LOG.error(e.toString());
mkto.setSuccess(false);
mkto.setErrors(Collections.singletonList(new MarketoError(SOAP, e.getMessage())));
}
return mkto;
}
Aggregations