diff --git a/build.gradle b/build.gradle index 2d5252c93..e3a50e60e 100644 --- a/build.gradle +++ b/build.gradle @@ -28,6 +28,7 @@ buildscript { [ 'fineract-api', 'fineract-core', + 'fineract-validation', 'fineract-command', 'fineract-accounting', 'fineract-provider', @@ -57,6 +58,7 @@ buildscript { 'fineract-api', 'fineract-client', 'fineract-core', + 'fineract-validation', 'fineract-command', 'fineract-accounting', 'fineract-provider', @@ -159,6 +161,10 @@ allprojects { } configurations { + implementation { + exclude group: 'commons-logging', module: 'commons-logging' + } + api { canBeResolved = true } @@ -370,8 +376,18 @@ configure(project.fineractJavaProjects) { withJavadocJar() } - tasks.withType(ProcessResources) { - destinationDir = layout.buildDirectory.dir('classes/java/main').get().asFile + // TODO: we are forcing Gradle to do something it shouldn't! This effects Gradle caching AND breaks Liquibase! + // tasks.withType(ProcessResources) { + // destinationDir = layout.buildDirectory.dir('classes/java/main').get().asFile + // } + + processResources { + destinationDir = file("${buildDir}/resources/main") + + doLast { + delete fileTree(dir: "${buildDir}/classes/java/main/db") + delete fileTree(dir: "${buildDir}/classes/java/main/META-INF") + } } // Add performance optimizations diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 0f1c21ba5..b54069a3c 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -20,7 +20,7 @@ import static org.slf4j.LoggerFactory.* plugins { - id 'io.spring.dependency-management' version '1.1.6' + id 'io.spring.dependency-management' version '1.1.7' id 'groovy' id 'java-gradle-plugin' id 'groovy-gradle-plugin' diff --git a/buildSrc/src/main/groovy/org.apache.fineract.dependencies.gradle b/buildSrc/src/main/groovy/org.apache.fineract.dependencies.gradle index 8ca6c8cef..076270405 100644 --- a/buildSrc/src/main/groovy/org.apache.fineract.dependencies.gradle +++ b/buildSrc/src/main/groovy/org.apache.fineract.dependencies.gradle @@ -38,6 +38,7 @@ dependencyManagement { mavenBom 'software.amazon.awssdk:bom:2.29.9' mavenBom 'io.github.resilience4j:resilience4j-bom:2.2.0' mavenBom 'org.testcontainers:testcontainers-bom:1.20.4' + mavenBom 'org.glassfish.jersey:jersey-bom:3.1.10' } dependencies { @@ -51,7 +52,6 @@ dependencyManagement { dependency 'ch.qos.logback.contrib:logback-jackson:0.1.5' dependency 'org.codehaus.janino:janino:3.1.12' - dependency 'org.eclipse.persistence:org.eclipse.persistence.jpa:4.0.2' dependency 'com.google.guava:guava:33.1.0-jre' dependency 'com.google.code.gson:gson:2.11.0' @@ -76,8 +76,13 @@ dependencyManagement { dependency 'org.ehcache:ehcache:3.10.8' dependency 'com.github.spullara.mustache.java:compiler:0.9.14' dependency 'com.jayway.jsonpath:json-path:2.9.0' - dependency 'org.apache.tika:tika-core:2.9.3' - dependency ('org.apache.tika:tika-parser-microsoft-module:2.9.3') { + dependency ('org.apache.tika:tika-core:2.9.3') { + exclude 'commons-logging:commons-logging' + } + dependency ('org.apache.tika:tika-core:2.9.3') { + exclude 'commons-logging:commons-logging' + } + dependency ('org.apache.tika:tika-parser-miscoffice-module:2.9.3') { exclude 'org.bouncycastle:bcprov-jdk15on' exclude 'org.bouncycastle:bcmail-jdk15on' exclude 'org.bouncycastle:bcprov-jdk18on' @@ -94,7 +99,7 @@ dependencyManagement { exclude 'org.apache.commons:commons-compress' exclude 'xml-apis:xml-apis' } - dependency ('org.apache.tika:tika-parser-miscoffice-module:2.9.3') { + dependency ('org.apache.tika:tika-parser-microsoft-module:2.9.3') { exclude 'org.bouncycastle:bcprov-jdk15on' exclude 'org.bouncycastle:bcmail-jdk15on' exclude 'org.bouncycastle:bcprov-jdk18on' @@ -117,7 +122,6 @@ dependencyManagement { dependency 'jakarta.management.j2ee:jakarta.management.j2ee-api:1.1.4' dependency 'jakarta.jms:jakarta.jms-api:3.1.0' dependency 'jakarta.ws.rs:jakarta.ws.rs-api:3.1.0' - dependency 'org.glassfish.jersey.media:jersey-media-multipart:3.1.10' dependency 'org.glassfish.jaxb:jaxb-runtime:2.3.6' // Swagger needs exactly this version dependency 'org.apache.bval:org.apache.bval.bundle:3.0.2' dependency 'joda-time:joda-time:2.13.1' @@ -195,6 +199,8 @@ dependencyManagement { dependency ('jakarta.xml.bind:jakarta.xml.bind-api:4.0.2') { exclude 'jakarta.activation:jakarta.activation-api' } + dependency 'jakarta.validation:jakarta.validation-api:3.1.1' + dependency 'org.hibernate.validator:hibernate-validator:8.0.2.Final' dependency ('org.liquibase:liquibase-core:4.31.1') { exclude 'javax.xml.bind:jaxb-api' @@ -243,6 +249,7 @@ dependencyManagement { dependency 'org.assertj:assertj-core:3.26.3' dependency 'org.apache.commons:commons-math3:3.6.1' + dependency 'commons-beanutils:commons-beanutils:1.11.0' dependency 'org.mockito:mockito-inline:5.2.0' diff --git a/fineract-command/dependencies.gradle b/fineract-command/dependencies.gradle index 5d914cfe8..8cb5b3f1c 100644 --- a/fineract-command/dependencies.gradle +++ b/fineract-command/dependencies.gradle @@ -38,8 +38,6 @@ dependencies { 'com.github.spotbugs:spotbugs-annotations', 'org.mapstruct:mapstruct', 'com.lmax:disruptor', - 'com.ibm.icu:icu4j', - 'org.yakworks:spring-icu4j', ) implementation('org.eclipse.persistence:org.eclipse.persistence.jpa') { exclude group: 'org.eclipse.persistence', module: 'jakarta.persistence' @@ -62,6 +60,7 @@ dependencies { exclude group: 'org.skyscreamer' } testImplementation ( + project(':fineract-validation'), 'org.springframework.boot:spring-boot-starter-web', 'org.mockito:mockito-inline', 'org.openjdk.jmh:jmh-core', diff --git a/fineract-command/src/main/java/org/apache/fineract/command/core/Command.java b/fineract-command/src/main/java/org/apache/fineract/command/core/Command.java index bbb7e5635..77aba0ca7 100644 --- a/fineract-command/src/main/java/org/apache/fineract/command/core/Command.java +++ b/fineract-command/src/main/java/org/apache/fineract/command/core/Command.java @@ -34,6 +34,8 @@ public class Command implements Serializable { private UUID id; + private String idempotencyKey; + private OffsetDateTime createdAt; private String tenantId; diff --git a/fineract-command/src/main/java/org/apache/fineract/command/persistence/CommandRepository.java b/fineract-command/src/main/java/org/apache/fineract/command/persistence/domain/CommandRepository.java similarity index 90% rename from fineract-command/src/main/java/org/apache/fineract/command/persistence/CommandRepository.java rename to fineract-command/src/main/java/org/apache/fineract/command/persistence/domain/CommandRepository.java index 3b261553f..26bf1ecce 100644 --- a/fineract-command/src/main/java/org/apache/fineract/command/persistence/CommandRepository.java +++ b/fineract-command/src/main/java/org/apache/fineract/command/persistence/domain/CommandRepository.java @@ -16,9 +16,8 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.fineract.command.persistence; +package org.apache.fineract.command.persistence.domain; -import org.apache.fineract.command.persistence.domain.CommandEntity; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; diff --git a/fineract-command/src/main/java/org/apache/fineract/command/persistence/mapping/CommandJsonMapper.java b/fineract-command/src/main/java/org/apache/fineract/command/persistence/mapping/CommandJsonMapper.java index 277fcd8ac..7ff101321 100644 --- a/fineract-command/src/main/java/org/apache/fineract/command/persistence/mapping/CommandJsonMapper.java +++ b/fineract-command/src/main/java/org/apache/fineract/command/persistence/mapping/CommandJsonMapper.java @@ -29,7 +29,7 @@ import org.springframework.stereotype.Component; @Slf4j @RequiredArgsConstructor @Component -public final class CommandJsonMapper { +final class CommandJsonMapper { private static final String CLASS_ATTRIBUTE = "@class"; private final ObjectMapper mapper; diff --git a/fineract-command/src/test/java/org/apache/fineract/command/CommandBaseTest.java b/fineract-command/src/test/java/org/apache/fineract/command/CommandBaseTest.java index b9116e93f..bbcaf3d06 100644 --- a/fineract-command/src/test/java/org/apache/fineract/command/CommandBaseTest.java +++ b/fineract-command/src/test/java/org/apache/fineract/command/CommandBaseTest.java @@ -20,7 +20,7 @@ package org.apache.fineract.command; import java.util.Map; import lombok.extern.slf4j.Slf4j; -import org.apache.fineract.command.persistence.CommandRepository; +import org.apache.fineract.command.persistence.domain.CommandRepository; import org.apache.fineract.command.persistence.mapping.CommandMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; diff --git a/fineract-command/src/test/java/org/apache/fineract/command/TestConfiguration.java b/fineract-command/src/test/java/org/apache/fineract/command/TestConfiguration.java index 2187a1c3b..fa42c6745 100644 --- a/fineract-command/src/test/java/org/apache/fineract/command/TestConfiguration.java +++ b/fineract-command/src/test/java/org/apache/fineract/command/TestConfiguration.java @@ -23,16 +23,11 @@ import org.apache.fineract.command.core.CommandProperties; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.MessageSource; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.scheduling.annotation.EnableAsync; -import org.springframework.validation.Validator; -import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; -import yakworks.i18n.icu.ICUBundleMessageSource; @Slf4j @Configuration @@ -42,22 +37,4 @@ import yakworks.i18n.icu.ICUBundleMessageSource; @EnableAsync @PropertySource("classpath:application-test.properties") @ComponentScan("org.apache.fineract.command.sample") -public class TestConfiguration { - - @Bean - MessageSource messageSource() { - var messageSource = new ICUBundleMessageSource(); - messageSource.setBasenames("classpath:org.apache.fineract.messages"); - messageSource.setDefaultEncoding("UTF-8"); - - return messageSource; - } - - @Bean - Validator validatorFactoryBean(MessageSource messageSource) { - var localValidatorFactoryBean = new LocalValidatorFactoryBean(); - localValidatorFactoryBean.setValidationMessageSource(messageSource); - - return localValidatorFactoryBean; - } -} +public class TestConfiguration {} diff --git a/fineract-command/src/test/java/org/apache/fineract/command/sample/api/DummyApiController.java b/fineract-command/src/test/java/org/apache/fineract/command/sample/api/DummyApiController.java index f53439dc5..e8c19a717 100644 --- a/fineract-command/src/test/java/org/apache/fineract/command/sample/api/DummyApiController.java +++ b/fineract-command/src/test/java/org/apache/fineract/command/sample/api/DummyApiController.java @@ -22,7 +22,6 @@ import static org.apache.fineract.command.core.CommandConstants.COMMAND_REQUEST_ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import static org.springframework.http.MediaType.APPLICATION_PROBLEM_JSON_VALUE; -import jakarta.validation.Valid; import java.time.OffsetDateTime; import java.time.ZoneId; import java.util.UUID; @@ -56,7 +55,7 @@ class DummyApiController { @PostMapping("/sync") DummyResponse dummySync(@RequestHeader(value = COMMAND_REQUEST_ID, required = false) UUID requestId, - @RequestHeader(value = "x-fineract-tenant-id", required = false) String tenantId, @Valid @RequestBody DummyRequest request) { + @RequestHeader(value = "x-fineract-tenant-id", required = false) String tenantId, @RequestBody DummyRequest request) { var command = new DummyCommand(); command.setId(requestId); command.setPayload(request); diff --git a/fineract-core/dependencies.gradle b/fineract-core/dependencies.gradle index b7bab1d2c..c93be8e14 100644 --- a/fineract-core/dependencies.gradle +++ b/fineract-core/dependencies.gradle @@ -23,9 +23,10 @@ dependencies { // Note that we never use 'api', because Fineract at least currently is a simple monolithic application ("WAR"), not a library. // We also (normally should have) no need to ever use 'compileOnly'. - implementation( - project(path: ':fineract-avro-schemas') - ) + implementation(project(path: ':fineract-avro-schemas')) + implementation(project(path: ':fineract-command')) + implementation(project(path: ':fineract-validation')) + // implementation dependencies are directly used (compiled against) in src/main (and src/test) implementation( diff --git a/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/api/BusinessDateApiResource.java b/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/api/BusinessDateApiResource.java index ebc0a3b81..96f45d9f1 100644 --- a/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/api/BusinessDateApiResource.java +++ b/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/api/BusinessDateApiResource.java @@ -20,30 +20,26 @@ package org.apache.fineract.infrastructure.businessdate.api; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.parameters.RequestBody; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; import jakarta.ws.rs.Consumes; import jakarta.ws.rs.GET; +import jakarta.ws.rs.HeaderParam; import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; import java.util.List; +import java.util.UUID; +import java.util.function.Supplier; import lombok.RequiredArgsConstructor; -import org.apache.fineract.commands.domain.CommandWrapper; -import org.apache.fineract.commands.service.CommandWrapperBuilder; -import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService; -import org.apache.fineract.infrastructure.businessdate.data.BusinessDateData; -import org.apache.fineract.infrastructure.businessdate.data.request.BusinessDateRequest; +import org.apache.fineract.command.core.CommandPipeline; +import org.apache.fineract.infrastructure.businessdate.command.BusinessDateUpdateCommand; +import org.apache.fineract.infrastructure.businessdate.data.BusinessDateResponse; +import org.apache.fineract.infrastructure.businessdate.data.BusinessDateUpdateRequest; import org.apache.fineract.infrastructure.businessdate.service.BusinessDateReadPlatformService; -import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; -import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer; -import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; +import org.apache.fineract.infrastructure.core.service.DateUtils; import org.springframework.stereotype.Component; @RequiredArgsConstructor @@ -52,19 +48,14 @@ import org.springframework.stereotype.Component; @Tag(name = "Business Date Management", description = "Business date management enables you to set up, fetch and adjust organisation business dates") public class BusinessDateApiResource { - private static final String BUSINESS_DATE = "BUSINESS_DATE"; - - private final PlatformSecurityContext securityContext; - private final DefaultToApiJsonSerializer jsonSerializer; private final BusinessDateReadPlatformService readPlatformService; - private final PortfolioCommandSourceWritePlatformService commandWritePlatformService; + private final CommandPipeline commandPipeline; @GET @Consumes({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON }) @Produces(MediaType.APPLICATION_JSON) @Operation(summary = "List all business dates", description = "") - public List getBusinessDates() { - securityContext.authenticatedUser().validateHasReadPermission(BUSINESS_DATE); + public List getBusinessDates() { return this.readPlatformService.findAll(); } @@ -73,8 +64,7 @@ public class BusinessDateApiResource { @Consumes({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON }) @Produces(MediaType.APPLICATION_JSON) @Operation(summary = "Retrieve a specific Business date", description = "") - public BusinessDateData getBusinessDate(@PathParam("type") @Parameter(description = "type") final String type) { - securityContext.authenticatedUser().validateHasReadPermission(BUSINESS_DATE); + public BusinessDateResponse getBusinessDate(@PathParam("type") @Parameter(description = "type") final String type) { return this.readPlatformService.findByType(type); } @@ -82,14 +72,19 @@ public class BusinessDateApiResource { @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) @Operation(summary = "Update Business Date", description = "") - @RequestBody(required = true, content = @Content(schema = @Schema(implementation = BusinessDateRequest.class))) - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = BusinessDateApiResourceSwagger.BusinessDateResponse.class))) }) - public CommandProcessingResult updateBusinessDate(BusinessDateRequest businessDateRequest) { - securityContext.authenticatedUser().validateHasUpdatePermission(BUSINESS_DATE); - final CommandWrapper commandRequest = new CommandWrapperBuilder().updateBusinessDate() - .withJson(jsonSerializer.serialize(businessDateRequest)).build(); - return commandWritePlatformService.logCommandSource(commandRequest); + public BusinessDateResponse updateBusinessDate(@HeaderParam("Idempotency-Key") String idempotencyKey, + @Valid BusinessDateUpdateRequest request) { + + final var command = new BusinessDateUpdateCommand(); + + command.setId(UUID.randomUUID()); + command.setIdempotencyKey(idempotencyKey); + command.setCreatedAt(DateUtils.getAuditOffsetDateTime()); + command.setPayload(request); + + final Supplier response = commandPipeline.send(command); + + return response.get(); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/IncreaseDateBy1DayService.java b/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/command/BusinessDateUpdateCommand.java similarity index 67% rename from fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/IncreaseDateBy1DayService.java rename to fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/command/BusinessDateUpdateCommand.java index 104aa9327..afb5ff83c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/IncreaseDateBy1DayService.java +++ b/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/command/BusinessDateUpdateCommand.java @@ -16,11 +16,13 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.fineract.infrastructure.jobs.service.increasedateby1day; +package org.apache.fineract.infrastructure.businessdate.command; -import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.apache.fineract.command.core.Command; +import org.apache.fineract.infrastructure.businessdate.data.BusinessDateUpdateRequest; -public interface IncreaseDateBy1DayService { - - void increaseDateByTypeByOneDay(BusinessDateType businessDateType); -} +@Data +@EqualsAndHashCode(callSuper = true) +public class BusinessDateUpdateCommand extends Command {} diff --git a/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/data/BusinessDateData.java b/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/data/BusinessDateResponse.java similarity index 59% rename from fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/data/BusinessDateData.java rename to fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/data/BusinessDateResponse.java index 7de861046..c60975bbc 100644 --- a/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/data/BusinessDateData.java +++ b/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/data/BusinessDateResponse.java @@ -21,24 +21,43 @@ package org.apache.fineract.infrastructure.businessdate.data; import java.io.Serial; import java.io.Serializable; import java.time.LocalDate; +import java.util.HashMap; +import java.util.Map; +import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; +@Builder @Data @NoArgsConstructor -@Accessors(chain = true) -public class BusinessDateData implements Serializable { +@AllArgsConstructor +public class BusinessDateResponse implements Serializable { @Serial private static final long serialVersionUID = 1L; - private String description; - private String type; - private LocalDate date; - public static BusinessDateData instance(BusinessDateType businessDateType, LocalDate value) { - return new BusinessDateData().setType(businessDateType.getName()).setDescription(businessDateType.getDescription()).setDate(value); + private String description; + private BusinessDateType type; + private LocalDate date; + private Map changes; + + public void addChange(final BusinessDateType businessDateType, final LocalDate date) { + if (this.changes == null) { + this.changes = new HashMap<>(); + } + + changes.put(businessDateType, date); } + public void addAllChanges(final Map changes) { + if (changes == null || changes.isEmpty()) { + return; + } + + for (final Map.Entry entry : changes.entrySet()) { + addChange(entry.getKey(), entry.getValue()); + } + } } diff --git a/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/data/BusinessDateUpdateRequest.java b/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/data/BusinessDateUpdateRequest.java new file mode 100644 index 000000000..23d0cc9cc --- /dev/null +++ b/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/data/BusinessDateUpdateRequest.java @@ -0,0 +1,52 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.infrastructure.businessdate.data; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import java.io.Serial; +import java.io.Serializable; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; +import org.apache.fineract.validation.constraints.LocalDate; +import org.apache.fineract.validation.constraints.Locale; + +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor +@LocalDate(dateField = "date", formatField = "dateFormat", localeField = "locale") +public class BusinessDateUpdateRequest implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + @NotBlank(message = "{org.apache.fineract.businessdate.date-format.not-blank}") + private String dateFormat; + @NotNull(message = "{org.apache.fineract.businessdate.type.not-null}") + private BusinessDateType type; + @NotBlank(message = "{org.apache.fineract.businessdate.date.not-blank}") + private String date; + @NotBlank(message = "{org.apache.fineract.businessdate.locale.not-blank}") + @Locale + private String locale; +} diff --git a/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/handler/BusinessDateUpdateHandler.java b/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/handler/BusinessDateUpdateHandler.java index 12a06b1de..ce7075391 100644 --- a/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/handler/BusinessDateUpdateHandler.java +++ b/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/handler/BusinessDateUpdateHandler.java @@ -18,26 +18,26 @@ */ package org.apache.fineract.infrastructure.businessdate.handler; -import jakarta.validation.constraints.NotNull; import lombok.RequiredArgsConstructor; -import org.apache.fineract.commands.annotation.CommandType; -import org.apache.fineract.commands.handler.NewCommandSourceHandler; +import lombok.extern.slf4j.Slf4j; +import org.apache.fineract.command.core.Command; +import org.apache.fineract.command.core.CommandHandler; +import org.apache.fineract.infrastructure.businessdate.data.BusinessDateResponse; +import org.apache.fineract.infrastructure.businessdate.data.BusinessDateUpdateRequest; import org.apache.fineract.infrastructure.businessdate.service.BusinessDateWritePlatformService; -import org.apache.fineract.infrastructure.core.api.JsonCommand; -import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; -import org.springframework.stereotype.Service; +import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; +@Slf4j +@Component @RequiredArgsConstructor -@Service -@CommandType(entity = "BUSINESS_DATE", action = "UPDATE") -public class BusinessDateUpdateHandler implements NewCommandSourceHandler { +public class BusinessDateUpdateHandler implements CommandHandler { private final BusinessDateWritePlatformService businessDateWritePlatformService; @Transactional @Override - public CommandProcessingResult processCommand(@NotNull final JsonCommand command) { - return businessDateWritePlatformService.updateBusinessDate(command); + public BusinessDateResponse handle(Command command) { + return businessDateWritePlatformService.updateBusinessDate(command.getPayload()); } } diff --git a/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/mapper/BusinessDateMapper.java b/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/mapper/BusinessDateMapper.java index 48f068566..76d8b1616 100644 --- a/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/mapper/BusinessDateMapper.java +++ b/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/mapper/BusinessDateMapper.java @@ -19,7 +19,7 @@ package org.apache.fineract.infrastructure.businessdate.mapper; import java.util.List; -import org.apache.fineract.infrastructure.businessdate.data.BusinessDateData; +import org.apache.fineract.infrastructure.businessdate.data.BusinessDateResponse; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDate; import org.apache.fineract.infrastructure.core.config.MapstructMapperConfig; import org.mapstruct.Mapper; @@ -29,8 +29,8 @@ import org.mapstruct.Mappings; @Mapper(config = MapstructMapperConfig.class) public interface BusinessDateMapper { - @Mappings({ @Mapping(target = "description", source = "source.type.description") }) - BusinessDateData map(BusinessDate source); + @Mappings({ @Mapping(target = "description", source = "source.type.description"), @Mapping(target = "changes", ignore = true) }) + BusinessDateResponse map(BusinessDate source); - List map(List sources); + List map(List sources); } diff --git a/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/mapper/BusinessDateUpdateRequestMapper.java b/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/mapper/BusinessDateUpdateRequestMapper.java new file mode 100644 index 000000000..b2d77beb5 --- /dev/null +++ b/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/mapper/BusinessDateUpdateRequestMapper.java @@ -0,0 +1,35 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.infrastructure.businessdate.mapper; + +import org.apache.fineract.infrastructure.businessdate.data.BusinessDateResponse; +import org.apache.fineract.infrastructure.businessdate.data.BusinessDateUpdateRequest; +import org.apache.fineract.infrastructure.core.config.MapstructMapperConfig; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper(config = MapstructMapperConfig.class) +public interface BusinessDateUpdateRequestMapper { + + @Mapping(target = "description", expression = "java(source.getType().getDescription())") + @Mapping(source = "type", target = "type") + @Mapping(target = "date", expression = "java(org.apache.fineract.infrastructure.core.service.DateUtils.toLocalDate(source.getLocale(), source.getDate(), source.getDateFormat()))") + @Mapping(target = "changes", ignore = true) + BusinessDateResponse map(BusinessDateUpdateRequest source); +} diff --git a/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateReadPlatformService.java b/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateReadPlatformService.java index 9633d1384..8408de00c 100644 --- a/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateReadPlatformService.java +++ b/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateReadPlatformService.java @@ -21,14 +21,14 @@ package org.apache.fineract.infrastructure.businessdate.service; import java.time.LocalDate; import java.util.HashMap; import java.util.List; -import org.apache.fineract.infrastructure.businessdate.data.BusinessDateData; +import org.apache.fineract.infrastructure.businessdate.data.BusinessDateResponse; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; public interface BusinessDateReadPlatformService { - List findAll(); + List findAll(); - BusinessDateData findByType(String type); + BusinessDateResponse findByType(String type); HashMap getBusinessDates(); } diff --git a/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateReadPlatformServiceImpl.java b/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateReadPlatformServiceImpl.java index 00a871128..83c0f545a 100644 --- a/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateReadPlatformServiceImpl.java +++ b/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateReadPlatformServiceImpl.java @@ -24,7 +24,7 @@ import java.util.List; import java.util.Optional; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.fineract.infrastructure.businessdate.data.BusinessDateData; +import org.apache.fineract.infrastructure.businessdate.data.BusinessDateResponse; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDate; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateRepository; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; @@ -40,17 +40,17 @@ import org.springframework.stereotype.Service; public class BusinessDateReadPlatformServiceImpl implements BusinessDateReadPlatformService { private final BusinessDateRepository repository; - private final BusinessDateMapper mapper; + private final BusinessDateMapper businessDatemapper; private final ConfigurationDomainService configurationDomainService; @Override - public List findAll() { + public List findAll() { List businessDateList = repository.findAll(); - return mapper.map(businessDateList); + return businessDatemapper.map(businessDateList); } @Override - public BusinessDateData findByType(String type) { + public BusinessDateResponse findByType(String type) { BusinessDateType businessDateType; try { businessDateType = BusinessDateType.valueOf(type); @@ -63,7 +63,7 @@ public class BusinessDateReadPlatformServiceImpl implements BusinessDateReadPlat log.error("Business date with the provided type cannot be found {}", type); throw BusinessDateNotFoundException.notFound(type); } - return mapper.map(businessDate.get()); + return businessDatemapper.map(businessDate.get()); } @Override @@ -73,9 +73,9 @@ public class BusinessDateReadPlatformServiceImpl implements BusinessDateReadPlat businessDateMap.put(BusinessDateType.BUSINESS_DATE, tenantDate); businessDateMap.put(BusinessDateType.COB_DATE, tenantDate); if (configurationDomainService.isBusinessDateEnabled()) { - final List businessDateDataList = this.findAll(); - for (BusinessDateData businessDateData : businessDateDataList) { - businessDateMap.put(BusinessDateType.valueOf(businessDateData.getType()), businessDateData.getDate()); + final List businessDateResponseList = this.findAll(); + for (BusinessDateResponse businessDateResponse : businessDateResponseList) { + businessDateMap.put(businessDateResponse.getType(), businessDateResponse.getDate()); } } return businessDateMap; diff --git a/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateWritePlatformService.java b/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateWritePlatformService.java index f04fdf77d..a22ea5703 100644 --- a/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateWritePlatformService.java +++ b/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateWritePlatformService.java @@ -18,19 +18,14 @@ */ package org.apache.fineract.infrastructure.businessdate.service; -import java.util.Map; -import org.apache.fineract.infrastructure.businessdate.data.BusinessDateData; -import org.apache.fineract.infrastructure.core.api.JsonCommand; -import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.businessdate.data.BusinessDateResponse; +import org.apache.fineract.infrastructure.businessdate.data.BusinessDateUpdateRequest; +import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; import org.apache.fineract.infrastructure.jobs.exception.JobExecutionException; public interface BusinessDateWritePlatformService { - CommandProcessingResult updateBusinessDate(JsonCommand command); + BusinessDateResponse updateBusinessDate(BusinessDateUpdateRequest request); - void adjustDate(BusinessDateData data, Map changes); - - void increaseCOBDateByOneDay() throws JobExecutionException; - - void increaseBusinessDateByOneDay() throws JobExecutionException; + void increaseDateByTypeByOneDay(BusinessDateType businessDateType) throws JobExecutionException; } diff --git a/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateWritePlatformServiceImpl.java b/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateWritePlatformServiceImpl.java index 9b25f4937..d4a546d67 100644 --- a/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateWritePlatformServiceImpl.java +++ b/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateWritePlatformServiceImpl.java @@ -18,27 +18,21 @@ */ package org.apache.fineract.infrastructure.businessdate.service; -import jakarta.validation.constraints.NotNull; import java.time.LocalDate; -import java.time.temporal.ChronoUnit; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Optional; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.fineract.infrastructure.businessdate.data.BusinessDateData; +import org.apache.fineract.infrastructure.businessdate.data.BusinessDateResponse; +import org.apache.fineract.infrastructure.businessdate.data.BusinessDateUpdateRequest; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDate; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateRepository; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; import org.apache.fineract.infrastructure.businessdate.exception.BusinessDateActionException; -import org.apache.fineract.infrastructure.businessdate.validator.BusinessDateDataParserAndValidator; +import org.apache.fineract.infrastructure.businessdate.mapper.BusinessDateUpdateRequestMapper; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; -import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.ApiParameterError; -import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; -import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException; import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; import org.apache.fineract.infrastructure.core.service.DateUtils; @@ -50,54 +44,30 @@ import org.springframework.stereotype.Service; @RequiredArgsConstructor public class BusinessDateWritePlatformServiceImpl implements BusinessDateWritePlatformService { - private final BusinessDateDataParserAndValidator dataValidator; private final BusinessDateRepository repository; private final ConfigurationDomainService configurationDomainService; + private final BusinessDateUpdateRequestMapper updateRequestMapper; @Override - public CommandProcessingResult updateBusinessDate(@NotNull final JsonCommand command) { - BusinessDateData data = dataValidator.validateAndParseUpdate(command); - Map changes = new HashMap<>(); - adjustDate(data, changes); - return new CommandProcessingResultBuilder().withCommandId(command.commandId()).with(changes).build(); + public BusinessDateResponse updateBusinessDate(BusinessDateUpdateRequest request) { + BusinessDateResponse businessDateDto = updateRequestMapper.map(request); + adjustDate(businessDateDto); + + return businessDateDto; } @Override - public void adjustDate(BusinessDateData data, Map changes) { - boolean isCOBDateAdjustmentEnabled = configurationDomainService.isCOBDateAdjustmentEnabled(); - boolean isBusinessDateEnabled = configurationDomainService.isBusinessDateEnabled(); - - if (!isBusinessDateEnabled) { - log.error("Business date functionality is not enabled!"); - throw new BusinessDateActionException("business.date.is.not.enabled", "Business date functionality is not enabled"); - } - updateOrCreateBusinessDate(data.getType(), data.getDate(), changes); - if (isCOBDateAdjustmentEnabled && BusinessDateType.BUSINESS_DATE.name().equals(data.getType())) { - updateOrCreateBusinessDate(BusinessDateType.COB_DATE.getName(), data.getDate().minus(1, ChronoUnit.DAYS), changes); - } - } - - @Override - public void increaseCOBDateByOneDay() throws JobExecutionException { - increaseDateByTypeByOneDay(BusinessDateType.COB_DATE); - } - - @Override - public void increaseBusinessDateByOneDay() throws JobExecutionException { - increaseDateByTypeByOneDay(BusinessDateType.BUSINESS_DATE); - } - - private void increaseDateByTypeByOneDay(BusinessDateType businessDateType) throws JobExecutionException { - Map changes = new HashMap<>(); + public void increaseDateByTypeByOneDay(BusinessDateType businessDateType) throws JobExecutionException { Optional businessDateEntity = repository.findByType(businessDateType); List exceptions = new ArrayList<>(); LocalDate businessDate = businessDateEntity.map(BusinessDate::getDate).orElse(DateUtils.getLocalDateOfTenant()); businessDate = businessDate.plusDays(1); try { - BusinessDateData businessDateData = BusinessDateData.instance(businessDateType, businessDate); - adjustDate(businessDateData, changes); + BusinessDateResponse response = BusinessDateResponse.builder().type(businessDateType) + .description(businessDateType.getDescription()).date(businessDate).build(); + adjustDate(response); } catch (final PlatformApiDataValidationException e) { final List errors = e.getErrors(); for (final ApiParameterError error : errors) { @@ -116,27 +86,44 @@ public class BusinessDateWritePlatformServiceImpl implements BusinessDateWritePl } } - private void updateOrCreateBusinessDate(String type, LocalDate newDate, Map changes) { - BusinessDateType businessDateType = BusinessDateType.valueOf(type); + private void adjustDate(BusinessDateResponse response) { + boolean isCOBDateAdjustmentEnabled = configurationDomainService.isCOBDateAdjustmentEnabled(); + boolean isBusinessDateEnabled = configurationDomainService.isBusinessDateEnabled(); + + if (!isBusinessDateEnabled) { + log.error("Business date functionality is not enabled!"); + throw new BusinessDateActionException("business.date.is.not.enabled", "Business date functionality is not enabled"); + } + updateOrCreateBusinessDate(response); + if (isCOBDateAdjustmentEnabled && BusinessDateType.BUSINESS_DATE.equals(response.getType())) { + BusinessDateResponse res = BusinessDateResponse.builder().type(BusinessDateType.COB_DATE) + .description(BusinessDateType.COB_DATE.getDescription()).date(response.getDate().minusDays(1)).build(); + updateOrCreateBusinessDate(res); + response.addAllChanges(res.getChanges()); + } + } + + private void updateOrCreateBusinessDate(BusinessDateResponse businessDateDto) { + BusinessDateType businessDateType = businessDateDto.getType(); Optional businessDate = repository.findByType(businessDateType); if (businessDate.isEmpty()) { - BusinessDate newBusinessDate = BusinessDate.instance(businessDateType, newDate); + BusinessDate newBusinessDate = BusinessDate.instance(businessDateType, businessDateDto.getDate()); repository.save(newBusinessDate); - changes.put(type, newBusinessDate.getDate()); + businessDateDto.addChange(businessDateType, newBusinessDate.getDate()); } else { - updateBusinessDate(businessDate.get(), newDate, changes); + updateBusinessDate(businessDate.get(), businessDateDto); } } - private void updateBusinessDate(BusinessDate businessDate, LocalDate newDate, Map changes) { - LocalDate oldDate = businessDate.getDate(); - - if (DateUtils.isEqual(oldDate, newDate)) { + private void updateBusinessDate(BusinessDate businessDate, BusinessDateResponse businessDateDto) { + if (DateUtils.isEqual(businessDate.getDate(), businessDateDto.getDate())) { return; } - businessDate.setDate(newDate); + + businessDate.setDate(businessDateDto.getDate()); repository.save(businessDate); - changes.put(businessDate.getType().name(), newDate); + + businessDateDto.addChange(businessDate.getType(), businessDateDto.getDate()); } } diff --git a/fineract-command/src/test/java/org/apache/fineract/command/sample/validation/.gitkeep b/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/validation/.gitkeep similarity index 100% rename from fineract-command/src/test/java/org/apache/fineract/command/sample/validation/.gitkeep rename to fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/validation/.gitkeep diff --git a/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/validator/BusinessDateDataParserAndValidator.java b/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/validator/BusinessDateDataParserAndValidator.java deleted file mode 100644 index 1d3087052..000000000 --- a/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/validator/BusinessDateDataParserAndValidator.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.infrastructure.businessdate.validator; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import jakarta.validation.constraints.NotNull; -import java.time.LocalDate; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.apache.fineract.infrastructure.businessdate.data.BusinessDateData; -import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; -import org.apache.fineract.infrastructure.core.api.JsonCommand; -import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; -import org.apache.fineract.infrastructure.core.exception.InvalidJsonException; -import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; -import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; -import org.springframework.stereotype.Component; - -@Slf4j -@RequiredArgsConstructor -@Component -public class BusinessDateDataParserAndValidator { - - private final FromJsonHelper jsonHelper; - - public BusinessDateData validateAndParseUpdate(@NotNull final JsonCommand command) { - final DataValidatorBuilder dataValidator = new DataValidatorBuilder(new ArrayList<>()).resource("businessdate.update"); - JsonObject element = extractJsonObject(command); - - BusinessDateData result = validateAndParseUpdate(dataValidator, element, jsonHelper); - throwExceptionIfValidationWarningsExist(dataValidator); - - return result; - } - - private JsonObject extractJsonObject(JsonCommand command) { - String json = command.json(); - if (StringUtils.isBlank(json)) { - throw new InvalidJsonException(); - } - - final JsonElement element = jsonHelper.parse(json); - return element.getAsJsonObject(); - } - - private void throwExceptionIfValidationWarningsExist(DataValidatorBuilder dataValidator) { - if (dataValidator.hasError()) { - log.error("Business date - Validation errors: {}", dataValidator.getDataValidationErrors()); - throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", - dataValidator.getDataValidationErrors()); - } - } - - private BusinessDateData validateAndParseUpdate(final DataValidatorBuilder dataValidator, JsonObject element, - FromJsonHelper jsonHelper) { - if (element == null) { - return null; - } - - jsonHelper.checkForUnsupportedParameters(element, List.of("type", "date", "dateFormat", "locale")); - - String businessDateTypeName = jsonHelper.extractStringNamed("type", element); - final String localeValue = jsonHelper.extractStringNamed("locale", element); - final String dateFormat = jsonHelper.extractDateFormatParameter(element); - final String dateValue = jsonHelper.extractStringNamed("date", element); - dataValidator.reset().parameter("type").value(businessDateTypeName).notBlank(); - dataValidator.reset().parameter("locale").value(localeValue).notBlank(); - dataValidator.reset().parameter("dateFormat").value(dateFormat).notBlank(); - dataValidator.reset().parameter("date").value(dateValue).notBlank(); - - if (dataValidator.hasError()) { - return null; - } - Locale locale = jsonHelper.extractLocaleParameter(element); - BusinessDateType type; - try { - type = BusinessDateType.valueOf(businessDateTypeName); - } catch (IllegalArgumentException e) { - dataValidator.reset().parameter("type").failWithCode("Invalid Business Type value: `" + businessDateTypeName + "`"); - return null; - } - LocalDate date = jsonHelper.extractLocalDateNamed("date", element, dateFormat, locale); - dataValidator.reset().parameter("date").value(date).notNull(); - return dataValidator.hasError() ? null : BusinessDateData.instance(type, date); - } -} diff --git a/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/exceptionmapper/JakartaValidationExceptionMapper.java b/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/exceptionmapper/JakartaValidationExceptionMapper.java new file mode 100644 index 000000000..04641cb2a --- /dev/null +++ b/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/exceptionmapper/JakartaValidationExceptionMapper.java @@ -0,0 +1,57 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.infrastructure.core.exceptionmapper; + +import jakarta.validation.ConstraintViolationException; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.core.Response.Status; +import jakarta.ws.rs.ext.ExceptionMapper; +import jakarta.ws.rs.ext.Provider; +import java.util.List; +import lombok.extern.slf4j.Slf4j; +import org.apache.fineract.infrastructure.core.data.ApiGlobalErrorResponse; +import org.apache.fineract.infrastructure.core.data.ApiParameterError; +import org.apache.fineract.infrastructure.core.exception.ErrorHandler; +import org.springframework.stereotype.Component; + +@Slf4j +@Provider +@Component +public class JakartaValidationExceptionMapper implements FineractExceptionMapper, ExceptionMapper { + + @Override + public Response toResponse(final ConstraintViolationException exception) { + log.warn("Exception occurred", ErrorHandler.findMostSpecificException(exception)); + final ApiGlobalErrorResponse dataValidationErrorResponse = ApiGlobalErrorResponse.badClientRequest(exception.getMessage(), + exception.getLocalizedMessage(), getApiParameterErrors(exception)); + + return Response.status(Status.BAD_REQUEST).entity(dataValidationErrorResponse).type(MediaType.APPLICATION_JSON).build(); + } + + @Override + public int errorCode() { + return 2002; + } + + private List getApiParameterErrors(final ConstraintViolationException exception) { + return exception.getConstraintViolations().stream().map(violation -> ApiParameterError + .parameterError(violation.getMessageTemplate(), violation.getMessage(), violation.getPropertyPath().toString())).toList(); + } +} diff --git a/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/service/DateUtils.java b/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/service/DateUtils.java index bdf4957a8..088a99ebc 100644 --- a/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/service/DateUtils.java +++ b/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/service/DateUtils.java @@ -28,7 +28,9 @@ import java.time.OffsetDateTime; import java.time.ZoneId; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; import java.time.format.DateTimeParseException; +import java.time.format.ResolverStyle; import java.time.temporal.ChronoField; import java.time.temporal.ChronoUnit; import java.time.temporal.TemporalAccessor; @@ -128,18 +130,10 @@ public final class DateUtils { return compare(first, second, truncate) == 0; } - public static boolean isEqualTenantDateTime(LocalDateTime dateTime) { - return isEqualTenantDateTime(dateTime, null); - } - public static boolean isEqualTenantDateTime(LocalDateTime dateTime, ChronoUnit truncate) { return isEqual(dateTime, getLocalDateTimeOfTenant(), truncate); } - public static boolean isEqualSystemDateTime(LocalDateTime dateTime) { - return isEqualSystemDateTime(dateTime, null); - } - public static boolean isEqualSystemDateTime(LocalDateTime dateTime, ChronoUnit truncate) { return isEqual(dateTime, getLocalDateTimeOfSystem(), truncate); } @@ -152,22 +146,6 @@ public final class DateUtils { return compare(first, second, truncate) < 0; } - public static boolean isBeforeTenantDateTime(LocalDateTime dateTime) { - return isBeforeTenantDateTime(dateTime, null); - } - - public static boolean isBeforeTenantDateTime(LocalDateTime dateTime, ChronoUnit truncate) { - return isBefore(dateTime, getLocalDateTimeOfTenant(), truncate); - } - - public static boolean isBeforeSystemDateTime(LocalDateTime dateTime) { - return isBeforeSystemDateTime(dateTime, null); - } - - public static boolean isBeforeSystemDateTime(LocalDateTime dateTime, ChronoUnit truncate) { - return isBefore(dateTime, getLocalDateTimeOfSystem(), truncate); - } - public static boolean isAfter(LocalDateTime first, LocalDateTime second) { return isAfter(first, second, null); } @@ -184,10 +162,6 @@ public final class DateUtils { return isAfter(dateTime, getLocalDateTimeOfTenant(), truncate); } - public static boolean isAfterSystemDateTime(LocalDateTime dateTime) { - return isAfterSystemDateTime(dateTime, null); - } - public static boolean isAfterSystemDateTime(LocalDateTime dateTime, ChronoUnit truncate) { return isAfter(dateTime, getLocalDateTimeOfSystem(), truncate); } @@ -228,10 +202,6 @@ public final class DateUtils { return compare(first, second, truncate) == 0; } - public static boolean isEqualTenantDateTime(OffsetDateTime dateTime) { - return isEqualTenantDateTime(dateTime, null); - } - public static boolean isEqualTenantDateTime(OffsetDateTime dateTime, ChronoUnit truncate) { return isEqual(dateTime, getOffsetDateTimeOfTenant(), truncate); } @@ -244,10 +214,6 @@ public final class DateUtils { return compare(first, second, truncate) < 0; } - public static boolean isBeforeTenantDateTime(OffsetDateTime dateTime) { - return isBeforeTenantDateTime(dateTime, null); - } - public static boolean isBeforeTenantDateTime(OffsetDateTime dateTime, ChronoUnit truncate) { return isBefore(dateTime, getOffsetDateTimeOfTenant(), truncate); } @@ -260,10 +226,6 @@ public final class DateUtils { return compare(first, second, truncate) > 0; } - public static boolean isAfterTenantDateTime(OffsetDateTime dateTime) { - return isAfterTenantDateTime(dateTime, null); - } - public static boolean isAfterTenantDateTime(OffsetDateTime dateTime, ChronoUnit truncate) { return isAfter(dateTime, getOffsetDateTimeOfTenant(), truncate); } @@ -274,10 +236,6 @@ public final class DateUtils { return ThreadLocalContextUtil.getBusinessDate(); } - public static int compareToBusinessDate(LocalDate date) { - return compare(date, getBusinessLocalDate()); - } - public static boolean isEqualTenantDate(LocalDate date) { return isEqual(date, getLocalDateOfTenant()); } @@ -286,10 +244,6 @@ public final class DateUtils { return isBefore(date, getLocalDateOfTenant()); } - public static boolean isAfterTenantDate(LocalDate date) { - return isAfter(date, getLocalDateOfTenant()); - } - public static boolean isEqualBusinessDate(LocalDate date) { return isEqual(date, getBusinessLocalDate()); } @@ -306,10 +260,6 @@ public final class DateUtils { return isAfterBusinessDate(localDate); } - public static boolean isDateInThePast(final LocalDate localDate) { - return isBeforeBusinessDate(localDate); - } - public static boolean isDateInRangeFromInclusiveToExclusive(final LocalDate fromInclusive, final LocalDate upToNotInclusive, final LocalDate target) { return (DateUtils.isEqual(target, fromInclusive) || DateUtils.isAfter(target, fromInclusive)) @@ -399,6 +349,16 @@ public final class DateUtils { } } + public static LocalDate toLocalDate(String local, String date, String dateFormat) { + Locale locale = Locale.forLanguageTag(local); + String patternISO = dateFormat.replace("y", "u"); + DateTimeFormatter formatter = new DateTimeFormatterBuilder().parseCaseInsensitive().parseLenient().appendPattern(patternISO) + .optionalStart().appendPattern(" HH:mm:ss").optionalEnd().parseDefaulting(ChronoField.HOUR_OF_DAY, 0) + .parseDefaulting(ChronoField.MINUTE_OF_HOUR, 0).parseDefaulting(ChronoField.SECOND_OF_MINUTE, 0).toFormatter(locale) + .withResolverStyle(ResolverStyle.STRICT); + return LocalDateTime.parse(date, formatter).toLocalDate(); + } + public static String format(LocalDate date) { return format(date, null); } diff --git a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/helper/BusinessDateHelper.java b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/helper/BusinessDateHelper.java index 12f35475e..fdf68593d 100644 --- a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/helper/BusinessDateHelper.java +++ b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/helper/BusinessDateHelper.java @@ -21,8 +21,8 @@ package org.apache.fineract.test.helper; import java.io.IOException; import java.time.format.DateTimeFormatter; import lombok.RequiredArgsConstructor; -import org.apache.fineract.client.models.BusinessDateRequest; import org.apache.fineract.client.models.BusinessDateResponse; +import org.apache.fineract.client.models.BusinessDateUpdateRequest; import org.apache.fineract.client.services.BusinessDateManagementApi; import org.apache.fineract.test.support.TestContext; import org.apache.fineract.test.support.TestContextKey; @@ -36,15 +36,14 @@ public class BusinessDateHelper { public static final String DATE_FORMAT = "dd MMMM yyyy"; public static final String DEFAULT_LOCALE = "en"; public static final String BUSINESS_DATE = "BUSINESS_DATE"; - public static final String DEFAULT = "BUSINESS_DATE"; public static final String COB = "COB_DATE"; private final BusinessDateManagementApi businessDateManagementApi; public void setBusinessDate(String businessDate) throws IOException { - BusinessDateRequest businessDateRequest = defaultBusinessDateRequest().date(businessDate); + BusinessDateUpdateRequest businessDateRequest = defaultBusinessDateRequest().date(businessDate); - Response businessDateRequestResponse = businessDateManagementApi.updateBusinessDate(businessDateRequest) + Response businessDateRequestResponse = businessDateManagementApi.updateBusinessDate(null, businessDateRequest) .execute(); ErrorHelper.checkSuccessfulApiCall(businessDateRequestResponse); TestContext.INSTANCE.set(TestContextKey.BUSINESS_DATE_RESPONSE, businessDateRequestResponse); @@ -56,11 +55,12 @@ public class BusinessDateHelper { setBusinessDate(today); } - public BusinessDateRequest defaultBusinessDateRequest() { - return new BusinessDateRequest().type(DEFAULT).dateFormat(DATE_FORMAT).locale(DEFAULT_LOCALE); + public BusinessDateUpdateRequest defaultBusinessDateRequest() { + return new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE).dateFormat(DATE_FORMAT) + .locale(DEFAULT_LOCALE); } public String getBusinessDate() throws IOException { - return businessDateManagementApi.getBusinessDate(DEFAULT).toString(); + return businessDateManagementApi.getBusinessDate(BUSINESS_DATE).toString(); } } diff --git a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/common/BusinessDateStepDef.java b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/common/BusinessDateStepDef.java index 7b2aa99a0..0bc536b6d 100644 --- a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/common/BusinessDateStepDef.java +++ b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/common/BusinessDateStepDef.java @@ -25,7 +25,7 @@ import io.cucumber.java.en.When; import java.io.IOException; import java.time.LocalDate; import java.time.format.DateTimeFormatter; -import org.apache.fineract.client.models.BusinessDateData; +import org.apache.fineract.client.models.BusinessDateResponse; import org.apache.fineract.client.services.BusinessDateManagementApi; import org.apache.fineract.test.helper.BusinessDateHelper; import org.apache.fineract.test.helper.ErrorHelper; @@ -53,7 +53,7 @@ public class BusinessDateStepDef extends AbstractStepDef { @Then("Admin checks that the business date is correctly set to {string}") public void checkBusinessDate(String businessDate) throws IOException { - Response businessDateResponse = businessDateManagementApi.getBusinessDate(BusinessDateHelper.BUSINESS_DATE) + Response businessDateResponse = businessDateManagementApi.getBusinessDate(BusinessDateHelper.BUSINESS_DATE) .execute(); ErrorHelper.checkSuccessfulApiCall(businessDateResponse); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d MMMM yyyy"); diff --git a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/LoanChargeAdjustmentStepDef.java b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/LoanChargeAdjustmentStepDef.java index efb2db2ef..652a6c4ff 100644 --- a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/LoanChargeAdjustmentStepDef.java +++ b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/LoanChargeAdjustmentStepDef.java @@ -29,7 +29,7 @@ import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; import lombok.extern.slf4j.Slf4j; -import org.apache.fineract.client.models.BusinessDateData; +import org.apache.fineract.client.models.BusinessDateResponse; import org.apache.fineract.client.models.GetLoansLoanIdLoanChargeData; import org.apache.fineract.client.models.GetLoansLoanIdResponse; import org.apache.fineract.client.models.GetLoansLoanIdTransactions; @@ -132,7 +132,7 @@ public class LoanChargeAdjustmentStepDef extends AbstractStepDef { Long transactionId = getTransactionIdForTransactionMetConditions(transactionDate, transactionAmount, loanDetailsResponse); - Response> businessDateResponse = businessDateManagementApi.getBusinessDates().execute(); + Response> businessDateResponse = businessDateManagementApi.getBusinessDates().execute(); LocalDate businessDate = businessDateResponse.body().get(0).getDate(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_FORMAT); String businessDateActual = formatter.format(businessDate); diff --git a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/LoanStepDef.java b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/LoanStepDef.java index 495695b75..18c2d9c4e 100644 --- a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/LoanStepDef.java +++ b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/LoanStepDef.java @@ -61,7 +61,7 @@ import org.apache.fineract.avro.loan.v1.LoanChargePaidByDataV1; import org.apache.fineract.avro.loan.v1.LoanStatusEnumDataV1; import org.apache.fineract.avro.loan.v1.LoanTransactionDataV1; import org.apache.fineract.client.models.AdvancedPaymentData; -import org.apache.fineract.client.models.BusinessDateData; +import org.apache.fineract.client.models.BusinessDateResponse; import org.apache.fineract.client.models.DeleteLoansLoanIdResponse; import org.apache.fineract.client.models.DisbursementDetail; import org.apache.fineract.client.models.GetLoanProductsChargeOffReasonOptions; @@ -2579,7 +2579,7 @@ public class LoanStepDef extends AbstractStepDef { // Only proceed with date check if catch-up is not running if (!statusResponse.body().getCatchUpRunning()) { // Get the current business date - Response businessDateResponse = businessDateApi.getBusinessDate(BusinessDateHelper.COB).execute(); + Response businessDateResponse = businessDateApi.getBusinessDate(BusinessDateHelper.COB).execute(); ErrorHelper.checkSuccessfulApiCall(businessDateResponse); LocalDate currentBusinessDate = businessDateResponse.body().getDate(); diff --git a/fineract-provider/dependencies.gradle b/fineract-provider/dependencies.gradle index 03dbb3122..bfbc20da4 100644 --- a/fineract-provider/dependencies.gradle +++ b/fineract-provider/dependencies.gradle @@ -25,6 +25,8 @@ dependencies { } implementation(project(path: ':fineract-core')) + implementation(project(path: ':fineract-command')) + implementation(project(path: ':fineract-validation')) implementation(project(path: ':fineract-accounting')) implementation(project(path: ':fineract-investor')) implementation(project(path: ':fineract-rates')) @@ -36,7 +38,6 @@ dependencies { implementation(project(path: ':fineract-progressive-loan')) implementation(project(path: ':fineract-report')) implementation(project(path: ':fineract-tax')) - implementation(project(path: ':fineract-command')) providedRuntime("org.springframework.boot:spring-boot-starter-tomcat") @@ -51,6 +52,7 @@ dependencies { ) implementation( 'org.springframework.boot:spring-boot-starter-web', + 'org.springframework.boot:spring-boot-starter-validation', 'org.springframework.boot:spring-boot-starter-security', 'org.springframework.boot:spring-boot-starter-cache', 'org.springframework.boot:spring-boot-starter-oauth2-resource-server', diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/SecurityConfig.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/SecurityConfig.java index 92e0a068f..380acdb09 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/SecurityConfig.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/SecurityConfig.java @@ -28,8 +28,6 @@ import static org.springframework.security.web.util.matcher.AntPathRequestMatche import java.util.ArrayList; import java.util.List; import java.util.Objects; -import org.apache.fineract.commands.domain.CommandSourceRepository; -import org.apache.fineract.commands.service.CommandSourceService; import org.apache.fineract.infrastructure.businessdate.service.BusinessDateReadPlatformService; import org.apache.fineract.infrastructure.cache.service.CacheWritePlatformService; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; @@ -48,7 +46,6 @@ import org.apache.fineract.infrastructure.security.filter.InsecureTwoFactorAuthe import org.apache.fineract.infrastructure.security.filter.TenantAwareBasicAuthenticationFilter; import org.apache.fineract.infrastructure.security.filter.TwoFactorAuthenticationFilter; import org.apache.fineract.infrastructure.security.service.BasicAuthTenantDetailsService; -import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.TenantAwareJpaPlatformUserDetailsService; import org.apache.fineract.infrastructure.security.service.TwoFactorService; import org.apache.fineract.notification.service.UserNotificationService; @@ -111,17 +108,11 @@ public class SecurityConfig { @Autowired private MDCWrapper mdcWrapper; @Autowired - private CommandSourceRepository commandSourceRepository; - @Autowired - private CommandSourceService commandSourceService; - @Autowired private FineractRequestContextHolder fineractRequestContextHolder; @Autowired(required = false) private LoanCOBFilterHelper loanCOBFilterHelper; @Autowired - private PlatformSecurityContext context; - @Autowired private IdempotencyStoreHelper idempotencyStoreHelper; @Bean @@ -141,6 +132,12 @@ public class SecurityConfig { .requestMatchers(antMatcher(HttpMethod.POST, "/api/*/echo")).permitAll() // .requestMatchers(antMatcher(HttpMethod.POST, "/api/*/authentication")).permitAll() // .requestMatchers(antMatcher(HttpMethod.PUT, "/api/*/instance-mode")).permitAll() // + // businessdate + .requestMatchers(antMatcher(HttpMethod.GET, "/api/*/businessdate/*")) + .hasAnyAuthority("ALL_FUNCTIONS", "ALL_FUNCTIONS_READ", "READ_BUSINESS_DATE") // + .requestMatchers(antMatcher(HttpMethod.POST, "/api/*/businessdate")) + .hasAnyAuthority("ALL_FUNCTIONS", "ALL_FUNCTIONS_WRITE", "UPDATE_BUSINESS_DATE") // + // .requestMatchers(antMatcher(HttpMethod.POST, "/api/*/twofactor/validate")).fullyAuthenticated() // .requestMatchers(antMatcher("/api/*/twofactor")).fullyAuthenticated() // .requestMatchers(antMatcher("/api/**")) diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/jersey/JerseyConfig.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/jersey/JerseyConfig.java index d44737f2e..50bdb5975 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/jersey/JerseyConfig.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/jersey/JerseyConfig.java @@ -46,6 +46,7 @@ public class JerseyConfig extends ResourceConfig { bind(PageableParamProvider.class).to(ValueParamProvider.class).in(Singleton.class); } }); + register(org.glassfish.jersey.server.validation.ValidationFeature.class); property(ServerProperties.WADL_FEATURE_DISABLE, true); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/IncreaseDateBy1DayServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/IncreaseDateBy1DayServiceImpl.java deleted file mode 100644 index 3a5043c13..000000000 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/IncreaseDateBy1DayServiceImpl.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.infrastructure.jobs.service.increasedateby1day; - -import java.time.LocalDate; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.fineract.infrastructure.businessdate.data.BusinessDateData; -import org.apache.fineract.infrastructure.businessdate.domain.BusinessDate; -import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateRepository; -import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; -import org.apache.fineract.infrastructure.businessdate.service.BusinessDateWritePlatformService; -import org.apache.fineract.infrastructure.core.data.ApiParameterError; -import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException; -import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; -import org.apache.fineract.infrastructure.core.service.DateUtils; -import org.springframework.stereotype.Service; - -@Service -@Slf4j -@RequiredArgsConstructor -public class IncreaseDateBy1DayServiceImpl implements IncreaseDateBy1DayService { - - private final BusinessDateRepository businessDateRepository; - private final BusinessDateWritePlatformService businessDateWritePlatformService; - - @Override - public void increaseDateByTypeByOneDay(BusinessDateType businessDateType) { - Map changes = new HashMap<>(); - Optional businessDateEntity = businessDateRepository.findByType(businessDateType); - LocalDate businessDate = businessDateEntity.map(BusinessDate::getDate).orElse(DateUtils.getLocalDateOfTenant()); - businessDate = businessDate.plusDays(1); - try { - BusinessDateData businessDateData = BusinessDateData.instance(businessDateType, businessDate); - businessDateWritePlatformService.adjustDate(businessDateData, changes); - } catch (final PlatformApiDataValidationException e) { - final List errors = e.getErrors(); - for (final ApiParameterError error : errors) { - log.error("Increasing {} by 1 day failed due to: {}", businessDateType.getDescription(), error.getDeveloperMessage()); - } - } catch (final AbstractPlatformDomainRuleException e) { - log.error("Increasing {} by 1 day failed due to: {}", businessDateType.getDescription(), e.getDefaultUserMessage()); - } catch (Exception e) { - log.error("Increasing {} by 1 day failed due to: {}", businessDateType.getDescription(), e.getMessage()); - } - } -} diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/increasebusinessdateby1day/IncreaseBusinessDateBy1DayConfig.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/increasebusinessdateby1day/IncreaseBusinessDateBy1DayConfig.java index e83333153..fbd7d4732 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/increasebusinessdateby1day/IncreaseBusinessDateBy1DayConfig.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/increasebusinessdateby1day/IncreaseBusinessDateBy1DayConfig.java @@ -18,16 +18,14 @@ */ package org.apache.fineract.infrastructure.jobs.service.increasedateby1day.increasebusinessdateby1day; +import org.apache.fineract.infrastructure.businessdate.service.BusinessDateWritePlatformService; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; import org.apache.fineract.infrastructure.jobs.service.JobName; -import org.apache.fineract.infrastructure.jobs.service.increasedateby1day.IncreaseDateBy1DayService; import org.springframework.batch.core.Job; -import org.springframework.batch.core.Step; import org.springframework.batch.core.job.builder.JobBuilder; import org.springframework.batch.core.launch.support.RunIdIncrementer; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.step.builder.StepBuilder; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.transaction.PlatformTransactionManager; @@ -35,29 +33,17 @@ import org.springframework.transaction.PlatformTransactionManager; @Configuration public class IncreaseBusinessDateBy1DayConfig { - @Autowired - private JobRepository jobRepository; - @Autowired - private PlatformTransactionManager transactionManager; - @Autowired - private IncreaseDateBy1DayService increaseDateBy1DayService; - @Autowired - private ConfigurationDomainService configurationDomainService; - @Bean - protected Step increaseBusinessDateBy1DayStep() { - return new StepBuilder(JobName.INCREASE_BUSINESS_DATE_BY_1_DAY.name(), jobRepository) - .tasklet(increaseBusinessDateBy1DayTasklet(), transactionManager).build(); + public IncreaseBusinessDateBy1DayTasklet increaseBusinessDateBy1DayTasklet( + BusinessDateWritePlatformService businessDateWritePlatformService, ConfigurationDomainService configurationDomainService) { + return new IncreaseBusinessDateBy1DayTasklet(businessDateWritePlatformService, configurationDomainService); } @Bean - public Job increaseBusinessDateBy1DayJob() { - return new JobBuilder(JobName.INCREASE_BUSINESS_DATE_BY_1_DAY.name(), jobRepository).start(increaseBusinessDateBy1DayStep()) + public Job increaseBusinessDateBy1DayJob(PlatformTransactionManager transactionManager, JobRepository jobRepository, + IncreaseBusinessDateBy1DayTasklet tasklet) { + return new JobBuilder(JobName.INCREASE_BUSINESS_DATE_BY_1_DAY.name(), jobRepository).start( + new StepBuilder(JobName.INCREASE_BUSINESS_DATE_BY_1_DAY.name(), jobRepository).tasklet(tasklet, transactionManager).build()) .incrementer(new RunIdIncrementer()).build(); } - - @Bean - public IncreaseBusinessDateBy1DayTasklet increaseBusinessDateBy1DayTasklet() { - return new IncreaseBusinessDateBy1DayTasklet(increaseDateBy1DayService, configurationDomainService); - } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/increasebusinessdateby1day/IncreaseBusinessDateBy1DayTasklet.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/increasebusinessdateby1day/IncreaseBusinessDateBy1DayTasklet.java index cae7ccb86..c22bf2060 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/increasebusinessdateby1day/IncreaseBusinessDateBy1DayTasklet.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/increasebusinessdateby1day/IncreaseBusinessDateBy1DayTasklet.java @@ -21,8 +21,8 @@ package org.apache.fineract.infrastructure.jobs.service.increasedateby1day.incre import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; +import org.apache.fineract.infrastructure.businessdate.service.BusinessDateWritePlatformService; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; -import org.apache.fineract.infrastructure.jobs.service.increasedateby1day.IncreaseDateBy1DayService; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.scope.context.ChunkContext; @@ -33,13 +33,13 @@ import org.springframework.batch.repeat.RepeatStatus; @RequiredArgsConstructor public class IncreaseBusinessDateBy1DayTasklet implements Tasklet { - private final IncreaseDateBy1DayService increaseDateBy1DayService; + private final BusinessDateWritePlatformService businessDateWritePlatformService; private final ConfigurationDomainService configurationDomainService; @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { if (configurationDomainService.isBusinessDateEnabled()) { - increaseDateBy1DayService.increaseDateByTypeByOneDay(BusinessDateType.BUSINESS_DATE); + businessDateWritePlatformService.increaseDateByTypeByOneDay(BusinessDateType.BUSINESS_DATE); } else { contribution.setExitStatus(ExitStatus.NOOP); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/increasecobdateby1day/IncreaseCobDateBy1DayConfig.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/increasecobdateby1day/IncreaseCobDateBy1DayConfig.java index 6362a4bdb..7d356682a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/increasecobdateby1day/IncreaseCobDateBy1DayConfig.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/increasecobdateby1day/IncreaseCobDateBy1DayConfig.java @@ -18,31 +18,28 @@ */ package org.apache.fineract.infrastructure.jobs.service.increasedateby1day.increasecobdateby1day; +import lombok.RequiredArgsConstructor; +import org.apache.fineract.infrastructure.businessdate.service.BusinessDateWritePlatformService; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; import org.apache.fineract.infrastructure.jobs.service.JobName; -import org.apache.fineract.infrastructure.jobs.service.increasedateby1day.IncreaseDateBy1DayService; import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; import org.springframework.batch.core.job.builder.JobBuilder; import org.springframework.batch.core.launch.support.RunIdIncrementer; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.step.builder.StepBuilder; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.transaction.PlatformTransactionManager; @Configuration +@RequiredArgsConstructor public class IncreaseCobDateBy1DayConfig { - @Autowired - private JobRepository jobRepository; - @Autowired - private PlatformTransactionManager transactionManager; - @Autowired - private IncreaseDateBy1DayService increaseDateBy1DayService; - @Autowired - private ConfigurationDomainService configurationDomainService; + private final JobRepository jobRepository; + private final PlatformTransactionManager transactionManager; + private final BusinessDateWritePlatformService businessDateWritePlatformService; + private final ConfigurationDomainService configurationDomainService; @Bean protected Step increaseCobDateBy1DayStep() { @@ -58,6 +55,6 @@ public class IncreaseCobDateBy1DayConfig { @Bean public IncreaseCobDateBy1DayTasklet increaseCobDateBy1DayTasklet() { - return new IncreaseCobDateBy1DayTasklet(increaseDateBy1DayService, configurationDomainService); + return new IncreaseCobDateBy1DayTasklet(businessDateWritePlatformService, configurationDomainService); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/increasecobdateby1day/IncreaseCobDateBy1DayTasklet.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/increasecobdateby1day/IncreaseCobDateBy1DayTasklet.java index a8094c595..94c4145c5 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/increasecobdateby1day/IncreaseCobDateBy1DayTasklet.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/increasecobdateby1day/IncreaseCobDateBy1DayTasklet.java @@ -21,8 +21,8 @@ package org.apache.fineract.infrastructure.jobs.service.increasedateby1day.incre import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; +import org.apache.fineract.infrastructure.businessdate.service.BusinessDateWritePlatformService; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; -import org.apache.fineract.infrastructure.jobs.service.increasedateby1day.IncreaseDateBy1DayService; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.scope.context.ChunkContext; @@ -33,13 +33,13 @@ import org.springframework.batch.repeat.RepeatStatus; @RequiredArgsConstructor public class IncreaseCobDateBy1DayTasklet implements Tasklet { - private final IncreaseDateBy1DayService increaseDateBy1DayService; + private final BusinessDateWritePlatformService businessDateWritePlatformService; private final ConfigurationDomainService configurationDomainService; @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { if (configurationDomainService.isBusinessDateEnabled()) { - increaseDateBy1DayService.increaseDateByTypeByOneDay(BusinessDateType.COB_DATE); + businessDateWritePlatformService.increaseDateByTypeByOneDay(BusinessDateType.COB_DATE); } else { contribution.setExitStatus(ExitStatus.NOOP); } diff --git a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/api/BusinessDateApiTest.java b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/api/BusinessDateApiTest.java deleted file mode 100644 index 7ffa686da..000000000 --- a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/api/BusinessDateApiTest.java +++ /dev/null @@ -1,141 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.infrastructure.businessdate.api; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoInteractions; - -import java.util.List; -import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService; -import org.apache.fineract.infrastructure.businessdate.data.BusinessDateData; -import org.apache.fineract.infrastructure.businessdate.data.request.BusinessDateRequest; -import org.apache.fineract.infrastructure.businessdate.service.BusinessDateReadPlatformService; -import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; -import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer; -import org.apache.fineract.infrastructure.security.exception.NoAuthorizationException; -import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; -import org.apache.fineract.useradministration.domain.AppUser; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.jupiter.MockitoExtension; -import org.mockito.junit.jupiter.MockitoSettings; -import org.mockito.quality.Strictness; - -@ExtendWith(MockitoExtension.class) -@MockitoSettings(strictness = Strictness.LENIENT) -class BusinessDateApiTest { - - @Mock - private BusinessDateReadPlatformService readPlatformService; - - @Mock - private PlatformSecurityContext securityContext; - - @Mock - private DefaultToApiJsonSerializer jsonSerializer; - - @Mock - private PortfolioCommandSourceWritePlatformService commandWritePlatformService; - - @InjectMocks - private BusinessDateApiResource underTest; - - @Test - void getBusinessDatesAPIHasPermission() { - AppUser appUser = Mockito.mock(AppUser.class); - List response = Mockito.mock(List.class); - given(readPlatformService.findAll()).willReturn(response); - // given - Mockito.doNothing().when(appUser).validateHasReadPermission("BUSINESS_DATE"); - given(securityContext.authenticatedUser()).willReturn(appUser); - // when - underTest.getBusinessDates(); - // then - verify(readPlatformService, Mockito.times(1)).findAll(); - } - - @Test - void getBusinessDatesAPIHasNoPermission() { - AppUser appUser = Mockito.mock(AppUser.class); - // given - Mockito.doThrow(NoAuthorizationException.class).when(appUser).validateHasReadPermission("BUSINESS_DATE"); - given(securityContext.authenticatedUser()).willReturn(appUser); - // when - assertThatThrownBy(() -> underTest.getBusinessDates()).isInstanceOf(NoAuthorizationException.class); - // then - verifyNoInteractions(readPlatformService); - } - - @Test - void getBusinessDateByTypeAPIHasPermission() { - AppUser appUser = Mockito.mock(AppUser.class); - BusinessDateData response = Mockito.mock(BusinessDateData.class); - given(readPlatformService.findByType("type")).willReturn(response); - // given - Mockito.doNothing().when(appUser).validateHasReadPermission("BUSINESS_DATE"); - given(securityContext.authenticatedUser()).willReturn(appUser); - // when - underTest.getBusinessDate("type"); - // then - verify(readPlatformService, Mockito.times(1)).findByType("type"); - } - - @Test - void getBusinessDateByTypeAPIHasNoPermission() { - AppUser appUser = Mockito.mock(AppUser.class); - // given - Mockito.doThrow(NoAuthorizationException.class).when(appUser).validateHasReadPermission("BUSINESS_DATE"); - given(securityContext.authenticatedUser()).willReturn(appUser); - // when - assertThatThrownBy(() -> underTest.getBusinessDate("type")).isInstanceOf(NoAuthorizationException.class); - // then - verifyNoInteractions(readPlatformService); - } - - @Test - void postBusinessDateAPIHasPermission() { - AppUser appUser = Mockito.mock(AppUser.class); - CommandProcessingResult response = Mockito.mock(CommandProcessingResult.class); - // given - Mockito.doNothing().when(appUser).validateHasUpdatePermission("BUSINESS_DATE"); - given(securityContext.authenticatedUser()).willReturn(appUser); - given(commandWritePlatformService.logCommandSource(Mockito.any())).willReturn(response); - // when - underTest.updateBusinessDate(BusinessDateRequest.ofNull()); - // then - verify(commandWritePlatformService, Mockito.times(1)).logCommandSource(Mockito.any()); - } - - @Test - void postBusinessDateAPIHasNoPermission() { - AppUser appUser = Mockito.mock(AppUser.class); - // given - Mockito.doThrow(NoAuthorizationException.class).when(appUser).validateHasUpdatePermission("BUSINESS_DATE"); - given(securityContext.authenticatedUser()).willReturn(appUser); - // when - assertThatThrownBy(() -> underTest.updateBusinessDate(BusinessDateRequest.ofNull())).isInstanceOf(NoAuthorizationException.class); - // then - verifyNoInteractions(readPlatformService); - } -} diff --git a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/data/BusinessDataSerialized.java b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/data/BusinessDataSerialized.java deleted file mode 100644 index 620aee6e0..000000000 --- a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/data/BusinessDataSerialized.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.infrastructure.businessdate.data; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.time.LocalDate; -import java.time.ZoneId; -import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; -import org.apache.fineract.infrastructure.core.serialization.CommandProcessingResultJsonSerializer; -import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer; -import org.apache.fineract.infrastructure.core.serialization.ExcludeNothingWithPrettyPrintingOffJsonSerializerGoogleGson; -import org.apache.fineract.infrastructure.core.serialization.GoogleGsonSerializerHelper; -import org.junit.jupiter.api.Test; - -public class BusinessDataSerialized { - - @Test - public void serializeBusinessDateData() { - DefaultToApiJsonSerializer jsonSerializer = new DefaultToApiJsonSerializer<>( - new ExcludeNothingWithPrettyPrintingOffJsonSerializerGoogleGson(), new CommandProcessingResultJsonSerializer(), - new GoogleGsonSerializerHelper()); - - LocalDate now = LocalDate.now(ZoneId.systemDefault()); - BusinessDateData businessDateData = BusinessDateData.instance(BusinessDateType.BUSINESS_DATE, now); - String result = jsonSerializer.serialize(businessDateData); - assertEquals("{\"description\":\"Business Date\",\"type\":\"BUSINESS_DATE\",\"date\":[" + now.getYear() + "," + now.getMonthValue() - + "," + now.getDayOfMonth() + "]}", result); - } - - @Test - public void serializeBusinessDateData_COB() { - DefaultToApiJsonSerializer jsonSerializer = new DefaultToApiJsonSerializer<>( - new ExcludeNothingWithPrettyPrintingOffJsonSerializerGoogleGson(), new CommandProcessingResultJsonSerializer(), - new GoogleGsonSerializerHelper()); - - LocalDate now = LocalDate.now(ZoneId.systemDefault()); - BusinessDateData businessDateData = BusinessDateData.instance(BusinessDateType.COB_DATE, now); - String result = jsonSerializer.serialize(businessDateData); - assertEquals("{\"description\":\"Close of Business Date\",\"type\":\"COB_DATE\",\"date\":[" + now.getYear() + "," - + now.getMonthValue() + "," + now.getDayOfMonth() + "]}", result); - } - -} diff --git a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/data/BusinessDataTypeTest.java b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/data/BusinessDataTypeTest.java index f0e944ee3..de3cefa42 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/data/BusinessDataTypeTest.java +++ b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/data/BusinessDataTypeTest.java @@ -23,11 +23,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; import org.junit.jupiter.api.Test; -public class BusinessDataTypeTest { +class BusinessDataTypeTest { @Test - public void typoCheck() { - for (BusinessDateType businessDateType : BusinessDateType.values()) { + void typoCheck() { + for (var businessDateType : BusinessDateType.values()) { switch (businessDateType) { case BUSINESS_DATE -> assertEquals("Business Date", businessDateType.getDescription()); case COB_DATE -> assertEquals("Close of Business Date", businessDateType.getDescription()); diff --git a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/data/BusinessDateSerializationTest.java b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/data/BusinessDateSerializationTest.java new file mode 100644 index 000000000..85cdc3e53 --- /dev/null +++ b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/data/BusinessDateSerializationTest.java @@ -0,0 +1,60 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.infrastructure.businessdate.data; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import java.time.LocalDate; +import java.time.ZoneId; +import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; +import org.junit.jupiter.api.Test; + +class BusinessDateSerializationTest { + + private final ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule()) + .setSerializationInclusion(JsonInclude.Include.NON_NULL); + + @Test + void serializeBusinessDateData() throws JsonProcessingException { + var now = LocalDate.now(ZoneId.systemDefault()); + var businessDateResponse = BusinessDateResponse.builder().type(BusinessDateType.BUSINESS_DATE) + .description(BusinessDateType.BUSINESS_DATE.getDescription()).date(now).build(); + + var result = mapper.writeValueAsString(businessDateResponse); + + assertEquals("{\"description\":\"Business Date\",\"type\":\"BUSINESS_DATE\",\"date\":[" + now.getYear() + "," + now.getMonthValue() + + "," + now.getDayOfMonth() + "]}", result); + } + + @Test + void serializeBusinessDateData_COB() throws JsonProcessingException { + var now = LocalDate.now(ZoneId.systemDefault()); + var businessDateResponse = BusinessDateResponse.builder().type(BusinessDateType.COB_DATE) + .description(BusinessDateType.COB_DATE.getDescription()).date(now).build(); + + var result = mapper.writeValueAsString(businessDateResponse); + + assertEquals("{\"description\":\"Close of Business Date\",\"type\":\"COB_DATE\",\"date\":[" + now.getYear() + "," + + now.getMonthValue() + "," + now.getDayOfMonth() + "]}", result); + } +} diff --git a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/mapper/BusinessDateMapperTest.java b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/mapper/BusinessDateUpdateRequestMapperTest.java similarity index 58% rename from fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/mapper/BusinessDateMapperTest.java rename to fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/mapper/BusinessDateUpdateRequestMapperTest.java index a028ea472..53b12bbca 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/mapper/BusinessDateMapperTest.java +++ b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/mapper/BusinessDateUpdateRequestMapperTest.java @@ -23,34 +23,32 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import java.time.LocalDate; import java.time.ZoneId; import java.util.Collections; -import java.util.List; -import org.apache.fineract.infrastructure.businessdate.data.BusinessDateData; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDate; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; import org.junit.jupiter.api.Test; import org.mapstruct.factory.Mappers; -public class BusinessDateMapperTest { +class BusinessDateUpdateRequestMapperTest { - private BusinessDateMapper businessDateMapper = Mappers.getMapper(BusinessDateMapper.class); + private final BusinessDateMapper businessDateMapper = Mappers.getMapper(BusinessDateMapper.class); @Test - public void testMapping() { - LocalDate now = LocalDate.now(ZoneId.systemDefault()); - BusinessDate businessDate = BusinessDate.instance(BusinessDateType.BUSINESS_DATE, now); - BusinessDateData businessDateData = businessDateMapper.map(businessDate); - assertEquals(businessDate.getDate(), businessDateData.getDate()); - assertEquals(businessDate.getType().getDescription(), businessDateData.getDescription()); - assertEquals(businessDate.getType().getName(), businessDateData.getType()); + void testMapping() { + var now = LocalDate.now(ZoneId.systemDefault()); + var businessDate = BusinessDate.instance(BusinessDateType.BUSINESS_DATE, now); + var businessDateResponse = businessDateMapper.map(businessDate); + assertEquals(businessDate.getDate(), businessDateResponse.getDate()); + assertEquals(businessDate.getType().getDescription(), businessDateResponse.getDescription()); + assertEquals(businessDate.getType(), businessDateResponse.getType()); } @Test - public void testMappingList() { - LocalDate now = LocalDate.now(ZoneId.systemDefault()); - BusinessDate businessDate = BusinessDate.instance(BusinessDateType.BUSINESS_DATE, now); - List businessDateData = businessDateMapper.map(Collections.singletonList(businessDate)); + void testMappingList() { + var now = LocalDate.now(ZoneId.systemDefault()); + var businessDate = BusinessDate.instance(BusinessDateType.BUSINESS_DATE, now); + var businessDateData = businessDateMapper.map(Collections.singletonList(businessDate)); assertEquals(businessDate.getDate(), businessDateData.get(0).getDate()); assertEquals(businessDate.getType().getDescription(), businessDateData.get(0).getDescription()); - assertEquals(businessDate.getType().getName(), businessDateData.get(0).getType()); + assertEquals(businessDate.getType(), businessDateData.get(0).getType()); } } diff --git a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateReadPlatformServiceTest.java b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateReadPlatformServiceTest.java index d2318c722..fee974a40 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateReadPlatformServiceTest.java +++ b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateReadPlatformServiceTest.java @@ -51,7 +51,7 @@ public class BusinessDateReadPlatformServiceTest { private BusinessDateRepository repository; @Mock - private BusinessDateMapper mapper; + private BusinessDateMapper businessDateMapper; @Test public void notFoundByTypeNonexistentType() { @@ -73,7 +73,7 @@ public class BusinessDateReadPlatformServiceTest { given(repository.findAll()).willReturn(resultList); businessDateReadPlatformService.findAll(); verify(repository, times(1)).findAll(); - verify(mapper, times(1)).map(resultList); + verify(businessDateMapper, times(1)).map(resultList); } @Test @@ -82,7 +82,7 @@ public class BusinessDateReadPlatformServiceTest { given(repository.findByType(BusinessDateType.COB_DATE)).willReturn(result); businessDateReadPlatformService.findByType("COB_DATE"); verify(repository, times(1)).findByType(BusinessDateType.COB_DATE); - verify(mapper, times(1)).map(result.get()); + verify(businessDateMapper, times(1)).map(result.get()); } @Test @@ -91,6 +91,6 @@ public class BusinessDateReadPlatformServiceTest { given(repository.findByType(BusinessDateType.BUSINESS_DATE)).willReturn(result); businessDateReadPlatformService.findByType("BUSINESS_DATE"); verify(repository, times(1)).findByType(BusinessDateType.BUSINESS_DATE); - verify(mapper, times(1)).map(result.get()); + verify(businessDateMapper, times(1)).map(result.get()); } } diff --git a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateWritePlatformServiceTest.java b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateWritePlatformServiceTest.java index eaabf6393..d9ad3a581 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateWritePlatformServiceTest.java +++ b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/service/BusinessDateWritePlatformServiceTest.java @@ -18,6 +18,8 @@ */ package org.apache.fineract.infrastructure.businessdate.service; +import static org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType.BUSINESS_DATE; +import static org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType.COB_DATE; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -27,17 +29,17 @@ import static org.mockito.Mockito.verify; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.time.LocalDate; -import java.time.ZoneId; +import java.util.HashMap; +import java.util.Map; import java.util.Optional; -import org.apache.fineract.infrastructure.businessdate.data.BusinessDateData; +import org.apache.fineract.infrastructure.businessdate.data.BusinessDateResponse; +import org.apache.fineract.infrastructure.businessdate.data.BusinessDateUpdateRequest; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDate; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateRepository; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; import org.apache.fineract.infrastructure.businessdate.exception.BusinessDateActionException; -import org.apache.fineract.infrastructure.businessdate.validator.BusinessDateDataParserAndValidator; +import org.apache.fineract.infrastructure.businessdate.mapper.BusinessDateUpdateRequestMapper; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; -import org.apache.fineract.infrastructure.core.api.JsonCommand; -import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant; import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil; @@ -64,7 +66,7 @@ public class BusinessDateWritePlatformServiceTest { private BusinessDateWritePlatformServiceImpl underTest; @Mock - private BusinessDateDataParserAndValidator businessDateDataParserAndValidator; + private BusinessDateUpdateRequestMapper updateBusinessDateMapper; @Mock private BusinessDateRepository businessDateRepository; @@ -87,163 +89,180 @@ public class BusinessDateWritePlatformServiceTest { @Test public void businessDateIsNotEnabled() { - JsonCommand command = JsonCommand.from(""); - BusinessDateData businessDateData = BusinessDateData.instance(BusinessDateType.BUSINESS_DATE, - LocalDate.now(ZoneId.systemDefault())); + BusinessDateUpdateRequest businessDateUpdateRequest = new BusinessDateUpdateRequest(); given(configurationDomainService.isBusinessDateEnabled()).willReturn(Boolean.FALSE); - given(businessDateDataParserAndValidator.validateAndParseUpdate(command)).willReturn(businessDateData); + BusinessDateActionException exception = assertThrows(BusinessDateActionException.class, - () -> underTest.updateBusinessDate(command)); + () -> underTest.updateBusinessDate(businessDateUpdateRequest)); assertEquals("Business date functionality is not enabled", exception.getDefaultUserMessage()); } @Test public void businessDateSetNew() { - JsonCommand command = JsonCommand.from(""); - BusinessDateData businessDateData = BusinessDateData.instance(BusinessDateType.BUSINESS_DATE, LocalDate.of(2022, 6, 13)); + BusinessDateUpdateRequest businessDateUpdateRequest = new BusinessDateUpdateRequest(); + final LocalDate localDate = LocalDate.of(2022, 6, 13); + final Map changes = new HashMap<>(Map.of(BUSINESS_DATE, localDate)); + BusinessDateResponse businessDateRes = BusinessDateResponse.builder().type(BUSINESS_DATE) + .description(BUSINESS_DATE.getDescription()).date(localDate).changes(changes).build(); given(configurationDomainService.isBusinessDateEnabled()).willReturn(Boolean.TRUE); given(configurationDomainService.isCOBDateAdjustmentEnabled()).willReturn(Boolean.FALSE); - given(businessDateDataParserAndValidator.validateAndParseUpdate(command)).willReturn(businessDateData); + given(updateBusinessDateMapper.map(businessDateUpdateRequest)).willReturn(businessDateRes); Optional newEntity = Optional.empty(); - given(businessDateRepository.findByType(BusinessDateType.BUSINESS_DATE)).willReturn(newEntity); - CommandProcessingResult result = underTest.updateBusinessDate(command); - LocalDate resultData = (LocalDate) result.getChanges().get("BUSINESS_DATE"); - assertEquals(LocalDate.of(2022, 6, 13), resultData); + given(businessDateRepository.findByType(BUSINESS_DATE)).willReturn(newEntity); + BusinessDateResponse result = underTest.updateBusinessDate(businessDateUpdateRequest); + final LocalDate resultDate = result.getChanges().get(BUSINESS_DATE); + assertEquals(LocalDate.of(2022, 6, 13), resultDate); verify(configurationDomainService, times(1)).isBusinessDateEnabled(); verify(configurationDomainService, times(1)).isCOBDateAdjustmentEnabled(); - verify(businessDateRepository, times(1)).findByType(BusinessDateType.BUSINESS_DATE); + verify(businessDateRepository, times(1)).findByType(BUSINESS_DATE); verify(businessDateRepository, times(1)).save(businessDateArgumentCaptor.capture()); assertEquals(LocalDate.of(2022, 6, 13), businessDateArgumentCaptor.getValue().getDate()); - assertEquals(BusinessDateType.BUSINESS_DATE, businessDateArgumentCaptor.getValue().getType()); + assertEquals(BUSINESS_DATE, businessDateArgumentCaptor.getValue().getType()); } @Test public void cobDateSetNew() { - JsonCommand command = JsonCommand.from(""); - BusinessDateData businessDateData = BusinessDateData.instance(BusinessDateType.COB_DATE, LocalDate.of(2022, 6, 13)); + BusinessDateUpdateRequest businessDateUpdateRequest = new BusinessDateUpdateRequest(); + final LocalDate localDate = LocalDate.of(2022, 6, 13); + final Map changes = new HashMap<>(Map.of(COB_DATE, localDate)); + BusinessDateResponse response = BusinessDateResponse.builder().type(COB_DATE).description(COB_DATE.getDescription()).date(localDate) + .changes(changes).build(); given(configurationDomainService.isBusinessDateEnabled()).willReturn(Boolean.TRUE); given(configurationDomainService.isCOBDateAdjustmentEnabled()).willReturn(Boolean.FALSE); - given(businessDateDataParserAndValidator.validateAndParseUpdate(command)).willReturn(businessDateData); + given(updateBusinessDateMapper.map(businessDateUpdateRequest)).willReturn(response); Optional newEntity = Optional.empty(); - given(businessDateRepository.findByType(BusinessDateType.COB_DATE)).willReturn(newEntity); - CommandProcessingResult result = underTest.updateBusinessDate(command); - LocalDate resultData = (LocalDate) result.getChanges().get("COB_DATE"); + given(businessDateRepository.findByType(COB_DATE)).willReturn(newEntity); + BusinessDateResponse result = underTest.updateBusinessDate(businessDateUpdateRequest); + LocalDate resultData = result.getChanges().get(COB_DATE); assertEquals(LocalDate.of(2022, 6, 13), resultData); verify(configurationDomainService, times(1)).isBusinessDateEnabled(); verify(configurationDomainService, times(1)).isCOBDateAdjustmentEnabled(); - verify(businessDateRepository, times(1)).findByType(BusinessDateType.COB_DATE); + verify(businessDateRepository, times(1)).findByType(COB_DATE); verify(businessDateRepository, times(1)).save(businessDateArgumentCaptor.capture()); assertEquals(LocalDate.of(2022, 6, 13), businessDateArgumentCaptor.getValue().getDate()); - assertEquals(BusinessDateType.COB_DATE, businessDateArgumentCaptor.getValue().getType()); + assertEquals(COB_DATE, businessDateArgumentCaptor.getValue().getType()); } @Test public void businessDateSetModifyExistingWhenItWasAfter() { - JsonCommand command = JsonCommand.from(""); - BusinessDateData businessDateData = BusinessDateData.instance(BusinessDateType.BUSINESS_DATE, LocalDate.of(2022, 6, 11)); + BusinessDateUpdateRequest businessDateUpdateRequest = new BusinessDateUpdateRequest(); + final LocalDate localDate = LocalDate.of(2022, 6, 11); + final Map changes = new HashMap<>(Map.of(COB_DATE, localDate)); + BusinessDateResponse response = BusinessDateResponse.builder().type(BUSINESS_DATE).description(BUSINESS_DATE.getDescription()) + .date(localDate).changes(changes).build(); given(configurationDomainService.isBusinessDateEnabled()).willReturn(Boolean.TRUE); given(configurationDomainService.isCOBDateAdjustmentEnabled()).willReturn(Boolean.FALSE); - given(businessDateDataParserAndValidator.validateAndParseUpdate(command)).willReturn(businessDateData); - Optional newEntity = Optional.of(BusinessDate.instance(BusinessDateType.BUSINESS_DATE, LocalDate.of(2022, 6, 12))); - given(businessDateRepository.findByType(BusinessDateType.BUSINESS_DATE)).willReturn(newEntity); - CommandProcessingResult result = underTest.updateBusinessDate(command); - LocalDate resultData = (LocalDate) result.getChanges().get("BUSINESS_DATE"); + given(updateBusinessDateMapper.map(businessDateUpdateRequest)).willReturn(response); + Optional newEntity = Optional.of(BusinessDate.instance(BUSINESS_DATE, LocalDate.of(2022, 6, 12))); + given(businessDateRepository.findByType(BUSINESS_DATE)).willReturn(newEntity); + BusinessDateResponse result = underTest.updateBusinessDate(businessDateUpdateRequest); + LocalDate resultData = result.getChanges().get(BUSINESS_DATE); assertEquals(LocalDate.of(2022, 6, 11), resultData); verify(configurationDomainService, times(1)).isBusinessDateEnabled(); verify(configurationDomainService, times(1)).isCOBDateAdjustmentEnabled(); - verify(businessDateRepository, times(1)).findByType(BusinessDateType.BUSINESS_DATE); + verify(businessDateRepository, times(1)).findByType(BUSINESS_DATE); verify(businessDateRepository, times(1)).save(businessDateArgumentCaptor.capture()); assertEquals(LocalDate.of(2022, 6, 11), businessDateArgumentCaptor.getValue().getDate()); - assertEquals(BusinessDateType.BUSINESS_DATE, businessDateArgumentCaptor.getValue().getType()); + assertEquals(BUSINESS_DATE, businessDateArgumentCaptor.getValue().getType()); } @Test public void businessDateSetModifyExistingWhenItWasBefore() { - JsonCommand command = JsonCommand.from(""); - BusinessDateData businessDateData = BusinessDateData.instance(BusinessDateType.BUSINESS_DATE, LocalDate.of(2022, 6, 13)); + BusinessDateUpdateRequest businessDateUpdateRequest = new BusinessDateUpdateRequest(); + final LocalDate localDate = LocalDate.of(2022, 6, 13); + final Map changes = new HashMap<>(Map.of(BUSINESS_DATE, localDate)); + BusinessDateResponse response = BusinessDateResponse.builder().type(BUSINESS_DATE).description(BUSINESS_DATE.getDescription()) + .date(localDate).changes(changes).build(); given(configurationDomainService.isBusinessDateEnabled()).willReturn(Boolean.TRUE); given(configurationDomainService.isCOBDateAdjustmentEnabled()).willReturn(Boolean.FALSE); - given(businessDateDataParserAndValidator.validateAndParseUpdate(command)).willReturn(businessDateData); - Optional newEntity = Optional.of(BusinessDate.instance(BusinessDateType.BUSINESS_DATE, LocalDate.of(2022, 6, 12))); - given(businessDateRepository.findByType(BusinessDateType.BUSINESS_DATE)).willReturn(newEntity); - CommandProcessingResult result = underTest.updateBusinessDate(command); - LocalDate resultData = (LocalDate) result.getChanges().get("BUSINESS_DATE"); + given(updateBusinessDateMapper.map(businessDateUpdateRequest)).willReturn(response); + Optional newEntity = Optional.of(BusinessDate.instance(BUSINESS_DATE, LocalDate.of(2022, 6, 12))); + given(businessDateRepository.findByType(BUSINESS_DATE)).willReturn(newEntity); + BusinessDateResponse result = underTest.updateBusinessDate(businessDateUpdateRequest); + LocalDate resultData = result.getChanges().get(BUSINESS_DATE); assertEquals(LocalDate.of(2022, 6, 13), resultData); verify(configurationDomainService, times(1)).isBusinessDateEnabled(); verify(configurationDomainService, times(1)).isCOBDateAdjustmentEnabled(); - verify(businessDateRepository, times(1)).findByType(BusinessDateType.BUSINESS_DATE); + verify(businessDateRepository, times(1)).findByType(BUSINESS_DATE); verify(businessDateRepository, times(1)).save(businessDateArgumentCaptor.capture()); assertEquals(LocalDate.of(2022, 6, 13), businessDateArgumentCaptor.getValue().getDate()); - assertEquals(BusinessDateType.BUSINESS_DATE, businessDateArgumentCaptor.getValue().getType()); + assertEquals(BUSINESS_DATE, businessDateArgumentCaptor.getValue().getType()); } @Test public void businessDateSetModifyExistingButNoChanges() { - JsonCommand command = JsonCommand.from(""); - BusinessDateData businessDateData = BusinessDateData.instance(BusinessDateType.BUSINESS_DATE, LocalDate.of(2022, 6, 13)); + BusinessDateUpdateRequest businessDateUpdateRequest = new BusinessDateUpdateRequest(); + final LocalDate localDate = LocalDate.of(2022, 6, 13); + BusinessDateResponse response = BusinessDateResponse.builder().type(BUSINESS_DATE).description(BUSINESS_DATE.getDescription()) + .date(localDate).build(); given(configurationDomainService.isBusinessDateEnabled()).willReturn(Boolean.TRUE); given(configurationDomainService.isCOBDateAdjustmentEnabled()).willReturn(Boolean.FALSE); - given(businessDateDataParserAndValidator.validateAndParseUpdate(command)).willReturn(businessDateData); - Optional newEntity = Optional.of(BusinessDate.instance(BusinessDateType.BUSINESS_DATE, LocalDate.of(2022, 6, 13))); - given(businessDateRepository.findByType(BusinessDateType.BUSINESS_DATE)).willReturn(newEntity); - CommandProcessingResult result = underTest.updateBusinessDate(command); + given(updateBusinessDateMapper.map(businessDateUpdateRequest)).willReturn(response); + + Optional newEntity = Optional.of(BusinessDate.instance(BUSINESS_DATE, LocalDate.of(2022, 6, 13))); + given(businessDateRepository.findByType(BUSINESS_DATE)).willReturn(newEntity); + BusinessDateResponse result = underTest.updateBusinessDate(businessDateUpdateRequest); assertNull(result.getChanges()); verify(configurationDomainService, times(1)).isBusinessDateEnabled(); verify(configurationDomainService, times(1)).isCOBDateAdjustmentEnabled(); - verify(businessDateRepository, times(1)).findByType(BusinessDateType.BUSINESS_DATE); + verify(businessDateRepository, times(1)).findByType(BUSINESS_DATE); verify(businessDateRepository, times(0)).save(businessDateArgumentCaptor.capture()); } @Test public void cobDateSetNewAutomatically() { - JsonCommand command = JsonCommand.from(""); - BusinessDateData businessDateData = BusinessDateData.instance(BusinessDateType.BUSINESS_DATE, LocalDate.of(2022, 6, 13)); + BusinessDateUpdateRequest request = new BusinessDateUpdateRequest(); + final LocalDate localDate = LocalDate.of(2022, 6, 13); + final Map changes = new HashMap<>(Map.of(BUSINESS_DATE, localDate)); + BusinessDateResponse response = BusinessDateResponse.builder().type(BUSINESS_DATE).description(BUSINESS_DATE.getDescription()) + .date(localDate).changes(changes).build(); given(configurationDomainService.isBusinessDateEnabled()).willReturn(Boolean.TRUE); given(configurationDomainService.isCOBDateAdjustmentEnabled()).willReturn(Boolean.TRUE); - given(businessDateDataParserAndValidator.validateAndParseUpdate(command)).willReturn(businessDateData); + given(updateBusinessDateMapper.map(request)).willReturn(response); Optional newEntity = Optional.empty(); - given(businessDateRepository.findByType(BusinessDateType.BUSINESS_DATE)).willReturn(newEntity); - CommandProcessingResult result = underTest.updateBusinessDate(command); - LocalDate businessDate = (LocalDate) result.getChanges().get("BUSINESS_DATE"); + given(businessDateRepository.findByType(BUSINESS_DATE)).willReturn(newEntity); + BusinessDateResponse result = underTest.updateBusinessDate(request); + LocalDate businessDate = result.getChanges().get(BUSINESS_DATE); assertEquals(LocalDate.of(2022, 6, 13), businessDate); - LocalDate cobDate = (LocalDate) result.getChanges().get("COB_DATE"); + LocalDate cobDate = result.getChanges().get(COB_DATE); assertEquals(LocalDate.of(2022, 6, 12), cobDate); verify(configurationDomainService, times(1)).isBusinessDateEnabled(); verify(configurationDomainService, times(1)).isCOBDateAdjustmentEnabled(); - verify(businessDateRepository, times(1)).findByType(BusinessDateType.BUSINESS_DATE); - verify(businessDateRepository, times(1)).findByType(BusinessDateType.COB_DATE); + verify(businessDateRepository, times(1)).findByType(BUSINESS_DATE); + verify(businessDateRepository, times(1)).findByType(COB_DATE); verify(businessDateRepository, times(2)).save(businessDateArgumentCaptor.capture()); assertEquals(LocalDate.of(2022, 6, 13), businessDateArgumentCaptor.getAllValues().get(0).getDate()); - assertEquals(BusinessDateType.BUSINESS_DATE, businessDateArgumentCaptor.getAllValues().get(0).getType()); + assertEquals(BUSINESS_DATE, businessDateArgumentCaptor.getAllValues().get(0).getType()); assertEquals(LocalDate.of(2022, 6, 12), businessDateArgumentCaptor.getAllValues().get(1).getDate()); - assertEquals(BusinessDateType.COB_DATE, businessDateArgumentCaptor.getAllValues().get(1).getType()); + assertEquals(COB_DATE, businessDateArgumentCaptor.getAllValues().get(1).getType()); } @Test public void businessDateAndCobDateSetModifyExistingButNoChanges() { - JsonCommand command = JsonCommand.from(""); - BusinessDateData businessDateData = BusinessDateData.instance(BusinessDateType.BUSINESS_DATE, LocalDate.of(2022, 6, 13)); + BusinessDateUpdateRequest request = new BusinessDateUpdateRequest(); + BusinessDateResponse response = BusinessDateResponse.builder().type(BUSINESS_DATE).description(BUSINESS_DATE.getDescription()) + .date(LocalDate.of(2022, 6, 13)).build(); given(configurationDomainService.isBusinessDateEnabled()).willReturn(Boolean.TRUE); given(configurationDomainService.isCOBDateAdjustmentEnabled()).willReturn(Boolean.TRUE); - given(businessDateDataParserAndValidator.validateAndParseUpdate(command)).willReturn(businessDateData); - Optional newBusinessEntity = Optional - .of(BusinessDate.instance(BusinessDateType.BUSINESS_DATE, LocalDate.of(2022, 6, 13))); - Optional newCOBEntity = Optional.of(BusinessDate.instance(BusinessDateType.COB_DATE, LocalDate.of(2022, 6, 12))); - given(businessDateRepository.findByType(BusinessDateType.BUSINESS_DATE)).willReturn(newBusinessEntity); - given(businessDateRepository.findByType(BusinessDateType.COB_DATE)).willReturn(newCOBEntity); - CommandProcessingResult result = underTest.updateBusinessDate(command); + given(updateBusinessDateMapper.map(request)).willReturn(response); + + Optional newBusinessEntity = Optional.of(BusinessDate.instance(BUSINESS_DATE, LocalDate.of(2022, 6, 13))); + Optional newCOBEntity = Optional.of(BusinessDate.instance(COB_DATE, LocalDate.of(2022, 6, 12))); + given(businessDateRepository.findByType(BUSINESS_DATE)).willReturn(newBusinessEntity); + given(businessDateRepository.findByType(COB_DATE)).willReturn(newCOBEntity); + BusinessDateResponse result = underTest.updateBusinessDate(request); assertNull(result.getChanges()); verify(configurationDomainService, times(1)).isBusinessDateEnabled(); verify(configurationDomainService, times(1)).isCOBDateAdjustmentEnabled(); - verify(businessDateRepository, times(1)).findByType(BusinessDateType.BUSINESS_DATE); - verify(businessDateRepository, times(1)).findByType(BusinessDateType.COB_DATE); + verify(businessDateRepository, times(1)).findByType(BUSINESS_DATE); + verify(businessDateRepository, times(1)).findByType(COB_DATE); verify(businessDateRepository, times(0)).save(Mockito.any()); } @Test public void businessDateIsNotEnabledTriggeredByJob() { given(configurationDomainService.isBusinessDateEnabled()).willReturn(Boolean.FALSE); - assertThrows(JobExecutionException.class, () -> underTest.increaseBusinessDateByOneDay()); + assertThrows(JobExecutionException.class, () -> underTest.increaseDateByTypeByOneDay(BUSINESS_DATE)); } @Test @@ -253,25 +272,25 @@ public class BusinessDateWritePlatformServiceTest { given(configurationDomainService.isBusinessDateEnabled()).willReturn(Boolean.TRUE); given(configurationDomainService.isCOBDateAdjustmentEnabled()).willReturn(Boolean.TRUE); Optional newEntity = Optional.empty(); - given(businessDateRepository.findByType(BusinessDateType.BUSINESS_DATE)).willReturn(newEntity); - underTest.increaseBusinessDateByOneDay(); + given(businessDateRepository.findByType(BUSINESS_DATE)).willReturn(newEntity); + underTest.increaseDateByTypeByOneDay(BUSINESS_DATE); verify(configurationDomainService, times(1)).isBusinessDateEnabled(); verify(configurationDomainService, times(1)).isCOBDateAdjustmentEnabled(); verify(businessDateRepository, times(2)).save(businessDateArgumentCaptor.capture()); assertEquals(localDatePlus1, businessDateArgumentCaptor.getAllValues().get(0).getDate()); - assertEquals(BusinessDateType.BUSINESS_DATE, businessDateArgumentCaptor.getAllValues().get(0).getType()); + assertEquals(BUSINESS_DATE, businessDateArgumentCaptor.getAllValues().get(0).getType()); assertEquals(localDate, businessDateArgumentCaptor.getAllValues().get(1).getDate()); - assertEquals(BusinessDateType.COB_DATE, businessDateArgumentCaptor.getAllValues().get(1).getType()); + assertEquals(COB_DATE, businessDateArgumentCaptor.getAllValues().get(1).getType()); } @Test public void cobDateModifyExistingTriggeredByJob() throws JobExecutionException { - Optional newCOBEntity = Optional.of(BusinessDate.instance(BusinessDateType.COB_DATE, LocalDate.of(2022, 6, 12))); - given(businessDateRepository.findByType(BusinessDateType.COB_DATE)).willReturn(newCOBEntity); + Optional newCOBEntity = Optional.of(BusinessDate.instance(COB_DATE, LocalDate.of(2022, 6, 12))); + given(businessDateRepository.findByType(COB_DATE)).willReturn(newCOBEntity); LocalDate localDate = LocalDate.of(2022, 6, 12).plusDays(1); given(configurationDomainService.isBusinessDateEnabled()).willReturn(Boolean.TRUE); given(configurationDomainService.isCOBDateAdjustmentEnabled()).willReturn(Boolean.TRUE); - underTest.increaseCOBDateByOneDay(); + underTest.increaseDateByTypeByOneDay(COB_DATE); verify(configurationDomainService, times(1)).isBusinessDateEnabled(); verify(configurationDomainService, times(1)).isCOBDateAdjustmentEnabled(); verify(businessDateRepository, times(1)).save(businessDateArgumentCaptor.capture()); diff --git a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/validation/BusinessDateValidationTest.java b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/validation/BusinessDateValidationTest.java new file mode 100644 index 000000000..c165f4100 --- /dev/null +++ b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/validation/BusinessDateValidationTest.java @@ -0,0 +1,88 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.infrastructure.businessdate.validation; + +import static org.assertj.core.api.Assertions.assertThat; + +import lombok.extern.slf4j.Slf4j; +import org.apache.fineract.infrastructure.businessdate.data.BusinessDateUpdateRequest; +import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; +import org.apache.fineract.validation.config.ValidationConfig; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.validation.Validator; + +@Slf4j +@SpringBootTest +@ContextConfiguration(classes = { ValidationConfig.class }) +class BusinessDateValidationTest { + + @Autowired + private Validator validator; + + @Test + void invalidAllBlank() { + var request = BusinessDateUpdateRequest.builder().dateFormat("").type(null).date(" ").locale(null).build(); + + var errors = validator.validateObject(request); + + assertThat(errors.getFieldErrorCount()).isEqualTo(5); + + assertThat(errors.getFieldErrors()).anyMatch(e -> e.getField().equals("date")); + assertThat(errors.getFieldErrors()).anyMatch(e -> e.getField().equals("dateFormat")); + assertThat(errors.getFieldErrors()).anyMatch(e -> e.getField().equals("locale")); + assertThat(errors.getFieldErrors()).anyMatch(e -> e.getField().equals("type")); + } + + @Test + void invalidLocale() { + var request = BusinessDateUpdateRequest.builder().dateFormat("dd-MM-yyyy").type(BusinessDateType.BUSINESS_DATE).date("12-05-2025") + .locale("EN").build(); + + var errors = validator.validateObject(request); + + assertThat(errors.getFieldErrorCount()).isEqualTo(1); + + assertThat(errors.getFieldErrors()).anyMatch(e -> e.getField().equals("locale")); + } + + @Test + void invalidDateFormat() { + var request = BusinessDateUpdateRequest.builder().dateFormat("dd/MM/yyyy").type(BusinessDateType.BUSINESS_DATE).date("12-05-2025") + .locale("en").build(); + + var errors = validator.validateObject(request); + + assertThat(errors.getErrorCount()).isEqualTo(1); + + assertThat(errors.getAllErrors()).anyMatch(e -> "Wrong local date fields.".equals(e.getDefaultMessage())); + } + + @Test + void valid() { + var request = BusinessDateUpdateRequest.builder().dateFormat("dd-MM-yyyy").type(BusinessDateType.BUSINESS_DATE).date("12-05-2025") + .locale("en").build(); + + var errors = validator.validateObject(request); + + assertThat(errors.getFieldErrorCount()).isEqualTo(0); + } +} diff --git a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/validator/BusinessDateValidatorTest.java b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/validator/BusinessDateValidatorTest.java deleted file mode 100644 index 5177bbcda..000000000 --- a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/businessdate/validator/BusinessDateValidatorTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.fineract.infrastructure.businessdate.validator; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import java.time.LocalDate; -import org.apache.fineract.infrastructure.businessdate.data.BusinessDateData; -import org.apache.fineract.infrastructure.core.api.JsonCommand; -import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; -import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; -import org.junit.jupiter.api.Test; - -public class BusinessDateValidatorTest { - - private BusinessDateDataParserAndValidator businessDateDataParserAndValidator = new BusinessDateDataParserAndValidator( - new FromJsonHelper()); - - @Test - public void validateAndParseUpdateWithEmptyRequest() { - String json = "{}"; - JsonCommand command = JsonCommand.from(json); - PlatformApiDataValidationException exception = assertThrows(PlatformApiDataValidationException.class, - () -> businessDateDataParserAndValidator.validateAndParseUpdate(command)); - assertEquals( - "PlatformApiDataValidationException{errors=[The parameter `type` is mandatory., The parameter `locale` is mandatory., The parameter `dateFormat` is mandatory., The parameter `date` is mandatory.]}", - exception.toString()); - } - - @Test - public void validateAndParseUpdateWithBlankFieldsInRequest() { - String json = "{\"type\":\"\", \"locale\":\"\",\"dateFormat\":\"\",\"date\":\"\"}"; - JsonCommand command = JsonCommand.from(json); - PlatformApiDataValidationException exception = assertThrows(PlatformApiDataValidationException.class, - () -> businessDateDataParserAndValidator.validateAndParseUpdate(command)); - assertEquals( - "PlatformApiDataValidationException{errors=[The parameter `type` is mandatory., The parameter `locale` is mandatory., The parameter `dateFormat` is mandatory., The parameter `date` is mandatory.]}", - exception.toString()); - } - - @Test - public void validateAndParseUpdateWithInvalidLocale() { - String json = "{\"type\":\"BUSINESS_DATE\", \"locale\":\"invalid\",\"dateFormat\":\"yyyy-MM-dd\",\"date\":\"2022-06-11\"}"; - JsonCommand command = JsonCommand.from(json); - PlatformApiDataValidationException exception = assertThrows(PlatformApiDataValidationException.class, - () -> businessDateDataParserAndValidator.validateAndParseUpdate(command)); - assertEquals("PlatformApiDataValidationException{errors=[The parameter `locale` has an invalid language value invalid .]}", - exception.toString()); - } - - @Test - public void validateAndParseUpdateWithInvalidBusinessType() { - String json = "{\"type\":\"invalid\", \"locale\":\"hu\",\"dateFormat\":\"yyyy-MM-dd\",\"date\":\"2022-06-11\"}"; - JsonCommand command = JsonCommand.from(json); - PlatformApiDataValidationException exception = assertThrows(PlatformApiDataValidationException.class, - () -> businessDateDataParserAndValidator.validateAndParseUpdate(command)); - assertEquals("PlatformApiDataValidationException{errors=[Failed data validation due to: Invalid Business Type value: `invalid`.]}", - exception.toString()); - } - - @Test - public void validateAndParseUpdateWithInvalidDateFormat() { - String json = "{\"type\":\"BUSINESS_DATE\", \"locale\":\"hu\",\"dateFormat\":\"y2yyy-MM-dd\",\"date\":\"2022-06-11\"}"; - JsonCommand command = JsonCommand.from(json); - PlatformApiDataValidationException exception = assertThrows(PlatformApiDataValidationException.class, - () -> businessDateDataParserAndValidator.validateAndParseUpdate(command)); - assertEquals( - "PlatformApiDataValidationException{errors=[The parameter `date` is invalid based on the dateFormat: `y2yyy-MM-dd` and locale: `hu` provided:]}", - exception.toString()); - } - - @Test - public void validateAndParseUpdateWithInvalidDate() { - String json = "{\"type\":\"BUSINESS_DATE\", \"locale\":\"hu\",\"dateFormat\":\"yyyy-MM-dd\",\"date\":\"2y22-06-11\"}"; - JsonCommand command = JsonCommand.from(json); - PlatformApiDataValidationException exception = assertThrows(PlatformApiDataValidationException.class, - () -> businessDateDataParserAndValidator.validateAndParseUpdate(command)); - assertEquals( - "PlatformApiDataValidationException{errors=[The parameter `date` is invalid based on the dateFormat: `yyyy-MM-dd` and locale: `hu` provided:]}", - exception.toString()); - } - - @Test - public void validateAndParseUpdateWithWrongDate() { - String json = "{\"type\":\"BUSINESS_DATE\", \"locale\":\"hu\",\"dateFormat\":\"yyyy-MM-dd\",\"date\":\"11-06-2022\"}"; - JsonCommand command = JsonCommand.from(json); - PlatformApiDataValidationException exception = assertThrows(PlatformApiDataValidationException.class, - () -> businessDateDataParserAndValidator.validateAndParseUpdate(command)); - assertEquals( - "PlatformApiDataValidationException{errors=[The parameter `date` is invalid based on the dateFormat: `yyyy-MM-dd` and locale: `hu` provided:]}", - exception.toString()); - } - - @Test - public void validateAndParseUpdateWithRightDate() { - String json = "{\"type\":\"COB_DATE\", \"locale\":\"hu\",\"dateFormat\":\"yyyy-MM-dd\",\"date\":\"2022-06-11\"}"; - JsonCommand command = JsonCommand.from(json); - BusinessDateData result = businessDateDataParserAndValidator.validateAndParseUpdate(command); - assertEquals("COB_DATE", result.getType()); - assertEquals("Close of Business Date", result.getDescription()); - assertEquals(LocalDate.of(2022, 6, 11), result.getDate()); - } -} diff --git a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/increasebusinessdateby1day/IncreaseBusinessDateBy1DayTaskletTest.java b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/increasebusinessdateby1day/IncreaseBusinessDateBy1DayTaskletTest.java index 4ede71b68..5ac38eb20 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/increasebusinessdateby1day/IncreaseBusinessDateBy1DayTaskletTest.java +++ b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/increasebusinessdateby1day/IncreaseBusinessDateBy1DayTaskletTest.java @@ -24,8 +24,8 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; +import org.apache.fineract.infrastructure.businessdate.service.BusinessDateWritePlatformService; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; -import org.apache.fineract.infrastructure.jobs.service.increasedateby1day.IncreaseDateBy1DayService; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -52,7 +52,7 @@ class IncreaseBusinessDateBy1DayTaskletTest { private ConfigurationDomainService configurationDomainService; @Mock - private IncreaseDateBy1DayService increaseDateBy1DayService; + private BusinessDateWritePlatformService businessDateWritePlatformService; @InjectMocks private IncreaseBusinessDateBy1DayTasklet underTest; @@ -73,7 +73,7 @@ class IncreaseBusinessDateBy1DayTaskletTest { RepeatStatus repeatStatus = underTest.execute(stepContribution, chunkContext); - verify(increaseDateBy1DayService, times(1)).increaseDateByTypeByOneDay(BusinessDateType.BUSINESS_DATE); + verify(businessDateWritePlatformService, times(1)).increaseDateByTypeByOneDay(BusinessDateType.BUSINESS_DATE); assertEquals(RepeatStatus.FINISHED, repeatStatus); } diff --git a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/increasecobdateby1day/IncreaseCobDateBy1DayTaskletTest.java b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/increasecobdateby1day/IncreaseCobDateBy1DayTaskletTest.java index 1c684ad45..f630a7726 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/increasecobdateby1day/IncreaseCobDateBy1DayTaskletTest.java +++ b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/jobs/service/increasedateby1day/increasecobdateby1day/IncreaseCobDateBy1DayTaskletTest.java @@ -24,8 +24,8 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; +import org.apache.fineract.infrastructure.businessdate.service.BusinessDateWritePlatformService; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; -import org.apache.fineract.infrastructure.jobs.service.increasedateby1day.IncreaseDateBy1DayService; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -52,7 +52,7 @@ class IncreaseCobDateBy1DayTaskletTest { private ConfigurationDomainService configurationDomainService; @Mock - private IncreaseDateBy1DayService increaseDateBy1DayService; + private BusinessDateWritePlatformService businessDateWritePlatformService; @InjectMocks private IncreaseCobDateBy1DayTasklet underTest; @@ -73,7 +73,7 @@ class IncreaseCobDateBy1DayTaskletTest { RepeatStatus repeatStatus = underTest.execute(stepContribution, chunkContext); - verify(increaseDateBy1DayService, times(1)).increaseDateByTypeByOneDay(BusinessDateType.COB_DATE); + verify(businessDateWritePlatformService, times(1)).increaseDateByTypeByOneDay(BusinessDateType.COB_DATE); assertEquals(RepeatStatus.FINISHED, repeatStatus); } diff --git a/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/data/request/BusinessDateRequest.java b/fineract-validation/build.gradle similarity index 55% rename from fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/data/request/BusinessDateRequest.java rename to fineract-validation/build.gradle index a3a5b5d27..8ac0c2e02 100644 --- a/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/data/request/BusinessDateRequest.java +++ b/fineract-validation/build.gradle @@ -16,17 +16,25 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.fineract.infrastructure.businessdate.data.request; +description = 'Fineract Validation' -import java.io.Serial; -import java.io.Serializable; +apply plugin: 'java' +apply plugin: 'eclipse' -public record BusinessDateRequest(String dateFormat, String type, String date, String locale) implements Serializable { +apply from: 'dependencies.gradle' - @Serial - private static final long serialVersionUID = 1L; +// If we are running Gradle within Eclipse to enhance classes with OpenJPA, +// set the classes directory to point to Eclipse's default build directory +if (project.hasProperty('env') && project.getProperty('env') == 'eclipse') { + sourceSets.main.java.outputDir = new File(rootProject.projectDir, "fineract-validation/bin/main") +} - public static BusinessDateRequest ofNull() { - return new BusinessDateRequest(null, null, null, null); +if (!(project.hasProperty('env') && project.getProperty('env') == 'dev')) { + sourceSets { + test { + java { + exclude '**/core/boot/tests/**' + } + } } } diff --git a/fineract-validation/dependencies.gradle b/fineract-validation/dependencies.gradle new file mode 100644 index 000000000..d894c94bd --- /dev/null +++ b/fineract-validation/dependencies.gradle @@ -0,0 +1,52 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +dependencies { + implementation( + 'org.springframework.boot:spring-boot-starter', + 'org.springframework.boot:spring-boot-starter-validation', + + 'org.apache.commons:commons-lang3', + 'commons-beanutils:commons-beanutils', + + 'com.github.spotbugs:spotbugs-annotations', + + 'jakarta.validation:jakarta.validation-api', + 'org.hibernate.validator:hibernate-validator', + + 'com.ibm.icu:icu4j', + 'org.yakworks:spring-icu4j', + ) + api('org.glassfish.jersey.ext:jersey-bean-validation') { + exclude group: 'jakarta.el', module: 'jakarta.el-api' + } + compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' + annotationProcessor 'org.mapstruct:mapstruct-processor' + + testImplementation ('org.springframework.boot:spring-boot-starter-test') { + exclude group: 'com.jayway.jsonpath', module: 'json-path' + exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' + exclude group: 'jakarta.activation' + exclude group: 'javax.activation' + exclude group: 'org.skyscreamer' + } + testImplementation( 'io.github.classgraph:classgraph' ) + testImplementation ('org.mockito:mockito-inline') +} diff --git a/fineract-validation/src/main/java/org/apache/fineract/validation/config/ValidationConfig.java b/fineract-validation/src/main/java/org/apache/fineract/validation/config/ValidationConfig.java new file mode 100644 index 000000000..e1e55b4c7 --- /dev/null +++ b/fineract-validation/src/main/java/org/apache/fineract/validation/config/ValidationConfig.java @@ -0,0 +1,91 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.validation.config; + +import jakarta.validation.MessageInterpolator; +import java.util.Locale; +import java.util.regex.Pattern; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.hibernate.validator.messageinterpolation.AbstractMessageInterpolator; +import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator; +import org.springframework.context.MessageSource; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.validation.Validator; +import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; +import org.springframework.validation.beanvalidation.MessageSourceResourceBundleLocator; +import yakworks.i18n.icu.ICUBundleMessageSource; + +@Slf4j +@RequiredArgsConstructor +@Configuration +public class ValidationConfig { + + @Bean + public MessageSource messageSource() { + var messageSource = new ICUBundleMessageSource(); + messageSource.setBasenames("classpath:fineract/validation/messages"); + messageSource.setCacheSeconds(3600); + messageSource.setDefaultEncoding("UTF-8"); + + return messageSource; + } + + @Bean + public MessageInterpolator messageInterpolator() { + var resourceBundleLocator = new MessageSourceResourceBundleLocator(messageSource()); + var messageInterpolator = new ResourceBundleMessageInterpolator(resourceBundleLocator); + return new RecursiveLocaleContextMessageInterpolator(messageInterpolator); + } + + @Bean + @Primary + public Validator validator() { + var localValidatorFactoryBean = new LocalValidatorFactoryBean(); + localValidatorFactoryBean.setMessageInterpolator(messageInterpolator()); + + return localValidatorFactoryBean; + } + + private static final class RecursiveLocaleContextMessageInterpolator extends AbstractMessageInterpolator { + + private static final Pattern PATTERN_PLACEHOLDER = Pattern.compile("\\{([^}]+)\\}"); + + private final MessageInterpolator interpolator; + + private RecursiveLocaleContextMessageInterpolator(MessageInterpolator interpolator) { + this.interpolator = interpolator; + } + + @Override + public String interpolate(MessageInterpolator.Context context, Locale locale, String message) { + int level = 0; + while (containsPlaceholder(message) && (level++ < 2)) { + message = this.interpolator.interpolate(message, context, locale); + } + return message; + } + + private boolean containsPlaceholder(String code) { + return PATTERN_PLACEHOLDER.matcher(code).find(); + } + } +} diff --git a/fineract-validation/src/main/java/org/apache/fineract/validation/constraints/LocalDate.java b/fineract-validation/src/main/java/org/apache/fineract/validation/constraints/LocalDate.java new file mode 100644 index 000000000..6d63b1428 --- /dev/null +++ b/fineract-validation/src/main/java/org/apache/fineract/validation/constraints/LocalDate.java @@ -0,0 +1,46 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.validation.constraints; + +import jakarta.validation.Constraint; +import jakarta.validation.Payload; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Documented +@Constraint(validatedBy = LocalDateValidator.class) +@Target({ ElementType.TYPE }) +@Retention(RetentionPolicy.RUNTIME) +public @interface LocalDate { + + String message() default "{org.apache.fineract.validation.local-date}"; + + String dateField(); + + String formatField(); + + String localeField(); + + Class[] groups() default {}; + + Class[] payload() default {}; +} diff --git a/fineract-validation/src/main/java/org/apache/fineract/validation/constraints/LocalDateValidator.java b/fineract-validation/src/main/java/org/apache/fineract/validation/constraints/LocalDateValidator.java new file mode 100644 index 000000000..7bb4eb81f --- /dev/null +++ b/fineract-validation/src/main/java/org/apache/fineract/validation/constraints/LocalDateValidator.java @@ -0,0 +1,83 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.validation.constraints; + +import static java.time.LocalDateTime.parse; + +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.ResolverStyle; +import java.time.temporal.ChronoField; +import java.util.Locale; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; + +@Slf4j +class LocalDateValidator implements ConstraintValidator { + + private String dateField; + private String formatField; + private String localeField; + + @Override + public void initialize(LocalDate annotation) { + this.dateField = annotation.dateField(); + this.formatField = annotation.formatField(); + this.localeField = annotation.localeField(); + } + + @Override + public boolean isValid(Object value, ConstraintValidatorContext context) { + try { + var dateAttr = value.getClass().getDeclaredField(dateField); + var formatAttr = value.getClass().getDeclaredField(formatField); + var localeAttr = value.getClass().getDeclaredField(localeField); + + dateAttr.setAccessible(true); + formatAttr.setAccessible(true); + localeAttr.setAccessible(true); + + var date = (String) dateAttr.get(value); + var format = (String) formatAttr.get(value); + var locale = (String) localeAttr.get(value); + + if (StringUtils.isBlank(date) || StringUtils.isBlank(format) || StringUtils.isBlank(locale)) { + return false; + } + + toLocalDate(date, format, locale); + + return true; + } catch (IllegalAccessException | NoSuchFieldException e) { + throw new RuntimeException("Invalid configuration for @LocalDate", e); + } catch (Exception e) { + return false; + } + } + + private void toLocalDate(String date, String format, String locale) { + var formatter = new DateTimeFormatterBuilder().parseCaseInsensitive().parseLenient().appendPattern(format.replace("y", "u")) + .optionalStart().appendPattern(" HH:mm:ss").optionalEnd().parseDefaulting(ChronoField.HOUR_OF_DAY, 0) + .parseDefaulting(ChronoField.MINUTE_OF_HOUR, 0).parseDefaulting(ChronoField.SECOND_OF_MINUTE, 0) + .toFormatter(Locale.forLanguageTag(locale)).withResolverStyle(ResolverStyle.STRICT); + + parse(date, formatter); + } +} diff --git a/fineract-validation/src/main/java/org/apache/fineract/validation/constraints/Locale.java b/fineract-validation/src/main/java/org/apache/fineract/validation/constraints/Locale.java new file mode 100644 index 000000000..5f25472a7 --- /dev/null +++ b/fineract-validation/src/main/java/org/apache/fineract/validation/constraints/Locale.java @@ -0,0 +1,40 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.validation.constraints; + +import jakarta.validation.Constraint; +import jakarta.validation.Payload; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Documented +@Constraint(validatedBy = LocaleValidator.class) +@Target({ ElementType.FIELD, ElementType.PARAMETER }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Locale { + + String message() default "{org.apache.fineract.validation.locale}"; + + Class[] groups() default {}; + + Class[] payload() default {}; +} diff --git a/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/api/BusinessDateApiResourceSwagger.java b/fineract-validation/src/main/java/org/apache/fineract/validation/constraints/LocaleValidator.java similarity index 61% rename from fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/api/BusinessDateApiResourceSwagger.java rename to fineract-validation/src/main/java/org/apache/fineract/validation/constraints/LocaleValidator.java index 40fea5412..fb410aec4 100644 --- a/fineract-core/src/main/java/org/apache/fineract/infrastructure/businessdate/api/BusinessDateApiResourceSwagger.java +++ b/fineract-validation/src/main/java/org/apache/fineract/validation/constraints/LocaleValidator.java @@ -16,26 +16,17 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.fineract.infrastructure.businessdate.api; +package org.apache.fineract.validation.constraints; -import io.swagger.v3.oas.annotations.media.Schema; -import java.util.Map; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; +import java.util.Arrays; +import org.apache.commons.lang3.StringUtils; -final class BusinessDateApiResourceSwagger { +class LocaleValidator implements ConstraintValidator { - private BusinessDateApiResourceSwagger() { - - } - - @Schema(description = "BusinessDateResponse") - public static final class BusinessDateResponse { - - @Schema(example = "1") - public Long commandId; - public Map changes; - - private BusinessDateResponse() { - - } + @Override + public boolean isValid(String value, ConstraintValidatorContext context) { + return StringUtils.isNotBlank(value) && Arrays.asList(java.util.Locale.getISOLanguages()).contains(value); } } diff --git a/fineract-validation/src/main/resources/fineract/validation/messages.properties b/fineract-validation/src/main/resources/fineract/validation/messages.properties new file mode 100644 index 000000000..25c7f718b --- /dev/null +++ b/fineract-validation/src/main/resources/fineract/validation/messages.properties @@ -0,0 +1,30 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# Validation + +org.apache.fineract.validation.local-date=Wrong local date fields. +org.apache.fineract.validation.locale=The parameter `locale` has an invalid language value: `${validatedValue}`. + +## Business Date + +org.apache.fineract.businessdate.date-format.not-blank=The parameter 'dateFormat' is mandatory: '${validatedValue}'. +org.apache.fineract.businessdate.type.not-null=The parameter 'type' is mandatory: '${validatedValue}'. +org.apache.fineract.businessdate.date.not-blank=The parameter 'date' is mandatory: '${validatedValue}'. +org.apache.fineract.businessdate.locale.not-blank=The parameter 'locale' is mandatory: '${validatedValue}'. diff --git a/fineract-validation/src/main/resources/fineract/validation/messages_en.properties b/fineract-validation/src/main/resources/fineract/validation/messages_en.properties new file mode 100644 index 000000000..25c7f718b --- /dev/null +++ b/fineract-validation/src/main/resources/fineract/validation/messages_en.properties @@ -0,0 +1,30 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# Validation + +org.apache.fineract.validation.local-date=Wrong local date fields. +org.apache.fineract.validation.locale=The parameter `locale` has an invalid language value: `${validatedValue}`. + +## Business Date + +org.apache.fineract.businessdate.date-format.not-blank=The parameter 'dateFormat' is mandatory: '${validatedValue}'. +org.apache.fineract.businessdate.type.not-null=The parameter 'type' is mandatory: '${validatedValue}'. +org.apache.fineract.businessdate.date.not-blank=The parameter 'date' is mandatory: '${validatedValue}'. +org.apache.fineract.businessdate.locale.not-blank=The parameter 'locale' is mandatory: '${validatedValue}'. diff --git a/fineract-validation/src/test/java/org/apache/fineract/validation/constraints/LocalDateValidationTest.java b/fineract-validation/src/test/java/org/apache/fineract/validation/constraints/LocalDateValidationTest.java new file mode 100644 index 000000000..105948470 --- /dev/null +++ b/fineract-validation/src/test/java/org/apache/fineract/validation/constraints/LocalDateValidationTest.java @@ -0,0 +1,96 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.validation.constraints; + +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.fineract.validation.config.ValidationConfig; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.validation.Validator; + +@Slf4j +@SpringBootTest +@ContextConfiguration(classes = { ValidationConfig.class }) +class LocalDateValidationTest { + + @Autowired + private Validator validator; + + @Test + void invalidAllBlank() { + var request = LocalDateModel.builder().format("").date(" ").locale(null).build(); + + var errors = validator.validateObject(request); + + assertThat(errors.getAllErrors()).hasSize(1); + + assertThat(errors.getAllErrors()).allMatch(e -> "Wrong local date fields.".equals(e.getDefaultMessage())); + } + + @Test + void invalidLocaleFormat() { + var request = LocalDateModel.builder().format("dd-MM-yyyy").date("12-05-2025").locale("").build(); + + var errors = validator.validateObject(request); + + assertThat(errors.getAllErrors()).hasSize(1); + + assertThat(errors.getAllErrors()).allMatch(e -> "Wrong local date fields.".equals(e.getDefaultMessage())); + } + + @Test + void invalidDateFormat() { + var request = LocalDateModel.builder().format("dd/MM/yyyy").date("12-05-2025").locale("en").build(); + + var errors = validator.validateObject(request); + + assertThat(errors.getAllErrors()).hasSize(1); + + assertThat(errors.getAllErrors()).allMatch(e -> "Wrong local date fields.".equals(e.getDefaultMessage())); + } + + @Test + void valid() { + var request = LocalDateModel.builder().format("dd-MM-yyyy").date("12-05-2025").locale("en").build(); + + var errors = validator.validateObject(request); + + assertThat(errors.getAllErrors()).isEmpty(); + } + + @Builder + @Data + @NoArgsConstructor + @AllArgsConstructor + @LocalDate(dateField = "date", formatField = "format", localeField = "locale") + static class LocalDateModel { + + private String date; + private String format; + private String locale; + } +} diff --git a/fineract-validation/src/test/java/org/apache/fineract/validation/constraints/LocaleValidationTest.java b/fineract-validation/src/test/java/org/apache/fineract/validation/constraints/LocaleValidationTest.java new file mode 100644 index 000000000..0de66519f --- /dev/null +++ b/fineract-validation/src/test/java/org/apache/fineract/validation/constraints/LocaleValidationTest.java @@ -0,0 +1,83 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.validation.constraints; + +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.fineract.validation.config.ValidationConfig; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.validation.Validator; + +@Slf4j +@SpringBootTest +@ContextConfiguration(classes = { ValidationConfig.class }) +class LocaleValidationTest { + + @Autowired + private Validator validator; + + @Test + void invalidBlank() { + var request = LocaleModel.builder().locale(null).build(); + + var errors = validator.validateObject(request); + + assertThat(errors.getFieldErrorCount()).isEqualTo(1); + + assertThat(errors.getFieldErrors()).anyMatch(e -> e.getField().equals("locale")); + } + + @Test + void invalidFormat() { + var request = LocaleModel.builder().locale("EN").build(); + + var errors = validator.validateObject(request); + + assertThat(errors.getFieldErrorCount()).isEqualTo(1); + + assertThat(errors.getFieldErrors()).anyMatch(e -> e.getField().equals("locale")); + } + + @Test + void valid() { + var request = LocaleModel.builder().locale("en").build(); + + var errors = validator.validateObject(request); + + assertThat(errors.getFieldErrorCount()).isEqualTo(0); + } + + @Builder + @Data + @NoArgsConstructor + @AllArgsConstructor + static class LocaleModel { + + @Locale + private String locale; + } +} diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/AdvancedPaymentAllocationLoanRepaymentScheduleTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/AdvancedPaymentAllocationLoanRepaymentScheduleTest.java index 3f48344b8..2bd83a92f 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/AdvancedPaymentAllocationLoanRepaymentScheduleTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/AdvancedPaymentAllocationLoanRepaymentScheduleTest.java @@ -42,7 +42,7 @@ import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import org.apache.fineract.client.models.AdvancedPaymentData; -import org.apache.fineract.client.models.BusinessDateRequest; +import org.apache.fineract.client.models.BusinessDateUpdateRequest; import org.apache.fineract.client.models.CreditAllocationData; import org.apache.fineract.client.models.CreditAllocationOrder; import org.apache.fineract.client.models.GetLoanProductsProductIdResponse; @@ -68,7 +68,6 @@ import org.apache.fineract.client.models.PostLoansResponse; import org.apache.fineract.client.models.PostUpdateRescheduleLoansRequest; import org.apache.fineract.client.models.PutLoansLoanIdRequest; import org.apache.fineract.client.util.CallFailedRuntimeException; -import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; import org.apache.fineract.infrastructure.configuration.api.GlobalConfigurationConstants; import org.apache.fineract.integrationtests.common.BusinessDateHelper; import org.apache.fineract.integrationtests.common.ClientHelper; @@ -2467,7 +2466,7 @@ public class AdvancedPaymentAllocationLoanRepaymentScheduleTest extends BaseLoan 0.0, 0.0, 0.0); assertTrue(loanDetails.getStatus().getActive()); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.09.16").dateFormat("yyyy.MM.dd").locale("en")); loanTransactionHelper.makeLoanRepayment(loanResponse.getLoanId(), new PostLoansLoanIdTransactionsRequest() @@ -2574,7 +2573,7 @@ public class AdvancedPaymentAllocationLoanRepaymentScheduleTest extends BaseLoan 0.0, 0.0, 0.0); assertTrue(loanDetails.getStatus().getActive()); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.09.16").dateFormat("yyyy.MM.dd").locale("en")); loanTransactionHelper.makeLoanRepayment(loanResponse.getLoanId(), new PostLoansLoanIdTransactionsRequest() @@ -2679,7 +2678,7 @@ public class AdvancedPaymentAllocationLoanRepaymentScheduleTest extends BaseLoan 0.0, 0.0, 0.0); assertTrue(loanDetails.getStatus().getActive()); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.09.16").dateFormat("yyyy.MM.dd").locale("en")); loanTransactionHelper.makeLoanRepayment(loanResponse.getLoanId(), new PostLoansLoanIdTransactionsRequest() @@ -2784,7 +2783,7 @@ public class AdvancedPaymentAllocationLoanRepaymentScheduleTest extends BaseLoan 0.0, 0.0, 0.0); assertTrue(loanDetails.getStatus().getActive()); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.09.16").dateFormat("yyyy.MM.dd").locale("en")); loanTransactionHelper.makeLoanRepayment(loanResponse.getLoanId(), new PostLoansLoanIdTransactionsRequest() diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/BaseLoanIntegrationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/BaseLoanIntegrationTest.java index 201e41caf..2203aea4f 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/BaseLoanIntegrationTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/BaseLoanIntegrationTest.java @@ -19,7 +19,6 @@ package org.apache.fineract.integrationtests; import static java.lang.System.lineSeparator; -import static org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType.BUSINESS_DATE; import static org.apache.fineract.integrationtests.BaseLoanIntegrationTest.TransactionProcessingStrategyCode.ADVANCED_PAYMENT_ALLOCATION_STRATEGY; import static org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder.DUE_PENALTY_INTEREST_PRINCIPAL_FEE_IN_ADVANCE_PENALTY_INTEREST_PRINCIPAL_FEE_STRATEGY; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -59,7 +58,7 @@ import org.apache.fineract.batch.domain.BatchRequest; import org.apache.fineract.batch.domain.BatchResponse; import org.apache.fineract.client.models.AdvancedPaymentData; import org.apache.fineract.client.models.AllowAttributeOverrides; -import org.apache.fineract.client.models.BusinessDateRequest; +import org.apache.fineract.client.models.BusinessDateUpdateRequest; import org.apache.fineract.client.models.GetJournalEntriesTransactionIdResponse; import org.apache.fineract.client.models.GetLoansLoanIdChargesChargeIdResponse; import org.apache.fineract.client.models.GetLoansLoanIdRepaymentPeriod; @@ -976,8 +975,8 @@ public abstract class BaseLoanIntegrationTest extends IntegrationTest { try { globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - businessDateHelper.updateBusinessDate( - new BusinessDateRequest().type(BUSINESS_DATE.getName()).date(date).dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date(date).dateFormat(DATETIME_PATTERN).locale("en")); runnable.run(); } finally { globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, @@ -1147,8 +1146,8 @@ public abstract class BaseLoanIntegrationTest extends IntegrationTest { } protected void updateBusinessDate(String date) { - businessDateHelper.updateBusinessDate( - new BusinessDateRequest().type(BUSINESS_DATE.getName()).date(date).dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date(date).dateFormat(DATETIME_PATTERN).locale("en")); } protected Long getTransactionId(Long loanId, String type, String date) { diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientLoanIntegrationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientLoanIntegrationTest.java index 586d7c0e7..5350eaa77 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientLoanIntegrationTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientLoanIntegrationTest.java @@ -55,7 +55,7 @@ import java.util.Set; import java.util.UUID; import org.apache.fineract.accounting.glaccount.domain.GLAccountType; import org.apache.fineract.client.models.AllowAttributeOverrides; -import org.apache.fineract.client.models.BusinessDateRequest; +import org.apache.fineract.client.models.BusinessDateUpdateRequest; import org.apache.fineract.client.models.ChargeRequest; import org.apache.fineract.client.models.GetJournalEntriesTransactionIdResponse; import org.apache.fineract.client.models.GetLoanTransactionRelation; @@ -87,7 +87,6 @@ import org.apache.fineract.client.models.PostLoansResponse; import org.apache.fineract.client.models.PutChargeTransactionChangesRequest; import org.apache.fineract.client.models.PutGlobalConfigurationsRequest; import org.apache.fineract.client.util.CallFailedRuntimeException; -import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; import org.apache.fineract.infrastructure.configuration.api.GlobalConfigurationConstants; import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.integrationtests.common.BusinessDateHelper; @@ -5320,7 +5319,7 @@ public class ClientLoanIntegrationTest extends BaseLoanIntegrationTest { try { globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - BUSINESS_DATE_HELPER.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + BUSINESS_DATE_HELPER.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("01 November 2022").dateFormat(DATETIME_PATTERN).locale("en")); final Account assetAccount = ACCOUNT_HELPER.createAssetAccount(); final Account incomeAccount = ACCOUNT_HELPER.createIncomeAccount(); @@ -5491,7 +5490,7 @@ public class ClientLoanIntegrationTest extends BaseLoanIntegrationTest { try { globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - BUSINESS_DATE_HELPER.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + BUSINESS_DATE_HELPER.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("01 November 2022").dateFormat(DATETIME_PATTERN).locale("en")); final Account assetAccount = ACCOUNT_HELPER.createAssetAccount(); final Account assetFeeAndPenaltyAccount = ACCOUNT_HELPER.createAssetAccount(); @@ -6172,7 +6171,7 @@ public class ClientLoanIntegrationTest extends BaseLoanIntegrationTest { new PutGlobalConfigurationsRequest().enabled(true)); globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - BUSINESS_DATE_HELPER.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + BUSINESS_DATE_HELPER.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("04 September 2022").dateFormat(DATETIME_PATTERN).locale("en")); final Account assetAccount = ACCOUNT_HELPER.createAssetAccount(); final Account incomeAccount = ACCOUNT_HELPER.createIncomeAccount(); @@ -6309,7 +6308,7 @@ public class ClientLoanIntegrationTest extends BaseLoanIntegrationTest { assertEquals(403, exception.getResponse().code()); assertTrue(exception.getMessage().contains("error.msg.loan.is.not.charged.off")); - BUSINESS_DATE_HELPER.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + BUSINESS_DATE_HELPER.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("08 September 2022").dateFormat(DATETIME_PATTERN).locale("en")); PostLoansLoanIdTransactionsResponse loanRepaymentResponse = LOAN_TRANSACTION_HELPER.makeLoanRepayment((long) loanID, @@ -6643,7 +6642,7 @@ public class ClientLoanIntegrationTest extends BaseLoanIntegrationTest { new PutGlobalConfigurationsRequest().enabled(true)); globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - BUSINESS_DATE_HELPER.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + BUSINESS_DATE_HELPER.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("10 October 2022").dateFormat(DATETIME_PATTERN).locale("en")); final Account assetAccount = ACCOUNT_HELPER.createAssetAccount(); @@ -6779,7 +6778,7 @@ public class ClientLoanIntegrationTest extends BaseLoanIntegrationTest { new PutGlobalConfigurationsRequest().enabled(true)); globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - BUSINESS_DATE_HELPER.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + BUSINESS_DATE_HELPER.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("10 October 2022").dateFormat(DATETIME_PATTERN).locale("en")); final Account assetAccount = ACCOUNT_HELPER.createAssetAccount(); @@ -6911,7 +6910,7 @@ public class ClientLoanIntegrationTest extends BaseLoanIntegrationTest { new PutGlobalConfigurationsRequest().enabled(true)); globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - BUSINESS_DATE_HELPER.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + BUSINESS_DATE_HELPER.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("10 October 2022").dateFormat(DATETIME_PATTERN).locale("en")); final Account assetAccount = ACCOUNT_HELPER.createAssetAccount(); @@ -6993,7 +6992,7 @@ public class ClientLoanIntegrationTest extends BaseLoanIntegrationTest { new PutGlobalConfigurationsRequest().enabled(true)); globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - BUSINESS_DATE_HELPER.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + BUSINESS_DATE_HELPER.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("01 January 2023").dateFormat(DATETIME_PATTERN).locale("en")); LOG.info("-----------------------------------NEW CLIENT-----------------------------------------"); final PostClientsRequest newClient = createRandomClientWithDate("01 January 2023"); @@ -7026,7 +7025,7 @@ public class ClientLoanIntegrationTest extends BaseLoanIntegrationTest { new PostLoansLoanIdChargesRequest().chargeId(penaltyCharge.getResourceId()).dateFormat(DATETIME_PATTERN).locale("en") .amount(10.0).dueDate("10 January 2023")); LOG.info("-------------------------------DO SOME PARTIAL REPAYMENTS-------------------------------------------"); - BUSINESS_DATE_HELPER.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + BUSINESS_DATE_HELPER.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("07 January 2023").dateFormat(DATETIME_PATTERN).locale("en")); String firstRepaymentUUID = UUID.randomUUID().toString(); PostLoansLoanIdTransactionsResponse firstRepaymentResult = LOAN_TRANSACTION_HELPER.makeLoanRepayment(loanId, diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/CustomSnapshotEventIntegrationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/CustomSnapshotEventIntegrationTest.java index 59786806a..07e99d127 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/CustomSnapshotEventIntegrationTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/CustomSnapshotEventIntegrationTest.java @@ -18,15 +18,13 @@ */ package org.apache.fineract.integrationtests; -import static org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType.BUSINESS_DATE; - import com.google.gson.Gson; import java.math.BigDecimal; import java.util.HashMap; import java.util.List; import java.util.Map; import lombok.extern.slf4j.Slf4j; -import org.apache.fineract.client.models.BusinessDateRequest; +import org.apache.fineract.client.models.BusinessDateUpdateRequest; import org.apache.fineract.client.models.PostLoanProductsRequest; import org.apache.fineract.client.models.PostLoanProductsResponse; import org.apache.fineract.infrastructure.event.external.service.validation.ExternalEventDTO; @@ -335,8 +333,8 @@ public class CustomSnapshotEventIntegrationTest extends BaseLoanIntegrationTest } private void updateBusinessDateAndExecuteCOBJob(String date) { - businessDateHelper.updateBusinessDate( - new BusinessDateRequest().type(BUSINESS_DATE.getName()).date(date).dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date(date).dateFormat(DATETIME_PATTERN).locale("en")); schedulerJobHelper.executeAndAwaitJob("Loan COB"); } diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/DelinquencyActionIntegrationTests.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/DelinquencyActionIntegrationTests.java index 61c170c53..5d45fdd20 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/DelinquencyActionIntegrationTests.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/DelinquencyActionIntegrationTests.java @@ -19,7 +19,6 @@ package org.apache.fineract.integrationtests; import static java.lang.Boolean.TRUE; -import static org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType.BUSINESS_DATE; import static org.apache.fineract.portfolio.delinquency.domain.DelinquencyAction.PAUSE; import static org.apache.fineract.portfolio.delinquency.domain.DelinquencyAction.RESUME; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -35,7 +34,7 @@ import java.util.UUID; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.tuple.Pair; -import org.apache.fineract.client.models.BusinessDateRequest; +import org.apache.fineract.client.models.BusinessDateUpdateRequest; import org.apache.fineract.client.models.GetDelinquencyActionsResponse; import org.apache.fineract.client.models.GetLoanProductsProductIdResponse; import org.apache.fineract.client.models.GetLoansLoanIdDelinquencyPausePeriod; @@ -137,8 +136,8 @@ public class DelinquencyActionIntegrationTests extends BaseLoanIntegrationTest { loanTransactionHelper.createLoanDelinquencyAction(loanId, PAUSE, "10 January 2023", "15 January 2023"); // Update business date - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("14 January 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("14 January 2023").dateFormat(DATETIME_PATTERN).locale("en")); // Create 2nd Delinquency Resume for the Loan loanTransactionHelper.createLoanDelinquencyAction(loanId, RESUME, "14 January 2023"); @@ -175,8 +174,8 @@ public class DelinquencyActionIntegrationTests extends BaseLoanIntegrationTest { loanTransactionHelper.createLoanDelinquencyAction(loanId, PAUSE, "10 January 2023", "15 January 2023"); // Update business date - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("14 January 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("14 January 2023").dateFormat(DATETIME_PATTERN).locale("en")); // Validate Loan Delinquency Pause Period on Loan validateLoanDelinquencyPausePeriods(loanId, pausePeriods("10 January 2023", "15 January 2023", true)); @@ -188,8 +187,8 @@ public class DelinquencyActionIntegrationTests extends BaseLoanIntegrationTest { validateLoanDelinquencyPausePeriods(loanId, pausePeriods("10 January 2023", "14 January 2023", true)); // Update business date to 15 January 2023 - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("15 January 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("15 January 2023").dateFormat(DATETIME_PATTERN).locale("en")); // Validate Loan Delinquency Pause Period on Loan validateLoanDelinquencyPausePeriods(loanId, pausePeriods("10 January 2023", "14 January 2023", false)); @@ -343,8 +342,8 @@ public class DelinquencyActionIntegrationTests extends BaseLoanIntegrationTest { disburseLoan(loanId, BigDecimal.valueOf(100.00), "01 November 2023"); // Update business date - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("05 November 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("05 November 2023").dateFormat(DATETIME_PATTERN).locale("en")); // Create Delinquency Pause for the Loan PostLoansDelinquencyActionResponse response = loanTransactionHelper.createLoanDelinquencyAction(loanId, PAUSE, @@ -352,8 +351,8 @@ public class DelinquencyActionIntegrationTests extends BaseLoanIntegrationTest { // run cob for business date 26 November final InlineLoanCOBHelper inlineLoanCOBHelper = new InlineLoanCOBHelper(requestSpec, responseSpec); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("26 November 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("26 November 2023").dateFormat(DATETIME_PATTERN).locale("en")); inlineLoanCOBHelper.executeInlineCOB(List.of(loanId.longValue())); // Loan delinquency data diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/DelinquencyBucketsIntegrationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/DelinquencyBucketsIntegrationTest.java index 90d65f440..f8c252272 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/DelinquencyBucketsIntegrationTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/DelinquencyBucketsIntegrationTest.java @@ -41,7 +41,7 @@ import java.util.HashMap; import java.util.List; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.tuple.Pair; -import org.apache.fineract.client.models.BusinessDateData; +import org.apache.fineract.client.models.BusinessDateResponse; import org.apache.fineract.client.models.DeleteDelinquencyBucketResponse; import org.apache.fineract.client.models.DeleteDelinquencyRangeResponse; import org.apache.fineract.client.models.DelinquencyBucketData; @@ -320,7 +320,7 @@ public class DelinquencyBucketsIntegrationTest extends BaseLoanIntegrationTest { final LocalDate bussinesLocalDate = Utils.getDateAsLocalDate("01 March 2012"); log.info("Current date {}", bussinesLocalDate); BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, bussinesLocalDate); - final BusinessDateData businessDateResponse = this.businessDateHelper.getBusinessDateByType(requestSpec, responseSpec, + final BusinessDateResponse businessDateResponse = this.businessDateHelper.getBusinessDateByType(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE); ArrayList rangeIds = new ArrayList<>(); diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/DueDateRespectiveLoanRepaymentScheduleTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/DueDateRespectiveLoanRepaymentScheduleTest.java index 6cffe97fb..ad8bf4c10 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/DueDateRespectiveLoanRepaymentScheduleTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/DueDateRespectiveLoanRepaymentScheduleTest.java @@ -32,7 +32,7 @@ import io.restassured.specification.ResponseSpecification; import java.time.LocalDate; import java.util.HashMap; import java.util.List; -import org.apache.fineract.client.models.BusinessDateRequest; +import org.apache.fineract.client.models.BusinessDateUpdateRequest; import org.apache.fineract.client.models.GetLoansLoanIdResponse; import org.apache.fineract.client.models.PostLoansLoanIdChargesChargeIdRequest; import org.apache.fineract.client.models.PostLoansLoanIdChargesChargeIdResponse; @@ -40,7 +40,6 @@ import org.apache.fineract.client.models.PostLoansLoanIdTransactionsRequest; import org.apache.fineract.client.models.PostLoansLoanIdTransactionsResponse; import org.apache.fineract.client.models.PostLoansLoanIdTransactionsTransactionIdRequest; import org.apache.fineract.client.models.PutGlobalConfigurationsRequest; -import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; import org.apache.fineract.infrastructure.configuration.api.GlobalConfigurationConstants; import org.apache.fineract.integrationtests.common.BusinessDateHelper; import org.apache.fineract.integrationtests.common.ClientHelper; @@ -96,7 +95,7 @@ public class DueDateRespectiveLoanRepaymentScheduleTest extends BaseLoanIntegrat try { globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.02.01").dateFormat("yyyy.MM.dd").locale("en")); Integer penalty = ChargesHelper.createCharges(requestSpec, responseSpec, @@ -213,7 +212,7 @@ public class DueDateRespectiveLoanRepaymentScheduleTest extends BaseLoanIntegrat try { globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.02.01").dateFormat("yyyy.MM.dd").locale("en")); Integer penalty = ChargesHelper.createCharges(requestSpec, responseSpec, @@ -344,7 +343,7 @@ public class DueDateRespectiveLoanRepaymentScheduleTest extends BaseLoanIntegrat try { globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.02.01").dateFormat("yyyy.MM.dd").locale("en")); Integer fee = ChargesHelper.createCharges(requestSpec, responseSpec, @@ -457,7 +456,7 @@ public class DueDateRespectiveLoanRepaymentScheduleTest extends BaseLoanIntegrat try { globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.02.01").dateFormat("yyyy.MM.dd").locale("en")); Integer fee = ChargesHelper.createCharges(requestSpec, responseSpec, @@ -542,7 +541,7 @@ public class DueDateRespectiveLoanRepaymentScheduleTest extends BaseLoanIntegrat try { globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.02.01").dateFormat("yyyy.MM.dd").locale("en")); Integer fee = ChargesHelper.createCharges(requestSpec, responseSpec, @@ -686,7 +685,7 @@ public class DueDateRespectiveLoanRepaymentScheduleTest extends BaseLoanIntegrat try { globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.03.01").dateFormat("yyyy.MM.dd").locale("en")); Integer fee = ChargesHelper.createCharges(requestSpec, responseSpec, @@ -769,7 +768,7 @@ public class DueDateRespectiveLoanRepaymentScheduleTest extends BaseLoanIntegrat try { globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.01.28").dateFormat("yyyy.MM.dd").locale("en")); Integer penalty = ChargesHelper.createCharges(requestSpec, responseSpec, @@ -823,7 +822,7 @@ public class DueDateRespectiveLoanRepaymentScheduleTest extends BaseLoanIntegrat (long) firstRepaymentId, new PostLoansLoanIdTransactionsTransactionIdRequest().dateFormat("dd MMMM yyyy") .transactionDate("28 January 2023").transactionAmount(0.0).locale("en")); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.01.31").dateFormat("yyyy.MM.dd").locale("en")); response = loanTransactionHelper.getLoanDetails((long) loanID); @@ -913,7 +912,7 @@ public class DueDateRespectiveLoanRepaymentScheduleTest extends BaseLoanIntegrat try { globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.02.15").dateFormat("yyyy.MM.dd").locale("en")); Integer fee = ChargesHelper.createCharges(requestSpec, responseSpec, @@ -987,7 +986,7 @@ public class DueDateRespectiveLoanRepaymentScheduleTest extends BaseLoanIntegrat Integer secondChargeId = loanTransactionHelper.addChargesForLoan(loanID, LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(penalty), "15 February 2023", "15")); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.03.01").dateFormat("yyyy.MM.dd").locale("en")); response = loanTransactionHelper.getLoanDetails((long) loanID); @@ -1159,7 +1158,7 @@ public class DueDateRespectiveLoanRepaymentScheduleTest extends BaseLoanIntegrat try { globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.02.15").dateFormat("yyyy.MM.dd").locale("en")); Integer fee = ChargesHelper.createCharges(requestSpec, responseSpec, @@ -1233,7 +1232,7 @@ public class DueDateRespectiveLoanRepaymentScheduleTest extends BaseLoanIntegrat Integer secondChargeId = loanTransactionHelper.addChargesForLoan(loanID, LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(penalty), "15 February 2023", "15")); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.03.01").dateFormat("yyyy.MM.dd").locale("en")); response = loanTransactionHelper.getLoanDetails((long) loanID); @@ -1328,7 +1327,7 @@ public class DueDateRespectiveLoanRepaymentScheduleTest extends BaseLoanIntegrat } assertEquals(2, response.getTransactions().get(4).getLoanChargePaidByList().size()); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.03.07").dateFormat("yyyy.MM.dd").locale("en")); PostLoansLoanIdTransactionsResponse secondReverseRepayment = loanTransactionHelper.reverseLoanTransaction((long) loanID, @@ -1338,7 +1337,7 @@ public class DueDateRespectiveLoanRepaymentScheduleTest extends BaseLoanIntegrat Integer thirdChargeId = loanTransactionHelper.addChargesForLoan(loanID, LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(penalty), "07 March 2023", "15")); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.03.08").dateFormat("yyyy.MM.dd").locale("en")); Integer thirdRepayment = (Integer) loanTransactionHelper.makeRepayment("08 March 2023", Float.parseFloat("15.00"), loanID) @@ -1500,7 +1499,7 @@ public class DueDateRespectiveLoanRepaymentScheduleTest extends BaseLoanIntegrat try { globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.05.14").dateFormat("yyyy.MM.dd").locale("en")); globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.CHARGE_ACCRUAL_DATE, new PutGlobalConfigurationsRequest().stringValue("submitted-date")); @@ -1525,7 +1524,7 @@ public class DueDateRespectiveLoanRepaymentScheduleTest extends BaseLoanIntegrat loanStatusHashMap = loanTransactionHelper.disburseLoanWithTransactionAmount("14 May 2023", loanID, "127.95"); LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.06.11").dateFormat("yyyy.MM.dd").locale("en")); final String requestJSON = new LoanRescheduleRequestTestBuilder().updateRescheduleFromDate("13 June 2023") @@ -1542,7 +1541,7 @@ public class DueDateRespectiveLoanRepaymentScheduleTest extends BaseLoanIntegrat this.loanRescheduleRequestHelper.approveLoanRescheduleRequest(loanRescheduleRequestId, aproveRequestJSON); Integer penalty1LoanChargeId = loanTransactionHelper.addChargesForLoan(loanID, LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(fee), "13 July 2023", "3.65")); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.06.12").dateFormat("yyyy.MM.dd").locale("en")); inlineLoanCOBHelper.executeInlineCOB(List.of(loanID.longValue())); @@ -1582,7 +1581,7 @@ public class DueDateRespectiveLoanRepaymentScheduleTest extends BaseLoanIntegrat assertEquals(3.65, Utils.getDoubleValue(loanDetails.getTransactions().get(1).getFeeChargesPortion())); assertEquals(0.0, Utils.getDoubleValue(loanDetails.getTransactions().get(1).getOutstandingLoanBalance())); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.06.17").dateFormat("yyyy.MM.dd").locale("en")); PostLoansLoanIdTransactionsResponse merchantIssuedRefund1 = loanTransactionHelper.makeMerchantIssuedRefund(Long.valueOf(loanID), new PostLoansLoanIdTransactionsRequest().locale("en").dateFormat("dd MMMM yyyy").transactionDate("17 June 2023") @@ -1692,7 +1691,7 @@ public class DueDateRespectiveLoanRepaymentScheduleTest extends BaseLoanIntegrat try { globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.05.14").dateFormat("yyyy.MM.dd").locale("en")); globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.CHARGE_ACCRUAL_DATE, new PutGlobalConfigurationsRequest().stringValue("submitted-date")); @@ -1717,7 +1716,7 @@ public class DueDateRespectiveLoanRepaymentScheduleTest extends BaseLoanIntegrat loanStatusHashMap = loanTransactionHelper.disburseLoanWithTransactionAmount("14 May 2023", loanID, "127.95"); LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.06.11").dateFormat("yyyy.MM.dd").locale("en")); final String requestJSON = new LoanRescheduleRequestTestBuilder().updateRescheduleFromDate("13 June 2023") @@ -1734,7 +1733,7 @@ public class DueDateRespectiveLoanRepaymentScheduleTest extends BaseLoanIntegrat this.loanRescheduleRequestHelper.approveLoanRescheduleRequest(loanRescheduleRequestId, aproveRequestJSON); Integer penalty1LoanChargeId = loanTransactionHelper.addChargesForLoan(loanID, LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(fee), "13 July 2023", "3.65")); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.06.12").dateFormat("yyyy.MM.dd").locale("en")); inlineLoanCOBHelper.executeInlineCOB(List.of(loanID.longValue())); @@ -1774,7 +1773,7 @@ public class DueDateRespectiveLoanRepaymentScheduleTest extends BaseLoanIntegrat assertEquals(3.65, Utils.getDoubleValue(loanDetails.getTransactions().get(1).getFeeChargesPortion())); assertEquals(0.0, Utils.getDoubleValue(loanDetails.getTransactions().get(1).getOutstandingLoanBalance())); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.06.17").dateFormat("yyyy.MM.dd").locale("en")); PostLoansLoanIdTransactionsResponse merchantIssuedRefund1 = loanTransactionHelper.makeMerchantIssuedRefund(Long.valueOf(loanID), diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/ExternalIdSupportIntegrationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/ExternalIdSupportIntegrationTest.java index a850e72bb..9f9539cd1 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/ExternalIdSupportIntegrationTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/ExternalIdSupportIntegrationTest.java @@ -31,7 +31,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.UUID; -import org.apache.fineract.client.models.BusinessDateRequest; +import org.apache.fineract.client.models.BusinessDateUpdateRequest; import org.apache.fineract.client.models.DeleteLoansLoanIdChargesChargeIdResponse; import org.apache.fineract.client.models.DeleteLoansLoanIdResponse; import org.apache.fineract.client.models.DelinquencyRangeData; @@ -62,7 +62,6 @@ import org.apache.fineract.client.models.PutLoansLoanIdChargesChargeIdResponse; import org.apache.fineract.client.models.PutLoansLoanIdRequest; import org.apache.fineract.client.models.PutLoansLoanIdResponse; import org.apache.fineract.client.util.CallFailedRuntimeException; -import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; import org.apache.fineract.infrastructure.configuration.api.GlobalConfigurationConstants; import org.apache.fineract.integrationtests.common.BusinessDateHelper; import org.apache.fineract.integrationtests.common.ClientHelper; @@ -832,7 +831,7 @@ public class ExternalIdSupportIntegrationTest extends BaseLoanIntegrationTest { new PutGlobalConfigurationsRequest().enabled(true)); globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - new BusinessDateHelper().updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + new BusinessDateHelper().updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2022.10.10").dateFormat("yyyy.MM.dd").locale("en")); try { ArrayList rangeIds = new ArrayList<>(); diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/InstallmentLevelDelinquencyAPIIntegrationTests.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/InstallmentLevelDelinquencyAPIIntegrationTests.java index 21d53e7c9..9d45bacf5 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/InstallmentLevelDelinquencyAPIIntegrationTests.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/InstallmentLevelDelinquencyAPIIntegrationTests.java @@ -18,7 +18,6 @@ */ package org.apache.fineract.integrationtests; -import static org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType.BUSINESS_DATE; import static org.junit.jupiter.api.Assertions.assertNotNull; import java.math.BigDecimal; @@ -26,7 +25,7 @@ import java.util.List; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.tuple.Pair; -import org.apache.fineract.client.models.BusinessDateRequest; +import org.apache.fineract.client.models.BusinessDateUpdateRequest; import org.apache.fineract.client.models.GetLoansLoanIdLoanInstallmentLevelDelinquency; import org.apache.fineract.client.models.GetLoansLoanIdResponse; import org.apache.fineract.client.models.PostLoanProductsRequest; @@ -595,8 +594,8 @@ public class InstallmentLevelDelinquencyAPIIntegrationTests extends BaseLoanInte } private void updateBusinessDateAndExecuteCOBJob(String date) { - businessDateHelper.updateBusinessDate( - new BusinessDateRequest().type(BUSINESS_DATE.getName()).date(date).dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date(date).dateFormat(DATETIME_PATTERN).locale("en")); schedulerJobHelper.executeAndAwaitJob("Loan COB"); } diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanChargePaymentWithAdvancedPaymentAllocationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanChargePaymentWithAdvancedPaymentAllocationTest.java index fb489e11c..23415ff9f 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanChargePaymentWithAdvancedPaymentAllocationTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanChargePaymentWithAdvancedPaymentAllocationTest.java @@ -35,14 +35,13 @@ import java.util.HashMap; import java.util.List; import lombok.extern.slf4j.Slf4j; import org.apache.fineract.client.models.AdvancedPaymentData; -import org.apache.fineract.client.models.BusinessDateRequest; +import org.apache.fineract.client.models.BusinessDateUpdateRequest; import org.apache.fineract.client.models.GetLoansLoanIdResponse; import org.apache.fineract.client.models.PostClientsResponse; import org.apache.fineract.client.models.PostLoansLoanIdRequest; import org.apache.fineract.client.models.PostLoansRequest; import org.apache.fineract.client.models.PostLoansResponse; import org.apache.fineract.client.models.PutGlobalConfigurationsRequest; -import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; import org.apache.fineract.infrastructure.configuration.api.GlobalConfigurationConstants; import org.apache.fineract.integrationtests.common.BusinessDateHelper; import org.apache.fineract.integrationtests.common.ClientHelper; @@ -165,7 +164,7 @@ public class LoanChargePaymentWithAdvancedPaymentAllocationTest extends BaseLoan globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.02.15").dateFormat("yyyy.MM.dd").locale("en")); final Integer savingsId = createSavingsAccountDailyPosting(client.getClientId().intValue(), startDate); diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanDelinquencyDetailsNextPaymentDateConfigurationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanDelinquencyDetailsNextPaymentDateConfigurationTest.java index f7fbfeb07..85fcaae9b 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanDelinquencyDetailsNextPaymentDateConfigurationTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanDelinquencyDetailsNextPaymentDateConfigurationTest.java @@ -19,7 +19,6 @@ package org.apache.fineract.integrationtests; import static java.lang.Boolean.TRUE; -import static org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType.BUSINESS_DATE; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -27,7 +26,7 @@ import java.math.BigDecimal; import java.time.LocalDate; import java.util.List; import org.apache.commons.lang3.tuple.Pair; -import org.apache.fineract.client.models.BusinessDateRequest; +import org.apache.fineract.client.models.BusinessDateUpdateRequest; import org.apache.fineract.client.models.GetLoanProductsProductIdResponse; import org.apache.fineract.client.models.GetLoansLoanIdResponse; import org.apache.fineract.client.models.PostLoanProductsRequest; @@ -80,20 +79,20 @@ public class LoanDelinquencyDetailsNextPaymentDateConfigurationTest extends Base verifyLoanDelinquencyNextPaymentDate(loanId, "01 November 2023", false); // Update business date - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("13 November 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("13 November 2023").dateFormat(DATETIME_PATTERN).locale("en")); // delinquency next payment date for 13 Nov Business date verifyLoanDelinquencyNextPaymentDate(loanId, "16 November 2023", false); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("16 November 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("16 November 2023").dateFormat(DATETIME_PATTERN).locale("en")); // delinquency next payment date for 16 Nov Business date verifyLoanDelinquencyNextPaymentDate(loanId, "01 December 2023", false); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("01 December 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("01 December 2023").dateFormat(DATETIME_PATTERN).locale("en")); // delinquency next payment date for 01 Dec Business date verifyLoanDelinquencyNextPaymentDate(loanId, "16 December 2023", false); @@ -111,14 +110,14 @@ public class LoanDelinquencyDetailsNextPaymentDateConfigurationTest extends Base installment(0.0, 0.0, 50.0, 50.0, false, "23 December 2023") // ); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("17 December 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("17 December 2023").dateFormat(DATETIME_PATTERN).locale("en")); // delinquency next payment date for 17 Dec Business date N + 1 verifyLoanDelinquencyNextPaymentDate(loanId, "23 December 2023", false); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("25 December 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("25 December 2023").dateFormat(DATETIME_PATTERN).locale("en")); } finally { // reset global config @@ -166,8 +165,8 @@ public class LoanDelinquencyDetailsNextPaymentDateConfigurationTest extends Base verifyLoanDelinquencyNextPaymentDate(loanId, "16 November 2023", false); // Update business date - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("13 November 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("13 November 2023").dateFormat(DATETIME_PATTERN).locale("en")); // delinquency next payment date for 13 Nov Business date verifyLoanDelinquencyNextPaymentDate(loanId, "16 November 2023", false); @@ -187,8 +186,8 @@ public class LoanDelinquencyDetailsNextPaymentDateConfigurationTest extends Base // delinquency next payment date for 13 Nov Business date after paying 16 November Installment verifyLoanDelinquencyNextPaymentDate(loanId, "01 December 2023", false); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("16 November 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("16 November 2023").dateFormat(DATETIME_PATTERN).locale("en")); // delinquency next payment date for 16 Nov Business date verifyLoanDelinquencyNextPaymentDate(loanId, "01 December 2023", false); @@ -208,8 +207,8 @@ public class LoanDelinquencyDetailsNextPaymentDateConfigurationTest extends Base // delinquency next payment date for 16 Nov Business date after partial payment of 01 Dec installment verifyLoanDelinquencyNextPaymentDate(loanId, "01 December 2023", false); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("01 December 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("01 December 2023").dateFormat(DATETIME_PATTERN).locale("en")); // delinquency next payment date for 01 December Business date verifyLoanDelinquencyNextPaymentDate(loanId, "16 December 2023", false); @@ -227,14 +226,14 @@ public class LoanDelinquencyDetailsNextPaymentDateConfigurationTest extends Base installment(0.0, 0.0, 50.0, 50.0, false, "23 December 2023") // ); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("17 December 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("17 December 2023").dateFormat(DATETIME_PATTERN).locale("en")); // delinquency next payment date for 17 Dec Business date N + 1 verifyLoanDelinquencyNextPaymentDate(loanId, "23 December 2023", false); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("25 December 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("25 December 2023").dateFormat(DATETIME_PATTERN).locale("en")); } finally { // reset global config globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.NEXT_PAYMENT_DUE_DATE, diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanSpecificDueDateChargeAfterMaturityTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanSpecificDueDateChargeAfterMaturityTest.java index abf0aade4..134c9ceb5 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanSpecificDueDateChargeAfterMaturityTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanSpecificDueDateChargeAfterMaturityTest.java @@ -35,7 +35,7 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; import java.util.List; -import org.apache.fineract.client.models.BusinessDateRequest; +import org.apache.fineract.client.models.BusinessDateUpdateRequest; import org.apache.fineract.client.models.ChargeRequest; import org.apache.fineract.client.models.GetLoansLoanIdResponse; import org.apache.fineract.client.models.PostChargesResponse; @@ -49,7 +49,6 @@ import org.apache.fineract.client.models.PostLoansLoanIdTransactionsTransactionI import org.apache.fineract.client.models.PostLoansRequest; import org.apache.fineract.client.models.PostLoansResponse; import org.apache.fineract.client.models.PutGlobalConfigurationsRequest; -import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; import org.apache.fineract.infrastructure.configuration.api.GlobalConfigurationConstants; import org.apache.fineract.integrationtests.common.BusinessDateHelper; import org.apache.fineract.integrationtests.common.ClientHelper; @@ -436,7 +435,7 @@ public class LoanSpecificDueDateChargeAfterMaturityTest extends BaseLoanIntegrat try { globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - BUSINESS_DATE_HELPER.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + BUSINESS_DATE_HELPER.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("01 September 2023").dateFormat(DATETIME_PATTERN).locale("en")); PostChargesResponse penaltyCharge = CHARGES_HELPER.createCharges(new ChargeRequest().penalty(true).amount(10.0) @@ -462,7 +461,7 @@ public class LoanSpecificDueDateChargeAfterMaturityTest extends BaseLoanIntegrat validateLoanTransaction(loanDetails, 0, 1000.0, 0.0, 0.0, 1000.0); assertTrue(loanDetails.getStatus().getActive()); - BUSINESS_DATE_HELPER.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + BUSINESS_DATE_HELPER.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("01 October 2023").dateFormat(DATETIME_PATTERN).locale("en")); PostLoansLoanIdTransactionsResponse repaymentTransaction = loanTransactionHelper.makeLoanRepayment(loanResponse.getLoanId(), @@ -475,7 +474,7 @@ public class LoanSpecificDueDateChargeAfterMaturityTest extends BaseLoanIntegrat validateLoanTransaction(loanDetails, 1, 1000.0, 1000.0, 0.0, 0.0); assertTrue(loanDetails.getStatus().getClosedObligationsMet()); - BUSINESS_DATE_HELPER.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + BUSINESS_DATE_HELPER.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("04 October 2023").dateFormat(DATETIME_PATTERN).locale("en")); loanTransactionHelper.makeMerchantIssuedRefund(loanResponse.getLoanId(), new PostLoansLoanIdTransactionsRequest() diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanTransactionInterestPaymentWaiverTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanTransactionInterestPaymentWaiverTest.java index 0de96295b..538ca7a41 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanTransactionInterestPaymentWaiverTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanTransactionInterestPaymentWaiverTest.java @@ -40,7 +40,7 @@ import org.apache.fineract.batch.command.internal.CreateTransactionLoanCommandSt import org.apache.fineract.batch.domain.BatchRequest; import org.apache.fineract.batch.domain.BatchResponse; import org.apache.fineract.client.models.AdvancedPaymentData; -import org.apache.fineract.client.models.BusinessDateRequest; +import org.apache.fineract.client.models.BusinessDateUpdateRequest; import org.apache.fineract.client.models.ChargeRequest; import org.apache.fineract.client.models.GetLoansLoanIdLoanChargeData; import org.apache.fineract.client.models.GetLoansLoanIdResponse; @@ -57,7 +57,6 @@ import org.apache.fineract.client.models.PostLoansLoanIdTransactionsResponse; import org.apache.fineract.client.models.PostLoansLoanIdTransactionsTransactionIdRequest; import org.apache.fineract.client.models.PostLoansRequest; import org.apache.fineract.client.models.PostLoansResponse; -import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; import org.apache.fineract.integrationtests.common.BatchHelper; import org.apache.fineract.integrationtests.common.BusinessDateHelper; import org.apache.fineract.integrationtests.common.ClientHelper; @@ -906,7 +905,7 @@ public class LoanTransactionInterestPaymentWaiverTest extends BaseLoanIntegratio 0.0, 0.0, 0.0); assertTrue(loanDetails.getStatus().getActive()); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.09.16").dateFormat("yyyy.MM.dd").locale("en")); loanTransactionHelper.makeLoanRepayment(loanResponse.getLoanId(), new PostLoansLoanIdTransactionsRequest() @@ -1013,7 +1012,7 @@ public class LoanTransactionInterestPaymentWaiverTest extends BaseLoanIntegratio 0.0, 0.0, 0.0); assertTrue(loanDetails.getStatus().getActive()); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.09.16").dateFormat("yyyy.MM.dd").locale("en")); loanTransactionHelper.makeLoanRepayment(loanResponse.getLoanId(), new PostLoansLoanIdTransactionsRequest() diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanTransactionReverseReplayTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanTransactionReverseReplayTest.java index 2b66aaf90..3cd581c41 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanTransactionReverseReplayTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanTransactionReverseReplayTest.java @@ -34,7 +34,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.UUID; -import org.apache.fineract.client.models.BusinessDateRequest; +import org.apache.fineract.client.models.BusinessDateUpdateRequest; import org.apache.fineract.client.models.GetLoanProductsProductIdResponse; import org.apache.fineract.client.models.GetLoansLoanIdResponse; import org.apache.fineract.client.models.GetLoansLoanIdTransactions; @@ -42,7 +42,6 @@ import org.apache.fineract.client.models.PostLoansLoanIdTransactionsRequest; import org.apache.fineract.client.models.PostLoansLoanIdTransactionsResponse; import org.apache.fineract.client.models.PostLoansLoanIdTransactionsTransactionIdRequest; import org.apache.fineract.client.models.PutGlobalConfigurationsRequest; -import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; import org.apache.fineract.infrastructure.configuration.api.GlobalConfigurationConstants; import org.apache.fineract.integrationtests.common.BusinessDateHelper; import org.apache.fineract.integrationtests.common.ClientHelper; @@ -97,7 +96,7 @@ public class LoanTransactionReverseReplayTest extends BaseLoanIntegrationTest { try { globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("04 October 2022").dateFormat(DATE_PATTERN).locale("en")); // Loan ExternalId @@ -123,13 +122,13 @@ public class LoanTransactionReverseReplayTest extends BaseLoanIntegrationTest { inlineLoanCOBHelper.executeInlineCOB(List.of(loanId.longValue())); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("05 October 2022").dateFormat(DATE_PATTERN).locale("en")); loanTransactionHelper.makeCreditBalanceRefund(loanExternalIdStr, new PostLoansLoanIdTransactionsRequest() .dateFormat(DATE_PATTERN).transactionDate("05 October 2022").locale("en").transactionAmount(500.0)); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("06 October 2022").dateFormat(DATE_PATTERN).locale("en")); loanTransactionHelper.reverseLoanTransaction(loanExternalIdStr, repaymentTransaction.getResourceId(), @@ -162,7 +161,7 @@ public class LoanTransactionReverseReplayTest extends BaseLoanIntegrationTest { try { globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("04 October 2022").dateFormat(DATE_PATTERN).locale("en")); // Loan ExternalId @@ -198,7 +197,7 @@ public class LoanTransactionReverseReplayTest extends BaseLoanIntegrationTest { assertEquals(LocalDate.of(2022, 10, 10), loansLoanIdResponse.getRepaymentSchedule().getPeriods().get(lastPeriodIndex).getDueDate()); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("06 October 2022").dateFormat(DATE_PATTERN).locale("en")); final PostLoansLoanIdTransactionsResponse repaymentTransaction = loanTransactionHelper.makeLoanRepayment(loanExternalIdStr, @@ -217,7 +216,7 @@ public class LoanTransactionReverseReplayTest extends BaseLoanIntegrationTest { assertEquals(LocalDate.of(2022, 10, 10), loansLoanIdResponse.getRepaymentSchedule().getPeriods().get(lastPeriodIndex).getDueDate()); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("11 October 2022").dateFormat(DATE_PATTERN).locale("en")); loanTransactionHelper.chargebackLoanTransaction(loanExternalIdStr, loanTransactionExternalIdStr, new PostLoansLoanIdTransactionsTransactionIdRequest().locale("en").transactionAmount(100.0).paymentTypeId(1L)); @@ -237,7 +236,7 @@ public class LoanTransactionReverseReplayTest extends BaseLoanIntegrationTest { try { globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("04 October 2022").dateFormat(DATE_PATTERN).locale("en")); final Account assetAccount = accountHelper.createAssetAccount(); @@ -277,7 +276,7 @@ public class LoanTransactionReverseReplayTest extends BaseLoanIntegrationTest { inlineLoanCOBHelper.executeInlineCOB(List.of(loanId.longValue())); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("05 October 2022").dateFormat(DATE_PATTERN).locale("en")); PostLoansLoanIdTransactionsResponse cbrTransactionResponse = loanTransactionHelper.makeCreditBalanceRefund(loanExternalIdStr, @@ -302,7 +301,7 @@ public class LoanTransactionReverseReplayTest extends BaseLoanIntegrationTest { assertEquals(1, cbrExpenseJournalEntries.size()); assertEquals(1, cbrAssetJournalEntries.size()); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("06 October 2022").dateFormat(DATE_PATTERN).locale("en")); loanTransactionHelper.reverseLoanTransaction(loanExternalIdStr, repaymentTransaction.getResourceId(), diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/RefundForActiveLoansWithAdvancedPaymentAllocationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/RefundForActiveLoansWithAdvancedPaymentAllocationTest.java index 93752ab6e..35a2b1daa 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/RefundForActiveLoansWithAdvancedPaymentAllocationTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/RefundForActiveLoansWithAdvancedPaymentAllocationTest.java @@ -31,7 +31,7 @@ import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; import lombok.extern.slf4j.Slf4j; import org.apache.fineract.client.models.AdvancedPaymentData; -import org.apache.fineract.client.models.BusinessDateRequest; +import org.apache.fineract.client.models.BusinessDateUpdateRequest; import org.apache.fineract.client.models.GetLoansLoanIdRepaymentPeriod; import org.apache.fineract.client.models.GetLoansLoanIdResponse; import org.apache.fineract.client.models.PostClientsResponse; @@ -39,7 +39,6 @@ import org.apache.fineract.client.models.PostLoansLoanIdRequest; import org.apache.fineract.client.models.PostLoansRequest; import org.apache.fineract.client.models.PostLoansResponse; import org.apache.fineract.client.models.PutGlobalConfigurationsRequest; -import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; import org.apache.fineract.infrastructure.configuration.api.GlobalConfigurationConstants; import org.apache.fineract.integrationtests.common.BusinessDateHelper; import org.apache.fineract.integrationtests.common.ClientHelper; @@ -87,7 +86,7 @@ public class RefundForActiveLoansWithAdvancedPaymentAllocationTest extends BaseL try { globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.02.15").dateFormat("yyyy.MM.dd").locale("en")); final Account assetAccount = accountHelper.createAssetAccount(); @@ -167,7 +166,7 @@ public class RefundForActiveLoansWithAdvancedPaymentAllocationTest extends BaseL assertEquals(250.00, Utils.getDoubleValue(thirdRepaymentInstallment.getTotalOutstandingForPeriod())); assertEquals(LocalDate.of(2023, 4, 1), thirdRepaymentInstallment.getDueDate()); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.03.01").dateFormat("yyyy.MM.dd").locale("en")); loanTransactionHelper.makeRepayment("01 March 2023", 810.0f, loanId); @@ -288,7 +287,7 @@ public class RefundForActiveLoansWithAdvancedPaymentAllocationTest extends BaseL try { globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.02.15").dateFormat("yyyy.MM.dd").locale("en")); final Account assetAccount = accountHelper.createAssetAccount(); @@ -368,7 +367,7 @@ public class RefundForActiveLoansWithAdvancedPaymentAllocationTest extends BaseL assertEquals(250.00, Utils.getDoubleValue(thirdRepaymentInstallment.getTotalOutstandingForPeriod())); assertEquals(LocalDate.of(2023, 4, 1), thirdRepaymentInstallment.getDueDate()); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2023.03.01").dateFormat("yyyy.MM.dd").locale("en")); loanTransactionHelper.makeRepayment("28 January 2023", 810.0f, loanId); diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/SchedulerJobsTestResults.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/SchedulerJobsTestResults.java index 445b0e80b..1428ee892 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/SchedulerJobsTestResults.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/SchedulerJobsTestResults.java @@ -49,7 +49,7 @@ import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.TimeZone; -import org.apache.fineract.client.models.BusinessDateRequest; +import org.apache.fineract.client.models.BusinessDateUpdateRequest; import org.apache.fineract.client.models.GetJournalEntriesTransactionIdResponse; import org.apache.fineract.client.models.GetLoansLoanIdResponse; import org.apache.fineract.client.models.JournalEntryTransactionItem; @@ -1348,7 +1348,7 @@ public class SchedulerJobsTestResults extends IntegrationTest { try { globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2022.09.04").dateFormat("yyyy.MM.dd").locale("en")); final Account assetAccount = this.accountHelper.createAssetAccount(); @@ -1375,7 +1375,7 @@ public class SchedulerJobsTestResults extends IntegrationTest { this.loanTransactionHelper.approveLoan("02 September 2022", loanId); this.loanTransactionHelper.disburseLoan("03 September 2022", loanId, "1000", null); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BusinessDateType.BUSINESS_DATE.getName()) + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) .date("2022.09.05").dateFormat("yyyy.MM.dd").locale("en")); LocalDate targetDate = LocalDate.of(2022, 9, 5); diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/UndoLoanDisbursalWithDownPaymentIntegrationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/UndoLoanDisbursalWithDownPaymentIntegrationTest.java index 1aa2b5eac..d85c13535 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/UndoLoanDisbursalWithDownPaymentIntegrationTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/UndoLoanDisbursalWithDownPaymentIntegrationTest.java @@ -19,12 +19,11 @@ package org.apache.fineract.integrationtests; import static java.lang.Boolean.TRUE; -import static org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType.BUSINESS_DATE; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import java.math.BigDecimal; -import org.apache.fineract.client.models.BusinessDateRequest; +import org.apache.fineract.client.models.BusinessDateUpdateRequest; import org.apache.fineract.client.models.GetLoanProductsProductIdResponse; import org.apache.fineract.client.models.PostLoanProductsRequest; import org.apache.fineract.client.models.PostLoanProductsResponse; @@ -795,8 +794,8 @@ public class UndoLoanDisbursalWithDownPaymentIntegrationTest extends BaseLoanInt installment(750.0, false, "31 January 2023") // ); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("15 January 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("15 January 2023").dateFormat(DATETIME_PATTERN).locale("en")); // 2nd Disburse Loan disburseLoan(loanId, BigDecimal.valueOf(400.0), "15 January 2023"); @@ -909,8 +908,8 @@ public class UndoLoanDisbursalWithDownPaymentIntegrationTest extends BaseLoanInt installment(750.0, false, "31 January 2023") // ); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("10 January 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("10 January 2023").dateFormat(DATETIME_PATTERN).locale("en")); addRepaymentForLoan(loanId, 300.0, "10 January 2023"); @@ -920,8 +919,8 @@ public class UndoLoanDisbursalWithDownPaymentIntegrationTest extends BaseLoanInt transaction(300.0, "Repayment", "10 January 2023") // ); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("15 January 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("15 January 2023").dateFormat(DATETIME_PATTERN).locale("en")); // 2nd Disburse Loan disburseLoan(loanId, BigDecimal.valueOf(400.0), "15 January 2023"); @@ -1047,8 +1046,8 @@ public class UndoLoanDisbursalWithDownPaymentIntegrationTest extends BaseLoanInt installment(750.0, false, "31 January 2023") // ); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("15 January 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("15 January 2023").dateFormat(DATETIME_PATTERN).locale("en")); // 2nd Disburse Loan disburseLoan(loanId, BigDecimal.valueOf(400.0), "15 January 2023"); @@ -1166,8 +1165,8 @@ public class UndoLoanDisbursalWithDownPaymentIntegrationTest extends BaseLoanInt installment(750.0, false, "31 January 2023") // ); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("15 January 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("15 January 2023").dateFormat(DATETIME_PATTERN).locale("en")); // 2nd Disburse Loan disburseLoan(loanId, BigDecimal.valueOf(400.0), "15 January 2023"); @@ -1201,8 +1200,8 @@ public class UndoLoanDisbursalWithDownPaymentIntegrationTest extends BaseLoanInt installment(1050.0, false, "31 January 2023") // ); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("20 January 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("20 January 2023").dateFormat(DATETIME_PATTERN).locale("en")); // make an additional repayment after the 2nd disbursal addRepaymentForLoan(loanId, 50.0, "20 January 2023"); @@ -1258,8 +1257,8 @@ public class UndoLoanDisbursalWithDownPaymentIntegrationTest extends BaseLoanInt installment(750.0, false, "31 January 2023") // ); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("15 January 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("15 January 2023").dateFormat(DATETIME_PATTERN).locale("en")); // 2nd Disburse Loan disburseLoan(loanId, BigDecimal.valueOf(400.0), "15 January 2023"); @@ -1296,8 +1295,8 @@ public class UndoLoanDisbursalWithDownPaymentIntegrationTest extends BaseLoanInt installment(1050.0, false, "31 January 2023") // ); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("20 January 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("20 January 2023").dateFormat(DATETIME_PATTERN).locale("en")); // make an additional repayment after the 2nd disbursal addRepaymentForLoan(loanId, 50.0, "20 January 2023"); @@ -1350,8 +1349,8 @@ public class UndoLoanDisbursalWithDownPaymentIntegrationTest extends BaseLoanInt installment(750.0, false, "31 January 2023") // ); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("15 January 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("15 January 2023").dateFormat(DATETIME_PATTERN).locale("en")); // 2nd Disburse Loan disburseLoan(loanId, BigDecimal.valueOf(400.0), "15 January 2023"); @@ -1472,8 +1471,8 @@ public class UndoLoanDisbursalWithDownPaymentIntegrationTest extends BaseLoanInt installment(750.0, false, "31 January 2023") // ); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("15 January 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("15 January 2023").dateFormat(DATETIME_PATTERN).locale("en")); // 2nd Disburse Loan disburseLoan(loanId, BigDecimal.valueOf(400.0), "15 January 2023"); @@ -1594,8 +1593,8 @@ public class UndoLoanDisbursalWithDownPaymentIntegrationTest extends BaseLoanInt installment(750.0, false, "31 January 2023") // ); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("15 January 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("15 January 2023").dateFormat(DATETIME_PATTERN).locale("en")); // 2nd Disburse Loan disburseLoan(loanId, BigDecimal.valueOf(400.0), "15 January 2023"); @@ -1629,8 +1628,8 @@ public class UndoLoanDisbursalWithDownPaymentIntegrationTest extends BaseLoanInt installment(1050.0, false, "31 January 2023") // ); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("20 January 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("20 January 2023").dateFormat(DATETIME_PATTERN).locale("en")); // make an additional repayment after the 2nd disbursal addRepaymentForLoan(loanId, 50.0, "20 January 2023"); @@ -1730,8 +1729,8 @@ public class UndoLoanDisbursalWithDownPaymentIntegrationTest extends BaseLoanInt installment(750.0, false, "31 January 2023") // ); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("15 January 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("15 January 2023").dateFormat(DATETIME_PATTERN).locale("en")); // 2nd Disburse Loan disburseLoan(loanId, BigDecimal.valueOf(400.0), "15 January 2023"); @@ -1767,8 +1766,8 @@ public class UndoLoanDisbursalWithDownPaymentIntegrationTest extends BaseLoanInt installment(1050.0, false, "31 January 2023") // ); - businessDateHelper.updateBusinessDate(new BusinessDateRequest().type(BUSINESS_DATE.getName()).date("20 January 2023") - .dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date("20 January 2023").dateFormat(DATETIME_PATTERN).locale("en")); // make an additional repayment after the 2nd disbursal addRepaymentForLoan(loanId, 50.0, "20 January 2023"); diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/BusinessDateHelper.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/BusinessDateHelper.java index 0ae7d0764..c5fa482de 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/BusinessDateHelper.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/BusinessDateHelper.java @@ -18,8 +18,6 @@ */ package org.apache.fineract.integrationtests.common; -import static org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType.BUSINESS_DATE; - import com.google.gson.Gson; import io.restassured.specification.RequestSpecification; import io.restassured.specification.ResponseSpecification; @@ -27,9 +25,8 @@ import java.time.LocalDate; import java.util.HashMap; import java.util.List; import lombok.extern.slf4j.Slf4j; -import org.apache.fineract.client.models.BusinessDateData; -import org.apache.fineract.client.models.BusinessDateRequest; import org.apache.fineract.client.models.BusinessDateResponse; +import org.apache.fineract.client.models.BusinessDateUpdateRequest; import org.apache.fineract.client.models.PutGlobalConfigurationsRequest; import org.apache.fineract.client.util.Calls; import org.apache.fineract.client.util.JSON; @@ -56,29 +53,29 @@ public final class BusinessDateHelper { return Utils.performServerPost(requestSpec, responseSpec, BUSINESS_DATE_API, buildBusinessDateRequest(type, date), "changes"); } - public static BusinessDateResponse updateBusinessDate(final BusinessDateRequest request) { + public static BusinessDateResponse updateBusinessDate(final BusinessDateUpdateRequest request) { log.info("------------------UPDATE BUSINESS DATE----------------------"); log.info("------------------Type: {}, date: {}----------------------", request.getType(), request.getDate()); - return Calls.ok(FineractClientHelper.getFineractClient().businessDateManagement.updateBusinessDate(request)); + return Calls.ok(FineractClientHelper.getFineractClient().businessDateManagement.updateBusinessDate(null, request)); } // TODO: Rewrite to use fineract-client instead! // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, // org.apache.fineract.client.models.PostLoansLoanIdRequest) @Deprecated(forRemoval = true) - public BusinessDateData getBusinessDateByType(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + public BusinessDateResponse getBusinessDateByType(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final BusinessDateType type) { final String BUSINESS_DATE_API = "/fineract-provider/api/v1/businessdate/" + type.name() + "?" + Utils.TENANT_IDENTIFIER; final String response = Utils.performServerGet(requestSpec, responseSpec, BUSINESS_DATE_API); log.info("{}", response); - return GSON.fromJson(response, BusinessDateData.class); + return GSON.fromJson(response, BusinessDateResponse.class); } - public BusinessDateData getBusinessDate(final String type) { + public BusinessDateResponse getBusinessDate(final String type) { return Calls.ok(FineractClientHelper.getFineractClient().businessDateManagement.getBusinessDate(type)); } - public List getBusinessDates() { + public List getBusinessDates() { return Calls.ok(FineractClientHelper.getFineractClient().businessDateManagement.getBusinessDates()); } @@ -100,8 +97,8 @@ public final class BusinessDateHelper { try { new GlobalConfigurationHelper().updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - updateBusinessDate( - new BusinessDateRequest().type(BUSINESS_DATE.getName()).date(date).dateFormat(DATETIME_PATTERN).locale("en")); + updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE).date(date) + .dateFormat(DATETIME_PATTERN).locale("en")); runnable.run(); } finally { new GlobalConfigurationHelper().updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/savings/base/BaseSavingsIntegrationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/savings/base/BaseSavingsIntegrationTest.java index 25d1c9068..95873fb26 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/savings/base/BaseSavingsIntegrationTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/savings/base/BaseSavingsIntegrationTest.java @@ -18,8 +18,6 @@ */ package org.apache.fineract.integrationtests.savings.base; -import static org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType.BUSINESS_DATE; - import io.restassured.builder.RequestSpecBuilder; import io.restassured.builder.ResponseSpecBuilder; import io.restassured.http.ContentType; @@ -36,7 +34,7 @@ import java.util.function.Consumer; import lombok.AllArgsConstructor; import lombok.ToString; import lombok.extern.slf4j.Slf4j; -import org.apache.fineract.client.models.BusinessDateRequest; +import org.apache.fineract.client.models.BusinessDateUpdateRequest; import org.apache.fineract.client.models.PostSavingsAccountTransactionsRequest; import org.apache.fineract.client.models.PostSavingsAccountTransactionsResponse; import org.apache.fineract.client.models.PostSavingsAccountsAccountIdRequest; @@ -102,8 +100,8 @@ public class BaseSavingsIntegrationTest extends IntegrationTest { try { globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, new PutGlobalConfigurationsRequest().enabled(true)); - businessDateHelper.updateBusinessDate( - new BusinessDateRequest().type(BUSINESS_DATE.getName()).date(date).dateFormat(DATETIME_PATTERN).locale("en")); + businessDateHelper.updateBusinessDate(new BusinessDateUpdateRequest().type(BusinessDateUpdateRequest.TypeEnum.BUSINESS_DATE) + .date(date).dateFormat(DATETIME_PATTERN).locale("en")); runnable.accept(date); } finally { globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, diff --git a/settings.gradle b/settings.gradle index 8a7e1df5c..cd4aa8b14 100644 --- a/settings.gradle +++ b/settings.gradle @@ -48,6 +48,7 @@ buildCache { rootProject.name='fineract' include ':fineract-core' +include ':fineract-validation' include ':fineract-command' include ':fineract-accounting' include ':fineract-provider' diff --git a/static-weaving.gradle b/static-weaving.gradle index 7d462ae20..e259a1ce3 100644 --- a/static-weaving.gradle +++ b/static-weaving.gradle @@ -43,6 +43,7 @@ project.afterEvaluate { copy { from persistenceXmlFile.toPath() into metaInf.toPath() + duplicatesStrategy = DuplicatesStrategy.EXCLUDE } javaexec {