Search in sources :

Example 1 with SuccessSyncMultipleLeads

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

the class MarketoSOAPClient method syncMultipleLeads.

@Override
public MarketoSyncResult syncMultipleLeads(TMarketoOutputProperties parameters, List<IndexedRecord> leads) {
    MarketoSyncResult mkto = new MarketoSyncResult();
    try {
        ParamsSyncMultipleLeads request = new ParamsSyncMultipleLeads();
        ArrayOfLeadRecord leadRecords = new ArrayOfLeadRecord();
        for (IndexedRecord r : leads) {
            leadRecords.getLeadRecords().add(convertToLeadRecord(r, parameters.mappingInput.getNameMappingsForMarketo()));
        }
        JAXBElement<Boolean> dedup = objectFactory.createParamsSyncMultipleLeadsDedupEnabled(parameters.deDupeEnabled.getValue());
        request.setDedupEnabled(dedup);
        request.setLeadRecordList(leadRecords);
        SuccessSyncMultipleLeads result = getPort().syncMultipleLeads(request, header);
        // 
        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());
            }
        }
        // 
        List<SyncStatus> records = new ArrayList<>();
        for (com.marketo.mktows.SyncStatus status : result.getResult().getSyncStatusList().getSyncStatuses()) {
            SyncStatus s = new SyncStatus(status.getLeadId(), status.getStatus().value());
            s.setErrorMessage(status.getError().getValue());
            records.add(s);
        }
        mkto.setSuccess(result.getResult().getSyncStatusList() != null);
        mkto.setRecords(records);
    } catch (Exception e) {
        LOG.error(e.toString());
        mkto.setSuccess(false);
        mkto.setErrors(Collections.singletonList(new MarketoError(SOAP, e.getMessage())));
    }
    return mkto;
}
Also used : Marshaller(javax.xml.bind.Marshaller) IndexedRecord(org.apache.avro.generic.IndexedRecord) JAXBException(javax.xml.bind.JAXBException) SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) ArrayList(java.util.ArrayList) JAXBContext(javax.xml.bind.JAXBContext) ParamsSyncMultipleLeads(com.marketo.mktows.ParamsSyncMultipleLeads) 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) MarketoError(org.talend.components.marketo.runtime.client.type.MarketoError) ArrayOfLeadRecord(com.marketo.mktows.ArrayOfLeadRecord) SuccessSyncMultipleLeads(com.marketo.mktows.SuccessSyncMultipleLeads)

Example 2 with SuccessSyncMultipleLeads

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

the class MarketoSOAPClientTest method getSyncMultipleLeadsResult.

public SuccessSyncMultipleLeads getSyncMultipleLeadsResult() {
    SuccessSyncMultipleLeads result = new SuccessSyncMultipleLeads();
    ResultSyncMultipleLeads rsml = new ResultSyncMultipleLeads();
    ArrayOfSyncStatus aoss = new ArrayOfSyncStatus();
    SyncStatus ss = new SyncStatus();
    ss.setLeadId(12345);
    ss.setStatus(LeadSyncStatus.CREATED);
    ss.setError(objectFactory.createSyncStatusError(null));
    aoss.getSyncStatuses().add(ss);
    rsml.setSyncStatusList(aoss);
    result.setResult(rsml);
    return result;
}
Also used : ArrayOfSyncStatus(com.marketo.mktows.ArrayOfSyncStatus) ResultSyncMultipleLeads(com.marketo.mktows.ResultSyncMultipleLeads) ArrayOfSyncStatus(com.marketo.mktows.ArrayOfSyncStatus) LeadSyncStatus(com.marketo.mktows.LeadSyncStatus) SyncStatus(com.marketo.mktows.SyncStatus) SuccessSyncMultipleLeads(com.marketo.mktows.SuccessSyncMultipleLeads)

Aggregations

SuccessSyncMultipleLeads (com.marketo.mktows.SuccessSyncMultipleLeads)2 ArrayOfLeadRecord (com.marketo.mktows.ArrayOfLeadRecord)1 ArrayOfSyncStatus (com.marketo.mktows.ArrayOfSyncStatus)1 LeadSyncStatus (com.marketo.mktows.LeadSyncStatus)1 ParamsSyncMultipleLeads (com.marketo.mktows.ParamsSyncMultipleLeads)1 ResultSyncMultipleLeads (com.marketo.mktows.ResultSyncMultipleLeads)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 ArrayList (java.util.ArrayList)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 IndexedRecord (org.apache.avro.generic.IndexedRecord)1 ComponentException (org.talend.components.api.exception.ComponentException)1 SyncStatus (org.talend.components.marketo.runtime.client.rest.type.SyncStatus)1