wiki:Grits_ProjectPreferenceStore

Version 9 (modified by shan, 5 years ago) (diff)

--

Project Preference Store (Local Preference Store for Project)


ProjectPreferenceStore is a local store for storing preference values related to project, e.g. preference for project's Task information. This local store caches the preference values in maps (map key is the id of the preference variable). It calls GritsPreferenceStore only if the value is not found in its map.

Major Advantages:

  1. Currently the central GritsPreferenceStore does not store any preference value in maps and reads from file each time a preference value is read. This local preference store minimizes multiple read from file by keeping a cache of preference values in memory that have been read once.
  1. Currently preference values are stored as string in the preference file. Each time a preference is read, a generic PreferenceEntity object is created by GritsPreference store. This PreferenceEntity object is later converted to more specific preference object for getting preference values. ProjectPreferenceStore reduces multiple unnecessary de-serialization of preference values from strings stored in file.
    For example, if there were four tasks, ProjectPreferenceStore would cache a list of four tasks (along with its default information) which would be otherwise each time read as string from file, unmarshalled to PreferenceEntity object and then converted to list of tasks.

These advantages are general for any similar local preference store in GRITS. Plugins that would be using preferences are recommended to maintain a local preference store.

Implementation

ProjectPreferenceStore works with enums and string. It takes enums as parameters and returns values in enums (single/multi-choice list).

Class Diagram for various Preferences in Project Preference store



Preferences in Project Preference store:

Currently there are four types of preferences for projects.

  • StringPreference - Simplest type of preference that has a string value. All other information related to it is available in the enum object.
  • Preference - Types of preference whose values are a list of string.
  • ParameterizedPreference - Types of preference whose values are a list of particular class object.
  • IntegerPreference - A special case of ParameterizedPreference whose values are a list of integers.

By using the above enum objects as parameter, the need of knowing preference variable names or the need of knowing filename for default values (when a preference is not found in the preference file) is removed. When one of the above enum is passed as parameter then user can get a generic SingleChoicePreference or MultiChoicePreference (or its special case MultiChoiceInteger) enum object.

A SingleChoicePreference is characterized by - a list of values and one default value.

A MultiChoicePreference is characterized by - a list of selected values and a list of unselected values.

A MultiChoiceInteger is a special case of MultiChoicePreference and is characterized by - a list of selected integers and a list of unselected integers.

Note: The simplest StringPreference is self-contained and has a single string value that can be directly accessed from the enum object.

Class Diagram for entire Project Preference store



Code Snippet

public class ProjectPreferenceStore
{
	@Inject private static IGritsPreferenceStore gritsPreferenceStore;
	private static Map<String, SingleChoicePreference> singleSelectionTypeMap =
			new HashMap<String, SingleChoicePreference>();
	private static Map<String, MultiChoicePreference<?>> multiSelectionTypeMap =
			new HashMap<String, MultiChoicePreference<?>>();

	public static SingleChoicePreference getSingleChoicePreference(Preference preference)
	{
		String preferenceName = preference.getPreferenceName();
		logger.info("Getting preference : " + preferenceName);
		SingleChoicePreference preferenceObject = singleSelectionTypeMap.get(preferenceName);
		if(preferenceObject == null)
		{
			preferenceObject = new SingleChoicePreference(gritsPreferenceStore, preference);
			singleSelectionTypeMap.put(preferenceName, preferenceObject);
		}
		return preferenceObject;
	}

	@SuppressWarnings("unchecked")
	public static <T> MultiChoicePreference <T> getMultiChoicePreference(
			ParameterizedPreference parameterizedPreference)
	{
		String preferenceName = parameterizedPreference.getPreferenceName();
		logger.info("Getting preference : " + preferenceName);
		MultiChoicePreference<T> preferenceObject = (MultiChoicePreference<T>) multiSelectionTypeMap.get(preferenceName);
		if(preferenceObject == null)
		{
			preferenceObject = new MultiChoicePreference<T>(gritsPreferenceStore, parameterizedPreference);
			multiSelectionTypeMap.put(preferenceName, preferenceObject);
		}
		return preferenceObject;
	}

....
}

Attachments (5)

Download all attachments as: .zip