use of org.talend.components.marketo.runtime.client.rest.response.PaginateResult 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;
}
Aggregations