@@ -132,7 +132,7 @@ public void validateForCreate(final JsonCommand command) {
132132 baseDataValidator .reset ().parameter (StandingInstructionApiConstants .instructionTypeParamName ).value (standingInstructionType )
133133 .notNull ().inMinMaxRange (1 , 2 );
134134
135- if (standingInstructionType != null && StandingInstructionType . fromInt (standingInstructionType ). isFixedAmoutTransfer ( )) {
135+ if (isAmountRequired (standingInstructionType )) {
136136 baseDataValidator .reset ().parameter (StandingInstructionApiConstants .amountParamName ).value (transferAmount ).notNull ();
137137 }
138138
@@ -156,7 +156,7 @@ public void validateForCreate(final JsonCommand command) {
156156 final MonthDay monthDay = this .fromApiJsonHelper
157157 .extractMonthDayNamed (StandingInstructionApiConstants .recurrenceOnMonthDayParamName , element );
158158
159- if (standingInstructionType == null || ! StandingInstructionType . fromInt (standingInstructionType ). isDuesAmoutTransfer ( )) {
159+ if (isRecurrenceRequired (standingInstructionType )) {
160160 baseDataValidator .reset ().parameter (StandingInstructionApiConstants .recurrenceOnMonthDayParamName ).value (monthDay )
161161 .notNull ();
162162 }
@@ -166,7 +166,7 @@ public void validateForCreate(final JsonCommand command) {
166166 final Integer recurrenceInterval = this .fromApiJsonHelper
167167 .extractIntegerNamed (StandingInstructionApiConstants .recurrenceIntervalParamName , element , Locale .getDefault ());
168168 if (isPeriodic ) {
169- if (standingInstructionType == null || ! StandingInstructionType . fromInt (standingInstructionType ). isDuesAmoutTransfer ( )) {
169+ if (isRecurrenceRequired (standingInstructionType )) {
170170 baseDataValidator .reset ().parameter (StandingInstructionApiConstants .recurrenceIntervalParamName ).value (recurrenceInterval )
171171 .notNull ();
172172 baseDataValidator .reset ().parameter (StandingInstructionApiConstants .recurrenceFrequencyParamName ).value (recurrenceFrequency )
@@ -187,7 +187,7 @@ public void validateForCreate(final JsonCommand command) {
187187 .inMinMaxRange (1 , 1 );
188188
189189 }
190- if (standingInstructionType != null && StandingInstructionType . fromInt (standingInstructionType ). isFixedAmoutTransfer ( )) {
190+ if (isAmountRequired (standingInstructionType )) {
191191 baseDataValidator .reset ().parameter (StandingInstructionApiConstants .amountParamName ).value (transferAmount ).notNull ();
192192 }
193193
@@ -252,7 +252,7 @@ public void validateForUpdate(final JsonCommand command) {
252252 .extractBigDecimalWithLocaleNamed (StandingInstructionApiConstants .amountParamName , element );
253253 baseDataValidator .reset ().parameter (StandingInstructionApiConstants .amountParamName ).value (transferAmount ).positiveAmount ();
254254
255- if (standingInstructionType != null && StandingInstructionType . fromInt (standingInstructionType ). isFixedAmoutTransfer ( )) {
255+ if (isAmountRequired (standingInstructionType )) {
256256 baseDataValidator .reset ().parameter (StandingInstructionApiConstants .amountParamName ).value (transferAmount ).notNull ();
257257 }
258258 }
@@ -289,7 +289,7 @@ public void validateForUpdate(final JsonCommand command) {
289289 final Integer recurrenceInterval = this .fromApiJsonHelper
290290 .extractIntegerNamed (StandingInstructionApiConstants .recurrenceIntervalParamName , element , Locale .getDefault ());
291291
292- if (standingInstructionType == null || ! StandingInstructionType . fromInt (standingInstructionType ). isDuesAmoutTransfer ( )) {
292+ if (isRecurrenceRequired (standingInstructionType )) {
293293 baseDataValidator .reset ().parameter (StandingInstructionApiConstants .recurrenceIntervalParamName ).value (recurrenceInterval )
294294 .integerGreaterThanZero ();
295295 }
@@ -308,4 +308,32 @@ private void throwExceptionIfValidationWarningsExist(final List<ApiParameterErro
308308 throw new PlatformApiDataValidationException (dataValidationErrors );
309309 }
310310 }
311+
312+ // ============================================
313+ // PRIVATE HELPER METHODS
314+ // ============================================
315+
316+ /**
317+ * Determines if the standing instruction type requires amount validation. Amount is required only for
318+ * FIXED_AMOUNT_TRANSFER type. For DUES type, amount is calculated based on outstanding dues.
319+ *
320+ * @param standingInstructionType
321+ * the instruction type code
322+ * @return true if amount validation is required, false otherwise
323+ */
324+ private boolean isAmountRequired (Integer standingInstructionType ) {
325+ return standingInstructionType != null && StandingInstructionType .fromInt (standingInstructionType ).isFixedAmoutTransfer ();
326+ }
327+
328+ /**
329+ * Determines if recurrence fields should be validated. Recurrence is required for all types except DUES. DUES
330+ * instructions are processed based on loan due dates, not recurrence pattern.
331+ *
332+ * @param standingInstructionType
333+ * the instruction type code
334+ * @return true if recurrence validation is required, false otherwise
335+ */
336+ private boolean isRecurrenceRequired (Integer standingInstructionType ) {
337+ return standingInstructionType == null || !StandingInstructionType .fromInt (standingInstructionType ).isDuesAmoutTransfer ();
338+ }
311339}
0 commit comments