Added flaging assignment. Coumetr froup infor needs to be added
This commit is contained in:
parent
1ddeb83cb4
commit
c34ce94fb0
@ -18,12 +18,17 @@ public class Assignment {
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "commision_id")
|
||||
private Commision commision;
|
||||
private boolean isPastAssignment;
|
||||
|
||||
public Assignment(Groups group, Commision commision) {
|
||||
public Assignment(Groups group, Commision commision, boolean isPastAssignment) {
|
||||
this.commision = commision;
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public Assignment(Groups group, Commision commision) {
|
||||
this(group, commision, false);
|
||||
}
|
||||
|
||||
public Assignment() {
|
||||
}
|
||||
|
||||
@ -34,4 +39,12 @@ public class Assignment {
|
||||
public Groups getGroup() {
|
||||
return this.group;
|
||||
}
|
||||
|
||||
public boolean isPastAssignment() {
|
||||
return isPastAssignment;
|
||||
}
|
||||
|
||||
public void setPastAssignment(boolean isPastAssignment) {
|
||||
this.isPastAssignment = isPastAssignment;
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
@ -21,9 +22,14 @@ public class Commision {
|
||||
private User commisionOwner;
|
||||
private Timestamp commisionDate;
|
||||
|
||||
@OneToMany(mappedBy = "commision")
|
||||
@OneToMany(mappedBy = "commision", fetch = FetchType.EAGER)
|
||||
private List<Assignment> assignments;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param user owner of commission. Can not be null otherwise saving commision
|
||||
* will fail.
|
||||
*/
|
||||
public Commision(User user) {
|
||||
this.commisionDate = new Timestamp(System.currentTimeMillis());
|
||||
this.commisionOwner = user;
|
||||
@ -44,4 +50,8 @@ public class Commision {
|
||||
return commisionOwner;
|
||||
}
|
||||
|
||||
public List<Assignment> getAssignments() {
|
||||
return this.assignments;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
@ -17,8 +18,8 @@ public class AssignmentService {
|
||||
public AssignmentService() {
|
||||
}
|
||||
|
||||
public void save(Assignment assignment) {
|
||||
this.repo.save(assignment);
|
||||
public Assignment save(Assignment assignment) {
|
||||
return this.repo.save(assignment);
|
||||
}
|
||||
|
||||
public List<Assignment> getCommisionAssignments(Commision com) {
|
||||
@ -28,4 +29,8 @@ public class AssignmentService {
|
||||
public long getAssignmentsAmmount() {
|
||||
return this.repo.count();
|
||||
}
|
||||
|
||||
public Optional<Assignment> getById(Long id) {
|
||||
return this.repo.findById(id);
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ import java.util.Optional;
|
||||
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.repositories.AssignmentRepository;
|
||||
import com.plannaplan.repositories.CommisionRepository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -14,11 +15,21 @@ import org.springframework.stereotype.Service;
|
||||
public class CommisionService {
|
||||
@Autowired
|
||||
private CommisionRepository repo;
|
||||
@Autowired
|
||||
private AssignmentRepository aRepository;
|
||||
|
||||
public CommisionService() {
|
||||
}
|
||||
|
||||
public Commision save(Commision commision) {
|
||||
Optional<Commision> lastCommision = this.getNewestCommision(commision.getCommisionOwner());
|
||||
if (lastCommision.isPresent()) {
|
||||
final Commision lastCom = lastCommision.get();
|
||||
lastCom.getAssignments().forEach(assignment -> {
|
||||
assignment.setPastAssignment(true);
|
||||
this.aRepository.save(assignment);
|
||||
});
|
||||
}
|
||||
this.repo.save(commision);
|
||||
return commision;
|
||||
|
||||
|
@ -11,8 +11,9 @@ import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
@ -26,24 +27,31 @@ public class AssignmentServiceTest {
|
||||
private AssignmentService service;
|
||||
@Autowired
|
||||
private CommisionService comServie;
|
||||
private Commision com;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
this.com = new Commision();
|
||||
this.comServie.save(this.com);
|
||||
}
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Test
|
||||
public void shouldSaveAssignment() {
|
||||
final User user = new User("Gibi", "Kovalsky", "shouldSaveAssignment@assignmentservice.test",
|
||||
UserRoles.STUDENT);
|
||||
this.userService.save(user);
|
||||
|
||||
long beginState = this.service.getAssignmentsAmmount();
|
||||
this.addAssignmentToCommision(this.com);
|
||||
Commision com = new Commision(user);
|
||||
this.comServie.save(com);
|
||||
this.addAssignmentToCommision(com);
|
||||
assertTrue("Assign ammount should increase", this.service.getAssignmentsAmmount() > beginState);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetCommisionAssignments() {
|
||||
this.addAssignmentToCommision(this.com);
|
||||
final User user = new User("Gibi", "Kovalsky", "shouldGetCommisionAssignments@assignmentservice.test",
|
||||
UserRoles.STUDENT);
|
||||
this.userService.save(user);
|
||||
Commision com = new Commision(user);
|
||||
this.comServie.save(com);
|
||||
this.addAssignmentToCommision(com);
|
||||
|
||||
final List<Assignment> response = this.service.getCommisionAssignments(com);
|
||||
assertTrue("Returned list size should be 1", response.size() == 1);
|
||||
}
|
||||
|
@ -7,8 +7,10 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -24,10 +26,15 @@ public class CommisionServiceTest {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private AssignmentService assignmentService;
|
||||
|
||||
@Test
|
||||
public void shouldSaveCommision() {
|
||||
User usr = new User();
|
||||
this.userService.save(usr);
|
||||
long beginState = this.service.getCommisionsAmmount();
|
||||
this.service.save(new Commision());
|
||||
this.service.save(new Commision(usr));
|
||||
assertTrue("Commision ammount should have changed", this.service.getCommisionsAmmount() > beginState);
|
||||
}
|
||||
|
||||
@ -57,4 +64,31 @@ public class CommisionServiceTest {
|
||||
assertTrue("Wrong commision was returned", result.getId().equals(newestCommision.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMarkAssignmentsOfPreviousCommisionPast() {
|
||||
final User usr = new User("Trevor", "Hammolt",
|
||||
"shouldMarkAssignmentsOfPreviousCommisionPast@commisionservice.test", UserRoles.STUDENT);
|
||||
this.userService.save(usr);
|
||||
|
||||
final Commision firstCommision = new Commision(usr);
|
||||
this.service.save(firstCommision);
|
||||
|
||||
Assignment firstCommisionAssignment = this.assignmentService.save(new Assignment(null, firstCommision));
|
||||
|
||||
assertTrue("FirstCommisionAssignment should be flaged as present assignment",
|
||||
!firstCommisionAssignment.isPastAssignment());
|
||||
|
||||
final Commision secondCommision = new Commision(usr);
|
||||
this.service.save(secondCommision);
|
||||
|
||||
Assignment secondCommisionAssignment = new Assignment(null, secondCommision);
|
||||
this.assignmentService.save(secondCommisionAssignment);
|
||||
|
||||
assertTrue("SecondCommisionAssignment should be flaged as present assignment",
|
||||
!secondCommisionAssignment.isPastAssignment());
|
||||
assertTrue("FirstCommisionAssignment should be flaged as past assignment",
|
||||
this.assignmentService.getById(firstCommisionAssignment.getId()).get().isPastAssignment());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public class App {
|
||||
filip.setEmail("filizy@st.amu.edu.pl");
|
||||
filip.setName("Filip");
|
||||
filip.setSurname("Izydorczyk");
|
||||
filip.setRole(UserRoles.ADMIN);
|
||||
filip.setRole(UserRoles.STUDENT);
|
||||
this.userService.save(filip);
|
||||
|
||||
User hub = new User();
|
||||
|
Loading…
Reference in New Issue
Block a user