Search in sources :

Example 11 with MarketoSyncResult

use of org.talend.components.marketo.runtime.client.type.MarketoSyncResult in project components by Talend.

the class MarketoClientCustomObjectsTestIT method testDeleteCustomObjectsByIdField.

@Test
public void testDeleteCustomObjectsByIdField() throws Exception {
    MarketoSyncResult rs = createCustomObjectRecords("");
    assertTrue(rs.isSuccess());
    List<String> mktoIds = new ArrayList<>();
    for (SyncStatus sr : rs.getRecords()) {
        mktoIds.add(sr.getMarketoGUID());
    }
    // 
    oprops.customObjectName.setValue(TEST_CO_NAME_SMARTPHONE);
    Schema s = // 
    SchemaBuilder.record("sn").fields().name(FIELD_CO_MARKETO_GUID).type().stringType().noDefault().endRecord();
    List<IndexedRecord> records = new ArrayList<>();
    IndexedRecord r1;
    for (String m : mktoIds) {
        r1 = new Record(s);
        r1.put(0, m);
        records.add(r1);
    }
    MarketoSource source = new MarketoSource();
    oprops.customObjectDeleteBy.setValue(CustomObjectDeleteBy.idField);
    source.initialize(null, oprops);
    MarketoRESTClient client = (MarketoRESTClient) source.getClientService(null);
    rs = client.deleteCustomObjects(oprops, records);
    assertTrue(rs.isSuccess());
    List<SyncStatus> changes = rs.getRecords();
    assertEquals(TEST_SMARTPHONE_MODELS.length, changes.size());
    for (SyncStatus r : changes) {
        assertNotNull(r);
        assertNotNull(r.getSeq());
        assertEquals(STATUS_DELETED, r.getStatus());
        LOG.debug("r = {}.", r);
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) Record(org.apache.avro.generic.GenericData.Record) IndexedRecord(org.apache.avro.generic.IndexedRecord) MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) Test(org.junit.Test)

Example 12 with MarketoSyncResult

use of org.talend.components.marketo.runtime.client.type.MarketoSyncResult 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 13 with MarketoSyncResult

use of org.talend.components.marketo.runtime.client.type.MarketoSyncResult 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 14 with MarketoSyncResult

use of org.talend.components.marketo.runtime.client.type.MarketoSyncResult in project components by Talend.

the class MarketoClientCustomObjectsTestIT method testGetCustomObjects.

@Test
public void testGetCustomObjects() throws Exception {
    MarketoSyncResult rs = createCustomObjectRecords("");
    MarketoSource source = new MarketoSource();
    source.initialize(null, irProps);
    MarketoRESTClient client = (MarketoRESTClient) source.getClientService(null);
    irProps.customObjectName.setValue(TEST_CO_NAME_SMARTPHONE);
    irProps.customObjectFilterType.setValue(FIELD_CO_SMARTPHONE_MODEL);
    irProps.customObjectFilterValues.setValue(MarketoRESTClient.csvString(TEST_SMARTPHONE_MODELS));
    irProps.batchSize.setValue(500);
    irProps.schemaInput.schema.setValue(MarketoConstants.getCustomObjectRecordSchema());
    MarketoRecordResult result = client.getCustomObjects(irProps, null);
    assertNotNull(result.getRecords());
    assertEquals(TEST_SMARTPHONE_MODELS.length, result.getRecords().size());
    LOG.debug("result = {}.", result.getRecords().get(0));
    checkCustomObjectRecord(result.getRecords().get(0));
}
Also used : MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) Test(org.junit.Test)

Example 15 with MarketoSyncResult

use of org.talend.components.marketo.runtime.client.type.MarketoSyncResult in project components by Talend.

the class MarketoClientCustomObjectsTestIT method createCustomObjectRecords.

public MarketoSyncResult createCustomObjectRecords(String dedupeBy) throws Exception {
    oprops.customObjectName.setValue(TEST_CO_NAME_SMARTPHONE);
    oprops.customObjectSyncAction.setValue(CustomObjectSyncAction.createOrUpdate);
    oprops.customObjectDedupeBy.setValue(dedupeBy);
    Schema s = // 
    SchemaBuilder.record("sn").fields().name(FIELD_CO_SMARTPHONE_BRAND).type().stringType().noDefault().name(FIELD_CO_SMARTPHONE_MODEL).type().stringType().noDefault().name(FIELD_CO_SMARTPHONE_CUSTOMER_ID).type().intType().noDefault().endRecord();
    List<IndexedRecord> records = new ArrayList<>();
    IndexedRecord r1;
    for (String m : TEST_SMARTPHONE_MODELS) {
        r1 = new Record(s);
        r1.put(0, TEST_SMARTPHONE_BRAND_SAMSUNG);
        r1.put(1, m);
        r1.put(2, 3113479);
        records.add(r1);
    }
    MarketoSource source = new MarketoSource();
    source.initialize(null, irProps);
    MarketoRESTClient client = (MarketoRESTClient) source.getClientService(null);
    MarketoSyncResult rs = client.syncCustomObjects(oprops, records);
    return rs;
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) Record(org.apache.avro.generic.GenericData.Record) IndexedRecord(org.apache.avro.generic.IndexedRecord) MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult)

Aggregations

MarketoSyncResult (org.talend.components.marketo.runtime.client.type.MarketoSyncResult)29 SyncStatus (org.talend.components.marketo.runtime.client.rest.type.SyncStatus)20 Test (org.junit.Test)18 MarketoSource (org.talend.components.marketo.runtime.MarketoSource)17 ArrayList (java.util.ArrayList)13 IndexedRecord (org.apache.avro.generic.IndexedRecord)10 Schema (org.apache.avro.Schema)9 ListOperationParameters (org.talend.components.marketo.runtime.client.type.ListOperationParameters)8 MarketoError (org.talend.components.marketo.runtime.client.type.MarketoError)5 Field (org.apache.avro.Schema.Field)4 Record (org.apache.avro.generic.GenericData.Record)4 MarketoException (org.talend.components.marketo.runtime.client.type.MarketoException)4 MalformedURLException (java.net.MalformedURLException)3 InvalidKeyException (java.security.InvalidKeyException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 ParseException (java.text.ParseException)3 JAXBContext (javax.xml.bind.JAXBContext)3 JAXBException (javax.xml.bind.JAXBException)3 Marshaller (javax.xml.bind.Marshaller)3 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)3