Search in sources :

Example 16 with ProcessException

use of com.walmartlabs.concord.server.process.ProcessException in project concord by walmartlabs.

the class FormFilesStoringProcessor method process.

@Override
@SuppressWarnings("unchecked")
public Payload process(Chain chain, Payload payload) {
    ProcessKey processKey = payload.getProcessKey();
    Map<String, Object> cfg = payload.getHeader(Payload.CONFIGURATION);
    if (cfg == null) {
        return chain.process(payload);
    }
    Map<String, String> formFiles = (Map<String, String>) cfg.get(Constants.Files.FORM_FILES);
    if (formFiles == null) {
        return chain.process(payload);
    }
    Path workspace = payload.getHeader(Payload.WORKSPACE_DIR);
    try {
        for (Map.Entry<String, String> e : formFiles.entrySet()) {
            Path formFile = workspace.resolve(e.getKey());
            Path tmpFile = Paths.get(e.getValue());
            Path p = formFile.getParent();
            if (!Files.exists(p)) {
                Files.createDirectories(p);
            }
            Files.move(tmpFile, formFile, StandardCopyOption.REPLACE_EXISTING);
        }
    } catch (IOException e) {
        logManager.error(processKey, "Error while saving form files", e);
        throw new ProcessException(processKey, "Error while saving form files", e);
    }
    return chain.process(payload);
}
Also used : Path(java.nio.file.Path) ProcessException(com.walmartlabs.concord.server.process.ProcessException) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) IOException(java.io.IOException) Map(java.util.Map)

Example 17 with ProcessException

use of com.walmartlabs.concord.server.process.ProcessException in project concord by walmartlabs.

the class ResumeMarkerStoringProcessor method process.

@Override
public Payload process(Chain chain, Payload payload) {
    ProcessKey processKey = payload.getProcessKey();
    Set<String> events = payload.getHeader(Payload.RESUME_EVENTS, Collections.emptySet());
    if (events.isEmpty()) {
        return chain.process(payload);
    }
    Path workspace = payload.getHeader(Payload.WORKSPACE_DIR);
    Path stateDir = workspace.resolve(Constants.Files.JOB_ATTACHMENTS_DIR_NAME).resolve(Constants.Files.JOB_STATE_DIR_NAME);
    try {
        if (!Files.exists(stateDir)) {
            Files.createDirectories(stateDir);
        }
        Path resumeMarker = stateDir.resolve(Constants.Files.RESUME_MARKER_FILE_NAME);
        Files.write(resumeMarker, events);
    } catch (IOException e) {
        logManager.error(processKey, "Error while saving resume event", e);
        throw new ProcessException(processKey, "Error while saving resume event", e);
    }
    return chain.process(payload);
}
Also used : Path(java.nio.file.Path) ProcessException(com.walmartlabs.concord.server.process.ProcessException) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) IOException(java.io.IOException)

Example 18 with ProcessException

use of com.walmartlabs.concord.server.process.ProcessException 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)

Example 19 with ProcessException

use of com.walmartlabs.concord.server.process.ProcessException in project concord by walmartlabs.

the class FormServiceV2 method submit.

public FormSubmitResult submit(ProcessKey processKey, String formName, Map<String, Object> data) throws FormUtils.ValidationException {
    Form form = get(processKey, formName);
    if (form == null) {
        throw new ProcessException(processKey, "Form not found: " + formName);
    }
    FormValidatorLocale locale = new ExternalFileFormValidatorLocaleV2(processKey, formName, stateManager);
    data = new LinkedHashMap<>(FormUtils.convert(locale, form, data));
    // optionally save the user who submitted the form
    boolean saveSubmittedBy = form.options().saveSubmittedBy();
    if (saveSubmittedBy) {
        UserInfo i = userManager.getCurrentUserInfo();
        data.put(Constants.Forms.SUBMITTED_BY_KEY, i);
    }
    try {
        FormValidator validator = new DefaultFormValidator(locale);
        List<ValidationError> errors = validator.validate(form, data);
        if (errors != null && !errors.isEmpty()) {
            return new FormSubmitResult(processKey.getInstanceId(), form.name(), errors);
        }
        // the new form's values will be available under the form's name key
        Map<String, Object> args = new LinkedHashMap<>();
        args.put(form.name(), new LinkedHashMap<>(data));
        // TODO refactor into the process manager
        Map<String, Object> m = new HashMap<>();
        m.put(Constants.Request.ARGUMENTS_KEY, args);
        m.put(Constants.Files.FORM_FILES, data.remove(Constants.Files.FORM_FILES));
        Object runAs = form.options().runAs();
        if (runAs != null) {
            m.put(INTERNAL_RUN_AS_KEY, runAs);
        }
        resume(processKey, form.eventName(), formName, m);
        return new FormSubmitResult(processKey.getInstanceId(), form.name(), null);
    } catch (Exception e) {
        throw new ProcessException(processKey, "Form submit error: " + e.getMessage(), e);
    }
}
Also used : UserInfo(com.walmartlabs.concord.server.user.UserInfoProvider.UserInfo) ProcessException(com.walmartlabs.concord.server.process.ProcessException) IOException(java.io.IOException) ProcessException(com.walmartlabs.concord.server.process.ProcessException)

Example 20 with ProcessException

use of com.walmartlabs.concord.server.process.ProcessException in project concord by walmartlabs.

the class PolicyProcessor method process.

@Override
public Payload process(Chain chain, Payload payload) {
    ProcessKey processKey = payload.getProcessKey();
    PolicyEngine policy = payload.getHeader(Payload.POLICY);
    if (policy == null) {
        return chain.process(payload);
    }
    logManager.info(processKey, "Applying policies...");
    try {
        // TODO merge check results
        for (PolicyApplier a : appliers) {
            a.apply(payload, policy);
        }
    } catch (ProcessException e) {
        throw e;
    } catch (Exception e) {
        logManager.error(processKey, "Error while applying policy '{}': {}", policy.policyNames(), e);
        throw new ProcessException(processKey, "Policy '" + policy.policyNames() + "' error", e);
    }
    return chain.process(payload);
}
Also used : PolicyApplier(com.walmartlabs.concord.server.process.pipelines.processors.policy.PolicyApplier) ProcessException(com.walmartlabs.concord.server.process.ProcessException) PolicyEngine(com.walmartlabs.concord.policyengine.PolicyEngine) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) ProcessException(com.walmartlabs.concord.server.process.ProcessException)

Aggregations

ProcessException (com.walmartlabs.concord.server.process.ProcessException)31 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)20 Path (java.nio.file.Path)19 IOException (java.io.IOException)18 UUID (java.util.UUID)9 InputStream (java.io.InputStream)4 Map (java.util.Map)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 PolicyEngine (com.walmartlabs.concord.policyengine.PolicyEngine)3 ProjectEntry (com.walmartlabs.concord.server.org.project.ProjectEntry)3 ProcessDefinition (com.walmartlabs.concord.process.loader.model.ProcessDefinition)2 Snapshot (com.walmartlabs.concord.repository.Snapshot)2 Payload (com.walmartlabs.concord.server.process.Payload)2 PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)2 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)2 UserInfo (com.walmartlabs.concord.server.user.UserInfoProvider.UserInfo)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 ConfigurationUtils (com.walmartlabs.concord.common.ConfigurationUtils)1 CycleChecker (com.walmartlabs.concord.common.CycleChecker)1