Data Models & Common Library

Domain models, DTOs, MapStruct mappers, exceptions, and utilities from arya-banking-common used by the admin-service.

Common Library

Artifact: org.arya.banking:arya-banking-common:1.1.9
Hosted on: GitHub Packages (Event-Based-Banking-Application)
Package base: org.arya.banking.common

The admin-service depends on arya-banking-common for shared MongoDB domain models, exception hierarchy, utility classes, Avro schemas, Kafka topic constants, and the BaseMapper interface. The main class scans org.arya.banking.common explicitly, so all common @Component beans (exception handlers, mappers) are loaded automatically.


Domain Models (MongoDB Documents)

ModelCollectionKey Fields
UseruseruserId (unique index), firstName, lastName, emailId, contactNumbers, addresses, primaryAddress, status, roleId
RegistrationProgressregistration_progressuserId, status, subStatus, lastStepCompleted, nextStep
SecurityDetailssecurity_detailsuserId, securityQuestions, twoFactorEnabled, isEmailVerified, isContactNumberVerified, loginFailedAttempts
UserCredentialsuser_credentialsuserId, passwordHash
RoleroleroleName, description, permissions: List<Permission>
AuditauditactionType, targetTable, targetId, userId, changeType, description, auditTime

All document classes extend AryaBase, which provides deleted, createdAt, and updatedAt fields populated automatically via @EnableMongoAuditing.

Embedded Models

ModelFields
Addressstreet, city, state, zipCode, country, addressType
ContactNumbercontactNumber, type, isVerified
Permissionmodule, actions: List<String>
SecurityQuestionsquestion, answer
KeyCloakUserBuilder DTO for Keycloak user creation

Enums

EnumValues
UserStatusACTIVE, BLOCKED, DORMANT
AddressTypePERMANENT, RESIDENTIAL
ContactNumberTypePRIMARY, SECONDARY, OTHERS
ModulesUSERS, ACCOUNTS, TRANSACTIONS, LOANS
RegistrationConstantsBASIC_DETAILS_ADDED, SECURITY_CREDENTIALS_ADDED, ADD_ADDRESS

RegistrationConstants carries state metadata: status, subStatus, nextStep, and lastStepCompleted — used to track where a user is in the three-step registration flow.


Exception Hierarchy

All exceptions extend GlobalException, which carries an HTTP error code, an application error code, and a message. The GlobalExceptionHandler (@RestControllerAdvice) catches all GlobalException subclasses and returns a standardised ErrorResponse(errorCode, errorMessage).

Text code-highlight
RuntimeException
└── GlobalException (httpErrorCode, errorCode, errorMessage)
    ├── UserAlreadyExistsException           (409)
    ├── UserNotFoundException                (404)
    ├── SecurityDetailsNotFoundException     (varies)
    ├── InvalidOAuth2Client                  (varies)
    ├── KeyCloakClientAlreadyExists          (409)
    ├── KeyCloakRealmRoleAlreadyExists       (409)
    ├── KeyCloakRealmRoleNotFoundException   (404)
    ├── KeyCloakServiceException             (varies)
    ├── UnAuthorizedException                (403)
    ├── RoleIdNotFoundException              (403)
    ├── SecretIdNotFoundException            (403)
    ├── AppRoleCreationException             (403)
    └── VaultSecretNotFoundException         (404)

Response Codes

Standardised response code constants used as values in VaultResponseDto.responseCode and KeyCloakResponse.responseCode:

ConstantHTTP Meaning
USER_CREATED_201User resource created
USER_UPDATED_200User resource updated
SECURITY_DETAILS_UPDATED_200Security details updated
KEYCLOAK_ROLE_CREATED_200Keycloak realm role created
VAULT_SECRET_CREATED_200Vault KV secret written
VAULT_SECRET_DELETED_200Vault KV secret deleted
VAULT_SECRET_UPDATED_200Vault KV secret patched

BaseMapper Interface

All MapStruct mappers in both the admin-service and the common library extend this contract:

Java code-highlight
public interface BaseMapper<E, D> {
    D toDto(E entity);
    E toEntity(D dto);
    List<D> toDtoList(List<E> entityList);
    List<E> toEntityList(List<D> dtoList);
}

The admin-service provides two implementations:

MapperEntityDTO
KeycloakRoleMapperRoleRepresentation (Keycloak)KeycloakRole (record)
VaultResponseMapperVaultResponse (Spring Vault)VaultApiResponseDto (record)

Utilities

CommonUtils

MethodDescription
isEmpty(Object)Null/blank/empty check for String, List, BigDecimal, Map
isNotEmpty(Object)Inverse of isEmpty
generateSHA256hash(String)SHA-256 hex digest via Apache Commons
loadConfig(String path)Loads a classpath resource as a UTF-8 string via SpringContextHolder
convertListIntoMap(List, keyExtractor)Converts a list into a Map<K, V>

loadConfig is used by VaultPolicyServiceImpl to read .hcl policy files from the classpath.

MetaDataUtils

Handles automatic schema versioning for MongoDB documents annotated with @TrackMetadata. It compares old vs new ColumnMetadata lists and increments version numbers:

  • MAJOR bump — column removed
  • MINOR bump — column added
  • PATCH bump — nullability changed

Avro Schemas

Two Avro schemas are defined in arya-banking-common for future Kafka event publishing:

SchemaNamespaceFields
AuditEvent.avscorg.arya.banking.common.avroactionType, targetTable, targetId, userId, changeType, details
UserCreateEvent.avscorg.arya.banking.common.avrouserId, status, isEmailVerified, isContactVerified

Kafka Topic Constants

ConstantTopic Name
USER_CREATE_EVENTuser.create.event
AUDIT_EVENTaudit.event
Kafka infrastructure (spring-kafka, kafka-streams, Avro) is declared as a dependency but no producers or consumers are implemented in the admin-service yet.
modelscommonmongodbmapstructexceptions