use of org.talend.components.marketo.runtime.client.rest.response.LeadChangesResult in project components by Talend.
the class MarketoLeadClient method getRecordResultForLead.
public MarketoRecordResult getRecordResultForLead(InputOperation operation, String requestParams, int limit, Schema schema, Map<String, String> mappings) {
MarketoRecordResult mkto = new MarketoRecordResult();
try {
PaginateResult result = null;
switch(operation) {
case getLead:
case getMultipleLeads:
result = executeFakeGetRequestForLead(requestParams);
break;
case getLeadActivity:
result = (LeadActivitiesResult) executeGetRequest(LeadActivitiesResult.class);
break;
case getLeadChanges:
result = (LeadChangesResult) executeGetRequest(LeadChangesResult.class);
break;
default:
throw new IllegalArgumentException("Invalid operation for getRecordResultForLead: " + operation);
}
mkto.setSuccess(result.isSuccess());
if (mkto.isSuccess()) {
mkto.setRecordCount(result.getResult().isEmpty() ? 0 : result.getResult().size());
mkto.setRemainCount((result.getNextPageToken() != null) ? limit : 0);
mkto.setStreamPosition(result.getNextPageToken());
if (mkto.getRecordCount() > 0) {
switch(operation) {
case getLead:
case getMultipleLeads:
mkto.setRecords(convertLeadRecords(((LeadResult) result).getResult(), schema, mappings));
break;
case getLeadActivity:
mkto.setRecords(convertLeadActivityRecords(((LeadActivitiesResult) result).getResult(), schema, mappings));
break;
case getLeadChanges:
mkto.setRecords(convertLeadChangesRecords(((LeadChangesResult) result).getResult(), schema, mappings));
break;
default:
throw new IllegalArgumentException("Invalid operation for getRecordResultForLead: " + operation);
}
}
} else {
mkto.setErrors(result.getErrors());
}
} catch (MarketoException e) {
LOG.error("Error {}.", e.toString());
mkto.setSuccess(false);
mkto.setErrors(Collections.singletonList(e.toMarketoError()));
}
return mkto;
}
use of org.talend.components.marketo.runtime.client.rest.response.LeadChangesResult in project components by Talend.
the class MarketoLeadClientTest method testGetLeadChanges.
@Test
public void testGetLeadChanges() throws Exception {
iprops.inputOperation.setValue(InputOperation.getLeadChanges);
iprops.sinceDateTime.setValue("2017-01-30 10:00:00 +0100");
iprops.afterInputOperation();
List<Field> moreFields = new ArrayList<>();
moreFields.add(new Field("attrName", AvroUtils._string(), "", null));
moreFields.add(new Field("campaignId", AvroUtils._int(), "", null));
iprops.schemaInput.schema.setValue(MarketoUtils.newSchema(iprops.schemaInput.schema.getValue(), "test", moreFields));
iprops.beforeMappingInput();
//
doThrow(new MarketoException("REST", "error")).when(client).executeGetRequest(LeadChangesResult.class);
mktoRR = client.getLeadChanges(iprops, null);
assertFalse(mktoRR.isSuccess());
assertFalse(mktoRR.getErrorsString().isEmpty());
//
doReturn(new LeadChangesResult()).when(client).executeGetRequest(LeadChangesResult.class);
mktoRR = client.getLeadChanges(iprops, null);
assertFalse(mktoRR.isSuccess());
//
LeadChangesResult lcr = new LeadChangesResult();
lcr.setSuccess(true);
List<LeadChangeRecord> lcrs = new ArrayList<>();
LeadChangeRecord lc = new LeadChangeRecord();
lc.setId(123456);
lc.setMarketoGUID("ABC-123-DEF");
lc.setLeadId(12345);
lc.setActivityTypeId(1);
lc.setActivityTypeValue("Visit Webpage");
lc.setActivityDate(new Date());
lc.setCampaignId(456);
List<Map<String, String>> fields = new ArrayList<>();
Map<String, String> field = new HashMap<>();
field.put("field1", "value1");
fields.add(field);
lc.setFields(fields);
List<Map<String, Object>> attributes = new ArrayList<>();
Map<String, Object> attribute = new HashMap<>();
attribute.put("name", "attrName");
attribute.put("value", "attrValue");
attributes.add(attribute);
lc.setAttributes(attributes);
lcrs.add(lc);
lcr.setResult(lcrs);
//
doReturn(lcr).when(client).executeGetRequest(LeadChangesResult.class);
mktoRR = client.getLeadChanges(iprops, null);
assertTrue(mktoRR.isSuccess());
List<IndexedRecord> records = mktoRR.getRecords();
assertNotNull(records);
IndexedRecord record = records.get(0);
assertNotNull(record);
Schema refSchema = iprops.schemaInput.schema.getValue();
assertEquals(refSchema, record.getSchema());
assertEquals(123456, record.get(refSchema.getField("id").pos()));
assertEquals("ABC-123-DEF", record.get(refSchema.getField("marketoGUID").pos()));
assertEquals(12345, record.get(refSchema.getField("leadId").pos()));
assertEquals(1, record.get(refSchema.getField("activityTypeId").pos()));
assertEquals("Visit Webpage", record.get(refSchema.getField("activityTypeValue").pos()));
assertEquals(456, record.get(refSchema.getField("campaignId").pos()));
assertEquals("[{\"field1\":\"value1\"}]", record.get(refSchema.getField("fields").pos()));
assertTrue(record.get(refSchema.getField("activityDate").pos()) instanceof Long);
assertEquals("attrValue", record.get(refSchema.getField("attrName").pos()));
}
Aggregations