Last active
August 29, 2015 14:20
-
-
Save DeepSky8/59e15f986e7cdcf0b82d to your computer and use it in GitHub Desktop.
Adding an ENUM to represent the issue's current stage. This must be changable as the issue moves through the resolution process. Application.java lines 37-39 don't currently recognize ENTERED, PROGRESSING, or REVIEWING as enums - java is currently trying to resolve them to variables. IssueController.java line 90-93 doesn't recognize the enums I …
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.kyrlach.issuetracker; | |
| import org.springframework.beans.factory.annotation.Autowired; | |
| import org.springframework.boot.CommandLineRunner; | |
| import org.springframework.boot.SpringApplication; | |
| import org.springframework.boot.autoconfigure.SpringBootApplication; | |
| import com.kyrlach.issuetracker.issue.Issue; | |
| import com.kyrlach.issuetracker.issue.IssueRepository; | |
| import com.kyrlach.issuetracker.login.User; | |
| import com.kyrlach.issuetracker.login.UserRepository; | |
| import com.kyrlach.issuetracker.issue.Stage; | |
| @SpringBootApplication | |
| public class Application implements CommandLineRunner { | |
| @Autowired | |
| private UserRepository userRepository; | |
| @Autowired | |
| private IssueRepository issueRepository; | |
| public static void main(String[] args) { | |
| SpringApplication.run(Application.class, args); | |
| } | |
| @Override | |
| public void run(String... arg0) throws Exception { | |
| User tom = new User("Tom", "Test"); | |
| User ben = new User("Ben", "Secr3t"); | |
| User joel = new User("Joel", "1234"); | |
| userRepository.save(tom); | |
| userRepository.save(ben); | |
| userRepository.save(joel); | |
| issueRepository.save(new Issue("Purple", "doesn't work", "Feature", 2, tom, ENTERED)); | |
| issueRepository.save(new Issue("Blue", "too much work", "Problem", 40, ben, PROGRESSING)); | |
| issueRepository.save(new Issue("Green", "need more", "Enhancement", 5, joel, REVIEWING)); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.kyrlach.issuetracker.issue; | |
| import javax.persistence.Entity; | |
| import javax.persistence.GeneratedValue; | |
| import javax.persistence.GenerationType; | |
| import javax.persistence.Id; | |
| import javax.persistence.ManyToOne; | |
| import com.kyrlach.issuetracker.login.User; | |
| import com.kyrlach.issuetracker.issue.Stage; | |
| @Entity | |
| public class Issue { | |
| @Id | |
| @GeneratedValue(strategy=GenerationType.AUTO) | |
| private long id; | |
| private String title; | |
| private String description; | |
| private String category; | |
| private float difficulty; | |
| private Stage stage; | |
| @ManyToOne | |
| private User assignedTo; | |
| public Issue() {} | |
| public Issue(String title, String description, String category, float difficulty, User assignedTo, Stage stage) { | |
| this.title = title; | |
| this.description = description; | |
| this.category= category; | |
| this.assignedTo = assignedTo; | |
| this.difficulty = difficulty; | |
| this.stage = stage; | |
| } | |
| public Stage getStage() { | |
| return stage; | |
| } | |
| public void setStage(Stage stage) { | |
| this.stage = stage; | |
| } | |
| public class Process { | |
| Stage stage; | |
| } | |
| public void Process(Stage stage) { | |
| this.stage = stage; | |
| } | |
| public long getId() { | |
| return id; | |
| } | |
| public void setId(long id) { | |
| this.id = id; | |
| } | |
| public String getTitle() { | |
| return title; | |
| } | |
| public void setTitle(String title) { | |
| this.title = title; | |
| } | |
| public String getDescription() { | |
| return description; | |
| } | |
| public void setDescription(String description) { | |
| this.description = description; | |
| } | |
| public String getCategory() { | |
| return category; | |
| } | |
| public float getDifficulty() { | |
| return difficulty; | |
| } | |
| public void setDifficulty(float difficulty) { | |
| this.difficulty = difficulty; | |
| } | |
| public User getAssignedTo() { | |
| return assignedTo; | |
| } | |
| public void setAssignedTo(User assignedTo) { | |
| this.assignedTo = assignedTo; | |
| } | |
| public void setCategory(String category) { | |
| this.category = category; | |
| } | |
| @Override | |
| public String toString() { | |
| return "Issue("+id+","+title+","+description+","+category+","+difficulty+","+assignedTo+","+stage+")"; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.kyrlach.issuetracker.issue; | |
| import java.util.ArrayList; | |
| import java.util.List; | |
| import org.apache.log4j.LogManager; | |
| import org.apache.log4j.Logger; | |
| import org.springframework.beans.factory.annotation.Autowired; | |
| import org.springframework.stereotype.Controller; | |
| import org.springframework.ui.Model; | |
| import org.springframework.web.bind.annotation.ModelAttribute; | |
| import org.springframework.web.bind.annotation.RequestMapping; | |
| import org.springframework.web.bind.annotation.RequestMethod; | |
| import com.kyrlach.issuetracker.login.LoginController; | |
| import com.kyrlach.issuetracker.login.LoginForm; | |
| import com.kyrlach.issuetracker.login.User; | |
| import com.kyrlach.issuetracker.login.UserRepository; | |
| import com.kyrlach.issuetracker.issue.Stage; | |
| @Controller | |
| @RequestMapping("/issues") | |
| public class IssueController { | |
| private static Logger logger = LogManager.getLogger(IssueController.class); | |
| @Autowired | |
| private IssueRepository issueRepository; | |
| @Autowired | |
| private UserRepository userRepository; | |
| @RequestMapping(method = RequestMethod.GET) | |
| public String issues(Model model) { | |
| model.addAttribute("issues", issueRepository.findAll()); | |
| return "issueList"; | |
| } | |
| @RequestMapping(value = "/new", method = RequestMethod.GET) | |
| public String newIssue(Model model) { | |
| model.addAttribute("userList", userRepository.findAll()); | |
| model.addAttribute("issueForm", new IssueForm()); | |
| return "newIssue"; | |
| } | |
| @RequestMapping(value = "/new", method = RequestMethod.POST) | |
| public String saveIssue(@ModelAttribute IssueForm issueForm, Model model) { | |
| User assignee = userRepository.findOne(issueForm.getAssignedTo()); | |
| Issue newIssue = new Issue(issueForm.getTitle(), issueForm.getDescription(), issueForm.getCategory(), issueForm.getDifficulty(), assignee, ENTERED); | |
| issueRepository.save(newIssue); | |
| return "redirect:/issues"; | |
| } | |
| @RequestMapping(value = "/search", method = RequestMethod.GET) | |
| public String newSearch(Model model) { | |
| model.addAttribute("searchTerms", new IssueSearchForm()); | |
| return "issueSearch"; | |
| } | |
| @RequestMapping(value = "/search", method = RequestMethod.POST) | |
| public String submittedData(@ModelAttribute IssueSearchForm searchTerms, Model model) { | |
| logger.info(searchTerms); | |
| List<String> categoriesA = searchTerms.getCategories(); | |
| logger.info(categoriesA); | |
| if (categoriesA == null){ | |
| categoriesA = new ArrayList<String>(); | |
| categoriesA.add("Feature"); | |
| categoriesA.add("Problem"); | |
| categoriesA.add("Enhancement"); | |
| } | |
| List<Float> difficultiesB = searchTerms.getDifficulties(); | |
| logger.info(difficultiesB); | |
| if(difficultiesB == null) { | |
| difficultiesB = new ArrayList<Float>(); | |
| difficultiesB.add(0f); | |
| difficultiesB.add(0.5f); | |
| difficultiesB.add(1f); | |
| difficultiesB.add(2f); | |
| difficultiesB.add(3f); | |
| difficultiesB.add(5f); | |
| difficultiesB.add(8f); | |
| difficultiesB.add(13f); | |
| difficultiesB.add(20f); | |
| difficultiesB.add(40f); | |
| difficultiesB.add(100f); | |
| } | |
| List<Stage> stagesC = searchTerms.getStage(); | |
| if (stagesC == null){ | |
| stagesC = new ArrayList<Stage>(); | |
| stagesC.add(ENTERED); | |
| stagesC.add(PROGRESSING); | |
| stagesC.add(REVIEWING); | |
| stagesC.add(ACCEPTED); | |
| } | |
| logger.info(categoriesA); | |
| logger.info(difficultiesB); | |
| List<Issue> searchResults = issueRepository.findByTitleLikeAndDescriptionLikeAndCategoryInAndDifficultyInAndStageIn("%" + searchTerms.getTitle() + "%","%" + searchTerms.getDescription() + "%", categoriesA, difficultiesB, stagesC); | |
| model.addAttribute("issues", searchResults); | |
| logger.info(searchResults); | |
| return "issueList"; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.kyrlach.issuetracker.issue; | |
| import java.util.List; | |
| import org.springframework.data.repository.CrudRepository; | |
| import com.kyrlach.issuetracker.issue.Stage; | |
| public interface IssueRepository extends CrudRepository<Issue, Long> { | |
| List<Issue> findByTitleLikeAndDescriptionLikeAndCategoryInAndDifficultyInAndStageIn(String title, String description, List<String> categories, List<Float> difficulties, List<Stage> stage); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE HTML> | |
| <html xmlns:th="http://www.thymeleaf.org"> | |
| <head> | |
| <title>Issue Tracker -- Search</title> | |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
| <link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/pure-min.css" /> | |
| </head> | |
| <form th:object="${searchTerms}" th:action="@{/issues/search}" action="#" method="post"> | |
| <body> | |
| <table class="pure-table pure-table-striped"> | |
| <tbody> | |
| <tr> | |
| <label for="findByTitleLike">Title</label> | |
| <textarea th:field="*{title}">Search Title</textarea> | |
| <label for="findByDescriptionLike">Description</label> | |
| <textarea th:field="*{description}">Search Description</textarea> | |
| <label for="categories">Search these Categories</label> | |
| <input type="checkbox" th:field="*{categories}" th:value="Feature" />New Feature Requests | |
| <input type="checkbox" th:field="*{categories}" th:value="Problem" />Reported Problems | |
| <input type="checkbox" th:field="*{categories}" th:value="Enhancement" />Enhancement Requests | |
| <label for="listDifficultiesIn">Difficulties</label> | |
| <input type="checkbox" th:field="*{difficulties}" th:value="0" />0 | |
| <input type="checkbox" th:field="*{difficulties}" th:value=".5" />.5 | |
| <input type="checkbox" th:field="*{difficulties}" th:value="1" />1 | |
| <input type="checkbox" th:field="*{difficulties}" th:value="2" />2 | |
| <input type="checkbox" th:field="*{difficulties}" th:value="3" />3 | |
| <input type="checkbox" th:field="*{difficulties}" th:value="5" />5 | |
| <input type="checkbox" th:field="*{difficulties}" th:value="8" />8 | |
| <input type="checkbox" th:field="*{difficulties}" th:value="13" />13 | |
| <input type="checkbox" th:field="*{difficulties}" th:value="20" />20 | |
| <input type="checkbox" th:field="*{difficulties}" th:value="40" />40 | |
| <input type="checkbox" th:field="*{difficulties}" th:value="100" />100 | |
| <label for="stage">Stage</label> | |
| <input type="checkbox" th:field="*{stage}" th:value="ENTERED" />Issues just entered | |
| <input type="checkbox" th:field="*{stage}" th:value="PROGRESSING" />Issues in progress | |
| <input type="checkbox" th:field="*{stage}" th:value="REVIEWING" />Issues being reviewed | |
| <input type="checkbox" th:field="*{stage}" th:value="ACCEPTED" />Issues that have been accepted | |
| </tr> | |
| </tbody> | |
| </table> | |
| <button type="submit" class="pure-button pure-button-primary">Search</button> | |
| </body> | |
| </form> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.kyrlach.issuetracker.issue; | |
| import java.util.ArrayList; | |
| import java.util.List; | |
| import com.kyrlach.issuetracker.issue.Stage; | |
| public class IssueSearchForm { | |
| private String title; | |
| private String description; | |
| private List<String> categories; | |
| private List<Float> difficulties; | |
| private List<Stage> stage; | |
| public IssueSearchForm () { | |
| this.title = null; | |
| this.description = null; | |
| this.categories = new ArrayList<String>(); | |
| this.difficulties = new ArrayList<Float>(); | |
| this.stage = new ArrayList<Stage>(); | |
| } | |
| public List<Stage> getStage() { | |
| return stage; | |
| } | |
| public void setStage(List<Stage> stage) { | |
| this.stage = stage; | |
| } | |
| public String getTitle() { | |
| return title; | |
| } | |
| public void setTitle(String title) { | |
| this.title = title; | |
| } | |
| public String getDescription() { | |
| return description; | |
| } | |
| public void setDescription(String description) { | |
| this.description = description; | |
| } | |
| public List<String> getCategories() { | |
| return categories; | |
| } | |
| public void setCategories(List<String> categories) { | |
| this.categories = categories; | |
| } | |
| public List<Float> getDifficulties() { | |
| return difficulties; | |
| } | |
| public void setDifficulties(List<Float> difficulties) { | |
| this.difficulties = difficulties; | |
| } | |
| @Override | |
| public String toString() { | |
| return "IssueSearchForm("+title+","+description+","+categories+","+difficulties+","+stage+")"; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.kyrlach.issuetracker.issue; | |
| public enum Stage { | |
| ENTERED, PROGRESSING, REVIEWING, ACCEPTED | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment