use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class AsyncAspect method runAsynchronously.
/**
* Intercept all the calls to a @RequestMapping method annotated with @AsyncOperation.
*
* @param pjp the proceeding join point.
*/
@Around(value = "@annotation(org.springframework.web.bind.annotation.RequestMapping) && @annotation(org.talend.dataprep.async.AsyncOperation)")
public Object runAsynchronously(final ProceedingJoinPoint pjp) {
String executionId = getExecutionId(pjp);
AsyncExecution asyncExecution = repository.get(executionId);
if (asyncExecution == null || asyncExecution.getStatus() != AsyncExecution.Status.RUNNING) {
// the method is not running actually
if (executeAsynchronously(pjp) || (asyncExecution != null && asyncExecution.getStatus() == AsyncExecution.Status.NEW)) {
// we need to launch it asynchronously or asyncMethod is on NEW status (we can resume it)
AsyncExecution future = scheduleAsynchroneTask(pjp, asyncExecution != null && asyncExecution.getStatus() == AsyncExecution.Status.NEW);
LOGGER.debug("Scheduling done, Redirecting to execution queue...");
// return at once with an HTTP 202 + location to get the progress
set202HeaderInformation(future);
LOGGER.debug("Redirection done.");
} else {
try {
return pjp.proceed();
} catch (Throwable throwable) {
throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, throwable);
}
}
} else {
LOGGER.debug("Async Method with id {} is already running", asyncExecution.getId());
set202HeaderInformation(asyncExecution);
}
return null;
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class SimpleManagedTaskExecutor method resume.
@Override
public AsyncExecution resume(ManagedTaskCallable task, String executionId, AsyncExecutionResult resultUrl) {
LOGGER.debug("Resuming execution '{}' from repository '{}'", executionId, repository);
final AsyncExecution execution = repository.get(executionId);
if (execution == null) {
LOGGER.error("Execution #{} can be resumed (not found).", executionId);
throw new TDPException(TransformationErrorCodes.UNABLE_TO_RESUME_EXECUTION, ExceptionContext.withBuilder().put("id", executionId).build());
} else if (execution.getStatus() != AsyncExecution.Status.RUNNING) {
// Execution is expected to be created as "RUNNING" before the dispatcher resumes it.
LOGGER.error("Execution #{} can be resumed (status is {}).", execution.getStatus());
throw new TDPException(TransformationErrorCodes.UNABLE_TO_RESUME_EXECUTION, ExceptionContext.withBuilder().put("id", executionId).build());
}
// Wrap callable to get the running status.
final Callable wrapper = wrapTaskWithProgressInformation(task, execution);
execution.setResult(resultUrl);
ListenableFuture future = delegate.submitListenable(wrapper);
future.addCallback(new AsyncListenableFutureCallback(execution));
futures.put(execution.getId(), future);
LOGGER.debug("Execution {} resumed for execution.", execution.getId());
return execution;
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class MailToCommand method run.
@Override
protected Void run() throws Exception {
try {
String body = "";
body += "Sender=" + mailDetails.getMail() + "<br/>";
body += "Type=" + mailDetails.getType() + "<br/>";
body += "Severity=" + mailDetails.getSeverity() + "<br/>";
body += "Description=" + mailDetails.getDescription() + "<br/>";
body += "Version=" + versionService.version() + "<br/>";
feedbackSender.send(mailDetails.getTitle(), body, mailDetails.getMail());
} catch (Exception e) {
throw new TDPException(APIErrorCodes.UNABLE_TO_SEND_MAIL, e);
}
return null;
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class OneNotBlankValidator method isValid.
@Override
public boolean isValid(final Object value, final ConstraintValidatorContext context) {
try {
for (final String name : fieldsName) {
final String prop = BeanUtils.getProperty(value, name);
if (isNotBlank(prop)) {
return true;
}
}
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
}
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate(context.getDefaultConstraintMessageTemplate()).addPropertyNode(fieldsName[0]).addConstraintViolation();
return false;
}
use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.
the class ErrorMessageTest method shouldReturnRightErrorMessageWhenHttpStatusIs500.
@Test
public void shouldReturnRightErrorMessageWhenHttpStatusIs500() {
// given
ErrorCode errorCode = new ErrorCode() {
@Override
public String getProduct() {
return "TDP";
}
@Override
public String getGroup() {
return "API";
}
@Override
public int getHttpStatus() {
return 500;
}
@Override
public Collection<String> getExpectedContextEntries() {
return Collections.emptyList();
}
@Override
public String getCode() {
return null;
}
};
TDPException exception = new TDPException(errorCode, null, null);
// then
assertEquals(errorCode, exception.getCode());
assertEquals("An unexpected error occurred and we could not complete your last operation. You can continue to use Data Preparation", exception.getMessage());
assertEquals("An error has occurred", exception.getMessageTitle());
assertFalse(exception.getContext().entries().iterator().hasNext());
}
Aggregations