use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class AbstractVersionSupplier method callVersionService.
/**
* Call the version service on the given service: dataset, preparation or transformation.
*
* @param serviceName the name of the service
* @return the version of the called service
*/
protected Version callVersionService(String serviceUrl, String serviceName, String entryPoint) {
HystrixCommand<InputStream> versionCommand = context.getBean(VersionCommand.class, serviceUrl, entryPoint);
try (InputStream content = versionCommand.execute()) {
final Version version = mapper.readerFor(Version.class).readValue(content);
version.setServiceName(serviceName);
return version;
} catch (IOException | TDPException e) {
LOGGER.warn("Unable to get the version of the service {}", serviceName);
return null;
}
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class DiffMetadata method onExecute.
private HttpRequestBase onExecute(final String dataSetId, final String preparationId, final List<Action> actionsToAdd) {
// original actions (currently applied on the preparation)
final List<Action> originalActions;
try {
originalActions = objectMapper.readerFor(new TypeReference<List<Action>>() {
}).readValue(getInput());
} catch (final IOException e) {
throw new TDPException(UNABLE_TO_READ_PREPARATION, e, withBuilder().put("id", preparationId).build());
}
// prepare the preview parameters out of the preparation actions
final List<PreviewParameters> previewParameters = IntStream.range(0, actionsToAdd.size()).mapToObj((index) -> {
try {
// base actions = original actions + actions to add from 0 to index
final List<Action> previousActionsToAdd = actionsToAdd.subList(0, index);
final List<Action> baseActions = new ArrayList<>(originalActions);
baseActions.addAll(previousActionsToAdd);
// diff actions actions = base actions + the action to add for diff
final Action singleActionToAdd = actionsToAdd.get(index);
final List<Action> diffActions = new ArrayList<>(baseActions);
diffActions.add(singleActionToAdd);
return new //
PreviewParameters(//
serializeActions(baseActions), //
serializeActions(diffActions), //
dataSetId, //
null, //
null, HEAD);
} catch (IOException e) {
throw new TDPException(UNABLE_TO_READ_PREPARATION, e, withBuilder().put("id", preparationId).build());
}
}).collect(toList());
// create the http action to perform
try {
final String uri = transformationServiceUrl + "/transform/diff/metadata";
final HttpPost transformationCall = new HttpPost(uri);
transformationCall.setEntity(new StringEntity(objectMapper.writer().writeValueAsString(previewParameters), APPLICATION_JSON));
return transformationCall;
} 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 PreparationCreate method onExecute.
private HttpRequestBase onExecute(Preparation preparation, String folderId) {
String uri = preparationServiceUrl + "/preparations";
if (StringUtils.isNotBlank(folderId)) {
uri += "?folderId=" + folderId;
}
HttpPost preparationCreation = new HttpPost(uri);
// Serialize preparation using configured serialization
preparationCreation.setHeader("Content-Type", APPLICATION_JSON_VALUE);
try {
byte[] preparationJSONValue = objectMapper.writeValueAsBytes(preparation);
preparationCreation.setEntity(new ByteArrayEntity(preparationJSONValue));
} catch (IOException e) {
throw new TDPException(UNABLE_TO_CREATE_PREPARATION, e);
}
return preparationCreation;
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class MailFeedbackSender method send.
@Override
public void send(String subject, String body, String sender) {
try {
final String recipientList = StringUtils.join((new HashSet<>(Arrays.asList(recipients))).toArray(), ',');
subject = subjectPrefix + subject;
body = bodyPrefix + "<br/>" + body + "<br/>" + bodySuffix;
InternetAddress from = new InternetAddress(this.sender);
InternetAddress replyTo = new InternetAddress(sender);
Properties p = new Properties();
p.put("mail.smtp.host", smtpHost);
p.put("mail.smtp.port", smtpPort);
p.put("mail.smtp.starttls.enable", "true");
p.put("mail.smtp.auth", "true");
MailAuthenticator authenticator = new MailAuthenticator(userName, password);
Session sendMailSession = Session.getInstance(p, authenticator);
MimeMessage msg = new MimeMessage(sendMailSession);
msg.setFrom(from);
msg.setReplyTo(new Address[] { replyTo });
msg.addRecipients(Message.RecipientType.TO, recipientList);
msg.setSubject(subject, "UTF-8");
msg.setSentDate(new Date());
Multipart mainPart = new MimeMultipart();
BodyPart html = new MimeBodyPart();
html.setContent(body, "text/html; charset=utf-8");
mainPart.addBodyPart(html);
msg.setContent(mainPart);
Transport.send(msg);
LOGGER.debug("Sending mail:'{}' to '{}'", subject, recipients);
} 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 CreateChildFolder method onExecute.
private HttpRequestBase onExecute(final String parentId, final String path) {
try {
URIBuilder uriBuilder = new URIBuilder(preparationServiceUrl + "/folders");
if (parentId != null) {
uriBuilder.addParameter("parentId", parentId);
}
uriBuilder.addParameter("path", path);
return new HttpPut(uriBuilder.build());
} catch (URISyntaxException e) {
throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
}
}
Aggregations