Skip to content

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

  1. Define the SELECT that retrieves USER_PREFERENCE_SEQ_NUM, USER_ID, APP_NAME, PAGE_NAME, and PREFERENCE_TEXT from USER_PREFERENCE for one user (SQL-003, USER_PREFERENCE).
  2. Create a JavaScriptSerializer, an empty List<Preference>, and a fresh parameter list containing :userid = userId.ToLower() (BR-001, SQL-003, USER_PREFERENCE).
  3. Create a SqlHelper.ResultSetQuery, attach the parameters, and execute the SELECT through the active data portal (SQL-003, USER_PREFERENCE).
  4. Create the portal request in the SqlHelper.ResultSetQuery constructor.
  5. Add :userid to DataRequest through AddParms.
  6. Set DataRequest.RequestType to ResultSet and DataRequest.SQLStatement to the SELECT text.
  7. Call IDataPortalInfo.ProcessPortalRequest, then cast DataRequest.Result back to clsResultSet.

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 new Preference instance. - Copy USER_PREFERENCE_SEQ_NUM into PreferenceId. - Copy APP_NAME into ApplicationName. - Copy PAGE_NAME into Pagename. - Reset PreferenceItems to an empty dictionary before examining the payload. 5. Read PREFERENCE_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 into Dictionary<string, string> and assign the result to PreferenceItems. - If the trimmed JSON text is empty, leave PreferenceItems as the empty dictionary created in step 4. 6. Append the hydrated Preference object 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 completed List<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_TEXT value produces an empty PreferenceItems dictionary rather than a null reference.
  • Invalid JSON in PREFERENCE_TEXT raises 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.

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