Search in sources :

Example 1 with SuccessSyncLead

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

Example 2 with SuccessSyncLead

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

the class MarketoSOAPClientTest method getSyncLeadResult.

public SuccessSyncLead getSyncLeadResult() {
    SuccessSyncLead resut = new SuccessSyncLead();
    ResultSyncLead rsl = new ResultSyncLead();
    rsl.setLeadId(12345);
    SyncStatus status = new SyncStatus();
    status.setLeadId(12345);
    status.setStatus(LeadSyncStatus.CREATED);
    status.setError(objectFactory.createSyncStatusError(null));
    rsl.setSyncStatus(status);
    LeadRecord r = objectFactory.createLeadRecord();
    r.setId(objectFactory.createLeadRecordId(12345));
    r.setEmail(objectFactory.createLeadRecordEmail("t@t.com"));
    r.setForeignSysPersonId(objectFactory.createLeadRecordForeignSysPersonId(""));
    r.setForeignSysType(objectFactory.createLeadRecordForeignSysType(null));
    rsl.setLeadRecord(objectFactory.createResultSyncLeadLeadRecord(r));
    resut.setResult(rsl);
    return resut;
}
Also used : ArrayOfLeadRecord(com.marketo.mktows.ArrayOfLeadRecord) LeadRecord(com.marketo.mktows.LeadRecord) ResultSyncLead(com.marketo.mktows.ResultSyncLead) ArrayOfSyncStatus(com.marketo.mktows.ArrayOfSyncStatus) LeadSyncStatus(com.marketo.mktows.LeadSyncStatus) SyncStatus(com.marketo.mktows.SyncStatus) SuccessSyncLead(com.marketo.mktows.SuccessSyncLead)

Aggregations

SuccessSyncLead (com.marketo.mktows.SuccessSyncLead)2 ArrayOfLeadRecord (com.marketo.mktows.ArrayOfLeadRecord)1 ArrayOfSyncStatus (com.marketo.mktows.ArrayOfSyncStatus)1 LeadRecord (com.marketo.mktows.LeadRecord)1 LeadSyncStatus (com.marketo.mktows.LeadSyncStatus)1 MktowsContextHeader (com.marketo.mktows.MktowsContextHeader)1 ParamsSyncLead (com.marketo.mktows.ParamsSyncLead)1 ResultSyncLead (com.marketo.mktows.ResultSyncLead)1 SyncStatus (com.marketo.mktows.SyncStatus)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