Search in sources :

Example 81 with TDPException

use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.

the class ResourceLoaderContentCache method evictMatch.

@Timed
@Override
public void evictMatch(ContentCacheKey key) {
    try {
        final DeletableResource[] resources = resolver.getResources("/cache/" + key.getPrefix() + "**");
        final Predicate<String> matcher = key.getMatcher();
        stream(resources).filter(r -> matcher.test(r.getFilename())).forEach(r -> {
            try {
                r.delete();
            } catch (IOException e) {
                throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
            }
        });
    } catch (IOException e) {
        throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
    }
}
Also used : VolumeMetered(org.talend.dataprep.metrics.VolumeMetered) StringUtils(org.apache.commons.lang.StringUtils) TDPException(org.talend.dataprep.exception.TDPException) ContentCacheKey(org.talend.dataprep.cache.ContentCacheKey) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) BinaryOperator.maxBy(java.util.function.BinaryOperator.maxBy) OutputStream(java.io.OutputStream) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) StringUtils.substringAfterLast(org.apache.commons.lang.StringUtils.substringAfterLast) Logger(org.slf4j.Logger) DeletableResource(org.talend.daikon.content.DeletableResource) Optional.ofNullable(java.util.Optional.ofNullable) Predicate(java.util.function.Predicate) IOException(java.io.IOException) ContentCache(org.talend.dataprep.cache.ContentCache) Component(org.springframework.stereotype.Component) ContentServiceEnabled(org.talend.daikon.content.ContentServiceEnabled) Optional(java.util.Optional) CommonErrorCodes(org.talend.dataprep.exception.error.CommonErrorCodes) ResourceResolver(org.talend.daikon.content.ResourceResolver) Long.parseLong(java.lang.Long.parseLong) Arrays.stream(java.util.Arrays.stream) Timed(org.talend.dataprep.metrics.Timed) InputStream(java.io.InputStream) TDPException(org.talend.dataprep.exception.TDPException) DeletableResource(org.talend.daikon.content.DeletableResource) IOException(java.io.IOException) Timed(org.talend.dataprep.metrics.Timed)

Example 82 with TDPException

use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.

the class UpdateStepRowMetadata method onExecute.

private HttpRequestBase onExecute(String stepId, RowMetadata rowMetadata) {
    try {
        final String stepsAsJson = objectMapper.writeValueAsString(rowMetadata);
        final HttpPut updater = new HttpPut(preparationServiceUrl + "/preparations/steps/" + stepId + "/metadata");
        updater.setHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE);
        updater.setEntity(new StringEntity(stepsAsJson, APPLICATION_JSON));
        return updater;
    } catch (JsonProcessingException e) {
        throw new TDPException(UNEXPECTED_EXCEPTION, e);
    }
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) StringEntity(org.apache.http.entity.StringEntity) Defaults.asString(org.talend.dataprep.command.Defaults.asString) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) HttpPut(org.apache.http.client.methods.HttpPut)

Example 83 with TDPException

use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.

the class DataSetJSONTest method should_iterate_row_with_metadata.

@Test
public void should_iterate_row_with_metadata() throws IOException {
    // given
    String[] columnNames = new String[] { "0001", "0002", "0003", "0004", "0005", "0006", "0007", "0008", "0009" };
    final InputStream input = this.getClass().getResourceAsStream("dataSetRowMetadata.json");
    try (JsonParser parser = mapper.getFactory().createParser(input)) {
        final DataSet dataSet = mapper.readerFor(DataSet.class).readValue(parser);
        final Iterator<DataSetRow> iterator = dataSet.getRecords().iterator();
        List<ColumnMetadata> actualColumns = new ArrayList<>();
        int recordCount = 0;
        while (iterator.hasNext()) {
            final DataSetRow next = iterator.next();
            actualColumns = next.getRowMetadata().getColumns();
            assertThat(actualColumns, not(empty()));
            recordCount++;
        }
        // then
        assertEquals(10, recordCount);
        for (int i = 0; i < actualColumns.size(); i++) {
            final ColumnMetadata column = actualColumns.get(i);
            assertEquals(columnNames[i], column.getId());
        }
    } catch (Exception e) {
        throw new TDPException(CommonErrorCodes.UNABLE_TO_PARSE_JSON, e);
    }
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) DataSet(org.talend.dataprep.api.dataset.DataSet) TDPException(org.talend.dataprep.exception.TDPException) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) TDPException(org.talend.dataprep.exception.TDPException) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) JsonParser(com.fasterxml.jackson.core.JsonParser) ServiceBaseTest(org.talend.ServiceBaseTest) Test(org.junit.Test)

Example 84 with TDPException

use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.

the class ErrorMessageTest method shouldReturnRightErrorMessageWhenHttpStatusIsZero.

@Test
public void shouldReturnRightErrorMessageWhenHttpStatusIsZero() {
    // given
    ErrorCode errorCode = new ErrorCode() {

        @Override
        public String getProduct() {
            return "TDP";
        }

        @Override
        public String getGroup() {
            return "API";
        }

        @Override
        public int getHttpStatus() {
            return 0;
        }

        @Override
        public Collection<String> getExpectedContextEntries() {
            return Collections.emptyList();
        }

        @Override
        public String getCode() {
            return null;
        }
    };
    TDPException exception = new TDPException(errorCode, null, null);
    // then
    assertEquals(errorCode, exception.getCode());
    assertEquals("Service unavailable", 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 85 with TDPException

use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.

the class ErrorMessageTest method shouldReturnRightErrorMessageWhenUnableToCreateDatasetThrown.

@Test
public void shouldReturnRightErrorMessageWhenUnableToCreateDatasetThrown() {
    // given
    ErrorCode errorCode = UNABLE_TO_CREATE_DATASET;
    // when
    TDPException exception = new TDPException(errorCode, null, null);
    // then
    assertEquals(errorCode, exception.getCode());
    assertEquals("An error occurred during import", exception.getMessage());
    assertEquals("Import 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)

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