blocking accep[ted assignment deletions
This commit is contained in:
parent
28e872ce3a
commit
8d007c259f
@ -38,6 +38,15 @@ public class Assignment {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param oldAssignment old assignment that we want to move to new commision
|
||||
* @param newCommision commsion to move assiongment
|
||||
*/
|
||||
public static Assignment getNewFromAssignment(Assignment oldAssignment, Commision newCommision) {
|
||||
return new Assignment(oldAssignment.getGroup(), newCommision);
|
||||
}
|
||||
|
||||
/**
|
||||
* If it returns trues it mesans u are assigned to group accepted by algorythm
|
||||
*
|
||||
@ -49,9 +58,10 @@ public class Assignment {
|
||||
|
||||
/**
|
||||
* Getter of commision
|
||||
*
|
||||
* @return Commision Commision of given assignments
|
||||
*/
|
||||
public Commision getCommision(){
|
||||
public Commision getCommision() {
|
||||
return this.commision;
|
||||
}
|
||||
|
||||
@ -69,8 +79,9 @@ public class Assignment {
|
||||
}
|
||||
|
||||
public void setCommision(Commision commision) {
|
||||
this.commision = commision;
|
||||
this.commision = commision;
|
||||
}
|
||||
|
||||
/**
|
||||
* Id getter
|
||||
*
|
||||
|
@ -1,8 +1,11 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.repositories.AssignmentRepository;
|
||||
@ -29,11 +32,33 @@ public class CommisionService {
|
||||
public Commision save(Commision commision) {
|
||||
Optional<Commision> lastCommision = this.getNewestCommision(commision.getCommisionOwner());
|
||||
if (lastCommision.isPresent()) {
|
||||
|
||||
final List<Assignment> assignments = commision.getAssignments();
|
||||
List<Long> newAssignments = null;
|
||||
if (assignments != null) {
|
||||
newAssignments = assignments.stream().map(Assignment::getId).collect(Collectors.toList());
|
||||
}
|
||||
final Commision lastCom = lastCommision.get();
|
||||
lastCom.getAssignments().forEach(assignment -> {
|
||||
assignment.setPastAssignment(true);
|
||||
this.aRepository.save(assignment);
|
||||
});
|
||||
|
||||
final List<Assignment> lastComAssignments = lastCom.getAssignments();
|
||||
if (newAssignments != null) {
|
||||
Iterator<Assignment> newAssignmentsIterator = lastComAssignments.iterator();
|
||||
|
||||
while (newAssignmentsIterator.hasNext()) {
|
||||
final Assignment a = newAssignmentsIterator.next();
|
||||
|
||||
if (!newAssignments.contains(a.getId()) && a.isAccepted()) {
|
||||
final Assignment assignment = Assignment.getNewFromAssignment(a, commision);
|
||||
this.aRepository.save(assignment);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
this.repo.save(commision);
|
||||
return commision;
|
||||
|
Loading…
Reference in New Issue
Block a user