diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java index af23d3d99..240f6f7fb 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java @@ -1336,6 +1336,7 @@ public class CommandWrapperBuilder { this.actionName = "UPDATE"; this.entityName = "CALENDAR"; this.entityId = calendarId; + this.groupId = supportedEntityId; this.href = "/" + supportedEntityType + "/" + supportedEntityId + "/calendars/" + calendarId; return this; } 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 36212efe0..5f721c218 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 @@ -153,13 +153,54 @@ public class CalendarWritePlatformServiceJpaRepositoryImpl implements CalendarWr } + + public void validateIsEditMeetingAllowed(Long groupId) { + + final List dataValidationErrors = new ArrayList<>(); + final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder( + dataValidationErrors).resource("calendar"); + Group centerOrGroup = null; + + if (groupId != null) { + centerOrGroup = this.groupRepository + .findOneWithNotFoundDetection(groupId); + final Group parent = centerOrGroup.getParent(); + /* Check if it is a Group and belongs to a center */ + if (centerOrGroup.isGroup() && parent != null) { + + Integer centerEntityTypeId = CalendarEntityType.CENTERS + .getValue(); + /* Check if calendar is created at center */ + final CalendarInstance collectionCalendarInstance = this.calendarInstanceRepository + .findByEntityIdAndEntityTypeIdAndCalendarTypeId( + parent.getId(), centerEntityTypeId, + CalendarType.COLLECTION.getValue()); + /* If calendar is created by parent group, then it cannot be edited by the child group */ + if (collectionCalendarInstance != null) { + final String errorMessage = "meeting.created.at.center.cannot.be.edited.at.group.level"; + baseDataValidator.reset() + .failWithCodeNoParameterAddedToErrorCode( + errorMessage); + } + } + + } + if (!dataValidationErrors.isEmpty()) { + throw new PlatformApiDataValidationException( + "validation.msg.validation.errors.exist", + "Validation errors exist.", dataValidationErrors); + } + + } + @Override public CommandProcessingResult updateCalendar(final JsonCommand command) { + /** Validate to check if Edit is Allowed **/ + this.validateIsEditMeetingAllowed(command.getGroupId()); /* * Validate all the data for updating the calendar */ - this.fromApiJsonDeserializer.validateForUpdate(command.json()); Boolean areActiveEntitiesSynced = false;