use of org.talend.components.api.exception.ComponentException in project components by Talend.
the class KafkaOutputDefinition method getRuntimeInfo.
@Override
public RuntimeInfo getRuntimeInfo(ExecutionEngine engine, ComponentProperties properties, ConnectorTopology connectorTopology) {
assertEngineCompatibility(engine);
assertConnectorTopologyCompatibility(connectorTopology);
try {
return new JarRuntimeInfo(new URL(KafkaFamilyDefinition.MAVEN_DEFAULT_RUNTIME_URI), DependenciesReader.computeDependenciesFilePath(KafkaFamilyDefinition.MAVEN_GROUP_ID, KafkaFamilyDefinition.MAVEN_DEFAULT_RUNTIME_ARTIFACT_ID), RUNTIME);
} catch (MalformedURLException e) {
throw new ComponentException(e);
}
}
use of org.talend.components.api.exception.ComponentException in project components by Talend.
the class FixedInputDefinition method getRuntimeInfo.
@Override
public RuntimeInfo getRuntimeInfo(ExecutionEngine engine, ComponentProperties properties, ConnectorTopology connectorTopology) {
assertEngineCompatibility(engine);
assertConnectorTopologyCompatibility(connectorTopology);
try {
return new JarRuntimeInfo(new URL(LocalIOComponentFamilyDefinition.MAVEN_DEFAULT_RUNTIME_URI), DependenciesReader.computeDependenciesFilePath(LocalIOComponentFamilyDefinition.MAVEN_GROUP_ID, LocalIOComponentFamilyDefinition.MAVEN_DEFAULT_RUNTIME_ARTIFACT_ID), RUNTIME);
} catch (MalformedURLException e) {
throw new ComponentException(e);
}
}
use of org.talend.components.api.exception.ComponentException in project components by Talend.
the class FixedFlowInputDefinition method getRuntimeInfo.
@Override
public RuntimeInfo getRuntimeInfo(ExecutionEngine engine, ComponentProperties properties, ConnectorTopology connectorTopology) {
assertEngineCompatibility(engine);
assertConnectorTopologyCompatibility(connectorTopology);
try {
return new JarRuntimeInfo(new URL(LocalIOComponentFamilyDefinition.MAVEN_DEFAULT_RUNTIME_URI), DependenciesReader.computeDependenciesFilePath(LocalIOComponentFamilyDefinition.MAVEN_GROUP_ID, LocalIOComponentFamilyDefinition.MAVEN_DEFAULT_RUNTIME_ARTIFACT_ID), RUNTIME);
} catch (MalformedURLException e) {
throw new ComponentException(e);
}
}
use of org.talend.components.api.exception.ComponentException in project components by Talend.
the class MarketoSOAPClient method getMultipleLeads.
/**
* In getMultipleLeadsJSON you have to add includeAttributes base fields like Email. Otherwise, they return null from
* API. WTF ?!? It's like that...
*/
@Override
public MarketoRecordResult getMultipleLeads(TMarketoInputProperties parameters, String offset) {
LOG.debug("MarketoSOAPClient.getMultipleLeadsJSON with {}", parameters.leadSelectorSOAP.getValue());
Schema schema = parameters.schemaInput.schema.getValue();
Map<String, String> mappings = parameters.mappingInput.getNameMappingsForMarketo();
int bSize = parameters.batchSize.getValue();
//
// Create Request
//
ParamsGetMultipleLeads request = new ParamsGetMultipleLeads();
//
if (parameters.leadSelectorSOAP.getValue().equals(LeadKeySelector)) {
LOG.info("LeadKeySelector - Key type: {} with value : {}.", parameters.leadKeyTypeSOAP.getValue().toString(), parameters.leadKeyValues.getValue());
LeadKeySelector keySelector = new LeadKeySelector();
keySelector.setKeyType(valueOf(parameters.leadKeyTypeSOAP.getValue().toString()));
ArrayOfString aos = new ArrayOfString();
String[] keys = parameters.leadKeyValues.getValue().split("(,|;|\\s)");
for (String s : keys) {
LOG.debug("Adding leadKeyValue : {}.", s);
aos.getStringItems().add(s);
}
keySelector.setKeyValues(aos);
request.setLeadSelector(keySelector);
} else if (parameters.leadSelectorSOAP.getValue().equals(LastUpdateAtSelector)) {
LOG.debug("LastUpdateAtSelector - since {} to {}.", parameters.oldestUpdateDate.getValue(), parameters.latestUpdateDate.getValue());
LastUpdateAtSelector leadSelector = new LastUpdateAtSelector();
try {
DatatypeFactory factory = newInstance();
Date oldest = MarketoUtils.parseDateString(parameters.oldestUpdateDate.getValue());
Date latest = MarketoUtils.parseDateString(parameters.latestUpdateDate.getValue());
GregorianCalendar gc = new GregorianCalendar();
gc.setTime(latest);
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);
} catch (ParseException | DatatypeConfigurationException e) {
LOG.error("Error for LastUpdateAtSelector : {}.", e.getMessage());
throw new ComponentException(e);
}
} else //
if (parameters.leadSelectorSOAP.getValue().equals(StaticListSelector)) {
LOG.info("StaticListSelector - List type : {} with value : {}.", parameters.listParam.getValue(), parameters.listParamListName.getValue());
StaticListSelector staticListSelector = new StaticListSelector();
if (parameters.listParam.getValue().equals(STATIC_LIST_NAME)) {
JAXBElement<String> listName = objectFactory.createStaticListSelectorStaticListName(parameters.listParamListName.getValue());
staticListSelector.setStaticListName(listName);
} else {
// you can find listId by examining the URL : https://app-abq.marketo.com/#ST29912B2
// #ST29912B2 :
// #ST -> Static list identifier
// 29912 -> our list FIELD_ID !
// B2 -> tab in the UI
JAXBElement<Integer> listId = objectFactory.createStaticListSelectorStaticListId(//
parameters.listParamListId.getValue());
staticListSelector.setStaticListId(listId);
}
request.setLeadSelector(staticListSelector);
} else {
// Duh !
LOG.error("Unknown LeadSelector : {}.", parameters.leadSelectorSOAP.getValue());
throw new ComponentException(new Exception("Incorrect parameter value for LeadSelector : " + parameters.leadSelectorSOAP.getValue()));
}
// attributes
// curiously we have to put some basic fields like Email in attributes if we have them feed...
ArrayOfString attributes = new ArrayOfString();
for (String s : mappings.values()) {
attributes.getStringItems().add(s);
}
attributes.getStringItems().add("Company");
request.setIncludeAttributes(attributes);
// batchSize : another curious behavior... Don't seem to work properly with leadKeySelector...
// nevertheless, the server automatically adjust batch size according request.
JAXBElement<Integer> batchSize = new ObjectFactory().createParamsGetMultipleLeadsBatchSize(bSize);
request.setBatchSize(batchSize);
// stream position
if (offset != null && !offset.isEmpty()) {
request.setStreamPosition(new ObjectFactory().createParamsGetMultipleLeadsStreamPosition(offset));
}
//
//
// Request execution
//
SuccessGetMultipleLeads result = null;
MarketoRecordResult mkto = new MarketoRecordResult();
try {
result = getPort().getMultipleLeads(request, header);
} catch (Exception e) {
LOG.error("Lead not found : {}.", e.getMessage());
mkto.setSuccess(false);
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.setSuccess(true);
mkto.setErrors(Collections.singletonList(new MarketoError(SOAP, MESSAGE_NO_LEADS_FOUND)));
mkto.setRecordCount(0);
mkto.setRemainCount(0);
return mkto;
} else {
String streamPos = result.getResult().getNewStreamPosition();
int recordCount = result.getResult().getReturnCount();
int remainCount = result.getResult().getRemainingCount();
// Process results
List<IndexedRecord> results = convertLeadRecords(result.getResult().getLeadRecordList().getValue().getLeadRecords(), schema, mappings);
return new MarketoRecordResult(true, streamPos, recordCount, remainCount, results);
}
}
use of org.talend.components.api.exception.ComponentException in project components by Talend.
the class ComponentExceptionsTest method testExceptionToValidationResult.
@Test
public void testExceptionToValidationResult() {
ValidationResult result1 = ComponentExceptions.exceptionToValidationResult(new WebServiceException("TEST"));
assertNotNull(result1);
assertEquals(ValidationResult.Result.ERROR, result1.getStatus());
assertEquals("TEST", result1.getMessage());
ValidationResult result2 = ComponentExceptions.exceptionToValidationResult(new ComponentException(CommonErrorCodes.UNEXPECTED_EXCEPTION, new WebServiceException("TEST")));
assertNotNull(result2);
assertEquals(ValidationResult.Result.ERROR, result2.getStatus());
assertEquals(CommonErrorCodes.UNEXPECTED_EXCEPTION.name(), result2.getMessage());
ValidationResult controlResult = new ValidationResult(ValidationResult.Result.ERROR, "TEST");
ValidationResult result3 = ComponentExceptions.exceptionToValidationResult(new ComponentException(controlResult));
assertEquals(controlResult, result3);
}
Aggregations