Add New Fields

Overview

This guide walks you through the end-to-end steps to add a new field (e.g., landmark) to the CCRS service module — from backend models to database, validation, and persisting.


Steps

1

Add Field in the Model

In Service.java (or the appropriate domain class):

private String landmark;
2

Add Validation (Optional)

In the validateCreate() method inside the Validator class:

if (request.getLandmark() == null) {
    throw new CustomException("PGR.LANDMARK_REQUIRED", "Landmark is required");
}
3

Enrich the Request (Optional)

In enrichCreateRequest() method:

if (request.getLandmark() == null) {
    request.setLandmark("Default");
}
4

Map DB Result (RowMapper)

In PGRRowMapper.java:

service.setLandmark(rs.getString("landmark"));
5

Update Persister Configuration

In persister.yml, under save-pgr-request and update-pgr-request topics:

- jsonPath: $.Service.landmark
  dbColumn: landmark
  type: STRING

👉 After updating, restart the Persister service.

6

Add to Search Query (Optional)

If you want to search/filter by landmark:

  • Update the query in PGRQueryBuilder.java

  • Add it to the parameter map


✅ Done!

Your new field is now fully integrated into the PGR backend — from request to persistence.


🔍 Understanding the PGR-Service Code

🔄 update(ServiceRequest request) — Main Update Method

This is the central method for handling service updates.

public ServiceRequest update(ServiceRequest request){
   String tenantId = request.getService().getTenantId();
   Object mdmsData = mdmsUtils.mDMSCall(request);
   validator.validateUpdate(request, mdmsData);
   enrichmentService.enrichUpdateRequest(request);
   workflowService.updateWorkflowStatus(request);
   producer.push(tenantId, config.getUpdateTopic(), request);
   return request;
}

What each line does:

Step
Purpose

tenantId

Extracts tenant info for validations, workflows, Kafka

mdmsUtils.mDMSCall()

Fetches config data (departments, services, etc.) from MDMS

validateUpdate()

Runs business validations

enrichUpdateRequest()

Adds audit info, modifies fields

updateWorkflowStatus()

Triggers workflow transitions

producer.push()

Sends updated data to Kafka for persistence

✨ Customize validations or enrichment here based on business needs.


🛡️ validateCreate(...) — Request Validation Logic

public void validateCreate(ServiceRequest request, Object mdmsData){
   Map<String, String> errorMap = new HashMap<>();
   validateUserData(request, errorMap);
   validateSource(request.getService().getSource());
   validateMDMS(request, mdmsData);
   validateDepartment(request, mdmsData);
   if (!errorMap.isEmpty())
       throw new CustomException(errorMap);
}

What’s Happening:

Validation
Description

validateUserData()

Validates citizen info (userId, phone, etc.)

validateSource()

Checks source channel (mobile, web, etc.) via MDMS

validateMDMS()

Ensures serviceCode/category is valid

validateDepartment()

Checks department validity via MDMS

CustomException

Aggregates and throws all validation errors

🧠 Add custom rules for new fields or business logic here.



🏗️ getMDMSRequest(...) — Building the MDMS Query

public MdmsCriteriaReq getMDMSRequest(RequestInfo requestInfo, String tenantId){
   List<ModuleDetail> moduleDetails = getPGRModuleRequest();

   MdmsCriteria mdmsCriteria = MdmsCriteria.builder()
       .moduleDetails(moduleDetails)
       .tenantId(tenantId)
       .build();

   return MdmsCriteriaReq.builder()
       .mdmsCriteria(mdmsCriteria)
       .requestInfo(requestInfo)
       .build();
}

What it does:

Step
What it Builds

getPGRModuleRequest()

List of master data modules to fetch

MdmsCriteria

Ties together tenant and modules

MdmsCriteriaReq

Final request to be sent to MDMS

🧩 Modify this if your feature needs new MDMS data (like a new department list, config options, etc.)


🧑‍💻 Developer Notes

  • ✅ Add new validations in validateCreate() or validateUpdate()

  • ✅ Enrich new fields in enrichCreateRequest() or enrichUpdateRequest()

  • ✅ Add workflows via the Workflow service or update the config in updateWorkflowStatus()

  • ✅ Register Kafka topics in persister.yml and application.yml

  • ✅ Always test against tenant-specific MDMS configs (e.g., pb, pg)

Last updated

Was this helpful?