Search in sources :

Example 1 with TDPException

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

the class MailServiceAPI method mailTo.

@RequestMapping(value = "/api/mail", method = PUT)
@ApiOperation(value = "Send feedback to Talend")
@Timed
public void mailTo(@RequestBody MailDetails mailDetails) {
    if (mailDetails.isEmpty()) {
        throw new TDPException(APIErrorCodes.UNABLE_TO_GET_MAIL_DETAILS);
    }
    try {
        final HystrixCommand<Void> sendFeedback = getCommand(MailToCommand.class, mailDetails);
        sendFeedback.execute();
    } catch (Exception e) {
        throw new TDPException(APIErrorCodes.UNABLE_TO_SEND_MAIL, e);
    }
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) TDPException(org.talend.dataprep.exception.TDPException) Timed(org.talend.dataprep.metrics.Timed) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with TDPException

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

the class SearchAPI method doSearch.

private void doSearch(String name, List<String> filter, boolean strict, OutputStream output) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Searching dataprep for '{}' (pool: {})...", name, getConnectionStats());
    }
    try (final JsonGenerator generator = mapper.getFactory().createGenerator(output)) {
        generator.writeStartObject();
        // Write category information
        generator.writeFieldName("categories");
        generator.writeStartArray();
        // Add static information about documentation category
        generator.writeStartObject();
        generator.writeStringField("type", "documentation");
        generator.writeStringField("label", messagesBundle.getString(LocaleContextHolder.getLocale(), "search.documentation"));
        generator.writeEndObject();
        // Now the search types categories
        searchDelegates.forEach(searchDelegate -> {
            final String categoryLabel = messagesBundle.getString(LocaleContextHolder.getLocale(), "search." + searchDelegate.getSearchLabel());
            try {
                generator.writeStartObject();
                generator.writeStringField("type", searchDelegate.getInventoryType());
                generator.writeStringField("label", categoryLabel);
                generator.writeEndObject();
            } catch (IOException e) {
                LOG.error("Unable to write category information for '{}'.", searchDelegate.getSearchCategory(), e);
            }
        });
        generator.writeEndArray();
        // Write results
        searchDelegates.forEach(searchDelegate -> {
            final String category = searchDelegate.getSearchCategory();
            if (filter == null || filter.contains(category)) {
                try {
                    generator.writeObjectField(category, searchDelegate.search(name, strict));
                } catch (IOException e) {
                    LOG.error("Unable to search '{}'.", category, e);
                }
            }
        });
        generator.writeEndObject();
    } catch (IOException e) {
        throw new TDPException(UNABLE_TO_SEARCH_DATAPREP, e);
    }
    LOG.debug("Search done on for '{}' with filter '{}' (strict mode: {})", name, filter, strict);
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) IOException(java.io.IOException)

Example 3 with TDPException

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

the class PreparationList method onExecute.

private HttpRequestBase onExecute(SortAndOrderHelper.Format format, String name, String folderPath, String path, Sort sort, Order order) {
    try {
        URIBuilder uriBuilder;
        if (SortAndOrderHelper.Format.SHORT.equals(format)) {
            // $NON-NLS-1$
            uriBuilder = new URIBuilder(preparationServiceUrl + "/preparations");
        } else if (SortAndOrderHelper.Format.SUMMARY.equals(format)) {
            // $NON-NLS-1$
            uriBuilder = new URIBuilder(preparationServiceUrl + "/preparations/summaries");
        } else {
            // $NON-NLS-1$
            uriBuilder = new URIBuilder(preparationServiceUrl + "/preparations/details");
        }
        if (name != null) {
            uriBuilder.addParameter("name", name);
        }
        if (folderPath != null) {
            uriBuilder.addParameter("folder_path", folderPath);
        }
        if (path != null) {
            uriBuilder.addParameter("path", path);
        }
        uriBuilder.addParameter("sort", sort.camelName());
        uriBuilder.addParameter("order", order.camelName());
        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 4 with TDPException

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

the class PreparationUpdateAction method onExecute.

private HttpRequestBase onExecute(String preparationId, String stepId, AppendStep updatedStep) {
    try {
        final String url = preparationServiceUrl + "/preparations/" + preparationId + "/actions/" + stepId;
        final Optional<StepDiff> firstStepDiff = toStream(StepDiff.class, objectMapper, input).findFirst();
        if (firstStepDiff.isPresent()) {
            // Only interested in first one
            final StepDiff diff = firstStepDiff.get();
            updatedStep.setDiff(diff);
        }
        final String stepAsString = objectMapper.writeValueAsString(updatedStep);
        final HttpPut actionAppend = new HttpPut(url);
        final InputStream stepInputStream = new ByteArrayInputStream(stepAsString.getBytes());
        actionAppend.setHeader(new BasicHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE));
        actionAppend.setEntity(new InputStreamEntity(stepInputStream));
        return actionAppend;
    } catch (IOException e) {
        throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
    }
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StepDiff(org.talend.dataprep.api.preparation.StepDiff) IOException(java.io.IOException) HttpPut(org.apache.http.client.methods.HttpPut) BasicHeader(org.apache.http.message.BasicHeader) InputStreamEntity(org.apache.http.entity.InputStreamEntity)

Example 5 with TDPException

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

the class CompatibleDataSetList method onExecute.

private HttpRequestBase onExecute(String dataSetId, Sort sort, Order order) {
    try {
        URIBuilder uriBuilder = new URIBuilder(datasetServiceUrl + "/datasets/" + dataSetId + "/compatibledatasets");
        uriBuilder.addParameter("dataSetId", dataSetId);
        uriBuilder.addParameter("sort", sort.camelName());
        uriBuilder.addParameter("order", order.camelName());
        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)

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