Skip to content

Commit fb296fe

Browse files
committed
fix: resolve Note service interface rebase conflicts and restore Locale.ROOT params
1 parent 377a62b commit fb296fe

3 files changed

Lines changed: 45 additions & 39 deletions

File tree

fineract-core/src/main/java/org/apache/fineract/portfolio/calendar/service/CalendarUtils.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,11 @@ public static String getRRuleReadable(final LocalDate startDate, final String re
299299
NthDayNameEnum nthDayName = NthDayNameEnum.from(nthDayType.toString());
300300
DayNameEnum weekdayType = DayNameEnum.from(weekDay.getDay().name());
301301
if (recur.getInterval() == 1 || recur.getInterval() == -1) {
302-
humanReadable = "Monthly on " + nthDayName.getCode().toLowerCase(java.util.Locale.ROOT) + " " + weekdayType.getCode().toLowerCase(java.util.Locale.ROOT);
303-
} else {
304-
humanReadable = "Every " + recur.getInterval() + " months on " + nthDayName.getCode().toLowerCase(java.util.Locale.ROOT) + " "
302+
humanReadable = "Monthly on " + nthDayName.getCode().toLowerCase(java.util.Locale.ROOT) + " "
305303
+ weekdayType.getCode().toLowerCase(java.util.Locale.ROOT);
304+
} else {
305+
humanReadable = "Every " + recur.getInterval() + " months on " + nthDayName.getCode().toLowerCase(java.util.Locale.ROOT)
306+
+ " " + weekdayType.getCode().toLowerCase(java.util.Locale.ROOT);
306307
}
307308
} else if (monthDay != null) {
308309
if (monthDay == -1) {
@@ -756,7 +757,8 @@ public static void validateNthDayOfMonthFrequency(DataValidatorBuilder baseDataV
756757
if (nthDayType == NthDayType.ONE || nthDayType == NthDayType.TWO || nthDayType == NthDayType.THREE
757758
|| nthDayType == NthDayType.FOUR) {
758759
baseDataValidator.reset().parameter(repeatsOnDayParamName).value(repeatsOnDay).cantBeBlankWhenParameterProvidedIs(
759-
repeatsOnNthDayOfMonthParamName, NthDayNameEnum.from(nthDayType.toString()).getCode().toLowerCase(java.util.Locale.ROOT));
760+
repeatsOnNthDayOfMonthParamName,
761+
NthDayNameEnum.from(nthDayType.toString()).getCode().toLowerCase(java.util.Locale.ROOT));
760762
}
761763
}
762764
}

fineract-core/src/main/java/org/apache/fineract/useradministration/domain/AppUser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,8 @@ public void validateHasDeletePermission(final String resourceType) {
551551
}
552552

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

