Search in sources :

Example 1 with ParamsGetLeadActivity

use of com.marketo.mktows.ParamsGetLeadActivity in project components by Talend.

the class MarketoSOAPClient method getLeadActivity.

@Override
public MarketoRecordResult getLeadActivity(TMarketoInputProperties parameters, String offset) {
    LOG.debug("MarketoSOAPClient.getLeadActivity with {}", parameters.leadKeyTypeSOAP.getValue());
    Schema schema = parameters.schemaInput.schema.getValue();
    Map<String, String> mappings = parameters.mappingInput.getNameMappingsForMarketo();
    int bSize = parameters.batchSize.getValue();
    String lkt = parameters.leadKeyTypeSOAP.getValue().toString();
    String lkv = parameters.leadKeyValue.getValue();
    // 
    // Create Request
    // 
    LOG.info("LeadKeySelector - Key type:  {} with value : {}.", lkt, lkv);
    ParamsGetLeadActivity request = new ParamsGetLeadActivity();
    LeadKey key = new LeadKey();
    key.setKeyType(valueOf(lkt));
    key.setKeyValue(lkv);
    request.setLeadKey(key);
    // attributes
    ArrayOfString attributes = new ArrayOfString();
    for (String s : mappings.values()) {
        attributes.getStringItems().add(s);
    }
    // Activity filter
    ActivityTypeFilter filter = new ActivityTypeFilter();
    if (parameters.setIncludeTypes.getValue()) {
        ArrayOfActivityType includes = new ArrayOfActivityType();
        for (String a : parameters.includeTypes.type.getValue()) {
            includes.getActivityTypes().add(fromValue(a));
        }
        filter.setIncludeTypes(includes);
    }
    if (parameters.setExcludeTypes.getValue()) {
        ArrayOfActivityType excludes = new ArrayOfActivityType();
        for (String a : parameters.excludeTypes.type.getValue()) {
            excludes.getActivityTypes().add(fromValue(a));
        }
        filter.setExcludeTypes(excludes);
    }
    JAXBElement<ActivityTypeFilter> typeFilter = objectFactory.createParamsGetLeadActivityActivityFilter(filter);
    request.setActivityFilter(typeFilter);
    // batch size
    JAXBElement<Integer> batchSize = objectFactory.createParamsGetMultipleLeadsBatchSize(bSize);
    request.setBatchSize(batchSize);
    // stream position
    if (offset != null && !offset.isEmpty()) {
        StreamPosition sposition = new StreamPosition();
        sposition.setOffset(objectFactory.createStreamPositionOffset(offset));
        JAXBElement<StreamPosition> position = objectFactory.createParamsGetLeadActivityStartPosition(sposition);
        request.setStartPosition(position);
    }
    // 
    // 
    // Request execution
    // 
    SuccessGetLeadActivity result = null;
    MarketoRecordResult mkto = new MarketoRecordResult();
    try {
        result = getPort().getLeadActivity(request, header);
        mkto.setSuccess(true);
    } catch (Exception e) {
        LOG.error("getLeadActivity error : {}.", e.getMessage());
        mkto.setSuccess(false);
        mkto.setRecordCount(0);
        mkto.setRemainCount(0);
        mkto.setErrors(Collections.singletonList(new MarketoError(SOAP, e.getMessage())));
        return mkto;
    }
    if (result == null || result.getLeadActivityList().getReturnCount() == 0) {
        LOG.debug(MESSAGE_REQUEST_RETURNED_0_MATCHING_LEADS);
        mkto.setErrors(Collections.singletonList(new MarketoError(SOAP, MESSAGE_NO_LEADS_FOUND)));
        return mkto;
    }
    String streamPos = result.getLeadActivityList().getNewStartPosition().getOffset().getValue();
    int recordCount = result.getLeadActivityList().getReturnCount();
    int remainCount = result.getLeadActivityList().getRemainingCount();
    // Process results
    List<IndexedRecord> results = convertLeadActivityRecords(result.getLeadActivityList().getActivityRecordList().getValue().getActivityRecords(), schema, mappings);
    mkto.setRecordCount(recordCount);
    mkto.setRemainCount(remainCount);
    mkto.setStreamPosition(streamPos);
    mkto.setRecords(results);
    return mkto;
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) ArrayOfActivityType(com.marketo.mktows.ArrayOfActivityType) Schema(org.apache.avro.Schema) StreamPosition(com.marketo.mktows.StreamPosition) 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) MarketoError(org.talend.components.marketo.runtime.client.type.MarketoError) SuccessGetLeadActivity(com.marketo.mktows.SuccessGetLeadActivity) ArrayOfString(com.marketo.mktows.ArrayOfString) LeadKey(com.marketo.mktows.LeadKey) ArrayOfLeadKey(com.marketo.mktows.ArrayOfLeadKey) ActivityTypeFilter(com.marketo.mktows.ActivityTypeFilter) ParamsGetLeadActivity(com.marketo.mktows.ParamsGetLeadActivity) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult)

Aggregations

ActivityTypeFilter (com.marketo.mktows.ActivityTypeFilter)1 ArrayOfActivityType (com.marketo.mktows.ArrayOfActivityType)1 ArrayOfLeadKey (com.marketo.mktows.ArrayOfLeadKey)1 ArrayOfString (com.marketo.mktows.ArrayOfString)1 LeadKey (com.marketo.mktows.LeadKey)1 ParamsGetLeadActivity (com.marketo.mktows.ParamsGetLeadActivity)1 StreamPosition (com.marketo.mktows.StreamPosition)1 SuccessGetLeadActivity (com.marketo.mktows.SuccessGetLeadActivity)1 MalformedURLException (java.net.MalformedURLException)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ParseException (java.text.ParseException)1 JAXBException (javax.xml.bind.JAXBException)1 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)1 WebServiceException (javax.xml.ws.WebServiceException)1 Schema (org.apache.avro.Schema)1 IndexedRecord (org.apache.avro.generic.IndexedRecord)1 ComponentException (org.talend.components.api.exception.ComponentException)1 MarketoError (org.talend.components.marketo.runtime.client.type.MarketoError)1 MarketoException (org.talend.components.marketo.runtime.client.type.MarketoException)1