nickus commented on code in PR #5439:
URL: https://github.com/apache/fineract/pull/5439#discussion_r2836188783


##########
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:
   Good catch @adamsaghy, you're right — the @UniqueConstraint annotation on 
the entity was just Hibernate metadata with no actual DB constraint behind it 
(since DDL auto-generation is disabled). I've added a Liquibase migration to 
create the campaign_name_UNIQUE constraint on the sms_campaign table.



-- 
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]

Reply via email to