From 6dea303b923346001e5d97b96523b521e5498f0a Mon Sep 17 00:00:00 2001 From: Avinash Rajesh Date: Fri, 12 Jun 2026 11:09:35 +0530 Subject: [PATCH 1/3] Implement Model Refactoring 1951: Model Refactoring UserStory #1951 1. Replaced CSV-based serialization and deserialization in ComboPackage, JobCard, Service, and ServiceBooking models with fixed-size SerializedRecord structures for shared memory storage. 2. Implemented serialize() methods to convert objects into SerializedComboPackage, SerializedJobCard, SerializedService, and SerializedServiceBooking records. 3. Implemented deserialize() methods to reconstruct objects directly from SerializedRecord types instead of parsing CSV strings. 4. Updated model class interfaces to use SerializedRecord types, removing legacy CSV serialization APIs and header generation functions. 5. Added SerializedRecords.h dependencies and forward declarations for Serialized structures across affected models. N/A Sreeja Reghukumar --- .../models/User.cpp | 82 +++++++------------ .../models/User.h | 6 +- 2 files changed, 33 insertions(+), 55 deletions(-) diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/User.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/User.cpp index 0b4e86e..c4dc928 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/User.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/User.cpp @@ -8,6 +8,7 @@ Date: 19-May-2026 */ #include +#include "SerializedRecords.h" #include "User.h" #include "Notification.h" #include "Enums.h" @@ -28,7 +29,8 @@ Returns: User::User() : m_id("USR" + std::to_string(++m_uid)), m_type(util::UserType::CUSTOMER), - m_status(util::State::ACTIVE) {} + m_status(util::State::ACTIVE) { +} /* Function: User @@ -51,7 +53,8 @@ User::User(const std::string& userName, const std::string& password, const std:: m_phone(phone), m_email(email), m_type(role), - m_status(util::State::ACTIVE) {} + m_status(util::State::ACTIVE) { +} /* Function: User (parameterized constructor with ID) @@ -324,68 +327,43 @@ void User::setState(util::State status) /* Function: serialize -Description: Serializes the user into a CSV-formatted string. +Description: Serializes the User object into a SerializedUser record. Parameters: - None Returns: - - std::string: Serialized user record + - SerializedUser: Serialized representation of the user */ -std::string User::serialize() const +SerializedUser User::serialize() const { - std::ostringstream serializedUser; - serializedUser << m_id << ',' - << m_userName << ',' - << m_password << ',' - << m_name << ',' - << m_phone << ',' - << m_email << ',' - << util::getUserTypeString(m_type) << ',' - << util::getStateString(m_status); - return serializedUser.str(); + SerializedUser serialized = {}; + strcpy_s(serialized.id, sizeof(serialized.id), m_id.c_str()); + strcpy_s(serialized.username, sizeof(serialized.username), m_userName.c_str()); + strcpy_s(serialized.password, sizeof(serialized.password), m_password.c_str()); + strcpy_s(serialized.name, sizeof(serialized.name), m_name.c_str()); + strcpy_s(serialized.phone, sizeof(serialized.phone), m_phone.c_str()); + strcpy_s(serialized.email, sizeof(serialized.email), m_email.c_str()); + serialized.userType = m_type; + serialized.status = m_status; + return serialized; } /* Function: deserialize -Description: Deserializes a CSV-formatted string into a User object. +Description: Deserializes a SerializedUser record into a User object. Parameters: - - record: const std::string&, serialized user record + - serializedUser: const SerializedUser&, serialized user record Returns: - User*: Pointer to the deserialized User object */ -User* User::deserialize(const std::string& record) +User* User::deserialize(const SerializedUser& serializedUser) { - std::string id, name, username, phone, password, email; - std::string userTypeString, stateString; - std::istringstream serializedUser(record); - getline(serializedUser, id, ','); - getline(serializedUser, username, ','); - getline(serializedUser, password, ','); - getline(serializedUser, name, ','); - getline(serializedUser, phone, ','); - getline(serializedUser, email, ','); - getline(serializedUser, userTypeString, ','); - getline(serializedUser, stateString); - util::UserType userType = util::getUserType(userTypeString); - util::State status = util::getState(stateString); - return Factory::getObject(id, - username, - password, - name, - phone, - email, - userType, - status); -} - -/* -Function: getHeaders -Description: Retrieves the CSV headers for user serialization. -Parameters: - - None -Returns: - - std::string: Header string ("ID,Username,Password,Name,Phone,Email,UserType,UserStatus") -*/ -std::string User::getHeaders() -{ - return "ID,Username,Password,Name,Phone,Email,UserType,UserStatus"; + return Factory::getObject( + serializedUser.id, + serializedUser.username, + serializedUser.password, + serializedUser.name, + serializedUser.phone, + serializedUser.email, + serializedUser.userType, + serializedUser.status); } \ No newline at end of file diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/User.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/User.h index 12923f6..1026bd3 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/User.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/User.h @@ -14,6 +14,7 @@ Date: 19-May-2026 #include "Enums.h" class Notification; +struct SerializedUser; class User : public Observer { @@ -51,7 +52,6 @@ public: void addNotification(Notification* notification) override; void setRole(util::UserType role); void setState(util::State status); - std::string serialize() const; - static User* deserialize(const std::string&); - static std::string getHeaders(); + SerializedUser serialize() const; + static User* deserialize(const SerializedUser& serializedUser); }; From 74dbbd9e82a1dc53e13f1e987b0a51d2d3be29e8 Mon Sep 17 00:00:00 2001 From: Avinash Rajesh Date: Fri, 12 Jun 2026 14:28:48 +0530 Subject: [PATCH 2/3] Implement Service Refactoring 1952: Service Refactoring UserStory #1952 1. Enhanced DataStore::getUsers to load SerializedUser records, refresh cache, and attach notifications to recipient users with validation for recipient IDs. 2. Updated DataStore::saveUsers to persist SerializedUser records and save notifications alongside user data. 3. Refactored AuthenticationManagementService::login to use DataStoreLockGuard and tracked user map with SerializedUser-backed records. 4. Modified AuthenticationManagementService::changePassword to ensure thread-safe updates, mark user record as MODIFIED, and persist changes via DataStore::saveUsers. 5. Added dependencies for Utility.h and DataStoreLockGuard.h in AuthenticationManagementService.cpp to support safe record handling. N/A Sreeja Reghukumar --- .../Trenser.VehicleServiceSystem.vcxproj | 1 + ...enser.VehicleServiceSystem.vcxproj.filters | 3 ++ .../datastores/DataStore.cpp | 18 ++++++++++++ .../datastores/DataStoreLockGuard.h | 28 +++++++++++++++++++ .../AuthenticationManagementService.cpp | 20 ++++++++++--- 5 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/datastores/DataStoreLockGuard.h diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj index 6a269f5..7c4bfd3 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj @@ -157,6 +157,7 @@ + diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj.filters b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj.filters index 7e74b19..94301c4 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj.filters +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj.filters @@ -278,5 +278,8 @@ Header Files\DataStores\SharedMemory + + Header Files\DataStores + \ No newline at end of file diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/datastores/DataStore.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/datastores/DataStore.cpp index 1cade32..f430184 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/datastores/DataStore.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/datastores/DataStore.cpp @@ -228,6 +228,22 @@ Returns: */ util::Map>& DataStore::getUsers() { + auto users = loadRecords(m_users); + refreshCache(m_userCache, users); + auto& notifications = getNotifications(); + int numberOfNotifications = m_notificationCache.getSize(); + for (int index = 0; index < numberOfNotifications; index++) + { + Notification* notification = notifications.getValueAt(index).data; + const std::string& recipientUserId = notification->getRecipientUserId(); + int userIndex = m_userCache.find(recipientUserId); + if (userIndex == -1) + { + throw std::runtime_error("Invalid recipient user ID"); + } + User* user = m_userCache.getValueAt(userIndex).data; + user->addNotification(notification); + } return m_userCache; } @@ -371,6 +387,8 @@ Returns: */ void DataStore::saveUsers() { + saveRecords(m_users, m_userCache); + saveNotifications(); } /* diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/datastores/DataStoreLockGuard.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/datastores/DataStoreLockGuard.h new file mode 100644 index 0000000..2e04eb0 --- /dev/null +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/datastores/DataStoreLockGuard.h @@ -0,0 +1,28 @@ +/* +File: DataStoreLockGuard.h +Description: Defines the DataStoreLockGuard class used to manage DataStore + locking and unlocking automatically within a scope. +Author: Trenser +Date: 12-June-2026 +*/ + +#pragma once +#include "DataStore.h" + +class DataStoreLockGuard +{ +public: + explicit DataStoreLockGuard(DataStore& dataStore) + : m_dataStore(dataStore) + { + m_dataStore.lockDataStore(); + } + ~DataStoreLockGuard() + { + m_dataStore.unlockDataStore(); + } + DataStoreLockGuard(const DataStoreLockGuard&) = delete; + DataStoreLockGuard& operator=(const DataStoreLockGuard&) = delete; +private: + DataStore& m_dataStore; +}; \ No newline at end of file diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/AuthenticationManagementService.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/AuthenticationManagementService.cpp index dc3a94c..27be89f 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/AuthenticationManagementService.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/AuthenticationManagementService.cpp @@ -10,6 +10,8 @@ Date:19-May-2026 #include #include "AuthenticationManagementService.h" #include "User.h" +#include "Utility.h" +#include "DataStoreLockGuard.h" User* AuthenticationManagementService::m_authenticatedUser = nullptr; @@ -24,11 +26,12 @@ Return type: bool - true if login successful, false otherwise */ bool AuthenticationManagementService::login(const std::string& username, const std::string& password) { - util::Map users = m_dataStore.getUsers(); - int usersMapSize = users.getSize(); - for (int index = 0; index < usersMapSize; index++) + DataStoreLockGuard lock(m_dataStore); + auto& trackedUserMap = m_dataStore.getUsers(); + int trackedUserMapSize = trackedUserMap.getSize(); + for (int index = 0; index < trackedUserMapSize; index++) { - User* user = users.getValueAt(index); + User* user = trackedUserMap.getValueAt(index).data; if (username == user->getUserName()) { if (password == user->getPassword()) @@ -74,9 +77,18 @@ Return type: void */ void AuthenticationManagementService::changePassword(const std::string& newPassword) { + DataStoreLockGuard lock(m_dataStore); + auto& trackedUsersMap = m_dataStore.getUsers(); + int index = trackedUsersMap.find(m_authenticatedUser->getId()); + if (index == -1) + { + throw std::runtime_error("User does not exist!\n"); + } if (m_authenticatedUser == nullptr) { throw std::runtime_error("There is no user currently logged in!"); } m_authenticatedUser->setPassword(newPassword); + trackedUsersMap.getValueAt(index).state = RecordState::MODIFIED; + m_dataStore.saveUsers(); } From d44cc86af0f1010b8240d0d65f94623d00007261 Mon Sep 17 00:00:00 2001 From: Avinash Rajesh Date: Mon, 15 Jun 2026 14:43:48 +0530 Subject: [PATCH 3/3] Implement the review fixes --- .../services/AuthenticationManagementService.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/AuthenticationManagementService.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/AuthenticationManagementService.cpp index 27be89f..71d66b6 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/AuthenticationManagementService.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/AuthenticationManagementService.cpp @@ -79,15 +79,15 @@ void AuthenticationManagementService::changePassword(const std::string& newPassw { DataStoreLockGuard lock(m_dataStore); auto& trackedUsersMap = m_dataStore.getUsers(); + if (m_authenticatedUser == nullptr) + { + throw std::runtime_error("There is no user currently logged in!"); + } int index = trackedUsersMap.find(m_authenticatedUser->getId()); if (index == -1) { throw std::runtime_error("User does not exist!\n"); } - if (m_authenticatedUser == nullptr) - { - throw std::runtime_error("There is no user currently logged in!"); - } m_authenticatedUser->setPassword(newPassword); trackedUsersMap.getValueAt(index).state = RecordState::MODIFIED; m_dataStore.saveUsers();