use of org.talend.components.marketo.runtime.client.rest.type.SyncStatus 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;
}
use of org.talend.components.marketo.runtime.client.rest.type.SyncStatus 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;
}
use of org.talend.components.marketo.runtime.client.rest.type.SyncStatus in project components by Talend.
the class MarketoSOAPClientTestIT method testIsMemberOfList.
@Test
public void testIsMemberOfList() 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.setStrict(true);
parms.setLeadKeyValue(new String[] { createdLeads.get(0).toString(), createdLeads.get(1).toString(), createdLeads.get(2).toString(), "12345" });
//
MarketoSyncResult result = client.isMemberOfList(parms);
LOG.debug("result = {}.", result);
List<SyncStatus> changes = result.getRecords();
assertTrue(changes.size() > 0);
for (SyncStatus r : changes) {
assertNotNull(r);
assertNotNull(r.getId());
assertNotNull(r.getStatus());
LOG.debug("r = {}.", r);
}
}
use of org.talend.components.marketo.runtime.client.rest.type.SyncStatus in project components by Talend.
the class MarketoSOAPClientTestIT method testSyncMultipleLeads.
@Test
public void testSyncMultipleLeads() throws Exception {
MarketoSource source = new MarketoSource();
outProperties.outputOperation.setValue(OutputOperation.syncLead);
outProperties.updateSchemaRelated();
source.initialize(null, listProperties);
MarketoClientService client = source.getClientService(null);
// test attributes
List<Field> fields = new ArrayList<>();
Field field = new Schema.Field("AccountType", Schema.create(Schema.Type.STRING), null, (Object) null);
fields.add(field);
Schema s = MarketoUtils.newSchema(outProperties.schemaInput.schema.getValue(), "leadAttribute", fields);
outProperties.schemaInput.schema.setValue(s);
outProperties.beforeMappingInput();
List<IndexedRecord> records = new ArrayList<>();
for (int i = 0; i < 3; i++) {
IndexedRecord record = new GenericData.Record(s);
record.put(0, null);
record.put(1, "undx" + i + "@undx.net");
record.put(2, "");
// CUSTOM, SFDC, NETSUITE;
record.put(3, "CUSTOM");
record.put(4, "customer" + i);
records.add(record);
}
//
MarketoSyncResult result = client.syncMultipleLeads(outProperties, records);
for (SyncStatus status : result.getRecords()) {
assertEquals("CREATED", status.getStatus());
}
//
outProperties.deDupeEnabled.setValue(true);
result = client.syncMultipleLeads(outProperties, records);
for (SyncStatus status : result.getRecords()) {
assertEquals("UPDATED", status.getStatus());
}
}
use of org.talend.components.marketo.runtime.client.rest.type.SyncStatus in project components by Talend.
the class MarketoRESTClientTestIT method testSyncLead.
/*
*
*
* syncLeads
*
*/
@Test
public void testSyncLead() throws Exception {
outProperties.outputOperation.setValue(OutputOperation.syncLead);
outProperties.operationType.setValue(OperationType.createOrUpdate);
outProperties.lookupField.setValue(RESTLookupFields.email);
outProperties.deDupeEnabled.setValue(false);
outProperties.updateSchemaRelated();
outProperties.updateOutputSchemas();
MarketoSource source = new MarketoSource();
source.initialize(null, outProperties);
MarketoClientService client = source.getClientService(null);
//
// test attributes
List<Field> fields = new ArrayList<>();
Field field = new Schema.Field("accountType", Schema.create(Schema.Type.STRING), null, (Object) null);
fields.add(field);
Schema s = MarketoUtils.newSchema(outProperties.schemaInput.schema.getValue(), "leadAttribute", fields);
IndexedRecord record = new GenericData.Record(s);
record.put(0, null);
record.put(1, "undx71@undx.net");
record.put(2, "ForeignPersonSysId");
// CUSTOM, SFDC, NETSUITE;
record.put(3, "SFDC");
record.put(4, "My firstName");
List<IndexedRecord> leads = Arrays.asList(record);
outProperties.schemaInput.schema.setValue(s);
outProperties.beforeMappingInput();
// /
MarketoSyncResult result = client.syncLead(outProperties, record);
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);
}
}
Aggregations