use of com.marketo.mktows.SuccessListOperation 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;
}
use of com.marketo.mktows.SuccessListOperation 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;
}
Aggregations