Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ private static String constructRecurrence(final CalendarFrequencyType frequencyT
final StringBuilder recurrenceBuilder = new StringBuilder(200);

recurrenceBuilder.append("FREQ=");
recurrenceBuilder.append(frequencyType.toString().toUpperCase());
recurrenceBuilder.append(frequencyType.toString().toUpperCase(java.util.Locale.ROOT));
if (interval > 1) {
recurrenceBuilder.append(";INTERVAL=");
recurrenceBuilder.append(interval);
Expand All @@ -528,7 +528,7 @@ private static String constructRecurrence(final CalendarFrequencyType frequencyT
final CalendarWeekDaysType weekDays = CalendarWeekDaysType.fromInt(repeatsOnDay);
if (!weekDays.isInvalid()) {
recurrenceBuilder.append(";BYDAY=");
recurrenceBuilder.append(weekDays.toString().toUpperCase());
recurrenceBuilder.append(weekDays.toString().toUpperCase(java.util.Locale.ROOT));
}
}
}
Expand All @@ -548,7 +548,7 @@ private static String constructRecurrence(final CalendarFrequencyType frequencyT
final CalendarWeekDaysType weekday = CalendarWeekDaysType.fromInt(repeatsOnDay);
if (!weekday.isInvalid()) {
recurrenceBuilder.append(";BYDAY=");
recurrenceBuilder.append(weekday.toString().toUpperCase());
recurrenceBuilder.append(weekday.toString().toUpperCase(java.util.Locale.ROOT));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,11 @@ public static String getRRuleReadable(final LocalDate startDate, final String re
NthDayNameEnum nthDayName = NthDayNameEnum.from(nthDayType.toString());
DayNameEnum weekdayType = DayNameEnum.from(weekDay.getDay().name());
if (recur.getInterval() == 1 || recur.getInterval() == -1) {
humanReadable = "Monthly on " + nthDayName.getCode().toLowerCase() + " " + weekdayType.getCode().toLowerCase();
humanReadable = "Monthly on " + nthDayName.getCode().toLowerCase(java.util.Locale.ROOT) + " "
+ weekdayType.getCode().toLowerCase(java.util.Locale.ROOT);
} else {
humanReadable = "Every " + recur.getInterval() + " months on " + nthDayName.getCode().toLowerCase() + " "
+ weekdayType.getCode().toLowerCase();
humanReadable = "Every " + recur.getInterval() + " months on " + nthDayName.getCode().toLowerCase(java.util.Locale.ROOT)
+ " " + weekdayType.getCode().toLowerCase(java.util.Locale.ROOT);
}
} else if (monthDay != null) {
if (monthDay == -1) {
Expand Down Expand Up @@ -756,7 +757,8 @@ public static void validateNthDayOfMonthFrequency(DataValidatorBuilder baseDataV
if (nthDayType == NthDayType.ONE || nthDayType == NthDayType.TWO || nthDayType == NthDayType.THREE
|| nthDayType == NthDayType.FOUR) {
baseDataValidator.reset().parameter(repeatsOnDayParamName).value(repeatsOnDay).cantBeBlankWhenParameterProvidedIs(
repeatsOnNthDayOfMonthParamName, NthDayNameEnum.from(nthDayType.toString()).getCode().toLowerCase());
repeatsOnNthDayOfMonthParamName,
NthDayNameEnum.from(nthDayType.toString()).getCode().toLowerCase(java.util.Locale.ROOT));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,9 @@ public void validateHasDeletePermission(final String resourceType) {
}

private void validateHasPermission(final String prefix, final String resourceType) {
final String authorizationMessage = "User has no authority to " + prefix + " " + resourceType.toLowerCase() + "s";
final String matchPermission = prefix + "_" + resourceType.toUpperCase();
final String authorizationMessage = "User has no authority to " + prefix + " " + resourceType.toLowerCase(java.util.Locale.ROOT)
+ "s";
final String matchPermission = prefix + "_" + resourceType.toUpperCase(java.util.Locale.ROOT);

if (!hasNotPermissionForAnyOf("ALL_FUNCTIONS", "ALL_FUNCTIONS_READ", matchPermission)) {
return;
Expand Down Expand Up @@ -635,7 +636,7 @@ public void validateHasReadPermission(final String function, final Long userId)
}

public void validateHasCheckerPermissionTo(final String function) {
final String checkerPermissionName = function.toUpperCase() + "_CHECKER";
final String checkerPermissionName = function.toUpperCase(java.util.Locale.ROOT) + "_CHECKER";
if (hasNotPermissionTo("CHECKER_SUPER_USER") && hasNotPermissionTo(checkerPermissionName)) {
final String authorizationMessage = "User has no authority to be a checker for: " + function;
throw new NoAuthorizationException(authorizationMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ private static String constructRecurrence(final CalendarFrequencyType frequencyT
final StringBuilder recurrenceBuilder = new StringBuilder(200);

recurrenceBuilder.append("FREQ=");
recurrenceBuilder.append(frequencyType.toString().toUpperCase());
recurrenceBuilder.append(frequencyType.toString().toUpperCase(java.util.Locale.ROOT));
if (interval > 1) {
recurrenceBuilder.append(";INTERVAL=");
recurrenceBuilder.append(interval);
Expand All @@ -533,7 +533,7 @@ private static String constructRecurrence(final CalendarFrequencyType frequencyT
final CalendarWeekDaysType weekDays = CalendarWeekDaysType.fromInt(repeatsOnDay);
if (!weekDays.isInvalid()) {
recurrenceBuilder.append(";BYDAY=");
recurrenceBuilder.append(weekDays.toString().toUpperCase());
recurrenceBuilder.append(weekDays.toString().toUpperCase(java.util.Locale.ROOT));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@
package org.apache.fineract.portfolio.note.service;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.Strings;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.portfolio.client.domain.ClientRepositoryWrapper;
import org.apache.fineract.portfolio.group.domain.GroupRepository;
import org.apache.fineract.portfolio.group.exception.GroupNotFoundException;
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepositoryWrapper;
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction;
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionRepository;
import org.apache.fineract.portfolio.loanaccount.exception.LoanTransactionNotFoundException;
import org.apache.fineract.portfolio.note.data.NoteCreateRequest;
Expand All @@ -38,6 +42,7 @@
import org.apache.fineract.portfolio.note.domain.NoteType;
import org.apache.fineract.portfolio.note.exception.NoteNotFoundException;
import org.apache.fineract.portfolio.note.exception.NoteResourceNotSupportedException;
import org.apache.fineract.portfolio.savings.domain.SavingsAccount;
import org.apache.fineract.portfolio.savings.domain.SavingsAccountRepository;
import org.apache.fineract.portfolio.savings.exception.SavingsAccountNotFoundException;

Expand Down Expand Up @@ -110,16 +115,77 @@ public NoteCreateResponse createNote(final NoteCreateRequest request) {

@Override
public NoteUpdateResponse updateNote(final NoteUpdateRequest request) {
final var result = getNote(request.getType(), request.getResourceId(), request.getId());
final var note = result.getLeft();
final var response = NoteUpdateResponse.builder().officeId(result.getRight()).resourceId(request.getResourceId());
final Note noteForUpdate = this.noteRepository.findById(request.getId())
.orElseThrow(() -> new NoteNotFoundException(request.getId(), request.getResourceId(),
request.getType().name().toLowerCase(java.util.Locale.ROOT)));

if (!Strings.CI.equals(note.getNote(), request.getNote())) {
response.changes(note.update(request.getNote()));
noteRepository.saveAndFlush(note);
noteForUpdate.update(request.getNote());
this.noteRepository.saveAndFlush(noteForUpdate);

return NoteUpdateResponse.builder().build();
}

private CommandProcessingResult updateLoanNote(final JsonCommand command) {
final Long resourceId = command.subentityId();
final Long noteId = command.entityId();
final NoteType type = NoteType.LOAN;

final Loan loan = this.loanRepository.findOneWithNotFoundDetection(resourceId);
final Note noteForUpdate = this.noteRepository.findByLoanAndId(loan, noteId);

if (noteForUpdate == null) {
throw new NoteNotFoundException(noteId, resourceId, type.name().toLowerCase(java.util.Locale.ROOT));
}

final String noteContent = command.stringValueOfParameterNamed("note");
noteForUpdate.update(noteContent);
this.noteRepository.saveAndFlush(noteForUpdate);

return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(noteForUpdate.getId())
.withLoanId(loan.getId()).withOfficeId(loan.getOfficeId()).build();
}

private CommandProcessingResult updateLoanTransactionNote(final JsonCommand command) {
final Long resourceId = command.subentityId();
final Long noteId = command.entityId();
final NoteType type = NoteType.LOAN_TRANSACTION;

final LoanTransaction loanTransaction = this.loanTransactionRepository.findById(resourceId)
.orElseThrow(() -> new LoanTransactionNotFoundException(resourceId));
final Loan loan = loanTransaction.getLoan();

final Note noteForUpdate = this.noteRepository.findByLoanAndId(loan, noteId);
if (noteForUpdate == null) {
throw new NoteNotFoundException(noteId, resourceId, type.name().toLowerCase(java.util.Locale.ROOT));
}

return response.build();
final String noteContent = command.stringValueOfParameterNamed("note");
noteForUpdate.update(noteContent);
this.noteRepository.saveAndFlush(noteForUpdate);

return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(noteForUpdate.getId())
.withLoanId(loan.getId()).withOfficeId(loan.getOfficeId()).build();
}

private CommandProcessingResult updateSavingAccountNote(final JsonCommand command) {
final Long resourceId = command.subentityId();
final Long noteId = command.entityId();
final NoteType type = NoteType.SAVING_ACCOUNT;

final SavingsAccount savingAccount = this.savingsAccountRepository.findById(resourceId)
.orElseThrow(() -> new SavingsAccountNotFoundException(resourceId));

final Note noteForUpdate = this.noteRepository.findBySavingsAccountAndId(savingAccount, noteId);
if (noteForUpdate == null) {
throw new NoteNotFoundException(noteId, resourceId, type.name().toLowerCase(java.util.Locale.ROOT));
}

final String noteContent = command.stringValueOfParameterNamed("note");
noteForUpdate.update(noteContent);
this.noteRepository.saveAndFlush(noteForUpdate);

return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(noteForUpdate.getId())
.withSavingsId(savingAccount.getId()).withOfficeId(savingAccount.officeId()).build();
}

@Override
Expand Down Expand Up @@ -173,11 +239,9 @@ private Pair<Note, Long> getNote(NoteType type, Long resourceId, Long noteId) {
log.error("Not yet implemented: {}", type);
break;
}

if (note == null) {
throw new NoteNotFoundException(noteId, resourceId, type.name().toLowerCase());
throw new NoteNotFoundException(noteId, resourceId, type.name().toLowerCase(java.util.Locale.ROOT));
}

return Pair.of(note, officeId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public class EnumValueValidator implements ConstraintValidator<EnumValue, String

@Override
public void initialize(EnumValue annotation) {
acceptedValues = Arrays.stream(annotation.enumClass().getEnumConstants()).map(e -> e.name().toLowerCase())
acceptedValues = Arrays.stream(annotation.enumClass().getEnumConstants()).map(e -> e.name().toLowerCase(java.util.Locale.ROOT))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please make sure to check whether this is an issue with other classes? I think you can extend this story and cover all "missing" locale compilation warning in one shot. What do you think?

.collect(Collectors.toSet());
}

@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
return value != null && acceptedValues.contains(value.toLowerCase());
return value != null && acceptedValues.contains(value.toLowerCase(java.util.Locale.ROOT));
}
}