galovics commented on code in PR #5439:
URL: https://github.com/apache/fineract/pull/5439#discussion_r2772964743
##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/campaigns/sms/service/SmsCampaignWritePlatformServiceJpaImpl.java:
##########
@@ -104,20 +105,32 @@ public class SmsCampaignWritePlatformServiceJpaImpl
implements SmsCampaignWriteP
@Transactional
@Override
public CommandProcessingResult create(JsonCommand command) {
- final AppUser currentUser = this.context.authenticatedUser();
- this.smsCampaignValidator.validateCreate(command.json());
- final Long runReportId =
command.longValueOfParameterNamed(SmsCampaignValidator.runReportId);
- Report report =
this.reportRepository.findById(runReportId).orElseThrow(() -> new
ReportNotFoundException(runReportId));
- LocalDateTime tenantDateTime = DateUtils.getLocalDateTimeOfTenant();
- SmsCampaign smsCampaign = SmsCampaign.instance(currentUser, report,
command);
- LocalDateTime recurrenceStartDate =
smsCampaign.getRecurrenceStartDate();
- if (recurrenceStartDate != null &&
DateUtils.isBefore(recurrenceStartDate, tenantDateTime)) {
- throw new
GeneralPlatformDomainRuleException("error.msg.campaign.recurrenceStartDate.in.the.past",
- "Recurrence start date cannot be the past date.",
recurrenceStartDate);
- }
- this.smsCampaignRepository.saveAndFlush(smsCampaign);
+ try {
+ final AppUser currentUser = this.context.authenticatedUser();
+ this.smsCampaignValidator.validateCreate(command.json());
- return new
CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(smsCampaign.getId()).build();
+ final String campaignName =
command.stringValueOfParameterNamed(SmsCampaignValidator.campaignName);
+ if (this.smsCampaignRepository.existsByCampaignName(campaignName))
{
+ throw new SmsCampaignNameAlreadyExistsException(campaignName);
+ }
Review Comment:
I think the default isolation level we use is read_committed, meaning only
committed things will be revealed by this check. It not guarantees anything.
2 transactions concurrently writing the same campaign name is possible.
If you wanna prevent it, ensure having a unique key on the DB level. This is
good for a best-effort check but it's not bullet-proof,.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]