Search in sources :

Example 86 with TDPException

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());
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) ErrorCode(org.talend.daikon.exception.error.ErrorCode) Test(org.junit.Test) ServiceBaseTest(org.talend.ServiceBaseTest)

Example 87 with TDPException

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());
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) ErrorCode(org.talend.daikon.exception.error.ErrorCode) Test(org.junit.Test) ServiceBaseTest(org.talend.ServiceBaseTest)

Example 88 with TDPException

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);
    }
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) DataSetGet(org.talend.dataprep.command.dataset.DataSetGet) InputStreamReader(java.io.InputStreamReader) DataSet(org.talend.dataprep.api.dataset.DataSet) IOException(java.io.IOException) JsonParser(com.fasterxml.jackson.core.JsonParser) PostConstruct(javax.annotation.PostConstruct)

Example 89 with TDPException

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());
    }
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) StringEntity(org.apache.http.entity.StringEntity) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) InputStream(java.io.InputStream) IOException(java.io.IOException) Test(org.junit.Test)

Example 90 with TDPException

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);
        }
    }
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) Schema(org.talend.dataprep.schema.Schema) IOException(java.io.IOException) TDPException(org.talend.dataprep.exception.TDPException) StreamingSheet(org.talend.dataprep.schema.xls.streaming.StreamingSheet)

Aggregations

TDPException (org.talend.dataprep.exception.TDPException)123 IOException (java.io.IOException)43 InputStream (java.io.InputStream)25 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)21 Test (org.junit.Test)17 ApiOperation (io.swagger.annotations.ApiOperation)16 Timed (org.talend.dataprep.metrics.Timed)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 DataSet (org.talend.dataprep.api.dataset.DataSet)13 ServiceBaseTest (org.talend.ServiceBaseTest)11 StringEntity (org.apache.http.entity.StringEntity)10 JsonParser (com.fasterxml.jackson.core.JsonParser)9 URISyntaxException (java.net.URISyntaxException)9 HttpPost (org.apache.http.client.methods.HttpPost)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)9 List (java.util.List)8 URIBuilder (org.apache.http.client.utils.URIBuilder)8 Marker (org.slf4j.Marker)8 ErrorCode (org.talend.daikon.exception.error.ErrorCode)8