use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class PreparationClientTest method getDetails.
/**
* Return the details of a preparation at a given (optional) step.
*
* @param preparationId the wanted preparation id.
* @param wantedStepId the optional wanted step id.
* @return the details of a preparation at a given (optional) step.
*/
public PreparationMessage getDetails(String preparationId, String wantedStepId) {
final RequestSpecification specs = given();
if (StringUtils.isNotBlank(wantedStepId)) {
specs.queryParam("stepId", wantedStepId);
}
final Response response = specs.when().get("/preparations/{id}/details", preparationId);
if (response.getStatusCode() != 200) {
throw new MockTDPException(response);
}
try {
return mapper.readerFor(PreparationMessage.class).readValue(response.asString());
} catch (IOException e) {
throw new TDPException(UNABLE_TO_READ_CONTENT);
}
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class JsonWriter method writeRowMetadataObject.
private void writeRowMetadataObject(RowMetadata rowMetadata) throws IOException {
generator.writeFieldName(METADATA_FIELD_NAME);
generator.writeStartObject();
generator.writeFieldName(METADATA_COLUMNS_FIELD_NAME);
generator.writeStartArray();
rowMetadata.getColumns().forEach(col -> {
try {
generator.writeObject(col);
} catch (IOException e) {
try {
// try to close JSon object before throwing an exception
generator.writeEndArray();
generator.writeEndObject();
closeRootObject();
} catch (IOException e1) {
LOGGER.debug("Could not close JSon object after columns writing error.", e1);
}
throw new TDPException(CommonErrorCodes.UNABLE_TO_WRITE_JSON, e);
}
});
generator.writeEndArray();
generator.writeEndObject();
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class BaseExportStrategy method getActions.
/**
* Returns the actions for the preparation with <code>preparationId</code> between <code>startStepId</code> and
* <code>endStepId</code>.
*
* @param preparationId The preparation id, if <code>null</code> or blank, returns <code>{actions: []}</code>
* @param startStepId A step id that must exist in given preparation id.
* @param endStepId A step id that must exist in given preparation id.
* @return The actions that can be parsed by ActionParser.
* @see org.talend.dataprep.transformation.api.action.ActionParser
*/
protected String getActions(String preparationId, String startStepId, String endStepId) {
if (Step.ROOT_STEP.id().equals(startStepId)) {
return getActions(preparationId, endStepId);
}
String actions;
if (StringUtils.isBlank(preparationId)) {
actions = "{\"actions\": []}";
} else {
try {
final PreparationGetActions startStepActions = applicationContext.getBean(PreparationGetActions.class, preparationId, startStepId);
final PreparationGetActions endStepActions = applicationContext.getBean(PreparationGetActions.class, preparationId, endStepId);
final StringWriter actionsAsString = new StringWriter();
final Action[] startActions = mapper.readValue(startStepActions.execute(), Action[].class);
final Action[] endActions = mapper.readValue(endStepActions.execute(), Action[].class);
if (endActions.length > startActions.length) {
final Action[] filteredActions = (Action[]) ArrayUtils.subarray(endActions, startActions.length, endActions.length);
LOGGER.debug("Reduced actions list from {} to {} action(s)", endActions.length, filteredActions.length);
mapper.writeValue(actionsAsString, filteredActions);
} else {
LOGGER.debug("Unable to reduce list of actions (has {})", endActions.length);
mapper.writeValue(actionsAsString, endActions);
}
return "{\"actions\": " + actionsAsString + '}';
} catch (IOException e) {
final ExceptionContext context = ExceptionContext.build().put("id", preparationId).put("version", endStepId);
throw new TDPException(UNABLE_TO_READ_PREPARATION, e, context);
}
}
return actions;
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class AggregationService method aggregate.
/**
* Process an aggregation.
*
* @param parameters the aggregation parameters.
* @param dataset the dataset input.
* @return the aggregation result.
*/
public AggregationResult aggregate(AggregationParameters parameters, DataSet dataset) {
// check the parameters
if (parameters.getOperations().isEmpty() || parameters.getGroupBy().isEmpty()) {
throw new TDPException(CommonErrorCodes.BAD_AGGREGATION_PARAMETERS);
}
AggregationResult result = new AggregationResult(parameters.getOperations().get(0).getOperator());
// get the aggregator
Aggregator aggregator = factory.get(parameters);
// Build optional filter
final DataSetMetadata metadata = dataset.getMetadata();
final RowMetadata rowMetadata = metadata != null ? metadata.getRowMetadata() : new RowMetadata();
final Predicate<DataSetRow> filter = filterService.build(parameters.getFilter(), rowMetadata);
// process the dataset
dataset.getRecords().filter(filter).forEach(row -> aggregator.accept(row, result));
// Normalize result (perform clean / optimization now that all input was processed).
aggregator.normalize(result);
return result;
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class DataSetServiceTest method createShouldFailBecauseNotEnoughSpaceAvailable.
@Test
public void createShouldFailBecauseNotEnoughSpaceAvailable() throws Exception {
// given
Mockito.reset(quotaService);
TDPException exception = new TDPException(DataSetErrorCodes.MAX_STORAGE_MAY_BE_EXCEEDED);
doThrow(exception).when(quotaService).checkIfAddingSizeExceedsAvailableStorage(500L);
// when
final InputStream content = this.getClass().getResourceAsStream(T_SHIRT_100_CSV);
final Response post = //
given().body(//
IOUtils.toString(content, UTF_8)).queryParam("Content-Type", //
"text/csv").queryParam("name", //
"cespasfaux").queryParam("size", //
500L).post("/datasets");
// then
assertEquals(413, post.getStatusCode());
}
Aggregations