Search in sources :

Example 1 with FormValidator

use of io.takari.bpm.form.FormValidator in project concord by walmartlabs.

the class FormServiceV1 method submit.

public FormSubmitResult submit(ProcessKey processKey, String formName, Map<String, Object> data) {
    Form form = get(processKey, formName);
    if (form == null) {
        throw new ProcessException(processKey, "Form not found: " + formName);
    }
    ResumeHandler resumeHandler = (f, args) -> {
        String resource = path(Constants.Files.JOB_ATTACHMENTS_DIR_NAME, Constants.Files.JOB_STATE_DIR_NAME, Constants.Files.JOB_FORMS_DIR_NAME, formName);
        stateManager.deleteFile(processKey, resource);
        @SuppressWarnings("unchecked") Map<String, Object> clearedData = (Map<String, Object>) args.get(f.getFormDefinition().getName());
        args.put(f.getFormDefinition().getName(), clearedData);
        // TODO refactor into the process manager
        Map<String, Object> m = new HashMap<>();
        m.put(Constants.Request.ARGUMENTS_KEY, args);
        if (data != null) {
            m.put(Constants.Files.FORM_FILES, data.remove(Constants.Files.FORM_FILES));
        }
        Map<String, Object> opts = f.getOptions();
        Object runAs = opts != null ? opts.get(Constants.Forms.RUN_AS_KEY) : null;
        if (runAs != null) {
            m.put(INTERNAL_RUN_AS_KEY, runAs);
        }
        resume(processKey, f.getEventName(), m);
    };
    Map<String, Object> merged = merge(form, data);
    // optionally save the user who submitted the form
    boolean saveSubmittedBy = MapUtils.getBoolean(form.getOptions(), Constants.Forms.SAVE_SUBMITTED_BY_KEY, false);
    if (saveSubmittedBy) {
        UserInfo i = userManager.getCurrentUserInfo();
        merged.put(Constants.Forms.SUBMITTED_BY_KEY, i);
    }
    try {
        FormValidator validator = createFormValidator(processKey, formName);
        return toResult(processKey, form, DefaultFormService.submit(resumeHandler, validator, form, merged));
    } catch (ExecutionException e) {
        throw new ProcessException(processKey, "Form submit error: " + e.getMessage(), e);
    }
}
Also used : MapUtils(com.walmartlabs.concord.sdk.MapUtils) PayloadManager(com.walmartlabs.concord.server.process.PayloadManager) UserInfo(com.walmartlabs.concord.server.user.UserInfoProvider.UserInfo) java.util(java.util) ObjectInputStream(java.io.ObjectInputStream) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) ProcessKeyCache(com.walmartlabs.concord.server.process.queue.ProcessKeyCache) Singleton(javax.inject.Singleton) ConfigurationUtils(com.walmartlabs.concord.common.ConfigurationUtils) ResumeHandler(io.takari.bpm.form.DefaultFormService.ResumeHandler) Function(java.util.function.Function) ValidationError(com.walmartlabs.concord.forms.ValidationError) ExecutionException(io.takari.bpm.api.ExecutionException) Inject(javax.inject.Inject) Constants(com.walmartlabs.concord.sdk.Constants) FormValidatorLocale(io.takari.bpm.form.FormValidatorLocale) Named(javax.inject.Named) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ProcessException(com.walmartlabs.concord.server.process.ProcessException) UserManager(com.walmartlabs.concord.server.user.UserManager) Payload(com.walmartlabs.concord.server.process.Payload) ProcessStateManager(com.walmartlabs.concord.server.process.state.ProcessStateManager) ProcessManager(com.walmartlabs.concord.server.process.ProcessManager) FormValidator(io.takari.bpm.form.FormValidator) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Form(io.takari.bpm.form.Form) ConcordFormValidator(com.walmartlabs.concord.common.form.ConcordFormValidator) ProcessStateManager.path(com.walmartlabs.concord.server.process.state.ProcessStateManager.path) DefaultFormService(io.takari.bpm.form.DefaultFormService) InputStream(java.io.InputStream) ResumeHandler(io.takari.bpm.form.DefaultFormService.ResumeHandler) Form(io.takari.bpm.form.Form) UserInfo(com.walmartlabs.concord.server.user.UserInfoProvider.UserInfo) FormValidator(io.takari.bpm.form.FormValidator) ConcordFormValidator(com.walmartlabs.concord.common.form.ConcordFormValidator) ProcessException(com.walmartlabs.concord.server.process.ProcessException) ExecutionException(io.takari.bpm.api.ExecutionException)

Aggregations

ConfigurationUtils (com.walmartlabs.concord.common.ConfigurationUtils)1 ConcordFormValidator (com.walmartlabs.concord.common.form.ConcordFormValidator)1 ValidationError (com.walmartlabs.concord.forms.ValidationError)1 Constants (com.walmartlabs.concord.sdk.Constants)1 MapUtils (com.walmartlabs.concord.sdk.MapUtils)1 Payload (com.walmartlabs.concord.server.process.Payload)1 PayloadManager (com.walmartlabs.concord.server.process.PayloadManager)1 ProcessException (com.walmartlabs.concord.server.process.ProcessException)1 ProcessManager (com.walmartlabs.concord.server.process.ProcessManager)1 ProcessKeyCache (com.walmartlabs.concord.server.process.queue.ProcessKeyCache)1 ProcessStateManager (com.walmartlabs.concord.server.process.state.ProcessStateManager)1 ProcessStateManager.path (com.walmartlabs.concord.server.process.state.ProcessStateManager.path)1 PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)1 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)1 UserInfo (com.walmartlabs.concord.server.user.UserInfoProvider.UserInfo)1 UserManager (com.walmartlabs.concord.server.user.UserManager)1 ExecutionException (io.takari.bpm.api.ExecutionException)1 DefaultFormService (io.takari.bpm.form.DefaultFormService)1 ResumeHandler (io.takari.bpm.form.DefaultFormService.ResumeHandler)1 Form (io.takari.bpm.form.Form)1