Skip to content
Open
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
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
<plugins>
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/AgileTracker/tracker/TrackerApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,33 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.Collections;

@SpringBootApplication
public class TrackerApplication {

@Bean
public CorsFilter corsFilter() {
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
final CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
// Don't do this in production, use a proper list of allowed origins
config.setAllowedOrigins(Collections.singletonList("*"));
config.setAllowedHeaders(Arrays.asList("Origin", "Content-Type", "Accept"));
config.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "OPTIONS", "DELETE", "PATCH"));
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}

public static void main(String[] args) {
SpringApplication.run(TrackerApplication.class, args);
}
Expand Down
134 changes: 134 additions & 0 deletions src/main/java/com/AgileTracker/tracker/controller/OKRController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package com.AgileTracker.tracker.controller;

import com.AgileTracker.tracker.exceptions.GenericException;
import com.AgileTracker.tracker.model.*;
import com.AgileTracker.tracker.repository.OKRRepository;
import com.AgileTracker.tracker.repository.ProjectRepository;
import com.AgileTracker.tracker.repository.TaskRepository;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@RestController
@RequestMapping("/okr")
@JsonIgnoreProperties(value={"status", "actualEndDate"}, allowGetters = true)
@CrossOrigin(origins = { "http://localhost:8080" }, maxAge = 6000)
public class OKRController {
@Autowired
OKRRepository okr_repo;

@PostMapping(value = "/add", consumes = MediaType.APPLICATION_JSON_VALUE)
public OKR addOKR(@Valid @RequestBody OKR okr){
okr.setState(enums.okrState.NOT_STARTED);
return okr_repo.save(okr);
}

@GetMapping("/{id}")
public OKR getOKRById(@PathVariable(value="id") Long id) throws GenericException {
return okr_repo.findById(id).orElseThrow(
() -> new GenericException("Error getting project."));
}

@DeleteMapping("/delete/{id}")
public ResponseEntity<?> deleteProject(@PathVariable(value="id") Long id) throws GenericException{
OKR okr = okr_repo.findById(id).orElseThrow(
() -> new GenericException("Error getting OKR object."));
okr_repo.delete(okr);
return ResponseEntity.ok().build();
}

// @PostMapping("/edit/{id}", consumes = MediaType.APPLICATION_JSON_VALUE)
// public Project editProject(@PathVariable(value="id") Long id, @Valid @RequestBody Project project) throws GenericException{
// Project project_ = project_repo.findById(id).orElseThrow(
// () -> new GenericException("Error getting project."));
// project_repo.
// return project;
// }

@GetMapping("/all")
public List<OKR> getOKR(){
List<OKR> okr = okr_repo.findAll();
for(OKR o : okr) {
o.setProjects(new ArrayList<Project>());
o.setTeams(new ArrayList<Team>());
}
return okr;
}

@GetMapping("/{id}/start")
public ResponseEntity<?> beginReview(@PathVariable(value="id") Long id) throws GenericException{
OKR okr = okr_repo.findById(id).orElseThrow(
() -> new GenericException("Error getting project."));
if(okr.getState() != enums.okrState.NOT_STARTED)
throw new GenericException("Invalid operation!");
okr.setState(enums.okrState.IN_PROGRESS);
okr_repo.save(okr);
return ResponseEntity.ok().build();
}

@GetMapping("/{id}/review-start")
public ResponseEntity<?> endOKR(@PathVariable(value="id") Long id) throws GenericException{
OKR okr = okr_repo.findById(id).orElseThrow(
() -> new GenericException("Error getting project."));
if(okr.getState() != enums.okrState.IN_PROGRESS)
throw new GenericException("Invalid operation!");
okr.setState(enums.okrState.FINISHED);
okr_repo.save(okr);
return ResponseEntity.ok().build();
}

public static <T> Set<T> convertListToSet(List<T> list)
{
// create an empty set
Set<T> set = new HashSet<>();

// Add each element of list into the set
for (T t : list)
set.add(t);

// return the set
return set;
}

@GetMapping("/{oid}/projects/all")
public List<Project> getAllProjects(@PathVariable(value="oid") Long oid) throws GenericException{
OKR okr = okr_repo.findById(oid).orElseThrow(
() -> new GenericException("Error getting OKR."));
List<Project> projects = (okr.getProjects());
for(Project project : projects)
project.setOkr(null);
return projects;
}

@PostMapping(value = "/{oid}/projects/add", consumes = MediaType.APPLICATION_JSON_VALUE)
public Project addProject(@PathVariable(value="oid") Long oid,
@Valid @RequestBody Project project) throws GenericException{
OKR okr = okr_repo.findById(oid).orElseThrow(
() -> new GenericException("Error getting OKR."));
project.setState(enums.projectState.NOT_STARTED);
okr.getProjects().add(project);
project.setOkr(okr);
okr_repo.save(okr);
return project;
}

@GetMapping("/{oid}/projects/{pid}")
public Project getTask(@PathVariable(value="oid") Long oid,
@PathVariable(value="oid") Long pid) throws GenericException{
OKR okr = okr_repo.findById(oid).orElseThrow(
() -> new GenericException("Error getting OKR."));
for(Project project : okr.getProjects()){
if(project.getId().equals(pid))
return project;
}
throw new GenericException("Error getting project");
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.AgileTracker.tracker.controller;

import com.AgileTracker.tracker.exceptions.GenericException;
import com.AgileTracker.tracker.model.Project;
import com.AgileTracker.tracker.model.enums;
import com.AgileTracker.tracker.model.*;
import com.AgileTracker.tracker.repository.ProjectRepository;
import com.AgileTracker.tracker.repository.TaskRepository;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
Expand All @@ -15,18 +15,9 @@
import javax.validation.Valid;
import java.util.List;

enum projectState{
NOT_STARTED,
STARTED,
FINISHED;
}

@RestController
@RequestMapping("/project")
@JsonIgnoreProperties(value={"status", "startDate", "expectedEndDate", "actualEndDate"}, allowGetters = true)
@JsonIdentityInfo(
generator = ObjectIdGenerators.StringIdGenerator.class,
property = "id")
@JsonIgnoreProperties(value={"status", "actualEndDate"}, allowGetters = true)
public class ProjectController {
@Autowired
ProjectRepository project_repo;
Expand All @@ -51,12 +42,103 @@ public ResponseEntity<?> deleteProject(@PathVariable(value="id") Long id) throws
return ResponseEntity.ok().build();
}

// @PostMapping("/edit/{id}", consumes = MediaType.APPLICATION_JSON_VALUE)
// public Project editProject(@PathVariable(value="id") Long id, @Valid @RequestBody Project project) throws GenericException{
// Project project_ = project_repo.findById(id).orElseThrow(
// () -> new GenericException("Error getting project."));
// project_repo.
// return project;
// }

@GetMapping("/all")
public List<Project> getAllProjects(){
// System.out.println("aaaaa");
return project_repo.findAll();
List<Project> projects = project_repo.findAll();
for(Project project: projects)
project.setOkr(null);
return projects;
}

@GetMapping("/{id}/start")
public ResponseEntity<?> beginProject(@PathVariable(value="id") Long id) throws GenericException{
Project project = project_repo.findById(id).orElseThrow(
() -> new GenericException("Error getting project."));
if(project.getState() != enums.projectState.NOT_STARTED)
throw new GenericException("Invalid operation!");
project.setState(enums.projectState.STARTED);
project_repo.save(project);
return ResponseEntity.ok().build();

}

@GetMapping("/{id}/review-start")
public ResponseEntity<?> beginReview(@PathVariable(value="id") Long id) throws GenericException{
Project project = project_repo.findById(id).orElseThrow(
() -> new GenericException("Error getting project."));
if(project.getState() != enums.projectState.STARTED)
throw new GenericException("Invalid operation!");
project.setState(enums.projectState.IN_REVIEW);
project_repo.save(project);
return ResponseEntity.ok().build();

}

@GetMapping("/{pid}/tasks/all")
public List<Task> getAllTasks(@PathVariable(value="pid") Long pid) throws GenericException{
Project project = project_repo.findById(pid).orElseThrow(
() -> new GenericException("Error getting project."));
return project.getTasks();

}

@Autowired
TaskRepository task_repo;

@PostMapping(value = "/{pid}/tasks/add", consumes = MediaType.APPLICATION_JSON_VALUE)
public Task addTask(@PathVariable(value="pid") Long pid,
@Valid @RequestBody Task task) throws GenericException{
Project project = project_repo.findById(pid).orElseThrow(
() -> new GenericException("Error getting project."));
project.getTasks().add(task);
task.setProject(project);
project_repo.save(project);
return task;
}

@GetMapping("/{pid}/tasks/{tid}")
public Task getTask(@PathVariable(value="pid") Long pid,
@PathVariable(value="tid") Long tid) throws GenericException{
Project project = project_repo.findById(pid).orElseThrow(
() -> new GenericException("Error getting project."));
for(Task task : project.getTasks()){
if(task.getId() == tid)
return task;
}
throw new GenericException("Error getting task");
}

@PostMapping("/{pid}/review")
public ProjectReview doReview(@PathVariable(value="pid") Long pid,
@Valid @RequestBody ProjectReview review) throws GenericException{
Project project = project_repo.findById(pid).orElseThrow(
() -> new GenericException("Error getting project."));
if(project.getState() != enums.projectState.STARTED)
throw new GenericException("Cant review a project not started.");
project.setReview(review);
project_repo.save(project);
return review;
}

@GetMapping("/{pid}/review")
public ProjectReview getReview(@PathVariable(value="pid") Long pid) throws GenericException{
Project project = project_repo.findById(pid).orElseThrow(
() -> new GenericException("Error getting project."));
return project.getReview();
}

@GetMapping("/{pid}/sprints")
public List<Sprint> getSprints(@PathVariable(value="pid") Long pid) throws GenericException{
Project project = project_repo.findById(pid).orElseThrow(
() -> new GenericException("Error getting project."));
return project.getSprints();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.AgileTracker.tracker.controller;

import com.AgileTracker.tracker.exceptions.GenericException;
import com.AgileTracker.tracker.exceptions.SprintNotFoundException;
import com.AgileTracker.tracker.exceptions.TaskNotFoundException;
import com.AgileTracker.tracker.model.*;
import com.AgileTracker.tracker.repository.SprintRepository;
import com.AgileTracker.tracker.repository.TaskRepository;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.awt.*;

@RestController
@RequestMapping("/sprint")
@JsonIgnoreProperties(value = {"state"}, allowGetters = true)
public class SprintController {
@Autowired
SprintRepository sprint_repo;

@Autowired
TaskRepository task_repo;

@PostMapping(value = "/", consumes = MediaType.APPLICATION_JSON_VALUE)
public Sprint addSprint(@Valid @RequestBody Sprint sprint){
sprint.setState(enums.sprintState.NOT_STARTED);
sprint_repo.save(sprint);
}

@GetMapping("/{id}")
public Sprint getProjectById(@PathVariable(value="id") Long id) throws GenericException {
return sprint_repo.findById(id).orElseThrow(() -> new SprintNotFoundException());
}

@PostMapping(value = "/{id}/planning")
public Sprint startPlanning(@PathVariable(value="sid") Long sid, @Valid @RequestBody List<Long> task_list)
throws TaskNotFoundException {
Sprint sprint = sprint_repo.findById(sid).orElseThrow(() -> new SprintNotFoundException());

// todo -- add check so that if addition fails midway, the state changes are reverted
for(Long id : task_list){
Task task = task_repo.findById(id).orElse(() -> new TaskNotFoundException());
task.setState(enums.taskState.IN_PROGRESS);
sprint.getTasks().add(task);
task.setSprint(sprint);
}

sprint.setState(enums.sprintState.IN_PLANNING);
sprint.setPlanning(new SprintPlanning());
return sprint_repo.save(sprint);
}

@PostMapping(value = "/{id}/planning/{comment}")
public Sprint addPlanningComment(@PathVariable(value="sid") Long sid,
@PathVariable(value = "comment") String comment)
throws TaskNotFoundException{
Sprint sprint = sprint_repo.findById(sid).orElseThrow(() -> new SprintNotFoundException());
sprint.getPlanning().setComments(comment);
return sprint_repo.save(sprint);
}

}
Loading