diff --git a/persistence/scripts/mysql/local_development.sql b/persistence/scripts/mysql/local_development.sql index 0bb4f8f..15934b0 100644 --- a/persistence/scripts/mysql/local_development.sql +++ b/persistence/scripts/mysql/local_development.sql @@ -38,6 +38,7 @@ CREATE TABLE proofs ( id INT NOT NULL AUTO_INCREMENT, theorem_name VARCHAR(512) NOT NULL, + proof VARCHAR(4096) NOT NULL, branch VARCHAR(512) NOT NULL, theorem INT NOT NULL, FOREIGN KEY fk_theorem (theorem) REFERENCES theorems (id) ON DELETE NO ACTION ON UPDATE NO ACTION, diff --git a/persistence/src/integrationTest/java/edu/msudenver/tsp/persistence/ProofsIntegrationTest.java b/persistence/src/integrationTest/java/edu/msudenver/tsp/persistence/ProofsIntegrationTest.java index 4af0f76..2061320 100644 --- a/persistence/src/integrationTest/java/edu/msudenver/tsp/persistence/ProofsIntegrationTest.java +++ b/persistence/src/integrationTest/java/edu/msudenver/tsp/persistence/ProofsIntegrationTest.java @@ -33,6 +33,7 @@ public class ProofsIntegrationTest { assertEquals("Test proof", savedProof.getTheoremName()); assertEquals("Test branch", savedProof.getBranch()); + assertEquals("test", savedProof.getProof()); assertNotNull(savedProof.getDateCreated()); assertNotNull(savedProof.getLastUpdated()); assertEquals(2, savedProof.getReferencedTheorems().size()); @@ -50,6 +51,7 @@ public class ProofsIntegrationTest { assertEquals(Integer.valueOf(0), updatedProof.getVersion()); assertEquals("Test proof", updatedProof.getTheoremName()); assertEquals("Test Update", updatedProof.getBranch()); + assertEquals("test", updatedProof.getProof()); assertNotNull(updatedProof.getLastUpdated()); assertNotNull(updatedProof.getDateCreated()); assertNotEquals(updatedProof.getDateCreated().toInstant(), updatedProof.getLastUpdated().toInstant()); @@ -77,6 +79,7 @@ public class ProofsIntegrationTest { final Proof proof = new Proof(); proof.setTheoremName("Test proof"); + proof.setProof("test"); proof.setBranch("Test branch"); proof.setDateCreated(new Date()); proof.setReferencedTheorems(referencedTheoremsList); diff --git a/persistence/src/integrationTest/java/edu/msudenver/tsp/persistence/TheoremsIntegrationTest.java b/persistence/src/integrationTest/java/edu/msudenver/tsp/persistence/TheoremsIntegrationTest.java index d5c22c3..7090456 100644 --- a/persistence/src/integrationTest/java/edu/msudenver/tsp/persistence/TheoremsIntegrationTest.java +++ b/persistence/src/integrationTest/java/edu/msudenver/tsp/persistence/TheoremsIntegrationTest.java @@ -32,6 +32,7 @@ public class TheoremsIntegrationTest { assertEquals("Test theorem", savedTheorem.getName()); assertEquals("Test branch", savedTheorem.getBranch()); + assertEquals("test", savedTheorem.getTheorem()); assertTrue(savedTheorem.getProvenStatus()); assertEquals(2, savedTheorem.getReferencedTheorems().size()); assertEquals(2, savedTheorem.getReferencedDefinitions().size()); @@ -48,6 +49,7 @@ public class TheoremsIntegrationTest { assertEquals(Integer.valueOf(0), updatedTheorem.getVersion()); assertEquals("Test theorem", updatedTheorem.getName()); assertEquals("Test Update", updatedTheorem.getBranch()); + assertEquals("test", updatedTheorem.getTheorem()); assertTrue(updatedTheorem.getProvenStatus()); assertEquals(2, updatedTheorem.getReferencedTheorems().size()); assertEquals(2, updatedTheorem.getReferencedDefinitions().size()); @@ -73,6 +75,7 @@ public class TheoremsIntegrationTest { final Theorem theorem = new Theorem(); theorem.setName("Test theorem"); + theorem.setTheorem("test"); theorem.setBranch("Test branch"); theorem.setProvenStatus(true); theorem.setTheoremType(TheoremType.THEOREM); diff --git a/persistence/src/main/java/edu/msudenver/tsp/persistence/controller/ProofController.java b/persistence/src/main/java/edu/msudenver/tsp/persistence/controller/ProofController.java index e218bbf..d682c32 100644 --- a/persistence/src/main/java/edu/msudenver/tsp/persistence/controller/ProofController.java +++ b/persistence/src/main/java/edu/msudenver/tsp/persistence/controller/ProofController.java @@ -75,13 +75,18 @@ public class ProofController { @GetMapping("/branch") public @ResponseBody - ResponseEntity> getAllProofsByBranch(@RequestParam("branch") final String branch) { + ResponseEntity> getAllProofsByBranch(@RequestParam("branch") String branch) { LOG.info("Received request to query for proofs related to the {} branch of mathematics", branch); if (branch == null) { LOG.error("ERROR: branch was null"); return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } + if (branch.contains("_") || branch.contains("-")) { + branch = branch.replace("_"," "); + branch = branch.replace("-", " "); + } + LOG.debug("Querying for proofs with branch {}", branch); final StopWatch stopWatch = new StopWatch(); @@ -105,13 +110,18 @@ public class ProofController { @GetMapping("/theorem_name") public @ResponseBody - ResponseEntity> getAllProofsByTheoremName(@RequestParam("theorem_name") final String theoremName) { + ResponseEntity> getAllProofsByTheoremName(@RequestParam("theorem_name") String theoremName) { LOG.info("Received request to query for proofs of the theorem {}", theoremName); if (theoremName == null) { LOG.error("ERROR: theorem name was null"); return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } + if (theoremName.contains("_") || theoremName.contains("-")) { + theoremName = theoremName.replace("_"," "); + theoremName = theoremName.replace("-", " "); + } + LOG.debug("Querying for proofs of the theorem {}", theoremName); final StopWatch stopWatch = new StopWatch(); diff --git a/persistence/src/main/java/edu/msudenver/tsp/persistence/dto/Proof.java b/persistence/src/main/java/edu/msudenver/tsp/persistence/dto/Proof.java index 683039b..bd927d8 100644 --- a/persistence/src/main/java/edu/msudenver/tsp/persistence/dto/Proof.java +++ b/persistence/src/main/java/edu/msudenver/tsp/persistence/dto/Proof.java @@ -8,6 +8,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; import javax.persistence.*; import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import java.io.Serializable; import java.util.Date; @@ -22,6 +23,9 @@ public class Proof extends BaseDto implements Serializable { @Size(min = 1, max = 512, message = "The name must be at least 1 character and at most 512 characters") @Column(name = "theorem_name") private String theoremName; + @NotNull(groups = Insert.class) + @Size(min = 1, max = 4096, message = "The proof must be at least 1 character and at most 4096 characters") + private String proof; @NotBlank(groups = Insert.class) @Size(min = 1, max = 512, message = "The branch must be at least 1 character and at most 512 characters") private String branch; diff --git a/persistence/src/test/java/edu/msudenver/tsp/persistence/controller/ProofControllerTest.java b/persistence/src/test/java/edu/msudenver/tsp/persistence/controller/ProofControllerTest.java index 6e77bb3..6ad1948 100644 --- a/persistence/src/test/java/edu/msudenver/tsp/persistence/controller/ProofControllerTest.java +++ b/persistence/src/test/java/edu/msudenver/tsp/persistence/controller/ProofControllerTest.java @@ -53,7 +53,7 @@ public class ProofControllerTest { when(proofRepository.findByBranch(anyString())).thenReturn(listOfProofs); - final ResponseEntity> responseEntity = proofController.getAllProofsByBranch("test"); + final ResponseEntity> responseEntity = proofController.getAllProofsByBranch("Test_branch"); assertNotNull(responseEntity); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); @@ -77,7 +77,7 @@ public class ProofControllerTest { public void testGetAllProofsByBranch_noProofsFound() { when(proofRepository.findByBranch(anyString())).thenReturn(Collections.emptyList()); - final ResponseEntity> responseEntity = proofController.getAllProofsByBranch("test nonexistent branch"); + final ResponseEntity> responseEntity = proofController.getAllProofsByBranch("test-nonexistent-branch"); assertNotNull(responseEntity); assertFalse(responseEntity.hasBody()); @@ -93,7 +93,7 @@ public class ProofControllerTest { when(proofRepository.findByTheoremName(anyString())).thenReturn(listOfProofs); - final ResponseEntity> responseEntity = proofController.getAllProofsByTheoremName("test"); + final ResponseEntity> responseEntity = proofController.getAllProofsByTheoremName("Test_proof"); assertNotNull(responseEntity); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); @@ -104,7 +104,7 @@ public class ProofControllerTest { } @Test - public void testGetAllProfsByTheoremName_nullTheoremName() { + public void testGetAllProofsByTheoremName_nullTheoremName() { final ResponseEntity> responseEntity = proofController.getAllProofsByTheoremName(null); assertNotNull(responseEntity); @@ -117,7 +117,7 @@ public class ProofControllerTest { public void testGetAllProofsByTheoremName_noProofsFound() { when(proofRepository.findByTheoremName(anyString())).thenReturn(Collections.emptyList()); - final ResponseEntity> responseEntity = proofController.getAllProofsByTheoremName("test nonexistent branch"); + final ResponseEntity> responseEntity = proofController.getAllProofsByTheoremName("test-nonexistent-proof"); assertNotNull(responseEntity); assertFalse(responseEntity.hasBody()); @@ -299,6 +299,7 @@ public class ProofControllerTest { final Proof proof = new Proof(); proof.setTheoremName("Test proof"); proof.setBranch("Test branch"); + proof.setProof("test proof"); proof.setDateCreated(new Date()); proof.setReferencedTheorems(referencedTheoremsList); proof.setReferencedDefinitions(referencedDefinitionsList);