use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class RenameFolder method onExecute.
private HttpRequestBase onExecute(final String id, final String newName) {
try {
final URIBuilder uriBuilder = new URIBuilder(preparationServiceUrl + "/folders/" + id + "/name");
uriBuilder.addParameter("newName", newName);
final HttpPut put = new HttpPut(uriBuilder.build());
put.setEntity(new StringEntity(newName));
return put;
} catch (UnsupportedEncodingException | URISyntaxException e) {
throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
}
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class Aggregate method onExecute.
/**
* Call the transformation service with the export parameters in json the request body.
*
* @param parameters the aggregate parameters.
* @return the http request to execute.
*/
private HttpRequestBase onExecute(AggregationParameters parameters) {
// must work on either a dataset or a preparation, if both parameters are set, an error is thrown
if (StringUtils.isNotBlank(parameters.getDatasetId()) && StringUtils.isNotBlank(parameters.getPreparationId())) {
LOG.error("Cannot aggregate on both dataset id & preparation id : {}", parameters);
throw new TDPException(CommonErrorCodes.BAD_AGGREGATION_PARAMETERS);
}
// $NON-NLS-1$
String uri = transformationServiceUrl + "/aggregate";
HttpPost aggregateCall = new HttpPost(uri);
try {
String paramsAsJson = objectMapper.writer().writeValueAsString(parameters);
aggregateCall.setEntity(new StringEntity(paramsAsJson, ContentType.APPLICATION_JSON));
} catch (JsonProcessingException e) {
throw new TDPException(CommonErrorCodes.UNABLE_TO_AGGREGATE, e);
}
return aggregateCall;
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class SuggestDataSetActions method onExecute.
/**
* Retrieve the dataset metadata and look for the possible actions.
*
* @return the dataset possible actions.
*/
private HttpRequestBase onExecute() {
try {
// retrieve dataset metadata
DataSetMetadata metadata = getInput();
// queries its possible actions
final HttpPost post = new HttpPost(transformationServiceUrl + "/suggest/dataset");
post.setHeader(new BasicHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE));
byte[] dataSetMetadataJSON = objectMapper.writer().writeValueAsBytes(metadata);
post.setEntity(new ByteArrayEntity(dataSetMetadataJSON));
return post;
} catch (JsonProcessingException e) {
throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
}
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class Export method onExecute.
/**
* @param parameters the export parameters.
* @return the request to perform.
*/
private HttpRequestBase onExecute(ExportParameters parameters) {
try {
final String parametersAsString = objectMapper.writerFor(ExportParameters.class).writeValueAsString(parameters);
final HttpPost post = new HttpPost(transformationServiceUrl + "/apply");
post.setEntity(new StringEntity(parametersAsString, ContentType.APPLICATION_JSON));
return post;
} catch (Exception e) {
throw new TDPException(APIErrorCodes.UNABLE_TO_EXPORT_CONTENT, e);
}
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class OnDemandManagedTaskExecutor method resume.
@Override
public AsyncExecution resume(ManagedTaskCallable task, String executionId, AsyncExecutionResult result) {
final AsyncExecution execution = repository.get(executionId);
if (execution == null) {
throw new TDPException(TransformationErrorCodes.UNABLE_TO_RESUME_EXECUTION, ExceptionContext.withBuilder().put("id", executionId).build());
} else if (execution.getStatus() != AsyncExecution.Status.NEW) {
throw new TDPException(TransformationErrorCodes.UNABLE_TO_RESUME_EXECUTION, ExceptionContext.withBuilder().put("id", executionId).build());
}
execution.setResult(result);
tasks.put(execution.getId(), task);
repository.save(execution);
return execution;
}
Aggregations