-
Notifications
You must be signed in to change notification settings - Fork 1
feat(forms): add form support with field types and access control #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.researchspace.api.clientmodel; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| /** | ||
| * Information about the permissions to view or edit a form. | ||
| * | ||
| * @author rspace | ||
| */ | ||
| @Data | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Builder | ||
| public class AccessControl { | ||
| private String ownerPermissionType; | ||
| private String groupPermissionType; | ||
| private String worldPermissionType; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package com.researchspace.api.clientmodel; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.experimental.SuperBuilder; | ||
|
|
||
| import javax.validation.constraints.Size; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * A Choice form field defines a list of checkboxes, some of which can be selected by default. | ||
| * @author rspace | ||
| */ | ||
| @Data | ||
| @EqualsAndHashCode(callSuper = true) | ||
| @NoArgsConstructor | ||
| @SuperBuilder | ||
| @JsonPropertyOrder(value = {"id", "globalId", "name", "type", "lastModified", "index", | ||
| "multipleChoice", "options", "defaultOptions"}) | ||
| public class ChoiceFormField extends FormField { | ||
|
|
||
| private boolean multipleChoice; | ||
| @Size(min = 1, message = "Please provide at least one option") | ||
| @Builder.Default | ||
| private List<String> options = new ArrayList<>(); | ||
| @Builder.Default | ||
| private List<String> defaultOptions = new ArrayList<>(); | ||
|
|
||
| public ChoiceFormField(String name, boolean multipleChoice, List<String> options, List<String> defaultOptions) { | ||
| super(); | ||
| setName(name); | ||
| setType("Choice"); | ||
| this.multipleChoice = multipleChoice; | ||
| this.options = options != null ? options : new ArrayList<>(); | ||
| this.defaultOptions = defaultOptions != null ? defaultOptions : new ArrayList<>(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package com.researchspace.api.clientmodel; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
| import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
| import com.researchspace.api.jackson.ISO8601DateSerialiser; | ||
| import lombok.Data; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.experimental.SuperBuilder; | ||
|
|
||
| import java.util.Date; | ||
|
|
||
| /** | ||
| * A Date form field - defines a DateField. | ||
| * @author rspace | ||
| */ | ||
| @Data | ||
| @EqualsAndHashCode(callSuper = true) | ||
| @NoArgsConstructor | ||
| @SuperBuilder | ||
| @JsonPropertyOrder(value = {"id", "globalId", "name", "type", "lastModified", "index", | ||
| "defaultValue", "min", "max"}) | ||
| public class DateFormField extends FormField { | ||
|
|
||
|
|
||
| @JsonSerialize(using = ISO8601DateSerialiser.class) | ||
| private Date defaultValue; | ||
| @JsonSerialize(using = ISO8601DateSerialiser.class) | ||
| private Date min; | ||
|
|
||
| @JsonSerialize(using = ISO8601DateSerialiser.class) | ||
| private Date max; | ||
|
|
||
| public DateFormField(String name, Date defaultValue, Date min, Date max) { | ||
| super(); | ||
| setName(name); | ||
| setType("Date"); | ||
| this.defaultValue = defaultValue != null ? new Date(defaultValue.getTime()) : null; | ||
| this.min = min != null ? new Date(min.getTime()) : null; | ||
| this.max = max != null ? new Date(max.getTime()) : null; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package com.researchspace.api.clientmodel; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.experimental.SuperBuilder; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * A Form. A complete form definition including field definitions. | ||
| * @author rspace | ||
| */ | ||
| @Data | ||
| @EqualsAndHashCode(callSuper = true) | ||
| @NoArgsConstructor | ||
| @SuperBuilder | ||
| @JsonPropertyOrder(value = { | ||
| "id", "globalId", "stableId", "version", "name", "tags", | ||
| "formState", "accessControl", "fields", "_links" | ||
| }) | ||
| public class Form extends FormInfo { | ||
|
|
||
| @Builder.Default | ||
| private List<FormField> fields = new ArrayList<>(); | ||
|
|
||
| /** | ||
| * Adds a field to this form | ||
| * @param field the FormField to add | ||
| * @return this Form for method chaining | ||
| */ | ||
| public Form addField(FormField field) { | ||
| if (this.fields == null) { | ||
| this.fields = new ArrayList<>(); | ||
| } | ||
| this.fields.add(field); | ||
| return this; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,49 @@ | ||||||
| package com.researchspace.api.clientmodel; | ||||||
|
|
||||||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||||||
| import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||||||
| import com.fasterxml.jackson.annotation.JsonSubTypes; | ||||||
| import com.fasterxml.jackson.annotation.JsonSubTypes.Type; | ||||||
| import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||||||
| import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; | ||||||
| import lombok.AllArgsConstructor; | ||||||
| import lombok.Data; | ||||||
| import lombok.EqualsAndHashCode; | ||||||
| import lombok.NoArgsConstructor; | ||||||
| import lombok.experimental.SuperBuilder; | ||||||
|
|
||||||
| /** | ||||||
| * A FormField definition. This is an abstract type for all form field types. | ||||||
| * The properties listed here are common to all types. | ||||||
| * | ||||||
| * @author rspace | ||||||
| */ | ||||||
| @Data | ||||||
| @EqualsAndHashCode(callSuper = true) | ||||||
| @NoArgsConstructor | ||||||
| @AllArgsConstructor | ||||||
| @SuperBuilder | ||||||
| @JsonTypeInfo( | ||||||
| use = Id.NAME, | ||||||
| include = JsonTypeInfo.As.PROPERTY, | ||||||
| property = "type", | ||||||
| visible = true | ||||||
| ) | ||||||
| @JsonSubTypes({ | ||||||
| @Type(value = ChoiceFormField.class, name = "Choice"), | ||||||
| @Type(value = TextFormField.class, name = "Text"), | ||||||
| @Type(value = StringFormField.class, name = "String"), | ||||||
| @Type(value = NumberFormField.class, name = "Number"), | ||||||
| @Type(value = RadioFormField.class, name = "Radio"), | ||||||
| @Type(value = DateFormField.class, name = "Date"), | ||||||
| @Type(value = TimeFormField.class, name = "Time"), | ||||||
| }) | ||||||
| @JsonPropertyOrder(value = {"id", "globalId", "name", "type", "lastModified", "index"}) | ||||||
| public abstract class FormField extends IdentifiableNameable { | ||||||
|
|
||||||
| @JsonProperty("lastModified") | ||||||
| private String lastModifiedMillis; | ||||||
|
||||||
| private String lastModifiedMillis; | |
| private Long lastModifiedMillis; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.researchspace.api.clientmodel; | ||
|
|
||
| /** | ||
| * Enumeration representing the publishing state of a Form. | ||
| * | ||
| * @author rspace | ||
| */ | ||
| public enum FormState { | ||
|
|
||
| NEW, | ||
| PUBLISHED, | ||
| UNPUBLISHED, | ||
| OLD | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.researchspace.api.clientmodel; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
| import lombok.Data; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.experimental.SuperBuilder; | ||
|
|
||
| import javax.validation.constraints.Min; | ||
|
|
||
| /** | ||
| * A Number form field - for numeric input with constraints. | ||
| * @author rspace | ||
| */ | ||
| @Data | ||
| @EqualsAndHashCode(callSuper = true) | ||
| @NoArgsConstructor | ||
| @SuperBuilder | ||
| @JsonPropertyOrder(value = {"id", "globalId", "name", "type", "lastModified", "index", | ||
| "min", "max", "decimalPlaces", "defaultValue"}) | ||
| public class NumberFormField extends FormField { | ||
| private Double min; | ||
| private Double max; | ||
| @Min(0) | ||
| private Byte decimalPlaces; | ||
| private Double defaultValue; | ||
|
|
||
| public NumberFormField(String name, Double defaultValue, Double min, Double max, Byte decimalPlaces) { | ||
| super(); | ||
| setName(name); | ||
| setType("Number"); | ||
| this.defaultValue = defaultValue; | ||
| this.min = min; | ||
| this.max = max; | ||
| this.decimalPlaces = decimalPlaces; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package com.researchspace.api.clientmodel; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.experimental.SuperBuilder; | ||
|
|
||
| import javax.validation.constraints.Size; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * A Radio form field defines a list of radio buttons, one of which can be selected by default. | ||
| * @author rspace | ||
| */ | ||
| @Data | ||
| @EqualsAndHashCode(callSuper = true) | ||
| @NoArgsConstructor | ||
| @SuperBuilder | ||
| @JsonPropertyOrder(value = {"id", "globalId", "name", "type", "lastModified", "index", | ||
| "options", "defaultOption"}) | ||
| public class RadioFormField extends FormField { | ||
|
|
||
| @Size(min = 1, message = "Please provide at least one option") | ||
| @Builder.Default | ||
| private List<String> options = new ArrayList<>(); | ||
| private String defaultOption; | ||
|
|
||
| public RadioFormField(String name, List<String> options, String defaultOption) { | ||
| super(); | ||
| setName(name); | ||
| setType("Radio"); | ||
| this.options = options != null ? options : new ArrayList<>(); | ||
| this.defaultOption = defaultOption; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR description mentions only the version bump, but this PR also introduces new Form/Field/AccessControl models and multiple new tests/resources. Please update the PR description to reflect the functional scope so reviewers/release notes are accurate.