Search in sources :

Example 1 with StreamPosition

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

the class MarketoSOAPClientTest method getLeadActivityResult.

public SuccessGetLeadActivity getLeadActivityResult() throws Exception {
    SuccessGetLeadActivity result = new SuccessGetLeadActivity();
    LeadActivityList res = new LeadActivityList();
    res.setReturnCount(1);
    res.setRemainingCount(0);
    StreamPosition sp = new StreamPosition();
    sp.setOffset(objectFactory.createStreamPositionOffset(""));
    res.setNewStartPosition(sp);
    ArrayOfActivityRecord arecords = new ArrayOfActivityRecord();
    // 
    ActivityRecord ar = new ActivityRecord();
    ar.setId(objectFactory.createActivityRecordId(123456L));
    ar.setMarketoGUID("ABC-123-DEF");
    ar.setMktgAssetName("mktgAssetName");
    ar.setActivityDateTime(factory.newXMLGregorianCalendar(gcDateTest));
    ar.setActivityType("activityType");
    ar.setCampaign(objectFactory.createActivityRecordCampaign("campaign"));
    ar.setForeignSysId(objectFactory.createActivityRecordForeignSysId("foreignSysId"));
    ar.setForeignSysOrgId(objectFactory.createActivityRecordForeignSysOrgId("foreignSysOrgId"));
    ar.setMktPersonId("mktPersonId");
    ar.setPersonName(objectFactory.createActivityRecordPersonName("personName"));
    ar.setOrgName(objectFactory.createActivityRecordOrgName("orgName"));
    ArrayOfAttribute aoa = objectFactory.createArrayOfAttribute();
    Attribute attr = new Attribute();
    attr.setAttrName("attrName");
    attr.setAttrValue("attrValue");
    aoa.getAttributes().add(attr);
    ar.setActivityAttributes(objectFactory.createActivityRecordActivityAttributes(aoa));
    // 
    arecords.getActivityRecords().add(ar);
    res.setActivityRecordList(objectFactory.createLeadActivityListActivityRecordList(arecords));
    result.setLeadActivityList(res);
    return result;
}
Also used : ArrayOfActivityRecord(com.marketo.mktows.ArrayOfActivityRecord) ArrayOfAttribute(com.marketo.mktows.ArrayOfAttribute) ArrayOfAttribute(com.marketo.mktows.ArrayOfAttribute) Attribute(com.marketo.mktows.Attribute) SuccessGetLeadActivity(com.marketo.mktows.SuccessGetLeadActivity) StreamPosition(com.marketo.mktows.StreamPosition) ArrayOfActivityRecord(com.marketo.mktows.ArrayOfActivityRecord) ActivityRecord(com.marketo.mktows.ActivityRecord) LeadActivityList(com.marketo.mktows.LeadActivityList)

Example 2 with StreamPosition

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

the class MarketoSOAPClient method getLeadChanges.

