Skip to content

Commit

Permalink
form name, txId to data.js
Browse files Browse the repository at this point in the history
  • Loading branch information
brig committed Sep 11, 2023
1 parent f1a584f commit 76bc818
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.walmartlabs.concord.forms.ValidationError;
import com.walmartlabs.concord.server.MultipartUtils;
import com.walmartlabs.concord.server.cfg.CustomFormConfiguration;
Expand All @@ -43,11 +45,13 @@
import io.takari.bpm.model.form.FormDefinition;
import io.takari.bpm.model.form.FormField;
import io.takari.bpm.model.form.FormField.Cardinality;
import org.immutables.value.Value;
import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonatype.siesta.Validate;

import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
Expand Down Expand Up @@ -334,7 +338,17 @@ private FormData prepareData(boolean success, boolean processFailed, Form form,
}
}

return new FormData(success, processFailed, submitUrl, fields, _definitions, _values, _errors);
return FormData.builder()
.txId(processInstanceId)
.formName(formName)
.success(success)
.processFailed(processFailed)
.submitUrl(submitUrl)
.fields(fields)
.definitions(_definitions)
.values(_values)
.errors(_errors)
.build();
}

private void writeData(Path baseDir, Object data) throws IOException {
Expand Down Expand Up @@ -396,56 +410,36 @@ private static String formPath(PartialProcessKey processKey, String formName) {
return String.format(FORMS_PATH_TEMPLATE, processKey, formName);
}

@JsonInclude(Include.NON_EMPTY)
public static class FormData implements Serializable {

private static final long serialVersionUID = -1591440785695774602L;

private final boolean success;
private final boolean processFailed;
private final String submitUrl;
private final List<String> fields;
private final Map<String, FormDataDefinition> definitions;
private final Map<String, Object> values;
private final Map<String, String> errors;

public FormData(boolean success, boolean processFailed, String submitUrl,
List<String> fields, Map<String, FormDataDefinition> definitions, Map<String, Object> values,
Map<String, String> errors) {

this.success = success;
this.processFailed = processFailed;
this.submitUrl = submitUrl;
this.fields = fields;
this.definitions = definitions;
this.values = values;
this.errors = errors;
}
@Value.Immutable
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonSerialize(as = ImmutableFormData.class)
@JsonDeserialize(as = ImmutableFormData.class)
public interface FormData extends Serializable {

public boolean isSuccess() {
return success;
}
long serialVersionUID = -1591440785695774602L;

public boolean isProcessFailed() {
return processFailed;
}
String txId();

public String getSubmitUrl() {
return submitUrl;
}
String formName();

public List<String> getFields() { return fields; }
boolean success();

public Map<String, FormDataDefinition> getDefinitions() {
return definitions;
}
boolean processFailed();

public Map<String, Object> getValues() {
return values;
}
String submitUrl();

List<String> fields();

Map<String, FormDataDefinition> definitions();

@Nullable
Map<String, Object> values();

@Nullable
Map<String, String> errors();

public Map<String, String> getErrors() {
return errors;
static ImmutableFormData.Builder builder() {
return ImmutableFormData.builder();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,18 @@ private FormData prepareData(boolean success, boolean processFailed, Form form,
}

String submitUrl = String.format(FORM_WIZARD_CONTINUE_URL_TEMPLATE, processInstanceId, form.name());
return new FormData(success, processFailed, submitUrl, fields, _definitions, _values, _errors);

return FormData.builder()
.txId(processInstanceId.toString())
.formName(form.name())
.success(success)
.processFailed(processFailed)
.submitUrl(submitUrl)
.fields(fields)
.definitions(_definitions)
.values(_values)
.errors(_errors)
.build();
}

private io.takari.bpm.model.form.FormField.Cardinality convert(FormField.Cardinality c) {
Expand Down

0 comments on commit 76bc818

Please sign in to comment.