Target Upload API
Base URL: project-factory/v1/
Endpoint: /data/_create
Method: POST
Request Structure:
Body Parameters:
RequestInfo: Object Containing RequestInfo
ResourceDetails: Details of a given Resource
type: Type of resource to create (e.g., boundarywithTarget)
tenantId: Tenant
fileStoreId: FileStoreId of Target Upload Sheet
action: Action to perform (e.g., validate for target upload)
hierarchyType: Name of Boundary Hierarchy
campaignId: CampaignId
additionalDetails: Additional details (optional)
Response Structure:
Success Response:
ResponseInfo: Object Containing ResponseInfo
ResourceDetails: Details of the created resource
Flow:
Client Initiates Request:
The client sends a POST request to /data/_create endpoint with action: validate.
Validation of Request:
Resource Details Validation:
Check if request.body.ResourceDetails exists and is not empty.
Throw a validation error if missing or empty with the message "ResourceDetails is missing or empty or null".
Schema Validation:
Validate request.body.ResourceDetails against createRequestSchema.
Hierarchy Type Validation:
Validate hierarchyType in request.body.ResourceDetails using validateHierarchyType function.
Tenant ID Validation:
Ensure that request.body.ResourceDetails.tenantId matches request.body.RequestInfo.userInfo.tenantId.
Throw a validation error if they do not match with the message "tenantId is not matching with userInfo".
Different Tab Headers Validation:
Validate whether headers are according to the template across all tabs of different districts.
Target Sheet Validation:
All validations will be on Sheets other than the ReadMe Sheet and Boundary Data Sheet.
Immediate validations:
District Tabs Validation:
Validate whether all district tabs are present in the Target Sheet uploaded.
Empty Sheet Validation:
Throw a validation error if any Target Sheet is empty.
Root (District) level boundary validation:
Throw a validation error if the root column (District) is empty in any row.
Validations for each row:
Boundary Codes Validation:
Check for missing or empty boundary codes in any row of any sheet.
Check for boundary code columns to be of type string.
Check for the presence of more than one boundary code in a given row of a given Target Sheet.
Check for duplicacy of the boundary code within the given Target Sheet.
Boundary Targets Validation:
Ensure that Target values are not missing and are positive numbers less than 1 Million.
The documentation details APIs for creating, searching, generating, and downloading data, including request/response structures, flows, and error handling.
Endpoint: /data/_create
Method: POST
Body Parameters:
RequestInfo: Object containing request information.
Resource Details: Object containing the details of the resource to be created or validated.
type: Type of resource (boundary, facility, user, boundaryWithTarget).
tenantId: Tenant identifier.
fileStoreId: File store identifier.
action: Action type (create or validate).
hierarchyType: Type of hierarchy.
campaignId: Campaign identifier.
additionalDetails: Additional details object (optional).
Success Response:
- ResponseInfo: Object containing response information.
- ResourceDetails: Array containing the detail objects of the created or validated resource.
Client Initiates Request: The client sends a createData request to the Project Factory service.
Validation of Request: The Project Factory service validates the request schema and the provided resource details.
Processing the Request:
If action is 'create':
Enrich resource details, set status to "data-accepted", and persist in the database.
Further creation process happens in the background.
After successful creation, set the status to 'completed' and persist resource details in the database.
If action is 'validate':
Enrich resource details, set the status to "validation-started", and persist in the database.
Further creation process happens in the background.
If file data is invalid, set the status to 'invalid' and persist in the database.
After successful creation, set the status to 'completed' and persist resource details in the database.
Fail case: If validation or creation fails, set the status to 'failed' and persist in the database with the error cause in additional details.
Response: The Project Factory service sends the response back to the client containing the resource details and status.
The getSheetData function retrieves and processes data from an Excel sheet, validating the structure according to the configuration provided in createAndSearchConfig. The key part of this process is the parseArrayConfig.parseLogic configuration, which specifies how to parse and validate the columns in the sheet. Here's a detailed explanation of how the function works, including the parsing logic:
The parseArrayConfig.parseLogic configuration specifies how each column in the sheet should be processed. Here's how the parsing logic works:
Each column configuration specifies:
sheetColumn
: The column letter in the sheet.
sheetColumnName
: The expected name of the column in the sheet.
resultantPath
: The path where the value will be stored in the resultant JSON.
type
: The expected type of the value (e.g., string, number, boolean).
conversionCondition
: Optional conditions for converting values.
During the validation step, the function checks that the first-row value matches the expected column name.
When mapping the rows to JSON, the function uses the resultantPath
to place the values in the correct location in the JSON object. It converts values according to the specified type
and conversionCondition
.
For a column configuration with type: "boolean"
and conversionCondition
, the function would convert "Permanent" to true and "Temporary" to an empty string.
In summary, the getSheetData function retrieves and processes data from an Excel sheet, validating the structure and content according to the createAndSearchConfig configuration. The parseArrayConfig.parseLogic configuration specifies how each column should be validated and processed into the resultant JSON format.
Endpoint: /data/_search
Method: POST
RequestInfo: Object containing request information.
SearchCriteria: Object containing search criteria.
id: (Optional) ID of the resource.
tenantId: Tenant identifier.
type: (Optional) Type of the resource (boundary, facility, user, boundaryWithTarget).
status: (Optional) Status of the resource.
ResponseInfo: Object containing response information.
ResourceDetails: Array containing the details object of the searched resource.
Client Request: The client sends a POST request to /data/_search.
Request Content: Includes RequestInfo and SearchCriteria.
Validation: The server validates request structure and content.
Response Creation: The server creates a response with info and resource details.
Response Dispatch: Sends response back to client.
Error Handling: If errors occur, generate an error response and send it.
Endpoint: /data/_generate
Method: POST
RequestInfo: Object containing request information.
Query Parameters:
type: Type of the resource for which data needs to be generated.
tenantId: Tenant identifier.
hierarchyType: Type of hierarchy.
forceUpdate: (Optional) Boolean indicating whether to force update existing data.
ResponseInfo: Object containing response information.
GeneratedResource: Array containing the details object of the generated resource.
Client Request: The client sends a POST request to /v1/data/_generate.
Request Validation: Aftern receiving the request, the server validates the request structure and parameters.
Generate Data Process:
Validation: The server validates the generated request.
Data Processing:
Fetch Data: Fetches existing data from the database.
Modify Data: Modify the retrieved data as necessary.
Generate New ID: Generates a new random ID and sets the file store ID to null.
Expire Old Data: Marks existing data status as expired.
Generate New Data: Generates new data based on the request parameters.
Update and Persist: Updates and persists the generated request along with the new data.
Force Update Logic:
If the forceUpdate parameter is set to true:
Search and Update: Searches for existing data of the specified type and updates the existing data information.
If the forceUpdate parameter is not provided or set to false:
Fetch Existing Data: Retrieves already persisted data from the database of the specified type.
Response Creation: After processing the request, the server creates a response containing the details of the generated resource.
Response Dispatch: The server sends the generated response back to the client.
Error Handling: If errors occur, generate an error response and send it.
Fetch Required Columns from MDMS:
Use callMdmsData
to get type schema columns in the correct order.
Define Headers:
MDMS schema required columns are headers and ensures column orders.
Localise Headers:
Use getLocalizedHeaders
with localizationMap
.
Localise Sheet Name:
Use getLocalizedName
with localizationMap
and generate a sheet.
To add a new column to the Generated sheet, follow these steps:
Search Schema Details
Locate the type schema from the HCM-ADMIN-CONSOLE.adminSchema
schema in the workbench.
Identify Column Type
Determine the column type based on the properties defined in the schema:
stringProperties
for string-based columns.
numberProperties
for numeric-based columns.
enumProperties
for enumerated columns.
Define New Column
Add the new column to the schema under the appropriate properties section:
String Column: Include attributes such as name
, type
, maxLength
, minLength
, isUnique
, isRequired
, description
, and orderNumber
.
Number Column: Include attributes such as name
, type
, maximum
, minimum
, isRequired
, description
, orderNumber
, and errorMessage
.
Enum Column: Include attributes such as name
, enum
, isRequired
, description
, and orderNumber
.
Ensure Column Uniqueness
Ensure that the isUnique
property is correctly set for string columns to enforce uniqueness.
Column Visibility (Future Implementation)
Note that hideColumn
and freezeColumn
features will be implemented in the next version.
This process is sufficient for validating the new column in the generated sheet.
If there's a need to reflect the column in APIs, follow these additional steps:
Update createAndSearch.ts
File
Modify the createAndSearch.ts
file under the defined type parseLogic
object.
Integrate the new column into the appropriate data structures used for API operations.
Example :
sheetColumn: A
sheetColumnName: HCM_ADMIN_CONSOLE_FACILITY_CODE
resultantPath: id
type: string
Mapping: Data from column A (HCM_ADMIN_CONSOLE_FACILITY_CODE) in the sheet will be mapped to id
in the API data.
By following these steps, you can successfully add and validate a new column in the generated sheet and ensure its reflection in the associated APIs.
General Rules
Locked Headers: The headers in the templates for each data type (user, facility, target) are locked and cannot be changed.
Sheet Protection: Certain sheets within the templates will have specific locked areas to ensure data integrity.
README Sheet: Each type of template includes a README sheet which is read-only and locked.
Target Template
Editable Columns: You can only modify the 'Target' column. All other columns are locked and cannot be edited.
Facility Template
Adding Rows: You are allowed to add new rows to create new facilities.
Editable Columns: You can modify the "Boundary Code" and 'Usage' columns.
Locked Sheets: The boundary data sheet within the facility template is locked and cannot be modified.
Dropdown Columns: The following columns are dropdowns:
Facility Type
Facility Status
Facility Usage
Facility Usage: Facility usage can be 'Active' or 'Inactive'. Active facilities are used in the campaign and require a boundary code to map.
User Template
Adding Rows: You are allowed to add new rows.
Locked Sheets: The boundary data sheet within the user template is locked and cannot be modified.
Dropdown Columns: The following columns are dropdowns:
Role
Employment Type
Data for Dropdowns
The data for the dropdown columns comes from the mdms
(Master Data Management System) under the adminSchema
master.
Endpoint: /data/_download
Method: POST
RequestInfo: Object containing request information.
Type: (Optional) Type of the resource being downloaded.
TenantId: Tenant identifier.
HierarchyType: Type of hierarchy.
Id: (Optional) ID of the resource being downloaded.
Filters: (Optional) Additional filters for the download request.
ResponseInfo: Object containing response information.
ResourceDetails: Array containing the details object of the downloaded resource.
Client Request: The client sends a POST request to download data.
Request Validation: Upon receiving the request, the server validates the request structure and parameters.
Data Download Process:
Validation: Validate the download request.
Fetch Data: Fetch existing data of the specified type from the data host service.
Processing: Process the retrieved data as necessary.
Response Creation: After processing the request, the server creates a response containing the details of the latest resource, ensuring that only one result is fetched.
Response Dispatch: The server sends the generated response back to the client.
Error Handling: If errors occur during the process, an error response is generated and sent.