@Override
public MarketoRecordResult getLeadChanges(TMarketoInputProperties parameters, String offset) {
    Schema schema = parameters.schemaInput.schema.getValue();
    Map<String, String> mappings = parameters.mappingInput.getNameMappingsForMarketo();
    int bSize = parameters.batchSize.getValue() > 100 ? 100 : parameters.batchSize.getValue();
    String sOldest = parameters.oldestCreateDate.getValue();
    String sLatest = parameters.latestCreateDate.getValue();
    LOG.debug("LeadChanges - from {} to {}.", sOldest, sLatest);
    // 
    // Create Request
    // 
    ParamsGetLeadChanges request = new ParamsGetLeadChanges();
    LastUpdateAtSelector leadSelector = new LastUpdateAtSelector();
    try {
        Date oldest = MarketoUtils.parseDateString(sOldest);
        Date latest = MarketoUtils.parseDateString(sLatest);
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(latest);
        DatatypeFactory factory = newInstance();
        JAXBElement<XMLGregorianCalendar> until = objectFactory.createLastUpdateAtSelectorLatestUpdatedAt(factory.newXMLGregorianCalendar(gc));
        GregorianCalendar since = new GregorianCalendar();
        since.setTime(oldest);
        leadSelector.setOldestUpdatedAt(factory.newXMLGregorianCalendar(since));
        leadSelector.setLatestUpdatedAt(until);
        request.setLeadSelector(leadSelector);
        JAXBElement<XMLGregorianCalendar> oldestCreateAtValue = objectFactory.createStreamPositionOldestCreatedAt(factory.newXMLGregorianCalendar(since));
        StreamPosition sp = new StreamPosition();
        sp.setOldestCreatedAt(oldestCreateAtValue);
        if (offset != null && !offset.isEmpty()) {
            sp.setOffset(objectFactory.createStreamPositionOffset(offset));
        }
        request.setStartPosition(sp);
    } catch (ParseException | DatatypeConfigurationException e) {
        LOG.error("Error for LastUpdateAtSelector : {}.", e.getMessage());
        throw new ComponentException(e);
    }
    // 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);
    // 
    // 
    // Request execution
    // 
    SuccessGetLeadChanges result = null;
    MarketoRecordResult mkto = new MarketoRecordResult();
    try {
        result = getPort().getLeadChanges(request, header);
        mkto.setSuccess(true);
    } catch (Exception e) {
        LOG.error("getLeadChanges 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.getResult().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.getResult().getNewStartPosition().getOffset().getValue();
    int recordCount = result.getResult().getReturnCount();
    int remainCount = result.getResult().getRemainingCount();
    // Process results
    List<IndexedRecord> results = convertLeadChangeRecords(result.getResult().getLeadChangeRecordList().getValue().getLeadChangeRecords(), schema, mappings);
    mkto.setRecordCount(recordCount);
    mkto.setRemainCount(remainCount);
    mkto.setStreamPosition(streamPos);
    mkto.setRecords(results);
    return mkto;
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) ArrayOfString(com.marketo.mktows.ArrayOfString) ParamsGetLeadChanges(com.marketo.mktows.ParamsGetLeadChanges) MarketoError(org.talend.components.marketo.runtime.client.type.MarketoError) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) LastUpdateAtSelector(com.marketo.mktows.LastUpdateAtSelector) LastUpdateAtSelector(org.talend.components.marketo.tmarketoinput.TMarketoInputProperties.LeadSelector.LastUpdateAtSelector) DatatypeFactory(javax.xml.datatype.DatatypeFactory) ArrayOfActivityType(com.marketo.mktows.ArrayOfActivityType) SuccessGetLeadChanges(com.marketo.mktows.SuccessGetLeadChanges) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) StreamPosition(com.marketo.mktows.StreamPosition) Date(java.util.Date) 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) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) ArrayOfString(com.marketo.mktows.ArrayOfString) ComponentException(org.talend.components.api.exception.ComponentException) ParseException(java.text.ParseException) ActivityTypeFilter(com.marketo.mktows.ActivityTypeFilter)

Example 3 with StreamPosition

use of com.marketo.mktows.StreamPosition 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)

Example 4 with StreamPosition

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

the class MarketoSOAPClientTest method getLeadChangeResult.

public SuccessGetLeadChanges getLeadChangeResult() {
    SuccessGetLeadChanges result = new SuccessGetLeadChanges();
    ResultGetLeadChanges res = new ResultGetLeadChanges();
    res.setReturnCount(1);
    res.setRemainingCount(0);
    StreamPosition sp = new StreamPosition();
    sp.setOffset(objectFactory.createStreamPositionOffset(""));
    res.setNewStartPosition(sp);
    // 
    ArrayOfLeadChangeRecord lcr = new ArrayOfLeadChangeRecord();
    LeadChangeRecord lc = new LeadChangeRecord();
    lc.setId(objectFactory.createLeadChangeRecordId(123456L));
    lc.setMarketoGUID("ABC-123-DEF");
    lc.setMktgAssetName(objectFactory.createLeadChangeRecordMktgAssetName("mktgAssetName"));
    lc.setActivityDateTime(factory.newXMLGregorianCalendar(gcDateTest));
    lc.setActivityType("activityType");
    lc.setCampaign("campaign");
    lc.setMktPersonId("mktPersonId");
    ArrayOfAttribute aoa = objectFactory.createArrayOfAttribute();
    Attribute attr = new Attribute();
    attr.setAttrName("attrName");
    attr.setAttrValue("attrValue");
    aoa.getAttributes().add(attr);
    lc.setActivityAttributes(objectFactory.createActivityRecordActivityAttributes(aoa));
    lcr.getLeadChangeRecords().add(lc);
    // 
    res.setLeadChangeRecordList(objectFactory.createResultGetLeadChangesLeadChangeRecordList(lcr));
    result.setResult(res);
    return result;
}
Also used : ArrayOfAttribute(com.marketo.mktows.ArrayOfAttribute) ArrayOfAttribute(com.marketo.mktows.ArrayOfAttribute) Attribute(com.marketo.mktows.Attribute) SuccessGetLeadChanges(com.marketo.mktows.SuccessGetLeadChanges) ResultGetLeadChanges(com.marketo.mktows.ResultGetLeadChanges) StreamPosition(com.marketo.mktows.StreamPosition) ArrayOfLeadChangeRecord(com.marketo.mktows.ArrayOfLeadChangeRecord) ArrayOfLeadChangeRecord(com.marketo.mktows.ArrayOfLeadChangeRecord) LeadChangeRecord(com.marketo.mktows.LeadChangeRecord)

Aggregations

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