Search in sources :

Example 1 with ParamsSyncMultipleLeads

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

Aggregations

ArrayOfLeadRecord (com.marketo.mktows.ArrayOfLeadRecord)1 ParamsSyncMultipleLeads (com.marketo.mktows.ParamsSyncMultipleLeads)1 SuccessSyncMultipleLeads (com.marketo.mktows.SuccessSyncMultipleLeads)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 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