Checkpint - algorythm works

This commit is contained in:
Filip Izydorczyk
2021-01-03 16:21:06 +01:00
parent 2c0008afe1
commit 0f8b4eafb5
5 changed files with 59 additions and 34 deletions

View File

@ -25,7 +25,6 @@ public class Assignment {
@JoinColumn(name = "commision_id")
private Commision commision;
private boolean isPastAssignment;
private boolean isAccepted;
/**
* Assignment
@ -37,7 +36,6 @@ public class Assignment {
public Assignment(Groups group, Commision commision, boolean isPastAssignment) {
this.commision = commision;
this.group = group;
this.isAccepted = false;
}
/**
@ -46,16 +44,7 @@ public class Assignment {
* @return boolean isAccepted
*/
public boolean isAccepted() {
return isAccepted;
}
/**
* Set is accepted by algorythm
*
* @param isAccepted boolean isAccepted
*/
public void setAccepted(boolean isAccepted) {
this.isAccepted = isAccepted;
return this.group.getRegisteredStudents().contains(this.commision.getCommisionOwner());
}
/**

View File

@ -4,6 +4,7 @@ import java.util.HashSet;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@ -40,7 +41,7 @@ public class Groups {
private Lecturer lecturer;
private Integer zajCykId;
private Integer grNr;
@ManyToMany(mappedBy = "studentRegisteredGrups")
@ManyToMany(mappedBy = "studentRegisteredGrups", fetch = FetchType.EAGER)
private Set<User> registeredStudents;
public Set<User> getRegisteredStudents() {

View File

@ -8,6 +8,7 @@ import java.util.concurrent.TimeUnit;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@ -38,7 +39,7 @@ public class User {
private String refreshToken;
private Timestamp tokenUsageDate;
private Integer ranking;
@ManyToMany(cascade = CascadeType.ALL)
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable
private Set<Groups> studentRegisteredGrups;

View File

@ -5,6 +5,7 @@ import java.util.Optional;
import com.plannaplan.entities.Assignment;
import com.plannaplan.entities.Commision;
import com.plannaplan.entities.Groups;
import com.plannaplan.entities.User;
import com.plannaplan.repositories.AssignmentRepository;
@ -21,6 +22,12 @@ public class AssignmentService {
@Autowired
private AssignmentRepository repo;
@Autowired
private CommisionService service;
@Autowired
private GroupService groupService;
@Autowired
private UserService userService;
@ -65,7 +72,17 @@ public class AssignmentService {
final List<User> students = this.userService.getStudentsSortedByRanking();
students.forEach(e -> {
System.out.println(e.getRanking());
final Optional<Commision> com = this.service.getNewestCommision(e);
if (com.isPresent()) {
final List<Assignment> assignments = this.getCommisionAssignments(com.get());
assignments.forEach(a -> {
final Groups group = a.getGroup();
if (group.getCapacity() > group.getRegisteredStudents().size()) {
e.claimGroup(group);
this.userService.save(e);
}
});
}
});
}
}