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);
|
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);
|
final String newRecurrence = Calendar.constructRecurrence(command, this);
|
||||||
if (!StringUtils.isBlank(this.recurrence) && !newRecurrence.equalsIgnoreCase(this.recurrence)) {
|
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);
|
actualChanges.put("recurrence", newRecurrence);
|
||||||
this.recurrence = StringUtils.defaultIfEmpty(newRecurrence, null);
|
this.recurrence = StringUtils.defaultIfEmpty(newRecurrence, null);
|
||||||
|
|||||||
-28
@@ -320,32 +320,4 @@ public class CalendarCommandFromApiJsonDeserializer extends AbstractFromApiJsonD
|
|||||||
"Validation errors exist.", dataValidationErrors); }
|
"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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-3
@@ -162,6 +162,7 @@ public class CalendarWritePlatformServiceJpaRepositoryImpl implements CalendarWr
|
|||||||
|
|
||||||
this.fromApiJsonDeserializer.validateForUpdate(command.json());
|
this.fromApiJsonDeserializer.validateForUpdate(command.json());
|
||||||
|
|
||||||
|
Boolean areActiveEntitiesSynced = false;
|
||||||
final Long calendarId = command.entityId();
|
final Long calendarId = command.entityId();
|
||||||
|
|
||||||
final Collection<Integer> loanStatuses = new ArrayList<>(Arrays.asList(LoanStatus.SUBMITTED_AND_PENDING_APPROVAL.getValue(),
|
final Collection<Integer> loanStatuses = new ArrayList<>(Arrays.asList(LoanStatus.SUBMITTED_AND_PENDING_APPROVAL.getValue(),
|
||||||
@@ -171,9 +172,14 @@ public class CalendarWritePlatformServiceJpaRepositoryImpl implements CalendarWr
|
|||||||
calendarId, loanStatuses);
|
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);
|
final Calendar calendarForUpdate = this.calendarRepository.findOne(calendarId);
|
||||||
if (calendarForUpdate == null) { throw new CalendarNotFoundException(calendarId); }
|
if (calendarForUpdate == null) { throw new CalendarNotFoundException(calendarId); }
|
||||||
@@ -222,7 +228,7 @@ public class CalendarWritePlatformServiceJpaRepositoryImpl implements CalendarWr
|
|||||||
changes = calendarForUpdate.updateStartDateAndDerivedFeilds(newMeetingDate);
|
changes = calendarForUpdate.updateStartDateAndDerivedFeilds(newMeetingDate);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
changes = calendarForUpdate.update(command);
|
changes = calendarForUpdate.update(command, areActiveEntitiesSynced);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!changes.isEmpty()) {
|
if (!changes.isEmpty()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user