Search in sources :

Example 1 with PaginateResult

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;
}
Also used : LeadActivitiesResult(org.talend.components.marketo.runtime.client.rest.response.LeadActivitiesResult) MarketoException(org.talend.components.marketo.runtime.client.type.MarketoException) LeadResult(org.talend.components.marketo.runtime.client.rest.response.LeadResult) PaginateResult(org.talend.components.marketo.runtime.client.rest.response.PaginateResult) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) LeadChangesResult(org.talend.components.marketo.runtime.client.rest.response.LeadChangesResult)

Aggregations

LeadActivitiesResult (org.talend.components.marketo.runtime.client.rest.response.LeadActivitiesResult)1 LeadChangesResult (org.talend.components.marketo.runtime.client.rest.response.LeadChangesResult)1 LeadResult (org.talend.components.marketo.runtime.client.rest.response.LeadResult)1 PaginateResult (org.talend.components.marketo.runtime.client.rest.response.PaginateResult)1 MarketoException (org.talend.components.marketo.runtime.client.type.MarketoException)1 MarketoRecordResult (org.talend.components.marketo.runtime.client.type.MarketoRecordResult)1