Allow to modifiy frequncy and intervals if calendar is NOT synced with any active entity
This commit is contained in:
+20
-1
@@ -221,7 +221,7 @@ public class Calendar extends AbstractAuditableCustom<AppUser, Long> {
|
||||
|
||||
}
|
||||
|
||||
public Map<String, Object> update(final JsonCommand command) {
|
||||
public Map<String, Object> update(final JsonCommand command, final Boolean areActiveEntitiesSynced ) {
|
||||
|
||||
final Map<String, Object> actualChanges = new LinkedHashMap<>(9);
|
||||
|
||||
@@ -328,6 +328,25 @@ public class Calendar extends AbstractAuditableCustom<AppUser, Long> {
|
||||
|
||||
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);
|
||||
|
||||
-28
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+11
-5
@@ -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<Integer> 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()) {
|
||||
|
||||
Reference in New Issue
Block a user