Search in sources :

Example 6 with TDPException

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

the class CreateDataSet method onExecute.

private HttpRequestBase onExecute(String name, String tag, String contentType, long size, InputStream dataSetContent) {
    try {
        URIBuilder uriBuilder = new URIBuilder(datasetServiceUrl + "/datasets");
        uriBuilder.addParameter("name", name);
        uriBuilder.addParameter("tag", tag);
        uriBuilder.addParameter("size", String.valueOf(size));
        final HttpPost post = new HttpPost(uriBuilder.build());
        post.addHeader("Content-Type", contentType);
        post.setEntity(new InputStreamEntity(dataSetContent));
        return post;
    } catch (URISyntaxException e) {
        throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
    }
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) HttpPost(org.apache.http.client.methods.HttpPost) URISyntaxException(java.net.URISyntaxException) URIBuilder(org.apache.http.client.utils.URIBuilder) InputStreamEntity(org.apache.http.entity.InputStreamEntity)

Example 7 with TDPException

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

the class DataSetList method onExecute.

private HttpRequestBase onExecute(Sort sort, Order order, String name, boolean certified, boolean favorite, boolean limit) {
    try {
        URIBuilder uriBuilder = new URIBuilder(datasetServiceUrl + "/datasets");
        uriBuilder.addParameter("sort", sort.camelName());
        uriBuilder.addParameter("order", order.camelName());
        uriBuilder.addParameter("name", name);
        uriBuilder.addParameter("certified", Boolean.toString(certified));
        uriBuilder.addParameter("favorite", Boolean.toString(favorite));
        uriBuilder.addParameter("limit", Boolean.toString(limit));
        return new HttpGet(uriBuilder.build());
    } catch (URISyntaxException e) {
        throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
    }
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) HttpGet(org.apache.http.client.methods.HttpGet) URISyntaxException(java.net.URISyntaxException) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 8 with TDPException

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

the class DataSetPreview method onExecute.

private HttpRequestBase onExecute(String dataSetId, boolean metadata, String sheetName) {
    try {
        URIBuilder uriBuilder = new URIBuilder(datasetServiceUrl + "/datasets/" + dataSetId + "/preview/");
        uriBuilder.addParameter("metadata", Boolean.toString(metadata));
        if (StringUtils.isNotEmpty(sheetName)) {
            // yup this sheet name can contains weird characters space, great french accents or even chinese
            // characters
            uriBuilder.addParameter("sheetName", sheetName);
        }
        return new HttpGet(uriBuilder.build());
    } catch (URISyntaxException e) {
        throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
    }
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) HttpGet(org.apache.http.client.methods.HttpGet) URISyntaxException(java.net.URISyntaxException) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 9 with TDPException

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

the class PreparationCopyStepsFrom method onExecute.

private HttpRequestBase onExecute(final String to, final String from) {
    try {
        URIBuilder builder = new URIBuilder(preparationServiceUrl + "/preparations/" + to + "/steps/copy");
        builder.addParameter("from", from);
        return new HttpPut(builder.build());
    } catch (URISyntaxException e) {
        throw new TDPException(UNEXPECTED_EXCEPTION, e);
    }
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) URISyntaxException(java.net.URISyntaxException) HttpPut(org.apache.http.client.methods.HttpPut) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 10 with TDPException

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

the class PreviewAbstract method onExecute.

private HttpRequestBase onExecute() {
    final String uri = this.transformationServiceUrl + "/transform/preview";
    HttpPost transformationCall = new HttpPost(uri);
    final String paramsAsJson;
    try {
        paramsAsJson = objectMapper.writeValueAsString(parameters);
    } catch (JsonProcessingException e) {
        throw new TDPException(TransformationErrorCodes.UNABLE_TO_PERFORM_PREVIEW, e);
    }
    HttpEntity reqEntity = new StringEntity(paramsAsJson, ContentType.APPLICATION_JSON);
    transformationCall.setEntity(reqEntity);
    return transformationCall;
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) HttpEntity(org.apache.http.HttpEntity) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

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