Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions demo/src/main/java/io/asfjava/ui/demo/screen/DemoForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ public class DemoForm implements Serializable {
@TextField(title = "Your Github Mail",fieldAddonRight="@github.com", description = "This is TextField with fieldAddonRight")
private String gitHub;


// @Tab(title = "Contact", index = 2)
@Password(title = "Password", placeHolder = "Please set you password", description = "This is password")
@Password(title = "Password", placeHolder = "Please set you password",minLenght=6,description = "This is password", validationMessage = "The password must contain a minimum of 6 characters ")
private String password;

@Tab(title = "Info", index = 1)
@TextField(title = "First Name", placeHolder = "Your first name", description = "This is a description for your first name field")
@TextField(title = "First Name", placeHolder = "Your first name",minLenght=3,maxLenght=10, validationMessage = "The First Name must contain a minimum of 3 and a max of 10 characters ", description = "This is a description for your first name field with minLenght and maxLenght")
private String firstName;

// @Tab(title = "Info", index = 1)
Expand Down Expand Up @@ -54,7 +55,7 @@ public class DemoForm implements Serializable {
private String civilState;

// @Tab(title = "Contact", index = 2)
@TextArea(title = "Address", placeHolder = "Fill your address please", description = "This is textarea")
@TextArea(title = "Address", placeHolder = "Fill your address please",maxLenght=30, description = "This is textarea" , validationMessage="Max 30 charactres")
private String address;

@Tab(title = "Additional Info", index = 3)
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/io/asfjava/ui/core/form/Password.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@

String description() default "";

int minLenght() default 0;

int maxLenght() default Integer.MAX_VALUE;

String pattern() default "";

String fieldAddonLeft() default"";

String fieldAddonRight() default"";
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/io/asfjava/ui/core/form/TextArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
String placeHolder() default "";

String description() default "";

int minLenght() default 0;

int maxLenght() default Integer.MAX_VALUE;

String fieldAddonLeft() default"";

String fieldAddonRight() default"";

boolean noTitle() default false;

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/asfjava/ui/core/form/TextField.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

String description() default "";

int minLenght() default 0;

int maxLenght() default Integer.MAX_VALUE;

String fieldAddonLeft() default"";

String fieldAddonRight() default"";
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/io/asfjava/ui/core/generators/TextAreaGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ public void generate(ObjectNode fieldFormDefinition, Field field) {
fieldFormDefinition.put("key", field.getName());
fieldFormDefinition.put("type", "textarea");

String fieldAddonLeft = annotation.fieldAddonLeft();
if (!fieldAddonLeft.isEmpty()) {
fieldFormDefinition.put("fieldAddonLeft", fieldAddonLeft);
}

String fieldAddonRight = annotation.fieldAddonRight();
if (!fieldAddonRight.isEmpty()) {
fieldFormDefinition.put("fieldAddonRight", fieldAddonRight);
}

String description = annotation.description();
if (!description.isEmpty()) {
fieldFormDefinition.put("description", description);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ public void customizeSchema(BeanProperty property, JsonSchema jsonschema) {
if (annotation != null && annotation.title() != null) {
((StringSchema) jsonschema).setTitle(annotation.title());
}
if (annotation.pattern() != null) {
((StringSchema) jsonschema).setPattern(annotation.pattern());
}
if (annotation.minLenght() != 0) {
((StringSchema) jsonschema).setMinLength(annotation.minLenght());
}
if (annotation.maxLenght() != Integer.MAX_VALUE) {
((StringSchema) jsonschema).setMaxLength(annotation.maxLenght());
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ public void customizeSchema(BeanProperty property, JsonSchema jsonschema) {
if (annotation != null && annotation.title() != null) {
((StringSchema) jsonschema).setTitle(annotation.title());
}

if (annotation.minLenght() != 0) {
((StringSchema) jsonschema).setMinLength(annotation.minLenght());
}
if (annotation.maxLenght() != Integer.MAX_VALUE) {
((StringSchema) jsonschema).setMaxLength(annotation.maxLenght());
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public void customizeSchema(BeanProperty property, JsonSchema jsonschema) {
if (annotation.pattern() != null) {
((StringSchema) jsonschema).setPattern(annotation.pattern());
}
if (annotation.minLenght() != 0) {
((StringSchema) jsonschema).setMinLength(annotation.minLenght());
}
if (annotation.maxLenght() != Integer.MAX_VALUE) {
((StringSchema) jsonschema).setMaxLength(annotation.maxLenght());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.junit.Test;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import io.asfjava.ui.core.GeneratorFactoryInitializer;
Expand Down Expand Up @@ -186,6 +185,7 @@ public void testGenerate_Password() throws JsonProcessingException {

String json = new ObjectMapper().writeValueAsString(ui);
Assert.assertThat(json, hasJsonPath("$.schema.properties.password.title", equalTo("Password")));
Assert.assertThat(json, hasJsonPath("$.schema.properties.password.pattern", equalTo("[a-z]")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')]", hasSize(1)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].description", hasItem("This is password")));
Assert.assertThat(json,
Expand All @@ -204,6 +204,7 @@ public void testGenerate_Password_WithFieldAddonLeft() throws JsonProcessingExce
String json = new ObjectMapper().writeValueAsString(ui);
Assert.assertThat(json, hasJsonPath("$.schema.properties.password.title",equalTo("Password")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')]",hasSize(1)));
Assert.assertThat(json, hasJsonPath("$.schema.properties.password.pattern", equalTo("[a-z]")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].description",hasItem("This is password")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].placeholder",hasItem("Please set you password")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].validationMessage",hasItem("this is a validation msg")));
Expand All @@ -221,6 +222,7 @@ public void testGenerate_Password_WithFieldAddonRight() throws JsonProcessingExc
String json = new ObjectMapper().writeValueAsString(ui);
Assert.assertThat(json, hasJsonPath("$.schema.properties.password.title",equalTo("Password")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')]",hasSize(1)));
Assert.assertThat(json, hasJsonPath("$.schema.properties.password.pattern", equalTo("[a-z]")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].description",hasItem("This is password")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].placeholder",hasItem("Please set you password")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].validationMessage",hasItem("this is a validation msg")));
Expand Down Expand Up @@ -248,6 +250,48 @@ public void testGenerate_TextArea() throws JsonProcessingException {
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')].notitle", hasItem(true)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')].readonly", hasItem(true)));

}

public void testGenerate_TextArea_WithFieldAddOnLeft() throws JsonProcessingException {
UiForm ui = UiFormSchemaGenerator.get().generate(TextAreaForm2.class);

String json = new ObjectMapper().writeValueAsString(ui);
Assert.assertThat(json, hasJsonPath("$.schema.properties.address.title", equalTo("Address")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')]", hasSize(1)));
Assert.assertThat(json, hasJsonPath("$.schema.properties.address.minLenght", equalTo(6)));
Assert.assertThat(json, hasJsonPath("$.schema.properties.address.maxLenght", equalTo(10)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')].description", hasItem("This is textarea")));
Assert.assertThat(json,
hasJsonPath("$.form[?(@.key=='address')].placeholder", hasItem("Fill your address please")));
Assert.assertThat(json,
hasJsonPath("$.form[?(@.key=='address')].validationMessage", hasItem("this is a validation msg")));
// Assert.assertThat(json,
// hasJsonPath("$.form[?(@.key=='password')].type",hasItem("textArea")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')].notitle", hasItem(true)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')].readonly", hasItem(true)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')].fieldAddonLeft", hasItem("@")));


}

public void testGenerate_TextArea_WithFieldAddOnRight() throws JsonProcessingException {
UiForm ui = UiFormSchemaGenerator.get().generate(TextAreaForm3.class);

String json = new ObjectMapper().writeValueAsString(ui);
Assert.assertThat(json, hasJsonPath("$.schema.properties.address.title", equalTo("Address")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')]", hasSize(1)));
Assert.assertThat(json, hasJsonPath("$.schema.properties.address.minLenght", equalTo(6)));
Assert.assertThat(json, hasJsonPath("$.schema.properties.address.maxLenght", equalTo(10)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')].description", hasItem("This is textarea")));
Assert.assertThat(json,
hasJsonPath("$.form[?(@.key=='address')].placeholder", hasItem("Fill your address please")));
Assert.assertThat(json,
hasJsonPath("$.form[?(@.key=='address')].validationMessage", hasItem("this is a validation msg")));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')].notitle", hasItem(true)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')].readonly", hasItem(true)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')].fieldAddonRight", hasItem("@")));


}

@Test
Expand Down Expand Up @@ -347,12 +391,12 @@ public void testGenerate_TabbedFormed() throws JsonProcessingException{
Assert.assertThat(json, hasJsonPath("$.form[?(@.tabs)].tabs[?(@.title=='Contact')].items[*]",hasSize(1)));
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='webSite')]"));
}

}


class TextFieldForm implements Serializable {

@TextField(title = "First Name", placeHolder = "Your first name", pattern = "[a-z]", noTitle = true, validationMessage = "this is a validation msg", description = "This is a description for your first name field", readOnly = true)
@TextField(title = "First Name", placeHolder = "Your first name", pattern = "[a-z]",minLenght=6,maxLenght=10, noTitle = true, validationMessage = "this is a validation msg", description = "This is a description for your first name field", readOnly = true)
private String firstName;

public String getFirstName() {
Expand All @@ -363,7 +407,7 @@ public String getFirstName() {

class TextFieldFormRight implements Serializable {

@TextField(title = "First Name", placeHolder = "Your first name", fieldAddonRight = "@", pattern = "[a-z]", noTitle = true, validationMessage = "this is a validation msg", description = "This is a description for your first name field")
@TextField(title = "First Name", placeHolder = "Your first name", fieldAddonRight = "@", pattern = "[a-z]",minLenght=6,maxLenght=10, noTitle = true, validationMessage = "this is a validation msg", description = "This is a description for your first name field")
private String firstName;

public String getFirstName() {
Expand Down Expand Up @@ -434,7 +478,7 @@ public Double getNumber() {

class PasswordForm implements Serializable {

@Password(title = "Password", placeHolder = "Please set you password", description = "This is password", noTitle = true, validationMessage = "this is a validation msg", readOnly = true)
@Password(title = "Password", placeHolder = "Please set you password", pattern = "[a-z]", description = "This is password", noTitle = true, validationMessage = "this is a validation msg", readOnly = true)
private String password;

public String getPassword() {
Expand All @@ -444,7 +488,7 @@ public String getPassword() {

class PasswordForm2 implements Serializable {

@Password(title = "Password", placeHolder = "Please set you password", fieldAddonRight = "@", description = "This is password", noTitle = true, validationMessage = "this is a validation msg", readOnly = true)
@Password(title = "Password", placeHolder = "Please set you password", pattern = "[a-z]",minLenght=6,maxLenght=10, fieldAddonRight = "@", description = "This is password", noTitle = true, validationMessage = "this is a validation msg", readOnly = true)
private String password;

public String getPassword() {
Expand All @@ -454,17 +498,37 @@ public String getPassword() {

class PasswordForm3 implements Serializable {

@Password(title = "Password", placeHolder = "Please set you password", fieldAddonLeft = "@", description = "This is password", noTitle = true, validationMessage = "this is a validation msg", readOnly = true)
@Password(title = "Password", placeHolder = "Please set you password", pattern = "[a-z]",minLenght=6,maxLenght=10, fieldAddonLeft = "@", description = "This is password", noTitle = true, validationMessage = "this is a validation msg", readOnly = true)
private String password;

public String getPassword() {
return password;
}
}

class TextAreaForm2 implements Serializable {

@TextArea(title = "Address", placeHolder = "Fill your address please", fieldAddonLeft = "@",minLenght=6,maxLenght=10, description = "This is textarea", noTitle = true, validationMessage = "this is a validation msg", readOnly = true)
private String address;

public String getAddress() {
return address;
}
}

class TextAreaForm3 implements Serializable {

@TextArea(title = "Address", placeHolder = "Fill your address please",fieldAddonRight = "@",minLenght=6,maxLenght=10, description = "This is textarea", noTitle = true, validationMessage = "this is a validation msg", readOnly = true)
private String address;

public String getAddress() {
return address;
}
}

class TextAreaForm implements Serializable {

@TextArea(title = "Address", placeHolder = "Fill your address please", description = "This is textarea", noTitle = true, validationMessage = "this is a validation msg", readOnly = true)
@TextArea(title = "Address", placeHolder = "Fill your address please", description = "This is textarea",minLenght=6,maxLenght=10, noTitle = true, validationMessage = "this is a validation msg", readOnly = true)
private String address;

public String getAddress() {
Expand Down