Search in sources :

Example 1 with SyncStatus

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

the class MarketoRuntimeTestBase method getSuccessSyncResult.

public MarketoSyncResult getSuccessSyncResult(String status) {
    MarketoSyncResult mkto = new MarketoSyncResult();
    mkto.setSuccess(true);
    mkto.setRecordCount(1);
    SyncStatus sts1 = new SyncStatus();
    sts1.setId(12345);
    sts1.setStatus(status);
    sts1.setMarketoGUID("mktoGUID");
    sts1.setSeq(0);
    mkto.setRecords(Arrays.asList(sts1));
    return mkto;
}
Also used : SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult)

Example 2 with SyncStatus

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

the class MarketoSOAPClient method listOperation.

public MarketoSyncResult listOperation(ListOperationType operationType, ListOperationParameters parameters) {
    LOG.debug("listOperation : {}", parameters);
    ParamsListOperation paramsListOperation = new ParamsListOperation();
    paramsListOperation.setListOperation(operationType);
    paramsListOperation.setStrict(objectFactory.createParamsListOperationStrict(parameters.getStrict()));
    ListKey listKey = new ListKey();
    listKey.setKeyValue(parameters.getListKeyValue());
    listKey.setKeyType(ListKeyType.valueOf(parameters.getListKeyType()));
    paramsListOperation.setListKey(listKey);
    ArrayOfLeadKey leadKeys = new ArrayOfLeadKey();
    for (String lkv : parameters.getLeadKeyValues()) {
        LeadKey lk = new LeadKey();
        lk.setKeyType(valueOf(parameters.getLeadKeyType()));
        lk.setKeyValue(lkv);
        leadKeys.getLeadKeies().add(lk);
    }
    paramsListOperation.setListMemberList(leadKeys);
    MarketoSyncResult mkto = new MarketoSyncResult();
    mkto.setRequestId(SOAP + "::" + operationType.name());
    try {
        SuccessListOperation result = getPort().listOperation(paramsListOperation, header);
        if (LOG.isDebugEnabled()) {
            try {
                JAXBContext context = JAXBContext.newInstance(SuccessListOperation.class);
                Marshaller m = context.createMarshaller();
                m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
                m.marshal(result, System.out);
            } catch (JAXBException e) {
                LOG.error(e.getMessage());
            }
        }
        mkto.setSuccess(true);
        if (!result.getResult().getStatusList().isNil()) {
            mkto.setRecordCount(result.getResult().getStatusList().getValue().getLeadStatuses().size());
            List<LeadStatus> statuses = result.getResult().getStatusList().getValue().getLeadStatuses();
            List<SyncStatus> resultStatus = new ArrayList<>();
            for (LeadStatus status : statuses) {
                SyncStatus sts = new SyncStatus(Integer.parseInt(status.getLeadKey().getKeyValue()), String.valueOf(status.isStatus()));
                if (!status.isStatus() && !ISMEMBEROFLIST.equals(operationType)) {
                    Map<String, String> reason = new HashMap<>();
                    reason.put("code", "20103");
                    reason.put("message", "Lead Not Found");
                    sts.setReasons(Collections.singletonList(reason));
                }
                resultStatus.add(sts);
            }
            mkto.setRecords(resultStatus);
        } else {
            LOG.debug("No detail about successed operation, building one...");
            String success = String.valueOf(result.getResult().isSuccess());
            mkto.setRecordCount(parameters.getLeadKeyValue().size());
            for (String leadk : parameters.getLeadKeyValue()) {
                SyncStatus status = new SyncStatus(Integer.parseInt(leadk), success);
                mkto.getRecords().add(status);
            }
        }
    } catch (Exception e) {
        LOG.error("[{}] error: {}", operationType.name(), e.getMessage());
        mkto.setSuccess(false);
        mkto.setErrors(Collections.singletonList(new MarketoError(SOAP, e.toString())));
    }
    return mkto;
}
Also used : ArrayOfLeadKey(com.marketo.mktows.ArrayOfLeadKey) SuccessListOperation(com.marketo.mktows.SuccessListOperation) Marshaller(javax.xml.bind.Marshaller) HashMap(java.util.HashMap) JAXBException(javax.xml.bind.JAXBException) SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) ArrayList(java.util.ArrayList) JAXBContext(javax.xml.bind.JAXBContext) ArrayOfString(com.marketo.mktows.ArrayOfString) 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) LeadStatus(com.marketo.mktows.LeadStatus) MarketoError(org.talend.components.marketo.runtime.client.type.MarketoError) ListKey(com.marketo.mktows.ListKey) ParamsListOperation(com.marketo.mktows.ParamsListOperation) LeadKey(com.marketo.mktows.LeadKey) ArrayOfLeadKey(com.marketo.mktows.ArrayOfLeadKey)

Example 3 with SyncStatus

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

the class MarketoSOAPClientTestIT method testAddToList.

/*
     * 
     * 
     * ListOperations
     * 
     * 
     */
