Skip to content
Merged
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
1 change: 1 addition & 0 deletions consumer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-liquibase'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:3.0.3'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
compileOnly 'org.projectlombok:lombok'
Expand Down
16 changes: 16 additions & 0 deletions consumer/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,14 @@ services:
condition: service_healthy
fineract:
condition: service_healthy
mailpit:
condition: service_healthy
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://bff-db:5432/${POSTGRES_DB:-consumerapp}
SPRING_DATASOURCE_USERNAME: ${POSTGRES_USER:-consumerapp}
SPRING_DATASOURCE_PASSWORD: ${POSTGRES_PASSWORD:-password}
FINERACT_BASE_URL: http://fineract:8080/fineract-provider/api/v1
SPRING_MAIL_HOST: mailpit
SERVER_FORWARD_HEADERS_STRATEGY: framework
JAVA_TOOL_OPTIONS: "-Xmx768m -Xms256m"
ports:
Expand All @@ -108,6 +111,19 @@ services:
start_period: 60s
mem_limit: 1g

mailpit:
image: axllent/mailpit:latest
container_name: mailpit
ports:
- "8025:8025"
- "1025:1025"
healthcheck:
test: ["CMD", "wget", "-qO-", "http://localhost:8025/api/v1/info"]
interval: 5s
timeout: 5s
retries: 10
mem_limit: 128m

configs:
fineract_init_sql:
content: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@EnableFeignClients(basePackages = "org.apache.fineract.consumer")
public class ConsumerApplication {

public static void main(String[] args) {
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.consumer.infrastructure.command;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.transaction.annotation.Transactional;

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Transactional
public @interface Command {}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.fineract.consumer.infrastructure.config;
package org.apache.fineract.consumer.infrastructure.configs;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.fineract.consumer.infrastructure.config;
package org.apache.fineract.consumer.infrastructure.configs;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -38,7 +38,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
"/v3/api-docs.yaml",
"/swagger-ui/**",
"/swagger-ui.html",
"/actuator/health"
"/actuator/health",
"/api/v1/registration/**"
).permitAll()
.anyRequest().authenticated())
// TODO: Setup CSRF
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.consumer.infrastructure.exception;

import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
public abstract class AbstractConsumerException extends RuntimeException {

private final HttpStatus httpStatus;
private final String code;
private final String errorMessage;

protected AbstractConsumerException(HttpStatus httpStatus, String code, String errorMessage) {
super(errorMessage);
this.httpStatus = httpStatus;
this.code = code;
this.errorMessage = errorMessage;
}

protected AbstractConsumerException(HttpStatus httpStatus, String code, String errorMessage, Throwable cause) {
super(errorMessage, cause);
this.httpStatus = httpStatus;
this.code = code;
this.errorMessage = errorMessage;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.consumer.infrastructure.exception;

import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

@Getter
@RequiredArgsConstructor
@Builder
@EqualsAndHashCode
@ToString
public final class ConsumerApiError {

private final String code;
private final String defaultMessage;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.consumer.infrastructure.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@Order(Ordered.HIGHEST_PRECEDENCE)
@RestControllerAdvice
public class ConsumerExceptionHandler {

@ExceptionHandler(AbstractConsumerException.class)
public ResponseEntity<ConsumerApiError> handle(AbstractConsumerException ex) {
if (ex.getHttpStatus().is5xxServerError()) {
log.error("{}: {}", ex.getClass().getSimpleName(), ex.getErrorMessage(), ex);
} else {
log.warn("{}: {}", ex.getClass().getSimpleName(), ex.getErrorMessage());
}
return ResponseEntity.status(ex.getHttpStatus())
.body(ConsumerApiError.builder()
.code(ex.getCode())
.defaultMessage(ex.getErrorMessage())
.build());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.consumer.infrastructure.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@Order(Ordered.LOWEST_PRECEDENCE)
@RestControllerAdvice
public class DefaultExceptionHandler {

public static final String CODE = "error.msg.consumer.internal.error";
private static final String DEFAULT_MESSAGE = "internal error";

@ExceptionHandler(Throwable.class)
public ResponseEntity<ConsumerApiError> handle(Throwable ex) {
log.error("unexpected error: {}", ex.getClass().getSimpleName(), ex);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(ConsumerApiError.builder()
.code(CODE)
.defaultMessage(DEFAULT_MESSAGE)
.build());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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.consumer.infrastructure.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@Order(Ordered.HIGHEST_PRECEDENCE)
@RestControllerAdvice
public class HttpMessageNotReadableExceptionHandler {

public static final String CODE = "error.msg.consumer.request.body.malformed";
private static final String DEFAULT_MESSAGE = "invalid request";

@ExceptionHandler(HttpMessageNotReadableException.class)
public ResponseEntity<ConsumerApiError> handle(HttpMessageNotReadableException ex) {
log.info("malformed request body: {}", ex.getClass().getSimpleName());
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(ConsumerApiError.builder()
.code(CODE)
.defaultMessage(DEFAULT_MESSAGE)
.build());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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.consumer.infrastructure.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@Order(Ordered.HIGHEST_PRECEDENCE)
@RestControllerAdvice
public class MethodArgumentNotValidExceptionHandler {

public static final String CODE = "error.msg.consumer.request.validation.failed";
private static final String DEFAULT_MESSAGE = "invalid request";

@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<ConsumerApiError> handle(MethodArgumentNotValidException ex) {
log.info("invalid request body: {}", ex.getClass().getSimpleName());
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(ConsumerApiError.builder()
.code(CODE)
.defaultMessage(DEFAULT_MESSAGE)
.build());
}
}
Loading
Loading