From 11ba1f53013f928a3e38cc856b0ef24205d35b18 Mon Sep 17 00:00:00 2001 From: Nayan Date: Wed, 17 Dec 2014 15:01:19 +0530 Subject: [PATCH] Allow to modifiy frequncy and intervals if calendar is NOT synced with any active entity --- .../portfolio/calendar/domain/Calendar.java | 21 +++++++++++++- ...alendarCommandFromApiJsonDeserializer.java | 28 ------------------- ...WritePlatformServiceJpaRepositoryImpl.java | 16 +++++++---- 3 files changed, 31 insertions(+), 34 deletions(-) diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/domain/Calendar.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/domain/Calendar.java index faa47e238..8889be7f6 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/domain/Calendar.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/domain/Calendar.java @@ -221,7 +221,7 @@ public class Calendar extends AbstractAuditableCustom { } - public Map update(final JsonCommand command) { + public Map update(final JsonCommand command, final Boolean areActiveEntitiesSynced ) { final Map actualChanges = new LinkedHashMap<>(9); @@ -328,6 +328,25 @@ public class Calendar extends AbstractAuditableCustom { final String newRecurrence = Calendar.constructRecurrence(command, this); if (!StringUtils.isBlank(this.recurrence) && !newRecurrence.equalsIgnoreCase(this.recurrence)) { + /* + * If active entities like JLG loan or RD accounts are synced to the + * calendar then do not allow to change meeting frequency + */ + + if ( areActiveEntitiesSynced && !CalendarUtils.isFrequencySame(this.recurrence, newRecurrence)) { + final String defaultUserMessage = "Update of meeting frequency is not supported"; + throw new CalendarParameterUpdateNotSupportedException("meeting.frequency", defaultUserMessage); + } + + /* + * If active entities like JLG loan or RD accounts are synced to the + * calendar then do not allow to change meeting interval + */ + + if (areActiveEntitiesSynced && !CalendarUtils.isIntervalSame(this.recurrence, newRecurrence)) { + final String defaultUserMessage = "Update of meeting interval is not supported"; + throw new CalendarParameterUpdateNotSupportedException("meeting.interval", defaultUserMessage); + } actualChanges.put("recurrence", newRecurrence); this.recurrence = StringUtils.defaultIfEmpty(newRecurrence, null); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/serialization/CalendarCommandFromApiJsonDeserializer.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/serialization/CalendarCommandFromApiJsonDeserializer.java index f32634abc..980136638 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/serialization/CalendarCommandFromApiJsonDeserializer.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/serialization/CalendarCommandFromApiJsonDeserializer.java @@ -319,33 +319,5 @@ public class CalendarCommandFromApiJsonDeserializer extends AbstractFromApiJsonD if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); } } - - public void validateBusinessRulesForUpdate(final String json, final Integer numberOfActiveLoansSyncedTheCalendar) { - - - final JsonElement element = this.fromApiJsonHelper.parse(json); - - /* - * BR1: If calendar is not associated with any of the active loans, RD - * accounts and any other active entity then only frequency and interval - * are allowed to change - */ - - if (numberOfActiveLoansSyncedTheCalendar > 0) { - - if (this.fromApiJsonHelper.parameterExists(CALENDAR_SUPPORTED_PARAMETERS.FREQUENCY.getValue(), element)) { - final String defaultUserMessage = "Update of meeting frequency is not supported"; - throw new CalendarParameterUpdateNotSupportedException("meeting.frequency", defaultUserMessage); - } - - if (this.fromApiJsonHelper.parameterExists(CALENDAR_SUPPORTED_PARAMETERS.INTERVAL.getValue(), element)) { - final String defaultUserMessage = "Update of meeting interval is not supported"; - throw new CalendarParameterUpdateNotSupportedException("meeting.interval", defaultUserMessage); - } - - } - - } - } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/service/CalendarWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/service/CalendarWritePlatformServiceJpaRepositoryImpl.java index 99ccdb4fb..36212efe0 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/service/CalendarWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/service/CalendarWritePlatformServiceJpaRepositoryImpl.java @@ -159,9 +159,10 @@ public class CalendarWritePlatformServiceJpaRepositoryImpl implements CalendarWr /* * Validate all the data for updating the calendar */ - + this.fromApiJsonDeserializer.validateForUpdate(command.json()); - + + Boolean areActiveEntitiesSynced = false; final Long calendarId = command.entityId(); final Collection loanStatuses = new ArrayList<>(Arrays.asList(LoanStatus.SUBMITTED_AND_PENDING_APPROVAL.getValue(), @@ -171,10 +172,15 @@ public class CalendarWritePlatformServiceJpaRepositoryImpl implements CalendarWr calendarId, loanStatuses); /* - * Validate all the business rules + * areActiveEntitiesSynced is set to true, if there are any active loans + * synced to this calendar. */ - this.fromApiJsonDeserializer.validateBusinessRulesForUpdate(command.json(), numberOfActiveLoansSyncedWithThisCalendar); + + if(numberOfActiveLoansSyncedWithThisCalendar > 0){ + areActiveEntitiesSynced = true; + } + final Calendar calendarForUpdate = this.calendarRepository.findOne(calendarId); if (calendarForUpdate == null) { throw new CalendarNotFoundException(calendarId); } @@ -222,7 +228,7 @@ public class CalendarWritePlatformServiceJpaRepositoryImpl implements CalendarWr changes = calendarForUpdate.updateStartDateAndDerivedFeilds(newMeetingDate); } else { - changes = calendarForUpdate.update(command); + changes = calendarForUpdate.update(command, areActiveEntitiesSynced); } if (!changes.isEmpty()) {