Search in sources :

Example 51 with ConcordApplicationException

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;
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) UUID(java.util.UUID)

Example 52 with ConcordApplicationException

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);
            }
    }
}
Also used : ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) ProcessEntry(com.walmartlabs.concord.server.process.ProcessEntry) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 53 with ConcordApplicationException

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);
}
Also used : Path(java.nio.file.Path) ValidationException(com.walmartlabs.concord.server.process.form.FormUtils.ValidationException) Form(io.takari.bpm.form.Form) ProcessStatus(com.walmartlabs.concord.server.sdk.ProcessStatus) FormSubmitResult(com.walmartlabs.concord.server.process.form.FormSubmitResult) ValidationException(com.walmartlabs.concord.server.process.form.FormUtils.ValidationException) IOException(java.io.IOException) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) ValidationError(com.walmartlabs.concord.forms.ValidationError) ExternalFileFormValidatorLocale(com.walmartlabs.concord.server.process.form.ExternalFileFormValidatorLocale)

Example 54 with ConcordApplicationException

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));
}
Also used : Path(java.nio.file.Path) Form(io.takari.bpm.form.Form) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) IOException(java.io.IOException)

Example 55 with ConcordApplicationException

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();
    }
}
Also used : ProcessStatus(com.walmartlabs.concord.server.sdk.ProcessStatus) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey)

Aggregations

ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)70 ApiOperation (io.swagger.annotations.ApiOperation)28 UUID (java.util.UUID)22 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)21 PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)18 IOException (java.io.IOException)14 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)12 GenericOperationResult (com.walmartlabs.concord.server.GenericOperationResult)11 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)11 Validate (org.sonatype.siesta.Validate)11 Path (java.nio.file.Path)10 UserPrincipal (com.walmartlabs.concord.server.security.UserPrincipal)9 OrganizationEntry (com.walmartlabs.concord.server.org.OrganizationEntry)8 EntryPoint (com.walmartlabs.concord.server.process.PayloadManager.EntryPoint)6 ProcessStatus (com.walmartlabs.concord.server.sdk.ProcessStatus)6 UnauthorizedException (org.apache.shiro.authz.UnauthorizedException)6 UserEntry (com.walmartlabs.concord.server.user.UserEntry)5 InputStream (java.io.InputStream)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Form (com.walmartlabs.concord.forms.Form)3