Search in sources :

Example 1 with FormField

use of com.walmartlabs.concord.forms.FormField in project concord by walmartlabs.

the class FormResourceV2 method get.

/**
 * Return the current state of a form instance.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public FormInstanceEntry get(UUID processInstanceId, String formName) {
    PartialProcessKey processKey = PartialProcessKey.from(processInstanceId);
    Form form = formService.get(processKey, formName);
    if (form == null) {
        throw new ConcordApplicationException("Form " + formName + " not found. Process ID: " + processKey, Status.NOT_FOUND);
    }
    List<FormInstanceEntry.Field> fields = new ArrayList<>();
    for (FormField f : form.fields()) {
        String fieldName = f.name();
        FormInstanceEntry.Cardinality c = map(f.cardinality());
        String type = f.type();
        Serializable value = f.defaultValue();
        Serializable allowedValue = f.allowedValue();
        Map options = f.options();
        fields.add(new FormInstanceEntry.Field(fieldName, f.label(), type, c, value, allowedValue, options));
    }
    String name = form.name();
    boolean yield = form.options().yield();
    String resourcePath = FORMS_RESOURCES_PATH + "/" + name;
    boolean isCustomForm = formService.exists(processKey, resourcePath);
    return new FormInstanceEntry(processInstanceId.toString(), name, fields, isCustomForm, yield);
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) Serializable(java.io.Serializable) Form(com.walmartlabs.concord.forms.Form) FormField(com.walmartlabs.concord.forms.FormField) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) FormField(com.walmartlabs.concord.forms.FormField)

Example 2 with FormField

use of com.walmartlabs.concord.forms.FormField in project concord by walmartlabs.

the class CustomFormServiceV2 method prepareData.

private FormData prepareData(boolean success, boolean processFailed, Form form, Map<String, Object> overrides, boolean skipMissingOverrides, List<ValidationError> errors, UUID processInstanceId) {
    // TODO merge with FormResource
    Map<String, FormDataDefinition> _definitions = new HashMap<>();
    // the order of precedence should be:
    // submitted value > form call value > field's default value > environment value
    Map<String, Object> _values = new HashMap<>(form.options().extraValues());
    Map<String, String> _errors = new HashMap<>();
    form.fields().stream().filter(f -> f.defaultValue() != null).forEach(f -> _values.put(f.name(), f.defaultValue()));
    List<String> fields = form.fields().stream().map(FormField::name).collect(Collectors.toList());
    for (FormField f : form.fields()) {
        Object allowedValue = f.allowedValue();
        _definitions.put(f.name(), new FormDataDefinition(f.label(), f.type(), convert(f.cardinality()), allowedValue));
        Object v = overrides != null ? overrides.get(f.name()) : null;
        if (v == null && skipMissingOverrides) {
            continue;
        }
        if (v == null) {
            continue;
        }
        _values.put(f.name(), v);
    }
    if (errors != null) {
        for (ValidationError e : errors) {
            _errors.put(e.fieldName(), e.error());
        }
    }
    String submitUrl = String.format(FORM_WIZARD_CONTINUE_URL_TEMPLATE, processInstanceId, form.name());
    return new FormData(success, processFailed, submitUrl, fields, _definitions, _values, _errors);
}
Also used : PathParam(javax.ws.rs.PathParam) java.util(java.util) FormField(com.walmartlabs.concord.forms.FormField) Produces(javax.ws.rs.Produces) ProcessStateManager.copyTo(com.walmartlabs.concord.server.process.state.ProcessStateManager.copyTo) LoggerFactory(org.slf4j.LoggerFactory) MultipartInput(org.jboss.resteasy.plugins.providers.multipart.MultipartInput) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) ProcessKeyCache(com.walmartlabs.concord.server.process.queue.ProcessKeyCache) Singleton(javax.inject.Singleton) ValidationError(com.walmartlabs.concord.forms.ValidationError) Inject(javax.inject.Inject) MultipartUtils(com.walmartlabs.concord.server.MultipartUtils) ProcessQueueDao(com.walmartlabs.concord.server.process.queue.ProcessQueueDao) Consumes(javax.ws.rs.Consumes) FormSubmitResult(com.walmartlabs.concord.server.process.form.FormSubmitResult) Named(javax.inject.Named) URI(java.net.URI) Status(javax.ws.rs.core.Response.Status) Path(java.nio.file.Path) PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) ProcessStateManager(com.walmartlabs.concord.server.process.state.ProcessStateManager) FormUtils(com.walmartlabs.concord.forms.FormUtils) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) FormData(com.walmartlabs.concord.server.console.CustomFormServiceV1.FormData) Files(java.nio.file.Files) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Validate(org.sonatype.siesta.Validate) StandardOpenOption(java.nio.file.StandardOpenOption) ExternalFileFormValidatorLocaleV2(com.walmartlabs.concord.server.process.form.ExternalFileFormValidatorLocaleV2) ProcessStatus(com.walmartlabs.concord.server.sdk.ProcessStatus) IOException(java.io.IOException) javax.ws.rs.core(javax.ws.rs.core) Collectors(java.util.stream.Collectors) CustomFormConfiguration(com.walmartlabs.concord.server.cfg.CustomFormConfiguration) SerializationFeature(com.fasterxml.jackson.databind.SerializationFeature) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) Form(com.walmartlabs.concord.forms.Form) FormDataDefinition(com.walmartlabs.concord.server.console.CustomFormServiceV1.FormDataDefinition) FormServiceV1(com.walmartlabs.concord.server.process.form.FormServiceV1) FormServiceV2(com.walmartlabs.concord.server.process.form.FormServiceV2) FormData(com.walmartlabs.concord.server.console.CustomFormServiceV1.FormData) ValidationError(com.walmartlabs.concord.forms.ValidationError) FormDataDefinition(com.walmartlabs.concord.server.console.CustomFormServiceV1.FormDataDefinition) FormField(com.walmartlabs.concord.forms.FormField)

Aggregations

Form (com.walmartlabs.concord.forms.Form)2 FormField (com.walmartlabs.concord.forms.FormField)2 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)2 PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)1 FormUtils (com.walmartlabs.concord.forms.FormUtils)1 ValidationError (com.walmartlabs.concord.forms.ValidationError)1 MultipartUtils (com.walmartlabs.concord.server.MultipartUtils)1 CustomFormConfiguration (com.walmartlabs.concord.server.cfg.CustomFormConfiguration)1 FormData (com.walmartlabs.concord.server.console.CustomFormServiceV1.FormData)1 FormDataDefinition (com.walmartlabs.concord.server.console.CustomFormServiceV1.FormDataDefinition)1 ExternalFileFormValidatorLocaleV2 (com.walmartlabs.concord.server.process.form.ExternalFileFormValidatorLocaleV2)1 FormServiceV1 (com.walmartlabs.concord.server.process.form.FormServiceV1)1 FormServiceV2 (com.walmartlabs.concord.server.process.form.FormServiceV2)1 FormSubmitResult (com.walmartlabs.concord.server.process.form.FormSubmitResult)1 ProcessKeyCache (com.walmartlabs.concord.server.process.queue.ProcessKeyCache)1 ProcessQueueDao (com.walmartlabs.concord.server.process.queue.ProcessQueueDao)1 ProcessStateManager (com.walmartlabs.concord.server.process.state.ProcessStateManager)1 ProcessStateManager.copyTo (com.walmartlabs.concord.server.process.state.ProcessStateManager.copyTo)1