bn-paper-rolls-adp

information icon
Adapter (ADP) responsible for intermediating paper rolls operations between Getnet's internal systems and backend services (BFF/GetConfig), exposing a standardized RESTful API for consumption by internal channels.

📋 Overview

bn-paper-rolls-adp is an adapter/BFF microservice, built with Spring Boot 3, acting as an abstraction and orchestration layer between internal consumers and the order management, stock, and manual order APIs for paper rolls.

The application centralizes responsibilities such as:

  • Automatic authentication with token renewal via Feign interceptor
  • Resilience protection with Circuit Breaker (Resilience4j)
  • Contract mapping and normalization between internal and external APIs
  • Standardized error handling via GlobalExceptionHandler

🏗️ Architecture

text
Internal Consumer │ ▼ ┌─────────────────────────────────┐ │ bn-paper-rolls-adp │ │ │ │ Controller → Service → Client │ │ ↕ ↕ │ │ Mapper FeignAuthInterceptor │ ↕ ↕ │ │ DTO Circuit Breaker│ └─────────────────────────────────┘ │ ▼ BFF GetConfig (bn-bff-getconfig)

Layers

LayerResponsibility
ControllerReceives HTTP requests, validates input and delegates to the Service
ServiceOrchestrates calls to the Client, applies retry on 401, handles exceptions
Client (Feign)Declarative interface for communication with external APIs
Mapper (MapStruct)Converts internal DTOs (getnet) into public DTOs (openapi)
FeignAuthInterceptorManages and injects Bearer Token into all Feign requests
GlobalExceptionHandlerCaptures and standardizes all application errors

🔌 Features

1. Stock Query — GET /v1/stocks/{merchant_id}

Retrieves the current paper rolls stock for a specific merchant (EC).

Flow:
  1. Receives merchant_id as a path parameter
  2. Calls StockClient (Feign) with automatic Bearer Token authentication
  3. On 401, invalidates the cached token and performs an automatic retry
  4. On 404, throws NotFoundException (not counted by the circuit breaker)
  5. Maps the internal response (BobStockResponseDTO) to the public contract (StockDTO)
Responses: 200 OK401 Unauthorized403 Forbidden404 Not Found500 Internal Server Error504 Gateway Timeout

2. Order Query — GET /v1/orders

Retrieves paper rolls orders with support for multiple optional filters.

Filter parameters:
ParameterTypeDescription
ecList<String>Merchant establishment code(s)
cpf_cnpjList<String>Holder's CPF/CNPJ
orderList<Integer>Order number(s)
tracking_numberList<String>Tracking code(s)
osList<String>Service order number(s)
typeList<String>Order type (I=Internal, R=Reactive, A=Automatic)
statusList<String>Order status (see enum AvailableOrderStatus)
pageIntegerPagination page number
limitIntegerNumber of records per page
immediate_deliveryBooleanFilter by immediate delivery
Flow:
  1. Validates and forwards filters to OrderManagementClient
  2. On 401, invalidates token and performs an automatic retry
  3. On 404, throws NotFoundException
  4. Maps the PedidoDTO list (internal contract) to OrderDTO (public contract)
Responses: 200 OK (list, may be empty), 400 Bad Request401403404500504

3. Manual Order — POST /v1/manual-orders

Creates a manual paper rolls replenishment order for a specific merchant.

Flow:
  1. Receives the OpenApiManualOrderRequestDTO payload (validated via Bean Validation)
  2. Queries the permission API (ManualOrderClient) to check whether the merchant is authorized for the given channel
  3. If granted (status = "Permitido"):
    • Retrieves the authorized quantity from the permission response
    • Creates the order via ManualOrderClient.create()
    • Returns 200 OK with the details of the created order
  4. If denied:
    • Returns 404 with denial: true and the denial reason (denial_reason)
    • The word "EC" in the denial message is replaced by "merchant_id" for standardization
  5. On 401 during any call, invalidates token and performs an automatic retry
  6. On 404 from the external API, throws NotFoundException
Responses: 200 OK400 Bad Request401403 Forbidden500504

🔐 Authentication

All communication with external APIs uses Bearer JWT Token managed by FeignAuthInterceptor:
  • Token obtained via AuthenticationClient on the first request
  • Token cached in memory (AtomicReference) for reuse
  • Token automatically invalidated when any service returns 401, followed by a retry of the operation with a new token

🛡️ Resilience — Circuit Breaker

All services are protected by Resilience4j Circuit Breaker:
ConfigurationValue
Sliding window size10 calls
Minimum number of calls to activate5
Failure rate to open the circuit50%
Wait duration in open state30 seconds
Permitted calls in half-open state3
Call timeout30 seconds
Monitored exceptions: FeignExceptionConnectExceptionTimeoutException
Ignored exceptions (not counted): NotFoundExceptionBadRequestExceptionFeignException.NotFoundFeignException.BadRequestFeignException.Unauthorized

🗂️ Module Structure

text
src/main/java/br/com/getnet/paper/rolls/ ├── client/ │ ├── authentication/ # Feign client for authentication │ ├── manualorder/ # Feign client for manual orders │ ├── ordermanagement/ # Feign client for order management │ └── stock/ # Feign client for stock ├── config/ │ ├── FeignAuthInterceptor.java # JWT token management │ └── OpenApiConfiguration.java # Swagger/OpenAPI configuration ├── controller/ │ ├── manualorder/ # Endpoint 600;">POST /v1/manual-orders │ ├── ordermanagement/ # Endpoint 600;">GET /v1/orders │ └── stock/ # Endpoint 600;">GET /v1/stocks/{merchant_id} ├── dto/ │ ├── authentication/ # Authentication DTOs │ ├── manualorder/ # Manual order DTOs (getnet + openapi) │ ├── ordermanagement/ # Order DTOs (getnet + openapi) │ └── stock/ # Stock DTOs (getnet + openapi) ├── exception/ │ ├── BadRequestException.java │ ├── NotFoundException.java │ ├── dto/ # ErrorDTO for standardized responses │ └── handler/ # GlobalExceptionHandler ├── mapper/ │ ├── manualorder/ # MapStruct mappers for manual orders │ ├── ordermanagement/ # MapStruct mapper for orders │ └── stock/ # MapStruct mapper for stock └── service/ ├── manualorder/ # Manual order orchestration ├── ordermanagement/ # Order query orchestration └── stock/ # Stock query orchestration

⚙️ Environments

ProfilePurpose
localLocal development
devDevelopment environment
htiIntegration testing (homologation)
hgGeneral homologation
prodProduction
testAutomated tests

📦 Tech Stack

TechnologyVersionUsage
Java17Language
Spring Boot3.5.xCore framework
Spring Cloud OpenFeign4.xDeclarative HTTP clients
Resilience4jCircuit Breaker
MapStruct1.5.5DTO mapping
Lombok1.18.xBoilerplate reduction
SpringDoc / Swagger UI2.3.xAPI documentation
JaCoCo0.8.11Test coverage
JUnit 5 + MockitoUnit and integration tests

🚀 Running Locally

text
# With Maven Wrapper ./mvnw spring-boot:run -Dspring-boot.run.profiles=local # Swagger UI available at: # http://localhost:8080/swagger-ui/index.html # Health check: # http://localhost:8080/healthcheck

📊 Test Coverage

Coverage is generated via JaCoCo during the test phase:
text
./mvnw clean test # Report generated at: target/site/jacoco/index.html