From 8d007c259f9066eeb2edcc61ab10a80b02e1448b Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Thu, 14 Jan 2021 16:13:09 +0100 Subject: [PATCH] blocking accep[ted assignment deletions --- .../com/plannaplan/entities/Assignment.java | 15 +++++++++-- .../plannaplan/services/CommisionService.java | 25 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/buisnesslogic/src/main/java/com/plannaplan/entities/Assignment.java b/buisnesslogic/src/main/java/com/plannaplan/entities/Assignment.java index 5d5550d..f9468c2 100755 --- a/buisnesslogic/src/main/java/com/plannaplan/entities/Assignment.java +++ b/buisnesslogic/src/main/java/com/plannaplan/entities/Assignment.java @@ -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 * diff --git a/buisnesslogic/src/main/java/com/plannaplan/services/CommisionService.java b/buisnesslogic/src/main/java/com/plannaplan/services/CommisionService.java index 109dfd4..acfd674 100755 --- a/buisnesslogic/src/main/java/com/plannaplan/services/CommisionService.java +++ b/buisnesslogic/src/main/java/com/plannaplan/services/CommisionService.java @@ -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 lastCommision = this.getNewestCommision(commision.getCommisionOwner()); if (lastCommision.isPresent()) { + + final List assignments = commision.getAssignments(); + List 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 lastComAssignments = lastCom.getAssignments(); + if (newAssignments != null) { + Iterator 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;