Search in sources :

Example 11 with TDPException

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);
    }
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) StringEntity(org.apache.http.entity.StringEntity) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URISyntaxException(java.net.URISyntaxException) HttpPut(org.apache.http.client.methods.HttpPut) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 12 with TDPException

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;
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 13 with TDPException

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);
    }
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) HttpPost(org.apache.http.client.methods.HttpPost) ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) BasicHeader(org.apache.http.message.BasicHeader)

Example 14 with TDPException

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);
    }
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) ExportParameters(org.talend.dataprep.api.export.ExportParameters) TDPException(org.talend.dataprep.exception.TDPException)

Example 15 with TDPException

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;
}
Also used : TDPException(org.talend.dataprep.exception.TDPException)

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