Skip to content

FINERACT-2238: New command processing - Business Date Management (org.apache.fineract.infrastructure.businessdate) #4805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ buildscript {
[
'fineract-api',
'fineract-core',
'fineract-validation',
'fineract-command',
'fineract-accounting',
'fineract-provider',
Expand Down Expand Up @@ -57,6 +58,7 @@ buildscript {
'fineract-api',
'fineract-client',
'fineract-core',
'fineract-validation',
'fineract-command',
'fineract-accounting',
'fineract-provider',
Expand Down Expand Up @@ -159,6 +161,10 @@ allprojects {
}

configurations {
implementation {
exclude group: 'commons-logging', module: 'commons-logging'
}

api {
canBeResolved = true
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
17 changes: 12 additions & 5 deletions buildSrc/src/main/groovy/org.apache.fineract.dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'

Expand Down
3 changes: 1 addition & 2 deletions fineract-command/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class Command<T> implements Serializable {

private UUID id;

private String idempotencyKey;

private OffsetDateTime createdAt;

private String tenantId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@Slf4j
@RequiredArgsConstructor
@Component
public final class CommandJsonMapper {
final class CommandJsonMapper {

private static final String CLASS_ATTRIBUTE = "@class";
private final ObjectMapper mapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,11 @@
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
Expand All @@ -42,22 +37,4 @@
@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 {}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
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;
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions fineract-core/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,26 @@

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
Expand All @@ -52,19 +48,14 @@
@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<BusinessDateData> 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<BusinessDateData> getBusinessDates() {
securityContext.authenticatedUser().validateHasReadPermission(BUSINESS_DATE);
public List<BusinessDateResponse> getBusinessDates() {
return this.readPlatformService.findAll();
}

Expand All @@ -73,23 +64,27 @@ public List<BusinessDateData> getBusinessDates() {
@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);
}

@POST
@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<BusinessDateResponse> response = commandPipeline.send(command);

return response.get();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<BusinessDateUpdateRequest> {}
Loading
Loading