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);
}
}
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);
}
}
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);
}
}
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());
}
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());
}
Aggregations