-
Notifications
You must be signed in to change notification settings - Fork 10
Separated out the prod-dev data based on the flag and made files name configurable #117
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
base: master
Are you sure you want to change the base?
Changes from 6 commits
228aad2
3ca544b
7a3f059
b4b68c8
7fc5b7f
bd5f75c
4a2a67c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,6 +85,8 @@ public void createDefaultData(DefaultDataRequest defaultDataRequest) { | |
| mdmsV2Util.createDefaultMdmsData(defaultMdmsDataRequest); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| // if (defaultDataRequest.getLocales() != null && defaultDataRequest.getModules() != null) { | ||
| // for (String locale : defaultDataRequest.getLocales()) { | ||
| // DefaultLocalizationDataRequest defaultLocalizationDataRequest = DefaultLocalizationDataRequest.builder().requestInfo(defaultDataRequest.getRequestInfo()).targetTenantId(defaultDataRequest.getTargetTenantId()).locale(locale).modules(defaultDataRequest.getModules()).build(); | ||
|
|
@@ -93,7 +95,7 @@ public void createDefaultData(DefaultDataRequest defaultDataRequest) { | |
| // } | ||
| } | ||
|
|
||
| public User createUserFromFile(TenantRequest tenantRequest) throws IOException { | ||
| public User createUserFromFile(TenantRequest tenantRequest, String userFilePath) throws IOException { | ||
| String tenantCode = tenantRequest.getTenant().getCode(); | ||
| StringBuilder uri = new StringBuilder(serviceConfig.getUserHost()) | ||
| .append(serviceConfig.getUserContextPath()) | ||
|
|
@@ -102,8 +104,8 @@ public User createUserFromFile(TenantRequest tenantRequest) throws IOException { | |
| ArrayList<User> userList = new ArrayList<>(); | ||
|
|
||
| try { | ||
| log.info("Reading User.json for tenant: {}", tenantCode); | ||
| Resource resource = resourceLoader.getResource("classpath:User.json"); | ||
| log.info("Reading User file from {} for tenant: {}", userFilePath, tenantCode); | ||
| Resource resource = resourceLoader.getResource(userFilePath); | ||
| String rawJson = StreamUtils.copyToString(resource.getInputStream(), StandardCharsets.UTF_8); | ||
|
|
||
| rawJson = rawJson.replace("{tenantid}", tenantCode); | ||
|
|
@@ -151,13 +153,14 @@ public User createUserFromFile(TenantRequest tenantRequest) throws IOException { | |
| } | ||
|
|
||
|
|
||
| public void createEmployeeFromFile(RequestInfo requestInfo) throws IOException { | ||
| public void createEmployeeFromFile(RequestInfo requestInfo, String employeeFilePath) throws IOException { | ||
| String uri = serviceConfig.getHrmsHost() + serviceConfig.getHrmsCreatePath(); | ||
| String userUpdateUrl = serviceConfig.getUserHost() +serviceConfig.getUserContextPath() + serviceConfig.getUserUpdateEndpoint(); | ||
| String tenantId = requestInfo.getUserInfo().getTenantId(); | ||
|
|
||
| try { | ||
| Resource resource = resourceLoader.getResource("classpath:HRMS.json"); | ||
| log.info("Reading Employee file from {}", employeeFilePath); | ||
| Resource resource = resourceLoader.getResource(employeeFilePath); | ||
| String rawJson = StreamUtils.copyToString(resource.getInputStream(), StandardCharsets.UTF_8); | ||
|
|
||
| // Replace placeholders with tenant ID | ||
|
|
@@ -603,4 +606,86 @@ public void defaultEmployeeSetup(String tenantId, String emailId) { | |
| createDefaultEmployee(tenantId, emailId, ASSIGNER, "John Smith"); | ||
| } | ||
|
|
||
| /** | ||
| * Load production tenant data (mdmsData, localisations, and schema) | ||
| * This method loads production data for a new tenant | ||
| * Uses all default schemas automatically | ||
| * @param newTenantRequest - Request containing tenant information (no schema codes needed) | ||
| */ | ||
| public void loadNewTenantProductionData(NewTenantRequest newTenantRequest) { | ||
| try { | ||
| String targetTenantId = newTenantRequest.getTargetTenantId(); | ||
| RequestInfo requestInfo = newTenantRequest.getRequestInfo(); | ||
|
|
||
| log.info("Loading production tenant data for new tenant: {}", targetTenantId); | ||
|
|
||
| // Ensure UserInfo is present (create dummy if needed) | ||
| if (requestInfo.getUserInfo() == null) { | ||
| org.egov.common.contract.request.User dummyUser = new org.egov.common.contract.request.User(); | ||
| dummyUser.setId(1L); | ||
| dummyUser.setUserName("system"); | ||
| dummyUser.setTenantId(targetTenantId); | ||
| requestInfo.setUserInfo(dummyUser); | ||
| log.info("Created dummy user info for tenant: {}", targetTenantId); | ||
| } else { | ||
| requestInfo.getUserInfo().setTenantId(targetTenantId); | ||
| } | ||
|
Comment on lines
+630
to
+632
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mutating the caller's Calling |
||
|
|
||
| // Create DefaultDataRequest with all default schemas | ||
| DefaultDataRequest defaultDataRequest = DefaultDataRequest.builder() | ||
| .requestInfo(requestInfo) | ||
| .targetTenantId(targetTenantId) | ||
| .schemaCodes(serviceConfig.getDefaultMdmsSchemaList()) | ||
| .onlySchemas(Boolean.FALSE) | ||
| .locales(serviceConfig.getDefaultLocalizationLocaleList()) | ||
| .modules(serviceConfig.getDefaultLocalizationModuleList()) | ||
| .build(); | ||
|
|
||
| log.info("Step 1: Creating MDMS schemas for tenant: {}", targetTenantId); | ||
| // 1. Create Schema from file | ||
| createMdmsSchemaFromFile(defaultDataRequest); | ||
| log.info("✓ Schemas created for new tenant: {}", targetTenantId); | ||
|
|
||
| log.info("Step 2: Loading production MDMS data"); | ||
| // 2. Load production MDMS data | ||
| mdmsBulkLoader.loadAllMdmsData(targetTenantId, | ||
| requestInfo, | ||
| serviceConfig.getDefaultMdmsDataPath()); | ||
| log.info("✓ Production MDMS data loaded for new tenant: {}", targetTenantId); | ||
|
|
||
| log.info("Step 3: Loading production localization data"); | ||
| // 3. Load production localization | ||
| localizationUtil.upsertLocalizationFromFile(defaultDataRequest, | ||
| serviceConfig.getDefaultLocalizationDataPath()); | ||
| log.info("✓ Production localization data loaded for new tenant: {}", targetTenantId); | ||
|
|
||
| log.info("Step 4: Creating tenant config in Tenant Management System"); | ||
| // 4. Create Tenant Configuration | ||
| Tenant newTenant = new Tenant(); | ||
| newTenant.setCode(targetTenantId); | ||
| newTenant.setName(targetTenantId); | ||
| newTenant.setEmail("admin@" + targetTenantId + ".com"); | ||
|
Comment on lines
+664
to
+667
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Check NewTenantRequest and Tenant classes structure
rg -n "class NewTenantRequest|class Tenant" --type=java -A 25 | head -100Repository: egovernments/Citizen-Complaint-Resolution-System Length of output: 11045 🏁 Script executed: # Check the context around lines 664-667 in DataHandlerService.java
sed -n '650,680p' utilities/default-data-handler/src/main/java/org/egov/handler/service/DataHandlerService.javaRepository: egovernments/Citizen-Complaint-Resolution-System Length of output: 1596 🏁 Script executed: # Check if there are configuration properties or defaults being used elsewhere
rg -n "defaultTenantName|defaultTenantEmail|admin@" --type=java -B 2 -A 2 | head -40Repository: egovernments/Citizen-Complaint-Resolution-System Length of output: 822 Add tenant name and email to NewTenantRequest or implement configuration defaults. The code hardcodes placeholder values (
The 🤖 Prompt for AI Agents |
||
|
|
||
| TenantRequest tenantRequest = TenantRequest.builder() | ||
| .requestInfo(requestInfo) | ||
| .tenant(newTenant) | ||
| .build(); | ||
|
|
||
| try { | ||
| createTenantConfig(tenantRequest); | ||
| log.info("✓ Tenant config created: {}", targetTenantId); | ||
| } catch (Exception e) { | ||
| log.warn("Could not create tenant config (non-critical): {}", e.getMessage()); | ||
| } | ||
|
|
||
| log.info("========================================"); | ||
| log.info("✓✓✓ Tenant {} created successfully", targetTenantId); | ||
| log.info("Loaded: Schemas + Production MDMS + Production Localization + Tenant Config"); | ||
| log.info("========================================"); | ||
| } catch (Exception e) { | ||
| log.error("Failed to load production tenant data for tenant: {}", newTenantRequest.getTargetTenantId(), e); | ||
| throw new CustomException("TENANT_CREATION_FAILED", "Failed to create new tenant with production data: " + e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package org.egov.handler.web.models; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import jakarta.validation.Valid; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import lombok.*; | ||
| import org.egov.common.contract.request.RequestInfo; | ||
| import org.springframework.validation.annotation.Validated; | ||
|
|
||
| @Validated | ||
| @Data | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @Builder | ||
| @ToString | ||
| public class NewTenantRequest { | ||
|
|
||
| @JsonProperty("RequestInfo") | ||
| @NotNull | ||
| @Valid | ||
| private RequestInfo requestInfo; | ||
|
|
||
| @JsonProperty("targetTenantId") | ||
| @NotNull | ||
| @Valid | ||
| private String targetTenantId; | ||
|
|
||
| } |
Uh oh!
There was an error while loading. Please reload this page.