use of org.talend.components.api.exception.DataRejectException in project components by Talend.
the class JDBCRowTestIT method test_reject_as_input.
@SuppressWarnings("rawtypes")
@Test
public void test_reject_as_input() throws Exception {
TJDBCRowDefinition definition = new TJDBCRowDefinition();
TJDBCRowProperties properties = DBTestUtils.createCommonJDBCRowProperties(allSetting, definition);
Schema schema = DBTestUtils.createTestSchema4(tablename);
properties.main.schema.setValue(schema);
properties.updateOutputSchemas();
properties.tableSelection.tablename.setValue(tablename);
properties.sql.setValue("select id, name from notexists");
properties.dieOnError.setValue(false);
randomCommit(properties);
// the field is the unique reason to use the component as a input
properties.propagateQueryResultSet.setValue(true);
// component
properties.beforeUseColumn();
properties.useColumn.setValue(properties.useColumn.getPossibleValues().get(0).toString());
JDBCRowSource source = new JDBCRowSource();
source.initialize(null, properties);
ValidationResult result = source.validate(null);
Assert.assertTrue(result.getStatus() == ValidationResult.Result.OK);
Reader reader = source.createReader(null);
try {
reader.start();
reader.getCurrent();
// should go to the exception before current statement
Assert.fail();
reader.advance();
reader.close();
} catch (DataRejectException e) {
Map<String, Object> info = e.getRejectInfo();
IndexedRecord data = (IndexedRecord) info.get("talend_record");
Assert.assertNull(data.get(0));
Assert.assertNotNull(data.get(1));
Assert.assertNotNull(data.get(2));
} finally {
reader.close();
}
}
use of org.talend.components.api.exception.DataRejectException in project components by Talend.
the class JDBCRowReader method handleReject.
private void handleReject(SQLException e) {
IndexedRecord reject = new GenericData.Record(rejectSchema);
for (Schema.Field outField : reject.getSchema().getFields()) {
Object outValue = null;
if ("errorCode".equals(outField.name())) {
outValue = e.getSQLState();
} else if ("errorMessage".equals(outField.name())) {
outValue = e.getMessage();
}
reject.put(outField.pos(), outValue);
}
Map<String, Object> resultMessage = new HashMap<String, Object>();
resultMessage.put("error", e.getMessage());
resultMessage.put("errorCode", e.getSQLState());
resultMessage.put("errorMessage", e.getMessage() + " - Line: " + result.totalCount);
resultMessage.put("talend_record", reject);
throw new DataRejectException(resultMessage);
}
use of org.talend.components.api.exception.DataRejectException in project components by Talend.
the class JdbcRowTestIT method test_reject_as_input.
@SuppressWarnings("rawtypes")
@Test
public void test_reject_as_input() throws Exception {
TJDBCRowDefinition definition = new TJDBCRowDefinition();
TJDBCRowProperties properties = DBTestUtils.createCommonJDBCRowProperties(allSetting, definition);
Schema schema = DBTestUtils.createTestSchema4(tablename);
properties.main.schema.setValue(schema);
properties.updateOutputSchemas();
properties.tableSelection.tablename.setValue(tablename);
properties.sql.setValue("select id, name from notexists");
properties.dieOnError.setValue(false);
randomCommit(properties);
// the field is the unique reason to use the component as a input
properties.propagateQueryResultSet.setValue(true);
// component
properties.beforeUseColumn();
properties.useColumn.setValue(properties.useColumn.getPossibleValues().get(0).toString());
try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(definition.getRuntimeInfo(ExecutionEngine.DI, properties, ConnectorTopology.OUTGOING), properties.getClass().getClassLoader())) {
JDBCRowSource source = (JDBCRowSource) sandboxedInstance.getInstance();
source.initialize(null, properties);
ValidationResult result = source.validate(null);
Assert.assertTrue(result.getStatus() == ValidationResult.Result.OK);
Reader reader = source.createReader(null);
try {
reader.start();
reader.getCurrent();
// should go to the exception before current statement
Assert.fail();
reader.advance();
reader.close();
} catch (DataRejectException e) {
Map<String, Object> info = e.getRejectInfo();
IndexedRecord data = (IndexedRecord) info.get("talend_record");
Assert.assertNull(data.get(0));
Assert.assertNotNull(data.get(1));
Assert.assertNotNull(data.get(2));
} finally {
reader.close();
}
}
}
use of org.talend.components.api.exception.DataRejectException in project components by Talend.
the class JiraWritersTestIT method testUpdateIssues.
/**
* Checks {@link JiraUpdateWriter#write(Object)} updates issues on Jira server
*
* @throws IOException
*/
public void testUpdateIssues() throws IOException {
IndexedRecord updateIssueRecord1 = new GenericData.Record(UPDATE_SCHEMA);
String updateIssue1 = "{\"fields\":{\"summary\":\"Updated test issue 1\"}}";
updateIssueRecord1.put(0, "ITP-1");
updateIssueRecord1.put(1, updateIssue1);
IndexedRecord updateIssueRecord2 = new GenericData.Record(UPDATE_SCHEMA);
String updateIssue2 = "{\"fields\":{\"summary\":\"Updated test issue 2\"}}";
updateIssueRecord2.put(0, "ITP-2");
updateIssueRecord2.put(1, updateIssue2);
JiraWriter updateIssueWriter = JiraTestsHelper.createWriter(HOST_PORT, USER, PASS, Resource.ISSUE, Action.UPDATE);
updateIssueWriter.open("updIss");
try {
updateIssueWriter.write(updateIssueRecord1);
updateIssueWriter.write(updateIssueRecord2);
updateIssueWriter.close();
} catch (DataRejectException e) {
String rejectError = e.getRejectInfo().get("error").toString();
LOG.error(rejectError);
collector.addError(new Throwable(rejectError));
}
}
use of org.talend.components.api.exception.DataRejectException in project components by Talend.
the class JiraWritersTestIT method testDeleteIssues.
/**
* Checks {@link JiraDeleteWriter#write(Object)} deletes issues from Jira server
*
* @throws IOException
*/
public void testDeleteIssues() throws IOException {
IndexedRecord deleteIssueRecord1 = new GenericData.Record(DELETE_SCHEMA);
deleteIssueRecord1.put(0, "ITP-1");
IndexedRecord deleteIssueRecord2 = new GenericData.Record(DELETE_SCHEMA);
deleteIssueRecord2.put(0, "ITP-2");
JiraWriter deleteIssueWriter = JiraTestsHelper.createWriter(HOST_PORT, USER, PASS, Resource.ISSUE, Action.DELETE);
deleteIssueWriter.open("delIss");
try {
deleteIssueWriter.write(deleteIssueRecord1);
deleteIssueWriter.write(deleteIssueRecord2);
} catch (DataRejectException e) {
String rejectError = e.getRejectInfo().get("error").toString();
LOG.error(rejectError);
collector.addError(new Throwable(rejectError));
}
}
Aggregations