PAN-54
This commit is contained in:
@@ -39,10 +39,8 @@ class ParserService {
|
||||
return root;
|
||||
}
|
||||
|
||||
private void recurse(final Node current)
|
||||
public void recurse(final Node current)
|
||||
{
|
||||
int startIndex;
|
||||
int endIndex;
|
||||
final String statement;
|
||||
|
||||
if (current != null) {
|
||||
@@ -51,60 +49,80 @@ class ParserService {
|
||||
return;
|
||||
}
|
||||
|
||||
String nextStatement;
|
||||
|
||||
if(statement.contains("let"))
|
||||
{
|
||||
current.setLeft(new Node("let", current));
|
||||
|
||||
startIndex = statement.indexOf("let")+"let".length();
|
||||
|
||||
if(statement.contains("if")){
|
||||
endIndex = statement.indexOf("if");
|
||||
} else if(statement.contains("then")){
|
||||
endIndex = statement.indexOf("then");
|
||||
} else {
|
||||
endIndex = statement.length();
|
||||
}
|
||||
|
||||
nextStatement = statement.substring(startIndex, endIndex);
|
||||
|
||||
current.getLeft().setCenter(new Node(nextStatement, current.getLeft()));
|
||||
recurse(current.getLeft().getCenter());
|
||||
separateByLet(current, statement);
|
||||
}
|
||||
|
||||
|
||||
if(statement.contains("if"))
|
||||
{
|
||||
current.setCenter(new Node("if", current));
|
||||
|
||||
startIndex = statement.indexOf("if")+"if".length();
|
||||
endIndex = (statement.contains("then") ? statement.indexOf("then") : statement.length());
|
||||
nextStatement = statement.substring(startIndex, endIndex);
|
||||
|
||||
current.getCenter().setCenter(new Node(nextStatement, current.getCenter()));
|
||||
recurse(current.getCenter().getCenter());
|
||||
separateByIf(current, statement);
|
||||
}
|
||||
|
||||
|
||||
if(current.getStatement().contains("then"))
|
||||
{
|
||||
current.setRight(new Node("then", current));
|
||||
|
||||
startIndex = statement.indexOf("then")+"then".length();
|
||||
nextStatement = statement.substring(startIndex);
|
||||
|
||||
current.getRight().setCenter(new Node(nextStatement, current.getRight()));
|
||||
recurse(current.getRight().getCenter());
|
||||
separateByThen(current, statement);
|
||||
}
|
||||
}
|
||||
|
||||
public void separateByLet(final Node current, final String statement){
|
||||
final int startIndex;
|
||||
final int endIndex;
|
||||
final String nextStatement;
|
||||
|
||||
current.setLeft(new Node("let", current));
|
||||
|
||||
startIndex = statement.indexOf("let")+"let".length();
|
||||
|
||||
if(statement.contains("if")){
|
||||
endIndex = statement.indexOf("if");
|
||||
} else if(statement.contains("then")){
|
||||
endIndex = statement.indexOf("then");
|
||||
} else {
|
||||
endIndex = statement.length();
|
||||
}
|
||||
|
||||
nextStatement = statement.substring(startIndex, endIndex);
|
||||
|
||||
current.getLeft().setCenter(new Node(nextStatement, current.getLeft()));
|
||||
recurse(current.getLeft().getCenter());
|
||||
}
|
||||
|
||||
public void separateByIf(final Node current, final String statement){
|
||||
final int startIndex;
|
||||
final int endIndex;
|
||||
final String nextStatement;
|
||||
|
||||
current.setCenter(new Node("if", current));
|
||||
|
||||
startIndex = statement.indexOf("if")+"if".length();
|
||||
endIndex = (statement.contains("then") ? statement.indexOf("then") : statement.length());
|
||||
nextStatement = statement.substring(startIndex, endIndex);
|
||||
|
||||
current.getCenter().setCenter(new Node(nextStatement, current.getCenter()));
|
||||
recurse(current.getCenter().getCenter());
|
||||
}
|
||||
|
||||
public void separateByThen(final Node current, final String statement){
|
||||
final int startIndex;
|
||||
final String nextStatement;
|
||||
|
||||
current.setRight(new Node("then", current));
|
||||
|
||||
startIndex = statement.indexOf("then")+"then".length();
|
||||
nextStatement = statement.substring(startIndex);
|
||||
|
||||
current.getRight().setCenter(new Node(nextStatement, current.getRight()));
|
||||
recurse(current.getRight().getCenter());
|
||||
}
|
||||
|
||||
public List<String> retrieveStatements(final Node parsedTree)
|
||||
{
|
||||
return populateStatementList(parsedTree, new ArrayList<>());
|
||||
}
|
||||
|
||||
private ArrayList<String> populateStatementList(final Node node, final ArrayList<String> statementList)
|
||||
public ArrayList<String> populateStatementList(final Node node, final ArrayList<String> statementList)
|
||||
{
|
||||
if(node == null)
|
||||
{
|
||||
|
||||
@@ -22,7 +22,19 @@ public class ParserServiceTest {
|
||||
@InjectMocks private ParserService parserService;
|
||||
|
||||
@Test
|
||||
public void testEmptyStringEqualsEmptyString() {
|
||||
public void testParseRawInput_EmptyString() {
|
||||
final String expected = "0: \n";
|
||||
final String actual;
|
||||
|
||||
when(parserService.parseRawInput("")).thenReturn(new Node("", null));
|
||||
|
||||
actual = parserService.parseRawInput("").toString();
|
||||
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseRawInputAndRecurse_EmptyStringEqualsEmptyString() {
|
||||
final String expected = "0: \n";
|
||||
final String actual = parserService.parseRawInput("").toString();
|
||||
|
||||
@@ -30,7 +42,7 @@ public class ParserServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUselessStringEqualsUselessString() {
|
||||
public void testParseRawInput_UselessStringEqualsUselessString() {
|
||||
final String expected = "0: cat\n";
|
||||
final String actual = parserService.parseRawInput("cat").toString();
|
||||
|
||||
@@ -38,7 +50,7 @@ public class ParserServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleIfReturnsIfPlusEmptyString() {
|
||||
public void testParseRawInput_SingleIfReturnsIfPlusEmptyString() {
|
||||
final String expected = "0: if\n... 1: if\n... 2: \n\n";
|
||||
final String actual = parserService.parseRawInput("if").toString();
|
||||
|
||||
@@ -46,7 +58,7 @@ public class ParserServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseCaseIfXIsEvenThenXSquaredIsEven() {
|
||||
public void testParseRawInput_BaseCaseIfXIsEvenThenXSquaredIsEven() {
|
||||
final String expected = "0: if x is even then x^2 is even\n" +
|
||||
"... 1: if\n" +
|
||||
"... 2: x is even \n" +
|
||||
@@ -59,7 +71,7 @@ public class ParserServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLetXBeEvenThenXSquaredIsEven() {
|
||||
public void testParseRawInput_LetXBeEvenThenXSquaredIsEven() {
|
||||
final String expected = "0: let x be even. then x^2 is even.\n" +
|
||||
"... 1: let\n" +
|
||||
"... 2: x be even. \n" +
|
||||
@@ -72,7 +84,7 @@ public class ParserServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLetIfThen() {
|
||||
public void testParseRawInput_LetIfThen() {
|
||||
final String expected = "0: let a. if b, then c.\n" +
|
||||
"... 1: let\n" +
|
||||
"... 2: a. \n" +
|
||||
@@ -87,7 +99,7 @@ public class ParserServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLetStatementWithoutAnyIfOrThenStatements() {
|
||||
public void testParseRawInput_LetStatementWithoutAnyIfOrThenStatements() {
|
||||
final String expected = "0: let a be equal to b.\n" +
|
||||
"... 1: let\n" +
|
||||
"... 2: a be equal to b.\n\n";
|
||||
@@ -98,7 +110,7 @@ public class ParserServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyStringReturnsEmptyList() {
|
||||
public void testRetrieveStatements_EmptyStringReturnsEmptyList() {
|
||||
final List<String> expectedList = new ArrayList<>();
|
||||
expectedList.add("");
|
||||
|
||||
@@ -109,7 +121,7 @@ public class ParserServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseCaseReturnsXIsEven() {
|
||||
public void testRetrieveStatements_BaseCaseReturnsXIsEven() {
|
||||
final List<String> expectedList = new ArrayList<>();
|
||||
expectedList.add("x is even");
|
||||
expectedList.add("x^2 is even");
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package edu.msudenver.tsp.website.controller;
|
||||
|
||||
import edu.msudenver.tsp.website.forms.UserCreationForm;
|
||||
|
||||
import javax.validation.ConstraintValidatorContext;
|
||||
|
||||
public class ConfirmPasswordValidator
|
||||
implements ConstraintValidator<PasswordMatchChecker, Object> {
|
||||
|
||||
@Override
|
||||
public void initialize(final PasswordMatchChecker constraintAnnotation) {
|
||||
}
|
||||
@Override
|
||||
public boolean isValid(final Object obj, final ConstraintValidatorContext context) {
|
||||
final UserCreationForm user = (UserCreationForm) obj;
|
||||
return user.getPassword().equals(user.getConfirmPassword());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package edu.msudenver.tsp.website.controller;
|
||||
|
||||
import javax.validation.Constraint;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({TYPE,ANNOTATION_TYPE})
|
||||
@Retention(RUNTIME)
|
||||
@Constraint(validatedBy = ConfirmPasswordValidator.class)
|
||||
@Documented
|
||||
public @interface PasswordMatchChecker {
|
||||
String message() default "Passwords don't match";
|
||||
Class<?>[] groups() default {};
|
||||
Class<? extends Payload>[] payload() default {};
|
||||
}
|
||||
@@ -27,6 +27,7 @@ public class UserCreationController {
|
||||
model.addAttribute("userID", userCreationForm.getUserID());
|
||||
model.addAttribute("username", userCreationForm.getUsername());
|
||||
model.addAttribute("password", userCreationForm.getPassword());
|
||||
model.addAttribute("confirmPassword", userCreationForm.getConfirmPassword());
|
||||
model.addAttribute("emailAddress", userCreationForm.getEmailAddress());
|
||||
model.addAttribute("firstName", userCreationForm.getFirstName());
|
||||
model.addAttribute("lastName", userCreationForm.getLastName());
|
||||
|
||||
@@ -3,16 +3,50 @@ package edu.msudenver.tsp.website.forms;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class UserCreationForm {
|
||||
@NotNull
|
||||
@NotEmpty
|
||||
private int userID;
|
||||
|
||||
@NotNull
|
||||
@NotEmpty
|
||||
private String username;
|
||||
|
||||
@NotNull
|
||||
@NotEmpty
|
||||
private String password;
|
||||
|
||||
@NotNull
|
||||
@NotEmpty
|
||||
private String confirmPassword;
|
||||
|
||||
public Boolean checkPassword(final String passwordInput, final String passwordCheck) {
|
||||
if(!passwordInput.equals(passwordCheck)) {
|
||||
return false;
|
||||
}
|
||||
else return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@NotEmpty
|
||||
private String emailAddress;
|
||||
|
||||
@NotNull
|
||||
@NotEmpty
|
||||
private String firstName;
|
||||
|
||||
@NotNull
|
||||
@NotEmpty
|
||||
private String lastName;
|
||||
|
||||
private String referrer; // optional
|
||||
|
||||
@NotNull
|
||||
@NotEmpty
|
||||
private boolean agreedToTerms;
|
||||
}
|
||||
|
||||
@@ -7,21 +7,28 @@
|
||||
<title>User Creation</title>
|
||||
</head>
|
||||
<body>
|
||||
<form method="post" action="">
|
||||
<form method="post" action="" enctype="utf8">
|
||||
<label>Username:
|
||||
<input type="text" name="username"/>
|
||||
<p th:each="error: ${#fields.errors('userName')}"
|
||||
th:text="${error}">Validation error</p>
|
||||
</label>
|
||||
<br>
|
||||
<label>Password:
|
||||
<input type="text" name="password"/>
|
||||
<input type="text" name="password" th:field="*{matchingPassword}"/>
|
||||
<p th:each="error : ${#fields.errors('password')}"
|
||||
th:text="${error}">Validation error</p>
|
||||
</label>
|
||||
<br>
|
||||
<label>Confirm Password:
|
||||
<input type="text" name="confirmPassword"/>
|
||||
|
||||
</label>
|
||||
<br>
|
||||
<label>Email Address:
|
||||
<input type="text" name="emailAddress"/>
|
||||
<p th:each="error : ${#fields.errors('email')}"
|
||||
th:text="${error}">Validation error</p>
|
||||
</label>
|
||||
<br>
|
||||
<label>First Name:
|
||||
@@ -34,6 +41,8 @@
|
||||
<br>
|
||||
<label>I agree to the terms and conditions.
|
||||
<input type="checkbox" name="agreedToTerms"/>
|
||||
<p th:each="error : ${#fields.errors('terms')}"
|
||||
th:text="${error}">Validation error</p>
|
||||
</label>
|
||||
<br>
|
||||
<input type="submit" value="Save">
|
||||
|
||||
Reference in New Issue
Block a user