Search in sources :

Example 1 with LeadKey

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

the class MarketoSOAPClientTest method getListOperation.

public SuccessListOperation getListOperation(boolean isSuccess, String status) {
    SuccessListOperation result = new SuccessListOperation();
    ResultListOperation rlo = new ResultListOperation();
    if (isSuccess) {
        rlo.setSuccess(true);
        ArrayOfLeadStatus aols = new ArrayOfLeadStatus();
        LeadStatus ls = new LeadStatus();
        LeadKey lk = new LeadKey();
        lk.setKeyType(LeadKeyRef.IDNUM);
        lk.setKeyValue("12345");
        ls.setLeadKey(lk);
        aols.getLeadStatuses().add(ls);
        rlo.setStatusList(objectFactory.createResultListOperationStatusList(aols));
        result.setResult(rlo);
    } else {
        rlo.setSuccess(false);
        rlo.setStatusList(objectFactory.createResultListOperationStatusList(null));
        result.setResult(rlo);
    }
    return result;
}
Also used : SuccessListOperation(com.marketo.mktows.SuccessListOperation) ResultListOperation(com.marketo.mktows.ResultListOperation) ArrayOfLeadStatus(com.marketo.mktows.ArrayOfLeadStatus) LeadKey(com.marketo.mktows.LeadKey) ArrayOfLeadStatus(com.marketo.mktows.ArrayOfLeadStatus) LeadStatus(com.marketo.mktows.LeadStatus)

Example 2 with LeadKey

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

the class MarketoSOAPClient method getLead.

@Override
public MarketoRecordResult getLead(TMarketoInputProperties parameters, String offset) {
    LOG.debug("MarketoSOAPClient.getLead with selector:{} key:{} value:{}.", parameters.leadSelectorSOAP.getValue(), parameters.leadKeyTypeSOAP.getValue(), parameters.leadKeyValue.getValue());
    String leadKeyType = parameters.leadKeyTypeSOAP.getValue().toString();
    String leadKeyValue = parameters.leadKeyValue.getValue();
    Schema schema = parameters.schemaInput.schema.getValue();
    Map<String, String> mappings = parameters.mappingInput.getNameMappingsForMarketo();
    // Create Request
    ParamsGetLead request = new ParamsGetLead();
    LeadKey key = new LeadKey();
    key.setKeyType(valueOf(leadKeyType));
    key.setKeyValue(leadKeyValue);
    request.setLeadKey(key);
    // 
    SuccessGetLead result = null;
    MarketoRecordResult mkto = new MarketoRecordResult();
    try {
        result = getPort().getLead(request, header);
    } catch (Exception e) {
        LOG.error("Lead not found : {}.", 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().getCount() == 0) {
        LOG.debug(MESSAGE_REQUEST_RETURNED_0_MATCHING_LEADS);
        mkto.setErrors(Collections.singletonList(new MarketoError(SOAP, MESSAGE_NO_LEADS_FOUND)));
        mkto.setSuccess(true);
    } else {
        int counted = result.getResult().getCount();
        List<IndexedRecord> results = convertLeadRecords(result.getResult().getLeadRecordList().getValue().getLeadRecords(), schema, mappings);
        mkto.setRecordCount(counted);
        mkto.setRemainCount(0);
        mkto.setSuccess(true);
        mkto.setRecords(results);
    }
    return mkto;
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) SuccessGetLead(com.marketo.mktows.SuccessGetLead) ArrayOfString(com.marketo.mktows.ArrayOfString) LeadKey(com.marketo.mktows.LeadKey) ArrayOfLeadKey(com.marketo.mktows.ArrayOfLeadKey) ParamsGetLead(com.marketo.mktows.ParamsGetLead) 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) MarketoRecordResult(org.talend.components.marketo.runtime.client.type.MarketoRecordResult) MarketoError(org.talend.components.marketo.runtime.client.type.MarketoError)

Example 3 with LeadKey

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

the class MarketoSOAPClient method listOperation.

