use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class ErrorMessageTest method shouldReturnRightErrorMessageWhenDefaultErrorThrown.
@Test
public void shouldReturnRightErrorMessageWhenDefaultErrorThrown() {
// given
ErrorCode errorCode = new ErrorCode() {
@Override
public String getProduct() {
return "TDP";
}
@Override
public String getGroup() {
return "API";
}
@Override
public int getHttpStatus() {
return 404;
}
@Override
public Collection<String> getExpectedContextEntries() {
return Collections.emptyList();
}
@Override
public String getCode() {
return null;
}
};
// when
TDPException exception = new TDPException(errorCode, null, null);
// then
assertEquals(errorCode, exception.getCode());
assertEquals("An unexpected error occurred and we could not complete your last operation. You can continue to use Data Preparation", exception.getMessage());
assertEquals("An error has occurred", exception.getMessageTitle());
assertFalse(exception.getContext().entries().iterator().hasNext());
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class ErrorMessageTest method shouldReturnRightErrorMessageWhenUnableToCreateOrUpdateDatasetThrown.
@Test
public void shouldReturnRightErrorMessageWhenUnableToCreateOrUpdateDatasetThrown() {
// given
ErrorCode errorCode = UNABLE_TO_CREATE_OR_UPDATE_DATASET;
// when
TDPException exception = new TDPException(errorCode, null, null);
// then
assertEquals(errorCode, exception.getCode());
assertEquals("An error occurred during update", exception.getMessage());
assertEquals("Update error", exception.getMessageTitle());
assertFalse(exception.getContext().entries().iterator().hasNext());
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class DataSetLookupRowMatcher method init.
/**
* Open the connection to get the dataset content and init the row iterator.
*/
@PostConstruct
private void init() {
final DataSetGet dataSetGet = context.getBean(DataSetGet.class, datasetId, true, true);
LOGGER.debug("opening {}", datasetId);
this.input = dataSetGet.execute();
try {
JsonParser jsonParser = mapper.getFactory().createParser(new InputStreamReader(input, UTF_8));
DataSet lookup = mapper.readerFor(DataSet.class).readValue(jsonParser);
this.lookupIterator = lookup.getRecords().iterator();
this.emptyRow = getEmptyRow(lookup.getMetadata().getRowMetadata().getColumns());
} catch (IOException e) {
throw new TDPException(TransformationErrorCodes.UNABLE_TO_READ_LOOKUP_DATASET, e);
}
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class DefaultsTest method shouldReturnString_handleIOError.
@Test
public void shouldReturnString_handleIOError() throws Exception {
// When
final BasicHttpResponse response = buildResponse();
response.setEntity(new StringEntity("") {
@Override
public InputStream getContent() throws IOException {
throw new IOException("Unexpected exception");
}
});
try {
Defaults.asString().apply(buildRequest(), response);
} catch (TDPException e) {
// Then
assertEquals(CommonErrorCodes.UNEXPECTED_EXCEPTION, e.getCode());
}
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class XlsSchemaParser method parseAllSheetsStream.
private List<Schema.SheetContent> parseAllSheetsStream(Request request) {
Workbook workbook = //
StreamingReader.builder().bufferSize(//
4096).rowCacheSize(//
1).open(request.getContent());
try {
List<Schema.SheetContent> schemas = new ArrayList<>();
int sheetNumber = 0;
for (Sheet sheet : workbook) {
List<ColumnMetadata> columnsMetadata = createMetadataFromFirstNonEmptyRowAndInitSheet(sheet);
int totalColumnsNumber = getTotalColumnsNumber((StreamingSheet) sheet);
/*
* Protecting the app against too large data sets => It would break mongo by submitting too large empty
* column metadata or saturate the memory during analysis.
*
* @see https://jira.talendforge.org/browse/TDP-3459
*/
if (totalColumnsNumber > maxNumberOfColumns) {
throw new TDPException(DataSetErrorCodes.DATASET_HAS_TOO_MANY_COLUMNS, ExceptionContext.build().put("number-of-columns", totalColumnsNumber).put("max-allowed", maxNumberOfColumns));
}
String sheetName = sheet.getSheetName();
Schema.SheetContent sheetContent = new Schema.SheetContent(StringUtils.isEmpty(sheetName) ? "sheet-" + sheetNumber : sheetName, columnsMetadata);
// if less columns found than the metadata we complete
completeWithEmptyColumnsMetadata(columnsMetadata, totalColumnsNumber);
schemas.add(sheetContent);
}
return schemas;
} finally {
try {
workbook.close();
} catch (IOException e) {
LOGGER.error("Unable to close excel file.", e);
}
}
}
Aggregations