557558
if (!hasNotPermissionForAnyOf("ALL_FUNCTIONS", "ALL_FUNCTIONS_READ", matchPermission)) {

fineract-provider/src/main/java/org/apache/fineract/portfolio/note/service/NoteWritePlatformServiceJpaRepositoryImpl.java

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@
1919
package org.apache.fineract.portfolio.note.service;
2020

2121
import lombok.extern.slf4j.Slf4j;
22-
import org.apache.commons.lang3.Strings;
2322
import org.apache.commons.lang3.tuple.Pair;
23+
import org.apache.fineract.infrastructure.core.api.JsonCommand;
24+
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
25+
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
2426
import org.apache.fineract.portfolio.client.domain.ClientRepositoryWrapper;
2527
import org.apache.fineract.portfolio.group.domain.GroupRepository;
2628
import org.apache.fineract.portfolio.group.exception.GroupNotFoundException;
29+
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
2730
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepositoryWrapper;
31+
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction;
2832
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionRepository;
2933
import org.apache.fineract.portfolio.loanaccount.exception.LoanTransactionNotFoundException;
3034
import org.apache.fineract.portfolio.note.data.NoteCreateRequest;
@@ -38,6 +42,7 @@
3842
import org.apache.fineract.portfolio.note.domain.NoteType;
3943
import org.apache.fineract.portfolio.note.exception.NoteNotFoundException;
4044
import org.apache.fineract.portfolio.note.exception.NoteResourceNotSupportedException;
45+
import org.apache.fineract.portfolio.savings.domain.SavingsAccount;
4146
import org.apache.fineract.portfolio.savings.domain.SavingsAccountRepository;
4247
import org.apache.fineract.portfolio.savings.exception.SavingsAccountNotFoundException;
4348

@@ -110,78 +115,77 @@ public NoteCreateResponse createNote(final NoteCreateRequest request) {
110115

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

122+
noteForUpdate.update(request.getNote());
123+
this.noteRepository.saveAndFlush(noteForUpdate);
124+
125+
return NoteUpdateResponse.builder().build();
126+
}
127+
128+
private CommandProcessingResult updateLoanNote(final JsonCommand command) {
129+
final Long resourceId = command.subentityId();
130+
final Long noteId = command.entityId();
117131
final NoteType type = NoteType.LOAN;
118132

119133
final Loan loan = this.loanRepository.findOneWithNotFoundDetection(resourceId);
120134
final Note noteForUpdate = this.noteRepository.findByLoanAndId(loan, noteId);
135+
121136
if (noteForUpdate == null) {
122137
throw new NoteNotFoundException(noteId, resourceId, type.name().toLowerCase(java.util.Locale.ROOT));
123138
}
124139

125-
final Map<String, Object> changes = noteForUpdate.update(command);
126-
127-
if (!changes.isEmpty()) {
128-
this.noteRepository.saveAndFlush(noteForUpdate);
129-
}
140+
final String noteContent = command.stringValueOfParameterNamed("note");
141+
noteForUpdate.update(noteContent);
142+
this.noteRepository.saveAndFlush(noteForUpdate);
130143

131144
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(noteForUpdate.getId())
132-
.withLoanId(loan.getId()).withOfficeId(loan.getOfficeId()).with(changes).build();
145+
.withLoanId(loan.getId()).withOfficeId(loan.getOfficeId()).build();
133146
}
134147

135148
private CommandProcessingResult updateLoanTransactionNote(final JsonCommand command) {
136-
137149
final Long resourceId = command.subentityId();
138150
final Long noteId = command.entityId();
139-
140151
final NoteType type = NoteType.LOAN_TRANSACTION;
141152

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

146-
final Note noteForUpdate = this.noteRepository.findByLoanTransactionAndId(loanTransaction, noteId);
147-
157+
final Note noteForUpdate = this.noteRepository.findByLoanAndId(loan, noteId);
148158
if (noteForUpdate == null) {
149159
throw new NoteNotFoundException(noteId, resourceId, type.name().toLowerCase(java.util.Locale.ROOT));
150160
}
151161

152-
final Map<String, Object> changes = noteForUpdate.update(command);
153-
154-
if (!changes.isEmpty()) {
155-
this.noteRepository.saveAndFlush(noteForUpdate);
156-
}
162+
final String noteContent = command.stringValueOfParameterNamed("note");
163+
noteForUpdate.update(noteContent);
164+
this.noteRepository.saveAndFlush(noteForUpdate);
157165

158166
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(noteForUpdate.getId())
159-
.withLoanId(loan.getId()).withOfficeId(loan.getOfficeId()).with(changes).build();
167+
.withLoanId(loan.getId()).withOfficeId(loan.getOfficeId()).build();
160168
}
161169

162170
private CommandProcessingResult updateSavingAccountNote(final JsonCommand command) {
163-
final Long resourceId = command.getSavingsId();
171+
final Long resourceId = command.subentityId();
164172
final Long noteId = command.entityId();
165173
final NoteType type = NoteType.SAVING_ACCOUNT;
174+
166175
final SavingsAccount savingAccount = this.savingsAccountRepository.findById(resourceId)
167176
.orElseThrow(() -> new SavingsAccountNotFoundException(resourceId));
168177

169178
final Note noteForUpdate = this.noteRepository.findBySavingsAccountAndId(savingAccount, noteId);
170179
if (noteForUpdate == null) {
171180
throw new NoteNotFoundException(noteId, resourceId, type.name().toLowerCase(java.util.Locale.ROOT));
172181
}
173-
final Map<String, Object> changes = noteForUpdate.update(command);
174-
if (!changes.isEmpty()) {
175-
this.noteRepository.saveAndFlush(noteForUpdate);
176-
}
177182

178-
return new CommandProcessingResultBuilder() //
179-
.withCommandId(command.commandId()) //
180-
.withEntityId(noteForUpdate.getId()) //
181-
.withOfficeId(savingAccount.getClient().getOffice().getId()) //
182-
.withSavingsId(savingAccount.getId()) //
183-
.with(changes) //
184-
.build();
183+
final String noteContent = command.stringValueOfParameterNamed("note");
184+
noteForUpdate.update(noteContent);
185+
this.noteRepository.saveAndFlush(noteForUpdate);
186+
187+
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(noteForUpdate.getId())
188+
.withSavingsId(savingAccount.getId()).withOfficeId(savingAccount.officeId()).build();
185189
}
186190

187191
@Override
@@ -235,10 +239,9 @@ private Pair<Note, Long> getNote(NoteType type, Long resourceId, Long noteId) {
235239
log.error("Not yet implemented: {}", type);
236240
break;
237241
}
238-
if (noteForUpdate == null) {
242+
if (note == null) {
239243
throw new NoteNotFoundException(noteId, resourceId, type.name().toLowerCase(java.util.Locale.ROOT));
240244
}
241-
242245
return Pair.of(note, officeId);
243246
}
244247
}

0 commit comments

Comments
 (0)