public MarketoSyncResult listOperation(ListOperationType operationType, ListOperationParameters parameters) {
    LOG.debug("listOperation : {}", parameters);
    ParamsListOperation paramsListOperation = new ParamsListOperation();
    paramsListOperation.setListOperation(operationType);
    paramsListOperation.setStrict(objectFactory.createParamsListOperationStrict(parameters.getStrict()));
    ListKey listKey = new ListKey();
    listKey.setKeyValue(parameters.getListKeyValue());
    listKey.setKeyType(ListKeyType.valueOf(parameters.getListKeyType()));
    paramsListOperation.setListKey(listKey);
    ArrayOfLeadKey leadKeys = new ArrayOfLeadKey();
    for (String lkv : parameters.getLeadKeyValues()) {
        LeadKey lk = new LeadKey();
        lk.setKeyType(valueOf(parameters.getLeadKeyType()));
        lk.setKeyValue(lkv);
        leadKeys.getLeadKeies().add(lk);
    }
    paramsListOperation.setListMemberList(leadKeys);
    MarketoSyncResult mkto = new MarketoSyncResult();
    mkto.setRequestId(SOAP + "::" + operationType.name());
    try {
        SuccessListOperation result = getPort().listOperation(paramsListOperation, header);
        if (LOG.isDebugEnabled()) {
            try {
                JAXBContext context = JAXBContext.newInstance(SuccessListOperation.class);
                Marshaller m = context.createMarshaller();
                m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
                m.marshal(result, System.out);
            } catch (JAXBException e) {
                LOG.error(e.getMessage());
            }
        }
        mkto.setSuccess(true);
        if (!result.getResult().getStatusList().isNil()) {
            mkto.setRecordCount(result.getResult().getStatusList().getValue().getLeadStatuses().size());
            List<LeadStatus> statuses = result.getResult().getStatusList().getValue().getLeadStatuses();
            List<SyncStatus> resultStatus = new ArrayList<>();
            for (LeadStatus status : statuses) {
                SyncStatus sts = new SyncStatus(Integer.parseInt(status.getLeadKey().getKeyValue()), String.valueOf(status.isStatus()));
                if (!status.isStatus() && !ISMEMBEROFLIST.equals(operationType)) {
                    Map<String, String> reason = new HashMap<>();
                    reason.put("code", "20103");
                    reason.put("message", "Lead Not Found");
                    sts.setReasons(Collections.singletonList(reason));
                }
                resultStatus.add(sts);
            }
            mkto.setRecords(resultStatus);
        } else {
            LOG.debug("No detail about successed operation, building one...");
            String success = String.valueOf(result.getResult().isSuccess());
            mkto.setRecordCount(parameters.getLeadKeyValue().size());
            for (String leadk : parameters.getLeadKeyValue()) {
                SyncStatus status = new SyncStatus(Integer.parseInt(leadk), success);
                mkto.getRecords().add(status);
            }
        }
    } catch (Exception e) {
        LOG.error("[{}] error: {}", operationType.name(), e.getMessage());
        mkto.setSuccess(false);
        mkto.setErrors(Collections.singletonList(new MarketoError(SOAP, e.toString())));
    }
    return mkto;
}
Also used : ArrayOfLeadKey(com.marketo.mktows.ArrayOfLeadKey) SuccessListOperation(com.marketo.mktows.SuccessListOperation) Marshaller(javax.xml.bind.Marshaller) HashMap(java.util.HashMap) JAXBException(javax.xml.bind.JAXBException) SyncStatus(org.talend.components.marketo.runtime.client.rest.type.SyncStatus) ArrayList(java.util.ArrayList) JAXBContext(javax.xml.bind.JAXBContext) 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) MarketoSyncResult(org.talend.components.marketo.runtime.client.type.MarketoSyncResult) LeadStatus(com.marketo.mktows.LeadStatus) MarketoError(org.talend.components.marketo.runtime.client.type.MarketoError) ListKey(com.marketo.mktows.ListKey) ParamsListOperation(com.marketo.mktows.ParamsListOperation) LeadKey(com.marketo.mktows.LeadKey) ArrayOfLeadKey(com.marketo.mktows.ArrayOfLeadKey)

Example 4 with LeadKey

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

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