diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/CalendarConstants.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/CalendarConstants.java index 4aa579033..0164bed95 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/CalendarConstants.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/CalendarConstants.java @@ -13,8 +13,9 @@ public class CalendarConstants { public static enum CALENDAR_SUPPORTED_PARAMETERS { CALENDAR_ID("id"), ENTITY_TYPE("entityType"), ENTITY_ID("entityId"), TITLE("title"), DESCRIPTION("description"), LOCATION( "location"), START_DATE("startDate"), END_DATE("endDate"), CREATED_DATE("createdDate"), DURATION("duration"), TYPE_ID( - "typeId"), REPEATING("repeating"), RECURRENCE("recurrence"), REMIND_BY_ID("remindById"), FIRST_REMINDER("firstReminder"), SECOND_REMINDER( - "secondReminder"), LOCALE("locale"), DATE_FORMAT("dateFormat"); + "typeId"), REPEATING("repeating"), REMIND_BY_ID("remindById"), FIRST_REMINDER("firstReminder"), SECOND_REMINDER( + "secondReminder"), LOCALE("locale"), DATE_FORMAT("dateFormat"), REPEATS("repeats"), REPEATS_EVERY("repeatsEvery"), + REPEATS_ON_DAY("repeatsOnDay"); private final String value; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/command/CalendarCommand.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/command/CalendarCommand.java index 5a9704a02..7d2a1d122 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/command/CalendarCommand.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/command/CalendarCommand.java @@ -28,8 +28,6 @@ public class CalendarCommand { @SuppressWarnings("unused") private final boolean repeating; @SuppressWarnings("unused") - private final String recurrence; - @SuppressWarnings("unused") private final Integer remindById; @SuppressWarnings("unused") private final Integer firstReminder; @@ -38,7 +36,7 @@ public class CalendarCommand { public CalendarCommand(final String title, final String description, final String location, final LocalDate startDate, final LocalDate endDate, final LocalDate createdDate, final Integer duration, final Integer typeId, final boolean repeating, - final String recurrence, final Integer remindById, final Integer firstReminder, final Integer secondReminder) { + final Integer remindById, final Integer firstReminder, final Integer secondReminder) { this.title = title; this.description = description; this.location = location; @@ -48,7 +46,6 @@ public class CalendarCommand { this.duration = duration; this.typeId = typeId; this.repeating = repeating; - this.recurrence = recurrence; this.remindById = remindById; this.firstReminder = firstReminder; this.secondReminder = secondReminder; 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 eb25c0a79..cb50d666d 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 @@ -113,12 +113,12 @@ public class Calendar extends AbstractAuditableCustom { final Integer duration = command.integerValueSansLocaleOfParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.DURATION.getValue()); final Integer typeId = command.integerValueSansLocaleOfParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.TYPE_ID.getValue()); final boolean repeating = command.booleanPrimitiveValueOfParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.REPEATING.getValue()); - final String recurrence = command.stringValueOfParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.RECURRENCE.getValue()); final Integer remindById = command.integerValueSansLocaleOfParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.REMIND_BY_ID.getValue()); final Integer firstReminder = command.integerValueSansLocaleOfParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.FIRST_REMINDER .getValue()); final Integer secondReminder = command.integerValueSansLocaleOfParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.SECOND_REMINDER .getValue()); + final String recurrence = Calendar.constructRecurrence(command, null); return new Calendar(title, description, location, startDate, endDate, duration, typeId, repeating, recurrence, remindById, firstReminder, secondReminder); @@ -205,27 +205,24 @@ public class Calendar extends AbstractAuditableCustom { this.repeating = newValue; } - //FIXME: AA Construct recurrence rule in API rather than getting it from UI - final String recurrenceParamName = CALENDAR_SUPPORTED_PARAMETERS.RECURRENCE.getValue(); - if (command.isChangeInStringParameterNamed(recurrenceParamName, this.recurrence)) { - final String newValue = command.stringValueOfParameterNamed(recurrenceParamName); + final String newRecurrence = Calendar.constructRecurrence(command, this); + if (this.recurrence != null && !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, newValue)){ + 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, newValue)){ + if(!CalendarUtils.isIntervalSame(this.recurrence, newRecurrence)){ final String defaultUserMessage = "Update of meeting interval is not supported"; throw new CalendarParameterUpdateNotSupportedException("meeting.interval", defaultUserMessage); } - - actualChanges.put(recurrenceParamName, newValue); - this.recurrence = StringUtils.defaultIfEmpty(newValue, null); + actualChanges.put("recurrence", newRecurrence); + this.recurrence = StringUtils.defaultIfEmpty(newRecurrence, null); } final String remindByParamName = CALENDAR_SUPPORTED_PARAMETERS.REMIND_BY_ID.getValue(); @@ -320,4 +317,36 @@ public class Calendar extends AbstractAuditableCustom { if (this.startDate != null && newStartDate != null && getStartDateLocalDate().isBefore(newStartDate)) { return true; } return false; } + + private static String constructRecurrence(final JsonCommand command, final Calendar calendar) { + final boolean repeating; + if (command.parameterExists(CALENDAR_SUPPORTED_PARAMETERS.REPEATING.getValue())) { + repeating = command.booleanPrimitiveValueOfParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.REPEATING.getValue()); + } else if (calendar != null) { + repeating = calendar.isRepeating(); + } else { + repeating = false; + } + + if (repeating) { + StringBuilder recurrenceBuilder = new StringBuilder(200); + final String repeats = command.stringValueOfParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.REPEATS.getValue()); + recurrenceBuilder.append("FREQ="); + recurrenceBuilder.append(repeats.toUpperCase()); + final Integer repeatsEvery = command.integerValueOfParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.REPEATS_EVERY.getValue()); + if (repeatsEvery > 1) { + recurrenceBuilder.append(";INTERVAL="); + recurrenceBuilder.append(repeatsEvery); + } + if (repeats.equalsIgnoreCase("Weekly")) { + final String repeatsOnDay = command.stringValueOfParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.REPEATS_ON_DAY.getValue()); + if (repeatsOnDay != null && repeatsOnDay != "") { + recurrenceBuilder.append(";BYDAY="); + recurrenceBuilder.append(repeatsOnDay); + } + } + return recurrenceBuilder.toString(); + } + return ""; + } } 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 8edafed63..f8198f49d 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 @@ -65,7 +65,6 @@ public class CalendarCommandFromApiJsonDeserializer extends AbstractFromApiJsonD final Integer typeId = this.fromApiJsonHelper.extractIntegerSansLocaleNamed(CALENDAR_SUPPORTED_PARAMETERS.TYPE_ID.getValue(), element); final boolean repeating = this.fromApiJsonHelper.extractBooleanNamed(CALENDAR_SUPPORTED_PARAMETERS.REPEATING.getValue(), element); - final String recurrence = this.fromApiJsonHelper.extractStringNamed(CALENDAR_SUPPORTED_PARAMETERS.RECURRENCE.getValue(), element); final Integer remindById = this.fromApiJsonHelper.extractIntegerSansLocaleNamed( CALENDAR_SUPPORTED_PARAMETERS.REMIND_BY_ID.getValue(), element); final Integer firstReminder = this.fromApiJsonHelper.extractIntegerSansLocaleNamed( @@ -73,8 +72,8 @@ public class CalendarCommandFromApiJsonDeserializer extends AbstractFromApiJsonD final Integer secondReminder = this.fromApiJsonHelper.extractIntegerSansLocaleNamed( CALENDAR_SUPPORTED_PARAMETERS.SECOND_REMINDER.getValue(), element); - return new CalendarCommand(title, description, location, startDate, endDate, createdDate, duration, typeId, repeating, recurrence, - remindById, firstReminder, secondReminder); + return new CalendarCommand(title, description, location, startDate, endDate, createdDate, duration, typeId, repeating, remindById, + firstReminder, secondReminder); } public void validateForCreate(final String json) { @@ -139,11 +138,25 @@ public class CalendarCommandFromApiJsonDeserializer extends AbstractFromApiJsonD final boolean repeating = this.fromApiJsonHelper.extractBooleanNamed(CALENDAR_SUPPORTED_PARAMETERS.REPEATING.getValue(), element); baseDataValidator.reset().parameter(CALENDAR_SUPPORTED_PARAMETERS.REPEATING.getValue()).value(repeating).notNull(); - - if(repeating){ - final String recurrence = this.fromApiJsonHelper.extractStringNamed(CALENDAR_SUPPORTED_PARAMETERS.RECURRENCE.getValue(), element); - baseDataValidator.reset().parameter(CALENDAR_SUPPORTED_PARAMETERS.RECURRENCE.getValue()).value(recurrence).notNull() - .notExceedingLengthOf(100).isValidRecurringRule(recurrence); + + if (repeating) { + final String repeats = this.fromApiJsonHelper.extractStringNamed(CALENDAR_SUPPORTED_PARAMETERS.REPEATS.getValue(), element); + baseDataValidator.reset().parameter(CALENDAR_SUPPORTED_PARAMETERS.REPEATS.getValue()).value(repeats).notBlank() + .notExceedingLengthOf(20); + + if (this.fromApiJsonHelper.parameterExists(CALENDAR_SUPPORTED_PARAMETERS.REPEATS_EVERY.getValue(), element)) { + final Integer repeatsEvery = this.fromApiJsonHelper.extractIntegerSansLocaleNamed( + CALENDAR_SUPPORTED_PARAMETERS.REPEATS_EVERY.getValue(), element); + baseDataValidator.reset().parameter(CALENDAR_SUPPORTED_PARAMETERS.REPEATS_EVERY.getValue()).value(repeatsEvery) + .notNull().integerGreaterThanZero(); + } + + if (this.fromApiJsonHelper.parameterExists(CALENDAR_SUPPORTED_PARAMETERS.REPEATS_ON_DAY.getValue(), element)) { + final String repeatsOnDay = this.fromApiJsonHelper.extractStringNamed( + CALENDAR_SUPPORTED_PARAMETERS.REPEATS_ON_DAY.getValue(), element); + baseDataValidator.reset().parameter(CALENDAR_SUPPORTED_PARAMETERS.REPEATS_ON_DAY.getValue()).value(repeatsOnDay) + .notBlank().notNull(); + } } } @@ -234,10 +247,24 @@ public class CalendarCommandFromApiJsonDeserializer extends AbstractFromApiJsonD element); baseDataValidator.reset().parameter(CALENDAR_SUPPORTED_PARAMETERS.REPEATING.getValue()).value(repeating).notNull(); - if(repeating){ - final String recurrence = this.fromApiJsonHelper.extractStringNamed(CALENDAR_SUPPORTED_PARAMETERS.RECURRENCE.getValue(), element); - baseDataValidator.reset().parameter(CALENDAR_SUPPORTED_PARAMETERS.RECURRENCE.getValue()).value(recurrence).notNull() - .notExceedingLengthOf(100).isValidRecurringRule(recurrence); + if (repeating) { + final String repeats = this.fromApiJsonHelper.extractStringNamed(CALENDAR_SUPPORTED_PARAMETERS.REPEATS.getValue(), element); + baseDataValidator.reset().parameter(CALENDAR_SUPPORTED_PARAMETERS.REPEATS.getValue()).value(repeats).ignoreIfNull() + .notBlank().notExceedingLengthOf(20); + + if (this.fromApiJsonHelper.parameterExists(CALENDAR_SUPPORTED_PARAMETERS.REPEATS_EVERY.getValue(), element)) { + final Integer repeatsEvery = this.fromApiJsonHelper.extractIntegerSansLocaleNamed( + CALENDAR_SUPPORTED_PARAMETERS.REPEATS_EVERY.getValue(), element); + baseDataValidator.reset().parameter(CALENDAR_SUPPORTED_PARAMETERS.REPEATS_EVERY.getValue()).value(repeatsEvery) + .notNull().integerGreaterThanZero(); + } + + if (this.fromApiJsonHelper.parameterExists(CALENDAR_SUPPORTED_PARAMETERS.REPEATS_ON_DAY.getValue(), element)) { + final String repeatsOnDay = this.fromApiJsonHelper.extractStringNamed( + CALENDAR_SUPPORTED_PARAMETERS.REPEATS_ON_DAY.getValue(), element); + baseDataValidator.reset().parameter(CALENDAR_SUPPORTED_PARAMETERS.REPEATS_ON_DAY.getValue()).value(repeatsOnDay) + .notBlank(); + } } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/service/CalendarReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/service/CalendarReadPlatformServiceImpl.java index 353c842f5..d82d58677 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/service/CalendarReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/service/CalendarReadPlatformServiceImpl.java @@ -72,7 +72,8 @@ public class CalendarReadPlatformServiceImpl implements CalendarReadPlatformServ if (remindById != null && remindById != 0) remindBy = CalendarEnumerations.calendarRemindBy(remindById); final Integer firstReminder = rs.getInt("firstReminder"); final Integer secondReminder = rs.getInt("secondReminder"); - final String humanReadable = CalendarUtils.getRRuleReadable(startDate, recurrence); + String humanReadable = null; + if (startDate != null && recurrence != null) humanReadable = CalendarUtils.getRRuleReadable(startDate, recurrence); final LocalDate createdDate = JdbcSupport.getLocalDate(rs, "createdDate"); final LocalDate lastUpdatedDate = JdbcSupport.getLocalDate(rs, "updatedDate"); 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 fe70c2e74..a329a15b1 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 @@ -135,6 +135,4 @@ public class CalendarWritePlatformServiceJpaRepositoryImpl implements CalendarWr .withEntityId(calendarForUpdate.getId()) // .build(); } - - }