Merge pull request #1164 from Nayan/MIFOSX-1680
#MIFOSX-1680 Option to change center meeting frequency and intervals
This commit is contained in:
-15
@@ -276,21 +276,6 @@ 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)) {
|
||||||
|
|
||||||
// FIXME: AA - Is this restriction required only for collection type
|
|
||||||
// meetings or for all?.
|
|
||||||
// Do not allow to change meeting frequency
|
|
||||||
|
|
||||||
if (!CalendarUtils.isFrequencySame(this.recurrence, newRecurrence)) {
|
|
||||||
final String defaultUserMessage = "Update of meeting frequency is not supported";
|
|
||||||
throw new CalendarParameterUpdateNotSupportedException("meeting.frequency", defaultUserMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do not allow to change meeting interval
|
|
||||||
if (!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);
|
||||||
}
|
}
|
||||||
|
|||||||
+8
@@ -41,4 +41,12 @@ public interface CalendarInstanceRepository extends JpaRepository<CalendarInstan
|
|||||||
@Query("from CalendarInstance ci where ci.entityId in (select id from Loan loan where loan.client.id = :clientId and loan.group.id = :groupId and (loan.loanStatus = 100 or loan.loanStatus = 200 or loan.loanStatus = 300)) and ci.entityTypeId = 3")
|
@Query("from CalendarInstance ci where ci.entityId in (select id from Loan loan where loan.client.id = :clientId and loan.group.id = :groupId and (loan.loanStatus = 100 or loan.loanStatus = 200 or loan.loanStatus = 300)) and ci.entityTypeId = 3")
|
||||||
List<CalendarInstance> findCalendarInstancesForActiveLoansByGroupIdAndClientId(@Param("groupId") Long groupId,
|
List<CalendarInstance> findCalendarInstancesForActiveLoansByGroupIdAndClientId(@Param("groupId") Long groupId,
|
||||||
@Param("clientId") Long clientId);
|
@Param("clientId") Long clientId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EntityType = 3 is for loan
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Query("SELECT COUNT(ci.id) FROM CalendarInstance ci, Loan ln WHERE ln.id = ci.entityId AND ci.entityTypeId = 3 AND ci.calendar.id = :calendarId AND ln.loanStatus IN :loanStatuses ")
|
||||||
|
Integer countOfActiveLoansWithSyncedToCalendar(@Param("calendarId") Long calendarId, @Param("loanStatuses") Collection<Integer> loanStatuses );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+29
@@ -25,6 +25,7 @@ import org.mifosplatform.portfolio.calendar.domain.CalendarEntityType;
|
|||||||
import org.mifosplatform.portfolio.calendar.domain.CalendarFrequencyType;
|
import org.mifosplatform.portfolio.calendar.domain.CalendarFrequencyType;
|
||||||
import org.mifosplatform.portfolio.calendar.domain.CalendarRemindBy;
|
import org.mifosplatform.portfolio.calendar.domain.CalendarRemindBy;
|
||||||
import org.mifosplatform.portfolio.calendar.domain.CalendarWeekDaysType;
|
import org.mifosplatform.portfolio.calendar.domain.CalendarWeekDaysType;
|
||||||
|
import org.mifosplatform.portfolio.calendar.exception.CalendarParameterUpdateNotSupportedException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -299,4 +300,32 @@ 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+19
@@ -6,6 +6,7 @@
|
|||||||
package org.mifosplatform.portfolio.calendar.service;
|
package org.mifosplatform.portfolio.calendar.service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -39,6 +40,7 @@ import org.mifosplatform.portfolio.group.domain.Group;
|
|||||||
import org.mifosplatform.portfolio.group.domain.GroupRepositoryWrapper;
|
import org.mifosplatform.portfolio.group.domain.GroupRepositoryWrapper;
|
||||||
import org.mifosplatform.portfolio.loanaccount.domain.Loan;
|
import org.mifosplatform.portfolio.loanaccount.domain.Loan;
|
||||||
import org.mifosplatform.portfolio.loanaccount.domain.LoanRepository;
|
import org.mifosplatform.portfolio.loanaccount.domain.LoanRepository;
|
||||||
|
import org.mifosplatform.portfolio.loanaccount.domain.LoanStatus;
|
||||||
import org.mifosplatform.portfolio.loanaccount.service.LoanWritePlatformService;
|
import org.mifosplatform.portfolio.loanaccount.service.LoanWritePlatformService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -154,9 +156,26 @@ public class CalendarWritePlatformServiceJpaRepositoryImpl implements CalendarWr
|
|||||||
@Override
|
@Override
|
||||||
public CommandProcessingResult updateCalendar(final JsonCommand command) {
|
public CommandProcessingResult updateCalendar(final JsonCommand command) {
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Validate all the data for updating the calendar
|
||||||
|
*/
|
||||||
|
|
||||||
this.fromApiJsonDeserializer.validateForUpdate(command.json());
|
this.fromApiJsonDeserializer.validateForUpdate(command.json());
|
||||||
|
|
||||||
final Long calendarId = command.entityId();
|
final Long calendarId = command.entityId();
|
||||||
|
|
||||||
|
final Collection<Integer> loanStatuses = new ArrayList<>(Arrays.asList(LoanStatus.SUBMITTED_AND_PENDING_APPROVAL.getValue(),
|
||||||
|
LoanStatus.APPROVED.getValue(), LoanStatus.ACTIVE.getValue()));
|
||||||
|
|
||||||
|
final Integer numberOfActiveLoansSyncedTheCalendar = this.calendarInstanceRepository.countOfActiveLoansWithSyncedToCalendar(calendarId, loanStatuses);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Validate all the business rules
|
||||||
|
*/
|
||||||
|
this.fromApiJsonDeserializer.validateBusinessRulesForUpdate(command.json(), numberOfActiveLoansSyncedTheCalendar);
|
||||||
|
|
||||||
|
|
||||||
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); }
|
||||||
final Date oldStartDate = calendarForUpdate.getStartDate();
|
final Date oldStartDate = calendarForUpdate.getStartDate();
|
||||||
|
|||||||
Reference in New Issue
Block a user