Follow me

Exercise 6 : Using user preferences

Now, we will try to adapt the illuminance based on User’s preferences.

In this exercise, we will assume that it is possible to identify who is in a given room. For that purpose we provide a LocationService that provides the ability to get a list of persons in a given room.

The user preferences service (Preferences) is able to store a set of user preferences (via setUserPropertyValue/getUserProperties)

Question 1 – Change the manager implementation to use the Preferences service Instead of having a targeted global illuminance configured globally, we will use the preference service to configure a value per users.

Initially, we will assume that there is only one person in the flat.

Use the location service to determine who is in the flat. Then use the the Preferences services to get the user preferences regarding illuminance.
preferences
Each person can express a preference. Use the following constant for the illuminance preference.

/**
* User preferences for illuminance
**/
public static final String USER_PROP_ILLUMINANCE = "illuminance";
public static final String USER_PROP_ILLUMINANCE_VALUE_SOFT = "SOFT";
public static final String USER_PROP_ILLUMINANCE_VALUE_SOFT = "MEDIUM";
public static final String USER_PROP_ILLUMINANCE_VALUE_SOFT = "FULL";

Example of using the Preferences service :

import fr.liglab.adele.icasa.service.preferences;
//..
public class FollowMeManagerImpl {
 
    // You have to create a new dependency :
    private Preferences preferencesService; //...
 
    //same applied for the person location service :
    private PersonLocationService personLocationService; //...
 
 
    public void ...{
        String AliceIlm = (String) preferencesService.getUserPropertyValue("Alice", USER_PROP_ILLUMINANCE);
        //..  
    }

You will have to convert the given String “SOFT”/”MEDIUM”/”FULL” into an illuminanceGoal. You have done this before in order to implement your command.

When the person has not expressed any preference, use the previously defined (global) preference.

Question 2 – Writing a command for the preference service Extend your command implementation so as to allow to store user preferences :

g! setIlluminancePreference Alice SOFT 
g! setIlluminancePreference John MEDIUM
g! setIlluminancePreference Bob FULL

preferencesCommand
Using this command, test that your implementation is working as expected.

Question 3 – More than one person: When more than one person is in the flat, use an average value for the targeted illuminance. You can experiment with this by defining another policy (priority based, user-type based, etc.).