use of com.walmartlabs.concord.server.sdk.ConcordApplicationException in project concord by walmartlabs.
the class ProcessKvResource method assertProjectId.
private UUID assertProjectId(UUID instanceId) {
PartialProcessKey processKey = PartialProcessKey.from(instanceId);
// TODO replace with getProjectId
ProcessEntry entry = processQueueManager.get(processKey);
if (entry == null) {
throw new ConcordApplicationException("Process instance not found", Response.Status.NOT_FOUND);
}
UUID projectId = entry.projectId();
if (projectId == null) {
log.warn("assertProjectId ['{}'] -> no project found, using the default value", processKey);
projectId = DEFAULT_PROJECT_ID;
}
return projectId;
}
use of com.walmartlabs.concord.server.sdk.ConcordApplicationException in project concord by walmartlabs.
the class ProcessCheckpointV2Resource method processCheckpoint.
@GET
@ApiOperation(value = "Process checkpoint")
@javax.ws.rs.Path("{id}/checkpoint")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public GenericCheckpointResponse processCheckpoint(@ApiParam @PathParam("id") UUID instanceId, @ApiParam @QueryParam("name") String checkpointName, @ApiParam @QueryParam("action") String action) {
ProcessEntry entry = processManager.assertProcess(instanceId);
ProcessKey processKey = new ProcessKey(entry.instanceId(), entry.createdAt());
switch(action) {
case RESTORE_PROCESS_ACTION:
{
return restore(processKey, checkpointName);
}
default:
{
throw new ConcordApplicationException("Invalid action type: " + action);
}
}
}
use of com.walmartlabs.concord.server.sdk.ConcordApplicationException in project concord by walmartlabs.
the class CustomFormServiceV1 method continueSession.
private Response continueSession(UriInfo uriInfo, HttpHeaders headers, ProcessKey processKey, String formName, Map<String, Object> data) {
// TODO locking
Form form = assertForm(processKey, formName);
// TODO constants
Map<String, Object> opts = form.getOptions();
boolean yield = opts != null && (boolean) opts.getOrDefault("yield", false);
Path dst = cfg.getBaseDir().resolve(processKey.toString()).resolve(formName);
Path formDir = dst.resolve(FORM_DIR_NAME);
try {
Map<String, Object> m = new HashMap<>();
try {
m = FormUtils.convert(new ExternalFileFormValidatorLocale(processKey, formName, stateManager), form, data);
FormSubmitResult r = formService.submit(processKey, formName, m);
if (r.isValid()) {
if (yield) {
// this was the last "interactive" form. The process will continue in "background"
// and users should get a success page.
writeData(formDir, success(form, m));
} else {
while (true) {
ProcessStatus s = queueDao.getStatus(processKey);
if (s == ProcessStatus.SUSPENDED) {
String nextFormId = formService.nextFormId(processKey);
if (nextFormId == null) {
writeData(formDir, success(form, m));
break;
} else {
FormSessionResponse nextSession = startSession(processKey, nextFormId);
return redirectTo(nextSession.getUri());
}
} else if (s == ProcessStatus.FAILED || s == ProcessStatus.CANCELLED || s == ProcessStatus.TIMED_OUT) {
writeData(formDir, processFailed(form, m));
break;
} else if (s == ProcessStatus.FINISHED) {
writeData(formDir, success(form, m));
break;
}
try {
// TODO exp back off?
Thread.sleep(STATUS_REFRESH_DELAY);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
} else {
writeData(formDir, prepareData(form, m, r.getErrors()));
}
} catch (ValidationException e) {
ValidationError err = ValidationError.of(e.getField().getName(), e.getMessage());
FormData d = prepareData(form, m, Collections.singletonList(err));
writeData(formDir, d);
}
} catch (Exception e) {
throw new ConcordApplicationException("Error while submitting a form", e);
}
return redirectToForm(uriInfo, headers, processKey, formName);
}
use of com.walmartlabs.concord.server.sdk.ConcordApplicationException in project concord by walmartlabs.
the class CustomFormServiceV1 method startSession.
private FormSessionResponse startSession(ProcessKey processKey, String formName) {
// TODO locking
Form form = assertForm(processKey, formName);
Path dst = cfg.getBaseDir().resolve(processKey.toString()).resolve(formName);
try {
Path formDir = dst.resolve(FORM_DIR_NAME);
if (!Files.exists(formDir)) {
Files.createDirectories(formDir);
}
String resource = FormServiceV1.FORMS_RESOURCES_PATH + "/" + form.getFormDefinition().getName();
// copy original branding files into the target directory
boolean branded = stateManager.exportDirectory(processKey, resource, copyTo(formDir));
if (!branded) {
// not branded, redirect to the default wizard
String uri = String.format(NON_BRANDED_FORM_URL_TEMPLATE, processKey, formName);
return new FormSessionResponse(uri);
}
// create JS file containing the form's data
writeData(formDir, initialData(form));
// copy shared resources (if present)
copySharedResources(processKey, dst);
} catch (IOException e) {
log.warn("startSession ['{}', '{}'] -> error while preparing a custom form: {}", processKey, formName, e);
throw new ConcordApplicationException("Error while preparing a custom form", e);
}
return new FormSessionResponse(formPath(processKey, formName));
}
use of com.walmartlabs.concord.server.sdk.ConcordApplicationException in project concord by walmartlabs.
the class ProjectProcessResource method proceed.
private Response proceed(PartialProcessKey processKey) {
ProcessEntry entry = processQueueManager.get(processKey);
if (entry == null) {
throw new ConcordApplicationException("Process not found: " + processKey, Status.NOT_FOUND);
}
ProcessKey pk = new ProcessKey(entry.instanceId(), entry.createdAt());
ProcessStatus s = entry.status();
if (s == ProcessStatus.FAILED || s == ProcessStatus.CANCELLED || s == ProcessStatus.TIMED_OUT) {
return processError(processKey, "Process failed: " + s, null);
} else if (s == ProcessStatus.FINISHED) {
return processFinished(processKey);
} else if (s == ProcessStatus.SUSPENDED) {
String nextFormId = nextFormId(pk);
if (nextFormId == null) {
return processError(processKey, "Invalid process state: no forms found", null);
}
String url = "/#/process/" + entry.instanceId() + "/wizard";
return Response.status(Status.MOVED_PERMANENTLY).header(HttpHeaders.LOCATION, url).build();
} else {
Map<String, Object> args = prepareArgumentsForInProgressTemplate(entry);
return responseTemplates.inProgressWait(Response.ok(), args).build();
}
}
Aggregations