Retrieve all preferences for a user¶
This operation is the library's bulk read path: it loads every preference row stored for a normalized user ID, materializes one Preference DTO per row, and deserializes non-empty JSON payloads into Preference.PreferenceItems.
| Field | Value |
|---|---|
| Operation ID | OP-PREF-002 |
| Trigger | Caller invokes PreferenceData.GetPreferencesForUser(userId). |
| Inputs | userId |
| Outputs | List<Preference> |
| Primary components | PreferenceData.GetPreferencesForUser, Preference, JavaScriptSerializer, SqlHelper.ResultSetQuery |
| Entry point | SAIF.Framework.Preferences\PreferenceData.cs |
Steps¶
- Define the SELECT that retrieves
USER_PREFERENCE_SEQ_NUM,USER_ID,APP_NAME,PAGE_NAME, andPREFERENCE_TEXTfrom USER_PREFERENCE for one user (SQL-003, USER_PREFERENCE). - Create a
JavaScriptSerializer, an emptyList<Preference>, and a fresh parameter list containing:userid = userId.ToLower()(BR-001, SQL-003, USER_PREFERENCE). - Create a
SqlHelper.ResultSetQuery, attach the parameters, and execute the SELECT through the active data portal (SQL-003, USER_PREFERENCE). - Create the portal request in the
SqlHelper.ResultSetQueryconstructor. - Add
:useridtoDataRequestthroughAddParms. - Set
DataRequest.RequestTypetoResultSetandDataRequest.SQLStatementto the SELECT text. - Call
IDataPortalInfo.ProcessPortalRequest, then castDataRequest.Resultback toclsResultSet.
Origin: Steps 3.1–3.4 are implemented by Execute a data portal request (
SAIF.Framework.Core) and executed on behalf of this operation. 4. Iterate each returned row and create a newPreferenceinstance. - CopyUSER_PREFERENCE_SEQ_NUMintoPreferenceId. - CopyAPP_NAMEintoApplicationName. - CopyPAGE_NAMEintoPagename. - ResetPreferenceItemsto an empty dictionary before examining the payload. 5. ReadPREFERENCE_TEXT, trim it, and decide whether to deserialize it (BR-006, SQL-003, USER_PREFERENCE). - If the trimmed JSON text has length greater than zero, deserialize it intoDictionary<string, string>and assign the result toPreferenceItems. - If the trimmed JSON text is empty, leavePreferenceItemsas the empty dictionary created in step 4. 6. Append the hydratedPreferenceobject to the output list and repeat for the remaining rows. - On failure: malformed JSON, portal failures, or row-conversion failures propagate because this method does not catch them. 7. Return the completedList<Preference>to the caller.
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([Caller invokes GetPreferencesForUser]) --> Query[Execute user-scoped SELECT]
Query --> Loop[For each returned row]
Loop --> Json{Trimmed JSON present?}
Json -->|Yes| Deserialize[Deserialize to dictionary]
Json -->|No| Empty[Keep empty dictionary]
Deserialize --> Add[Add Preference to list]
Empty --> Add
Add --> More{More rows?}
More -->|Yes| Loop
More -->|No| EndOk([Return List<Preference>])
Failure and edge-case behavior¶
- An empty
PREFERENCE_TEXTvalue produces an emptyPreferenceItemsdictionary rather than anullreference. - Invalid JSON in
PREFERENCE_TEXTraises a serializer exception that this method does not catch. - The method applies no application or page filter; it returns every stored row for the normalized user ID.
Related documentation¶
Sources¶
- SAIF.Framework.Preferences\PreferenceData.cs
- SAIF.Framework.Preferences\Preference.cs
- SAIF.Framework.Core\V1\DataAccessLayer\SqlHelper.vb
- SAIF.Framework.Core\V1\DataAccessLayer\clsResultSet.vb