Merge pull request #534 from mifoscontributer/mifosx-440
Meeting calendar cleanup
This commit is contained in:
+3
-2
@@ -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;
|
||||
|
||||
|
||||
+1
-4
@@ -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;
|
||||
|
||||
+39
-10
@@ -113,12 +113,12 @@ public class Calendar extends AbstractAuditableCustom<AppUser, Long> {
|
||||
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<AppUser, Long> {
|
||||
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<AppUser, Long> {
|
||||
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 "";
|
||||
}
|
||||
}
|
||||
|
||||
+39
-12
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -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");
|
||||
|
||||
-2
@@ -135,6 +135,4 @@ public class CalendarWritePlatformServiceJpaRepositoryImpl implements CalendarWr
|
||||
.withEntityId(calendarForUpdate.getId()) //
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user