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);
}
}
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);
}
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);
}
}
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);
}
}
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);
}
}
Aggregations