Skip to content

Commit

Permalink
Merge pull request #1644 from ricardorcr/preventDuplicateDebts/ACDM-1768
Browse files Browse the repository at this point in the history
Prevented duplicating debts events ACDM-1768 #resolve
  • Loading branch information
ricardorcr authored Jul 24, 2020
2 parents 2646c53 + 7a248bf commit 8878b6a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,27 @@ private static Optional<EventType> getEventType(EnrolmentEvaluation enrolmentEva

public static EnrolmentEvaluationEvent create(EnrolmentEvaluation enrolmentEvaluation) {
final Person student = enrolmentEvaluation.getStudentCurricularPlan().getPerson();

final AdministrativeOffice administrativeOffice = enrolmentEvaluation.getStudentCurricularPlan()
.getAdministrativeOffice();

final EventType eventType = getEventType(enrolmentEvaluation).orElseThrow(
() -> new DomainException("Unsupported enrolment evaluation",
enrolmentEvaluation.getEvaluationSeason().getName().getContent()));

EnrolmentEvaluationEvent enrolmentEvaluationEvent = enrolmentEvaluation.getEnrolment().getPerson().getEventsByEventType(eventType).stream()
.filter(EnrolmentEvaluationEvent.class::isInstance)
.map(EnrolmentEvaluationEvent.class::cast)
.filter(e -> e.getEnrolmentEvaluation() == null)
.filter(e -> !e.isCancelled())
.filter(e -> enrolmentEvaluation.getEnrolment().getName().equals(e.getCourseName()))
.filter(e -> enrolmentEvaluation.getExecutionPeriod().getQualifiedName().equals(e.getExecutionPeriodName()))
.findAny().orElse(null);
if (enrolmentEvaluationEvent != null) {
FenixFramework.atomic(() -> enrolmentEvaluationEvent.setEnrolmentEvaluation(enrolmentEvaluation));
return enrolmentEvaluationEvent;
}

final PostingRule eventTypePR =
administrativeOffice.getServiceAgreementTemplate().findPostingRuleByEventType(eventType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@ public void cancel(Person responsible, String cancelJustification) {
public static EnrolmentGratuityEvent create(Person person, Enrolment enrolment, EventType eventType, boolean forAliens) {
final ExecutionYear executionYear = enrolment.getExecutionYear();

//when there are enrollments and unenrollments in curricular units the connection to the enrolment is lost but the event still remains
//whe don't want to create several different events for the same curricular unit
EnrolmentGratuityEvent enrolmentGratuityEvent = person.getEventsByEventType(eventType).stream()
.filter(EnrolmentGratuityEvent.class::isInstance)
.map(EnrolmentGratuityEvent.class::cast)
.filter(e -> e.getEnrolment() == null)
.filter(e -> !e.isCancelled())
.filter(e -> e.getEventPostingRule().isForAliens() == forAliens)
.filter(e -> e.getCourseName().equals(enrolment.getName()))
.filter(e -> e.getExecutionPeriodName().equals(enrolment.getExecutionPeriod().getQualifiedName()))
.filter(e -> e.getEcts().equals(enrolment.getEctsCreditsForCurriculum()))
.findAny().orElse(null);
if (enrolmentGratuityEvent != null) {
FenixFramework.atomic(() -> enrolmentGratuityEvent.setEnrolment(enrolment));
return enrolmentGratuityEvent;
}

Set<PostingRule> postingRules =
enrolment.getStudentCurricularPlan().getDegreeCurricularPlan().getServiceAgreementTemplate()
.getPostingRulesBy(eventType, executionYear.getBeginLocalDate().toDateTimeAtStartOfDay(),
Expand Down

0 comments on commit 8878b6a

Please sign in to comment.