Search in sources :

Example 1 with MktowsContextHeader

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;
}
Also used : MktowsContextHeader(com.marketo.mktows.MktowsContextHeader) Marshaller(javax.xml.bind.Marshaller) ParamsSyncLead(com.marketo.mktows.ParamsSyncLead) JAXBException(javax.xml.bind.JAXBException) SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) JAXBContext(javax.xml.bind.JAXBContext) 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) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) SuccessSyncLead(com.marketo.mktows.SuccessSyncLead) MarketoError(org.talend.components.marketo.runtime.client.type.MarketoError)

Aggregations

MktowsContextHeader (com.marketo.mktows.MktowsContextHeader)1 ParamsSyncLead (com.marketo.mktows.ParamsSyncLead)1 SuccessSyncLead (com.marketo.mktows.SuccessSyncLead)1 MalformedURLException (java.net.MalformedURLException)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ParseException (java.text.ParseException)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Marshaller (javax.xml.bind.Marshaller)1 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)1 WebServiceException (javax.xml.ws.WebServiceException)1 ComponentException (org.talend.components.api.exception.ComponentException)1 SyncStatus (org.talend.components.marketo.runtime.client.rest.type.SyncStatus)1 MarketoError (org.talend.components.marketo.runtime.client.type.MarketoError)1 MarketoException (org.talend.components.marketo.runtime.client.type.MarketoException)1 MarketoSyncResult (org.talend.components.marketo.runtime.client.type.MarketoSyncResult)1