@Test
public void testAddToList() throws Exception {
    MarketoSource source = new MarketoSource();
    source.initialize(null, listProperties);
    MarketoClientService client = source.getClientService(null);
    // 
    ListOperationParameters parms = new ListOperationParameters();
    parms.setApiMode(SOAP.name());
    parms.setListKeyValue(UNDX_TEST_LIST_SMALL);
    parms.setLeadKeyValue(new String[] { createdLeads.get(10).toString() });
    // first make sure to remove lead
    MarketoSyncResult result = client.removeFromList(parms);
    LOG.debug("result = {}.", result);
    List<SyncStatus> changes = result.getRecords();
    assertTrue(changes.size() > 0);
    for (SyncStatus r : changes) {
        assertNotNull(r);
        assertNotNull(r.getId());
        LOG.debug("r = {}.", r);
    }
    // then add it
    result = client.addToList(parms);
    LOG.debug("result = {}.", result);
    changes = result.getRecords();
    assertTrue(changes.size() > 0);
    for (SyncStatus r : changes) {
        assertNotNull(r);
        assertNotNull(r.getId());
        assertTrue(Boolean.parseBoolean(r.getStatus()));
        LOG.debug("r = {}.", r);
    }
}
Also used : ListOperationParameters(org.talend.components.marketo.runtime.client.type.ListOperationParameters) SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) Test(org.junit.Test)

Example 4 with SyncStatus

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

the class MarketoSOAPClientTestIT method testAddToListFail.

@Test
public void testAddToListFail() throws Exception {
    MarketoSource source = new MarketoSource();
    source.initialize(null, listProperties);
    MarketoClientService client = source.getClientService(null);
    // 
    ListOperationParameters parms = new ListOperationParameters();
    parms.setApiMode(SOAP.name());
    parms.setListKeyValue(UNDX_TEST_LIST_SMALL);
    parms.setLeadKeyValue(new String[] { "12345" });
    // first make sure to remove lead
    MarketoSyncResult result;
    List<SyncStatus> changes;
    result = client.addToList(parms);
    LOG.debug("result = {}.", result);
    changes = result.getRecords();
    assertTrue(changes.size() > 0);
    for (SyncStatus r : changes) {
        assertNotNull(r);
        assertNotNull(r.getId());
        assertFalse(Boolean.parseBoolean(r.getStatus()));
        assertEquals("[20103] Lead Not Found.", r.getAvailableReason());
        LOG.debug("r = {}.", r);
    }
}
Also used : ListOperationParameters(org.talend.components.marketo.runtime.client.type.ListOperationParameters) SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) Test(org.junit.Test)

Example 5 with SyncStatus

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

the class MarketoSOAPClientTestIT method testRemoveFromList.

@Test
public void testRemoveFromList() throws Exception {
    MarketoSource source = new MarketoSource();
    source.initialize(null, listProperties);
    MarketoClientService client = source.getClientService(null);
    // 
    ListOperationParameters parms = new ListOperationParameters();
    parms.setApiMode(SOAP.name());
    parms.setListKeyValue(UNDX_TEST_LIST_SMALL);
    parms.setLeadKeyValue(new String[] { createdLeads.get(20).toString() });
    // first subscribe lead
    MarketoSyncResult result = client.addToList(parms);
    List<SyncStatus> changes = result.getRecords();
    assertTrue(changes.size() > 0);
    for (SyncStatus r : changes) {
        assertNotNull(r);
        assertNotNull(r.getId());
        assertTrue(Boolean.parseBoolean(r.getStatus()));
        LOG.debug("r = {}.", r);
    }
    // then remove it
    result = client.removeFromList(parms);
    LOG.debug("result = {}.", result);
    changes = result.getRecords();
    assertTrue(changes.size() > 0);
    for (SyncStatus r : changes) {
        assertNotNull(r);
        assertNotNull(r.getId());
        assertTrue(Boolean.parseBoolean(r.getStatus()));
        LOG.debug("r = {}.", r);
    }
}
Also used : ListOperationParameters(org.talend.components.marketo.runtime.client.type.ListOperationParameters) SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) MarketoSource(org.talend.components.marketo.runtime.MarketoSource) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) Test(org.junit.Test)

Aggregations

SyncStatus (org.talend.components.marketo.runtime.client.rest.type.SyncStatus)25 MarketoSyncResult (org.talend.components.marketo.runtime.client.type.MarketoSyncResult)23 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)13 MarketoSource (org.talend.components.marketo.runtime.MarketoSource)13 IndexedRecord (org.apache.avro.generic.IndexedRecord)11 ListOperationParameters (org.talend.components.marketo.runtime.client.type.ListOperationParameters)8 Schema (org.apache.avro.Schema)7 Record (org.apache.avro.generic.GenericData.Record)5 MarketoError (org.talend.components.marketo.runtime.client.type.MarketoError)5 MarketoException (org.talend.components.marketo.runtime.client.type.MarketoException)5 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 WebServiceException (javax.xml.ws.WebServiceException)3