atg.svc.repository.service
Class SegmentedOptionService

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.svc.repository.service.BaseService
              extended by atg.svc.repository.service.KnowledgeBaseService
                  extended by atg.svc.repository.service.SegmentedOptionService
All Implemented Interfaces:
atg.naming.NameContextBindingListener, atg.naming.NameContextElement, atg.naming.NameResolver, atg.nucleus.AdminableService, atg.nucleus.logging.ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, atg.nucleus.logging.VariableArgumentApplicationLogging, atg.nucleus.naming.ComponentNameResolver, atg.nucleus.Service, atg.nucleus.ServiceListener, java.util.EventListener

public class SegmentedOptionService
extends KnowledgeBaseService

Business methods for editing/reading/saving options that are segmented by profile group.


Nested Class Summary
protected  class SegmentedOptionService.LazySegmentedOptionsMap
          A Map for SegmentedOptions that waits until get() or containsKey() is called to load the SegmentedOption value into the Map.
 
Field Summary
static java.lang.String CLASS_VERSION
           
 SegmentService mSegmentService
           
static java.lang.String SEGMENT_REQ_ATTR
           
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
SegmentedOptionService()
           
 
Method Summary
 void createOptionsSegment(java.lang.String pApplicationId, java.lang.String pSrcSegmentName, java.lang.String pDstSegmentName)
          Creates a new options segment, copies the set of SegmentedOption from the source segment to the new one and sets the new segment priority to the beginning of the list.
 atg.svc.repository.beans.SegmentedOption findOptionBySegmentAndName(java.lang.String pSegment, java.lang.String pOptionName)
          Finds a single SegmentedOption given the segment and option name.
 java.util.Collection findOptionsBySegment(java.lang.String pSegment)
          Gets the collection of SegmentedOption objects given the segment.
 atg.svc.repository.beans.OptionSegment findOptionSegmentById(java.lang.String pId)
          Finds an OptionSegment object by the given id.
 atg.svc.repository.beans.OptionSegment findOptionSegmentByName(java.lang.String pSegment)
          Gets an option segment given the name of the segment.
 java.util.List getAllOptionSegments()
          Gets the list of options segments in priority order.
 java.lang.String[] getArrayValue(atg.repository.RepositoryItem pProfile, java.lang.String pOptionName)
          Gets an option by name in the highest priority segment the given user belongs to and returns its value as a String.
 java.lang.String[] getArrayValue(java.lang.String pOptionName)
          Gets an option by name in the highest priority segment the current user belongs to and returns its value as a String.
 java.lang.String[] getArrayValue(java.lang.String pSegment, java.lang.String pOptionName)
          Gets a Segmented option by name and returns its value as an array of Strings.
 boolean getBooleanValue(atg.repository.RepositoryItem pProfile, java.lang.String pOptionName)
          Gets an option by name in the highest priority segment the given user belongs to and returns its value as a boolean.
 boolean getBooleanValue(java.lang.String pOptionName)
          Gets an option by name in the highest priority segment the current user belongs to and returns its value as a boolean.
 boolean getBooleanValue(java.lang.String pSegment, java.lang.String pOptionName)
          Gets a Segmented option by name and returns its value as a boolean.
 java.lang.String getHighestPriorityOptionSegment(atg.repository.RepositoryItem pProfile)
          Gets the highest priority segment the given user belongs to.
 java.lang.String getHighestPriorityOptionSegmentForCurrentUser()
          Gets the highest priority segment the current user belongs to.
 int getIntegerValue(atg.repository.RepositoryItem pProfile, java.lang.String pOptionName)
          Gets an option by name in the highest priority segment the given user belongs to and returns its value as a int.
 int getIntegerValue(java.lang.String pOptionName)
          Gets an option by name in the highest priority segment the current user belongs to and returns its value as a int.
 int getIntegerValue(java.lang.String pSegment, java.lang.String pOptionName)
          Gets a Segmented option by name and returns its value as an int.
 java.util.Map getOptions(java.lang.String pSegment)
          Returns a Map that can be used to edit Segmented options.
 SegmentService getSegmentService()
          Gets the SegmentService business component.
 java.lang.String getStringValue(atg.repository.RepositoryItem pProfile, java.lang.String pOptionName)
          Gets an option by name in the highest priority segment the given user belongs to and returns its value as a String.
 java.lang.String getStringValue(java.lang.String pOptionName)
          Gets an option by name in the highest priority segment the current user belongs to and returns its value as a String.
 java.lang.String getStringValue(java.lang.String pSegment, java.lang.String pOptionName)
          Gets a Segmented option by name and returns its value as a String.
 UIService getUiService()
          Gets the UIService business component.
 void removeOptionsSegment(java.lang.String pApplicationId, java.lang.String pId)
          Removes all options associated with the given segment and the option segment as well.
 void restoreDefaultValues(java.lang.String pSegmentName, java.lang.String[] pOptionNames)
          Restores the given options to their default value.
 void saveOptions(java.util.Map pSegmentedOptions)
          Saves a Map of segmented options to the repository.
 void saveOptionSegment(atg.svc.repository.beans.OptionSegment pOptionSegment)
          Commits changes in the given OptionSegment to the repository.
 void setSegmentService(SegmentService pSegmentService)
          Sets the SegmentService business component.
 void setUiService(UIService pUIService)
          Sets the UIService business component.
 void swapOptionSegmentPriorities(java.lang.String pId1, java.lang.String pId2)
          Swaps the priority of the two given OptionSegment objects given their ids and commits the changed to the repository.
 void validateOptionSegmentIsUnique(atg.svc.repository.beans.OptionSegment pOptionSegment)
          Looks for another checked-in OptionSegment with the same segment name.
 void validateSegmentedOptionIsUnique(atg.svc.repository.beans.SegmentedOption pSegmentedOption)
          Looks for another checked-in SegmentedOption with the same segment name and option name.
 
Methods inherited from class atg.svc.repository.service.KnowledgeBaseService
getKnowledgeHomesFactory, getOptionBeanHomes, getOptionRepositoryHomes, getServiceSegmentBeanHomes, getServiceSegmentRepositoryHomes, getSolutionBeanHomes, getSolutionRepositoryHomes, getUserOptionBeanHomes, getUserOptionRepositoryHomes, setKnowledgeHomesFactory
 
Methods inherited from class atg.svc.repository.service.BaseService
getRepositoryService, getToday, setRepositoryService
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStartService, doStopService, getAbsoluteName, getAdminServlet, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static final java.lang.String CLASS_VERSION
See Also:
Constant Field Values

SEGMENT_REQ_ATTR

public static final java.lang.String SEGMENT_REQ_ATTR
See Also:
Constant Field Values

mSegmentService

public SegmentService mSegmentService
Constructor Detail

SegmentedOptionService

public SegmentedOptionService()
Method Detail

getOptions

public java.util.Map getOptions(java.lang.String pSegment)
Returns a Map that can be used to edit Segmented options. The map is a wrapper around an LazyOptionsMap that lazy-loads editable SegmentedOption objects into the Map on a call to the get method on the HashMap. This is transparent to the caller however.

Returns:
A Map of all editable Segmented options keyed by the option name.

saveOptions

public void saveOptions(java.util.Map pSegmentedOptions)
                 throws DuplicateRecordException,
                        PersistenceException
Saves a Map of segmented options to the repository.

Parameters:
pSegmentedOptions - The map of user options as SegmentedOption beans.
Throws:
PersistenceException - If the save fails.
DuplicateRecordException

restoreDefaultValues

public void restoreDefaultValues(java.lang.String pSegmentName,
                                 java.lang.String[] pOptionNames)
                          throws ObjectNotFoundException,
                                 PersistenceException
Restores the given options to their default value.

Parameters:
pSegmentName - The name of the segment the options belong to.
pOptionNames - The names of the option to restore.
Throws:
ObjectNotFoundException - If an option cannot be found with the given segment and name.
PersistenceException - If the write of an option to the repository fails.
java.lang.IllegalArgumentException - If the segmentName is blank or the option names are empty.

getStringValue

public java.lang.String getStringValue(java.lang.String pOptionName)
                                throws javax.ejb.FinderException,
                                       ObjectNotFoundException
Gets an option by name in the highest priority segment the current user belongs to and returns its value as a String.

Parameters:
pOptionName - The name of option to find.
Returns:
A string representation of the value.
Throws:
ObjectNotFoundException - If the SegmentedOption is not found by the given name in the given segment.
javax.ejb.FinderException - If the underlying finder call to get the list of segments fails.

getBooleanValue

public boolean getBooleanValue(java.lang.String pOptionName)
                        throws javax.ejb.FinderException,
                               ObjectNotFoundException
Gets an option by name in the highest priority segment the current user belongs to and returns its value as a boolean.

Parameters:
pOptionName - The name of option to find.
Returns:
A boolean representation of the value.
Throws:
ObjectNotFoundException - If the default option is not found for the given name.
javax.ejb.FinderException - If the underlying finder call to get the list of segments fails.

getIntegerValue

public int getIntegerValue(java.lang.String pOptionName)
                    throws javax.ejb.FinderException,
                           ObjectNotFoundException
Gets an option by name in the highest priority segment the current user belongs to and returns its value as a int.

Parameters:
pOptionName - The name of option to find.
Returns:
A int representation of the value.
Throws:
ObjectNotFoundException - If the default option is not found for the given name.
javax.ejb.FinderException - If the underlying finder call to get the list of segments fails.

getArrayValue

public java.lang.String[] getArrayValue(java.lang.String pOptionName)
                                 throws javax.ejb.FinderException,
                                        ObjectNotFoundException
Gets an option by name in the highest priority segment the current user belongs to and returns its value as a String.

Parameters:
pOptionName - The name of the option.
Returns:
The array of String values for the Segmented option.
Throws:
ObjectNotFoundException - If the SegmentedOption is not found by the given name in the given segment.
javax.ejb.FinderException - If the underlying finder call to get the list of segments fails.

getStringValue

public java.lang.String getStringValue(atg.repository.RepositoryItem pProfile,
                                       java.lang.String pOptionName)
                                throws javax.ejb.FinderException,
                                       ObjectNotFoundException
Gets an option by name in the highest priority segment the given user belongs to and returns its value as a String.

Parameters:
pProfile - The user to find the highest priority segment to be used to lookup the value.
pOptionName - The name of option to find.
Returns:
A string representation of the value.
Throws:
ObjectNotFoundException - If the SegmentedOption is not found by the given name in the given segment.
javax.ejb.FinderException - If the underlying finder call to get the list of segments fails.

getBooleanValue

public boolean getBooleanValue(atg.repository.RepositoryItem pProfile,
                               java.lang.String pOptionName)
                        throws javax.ejb.FinderException,
                               ObjectNotFoundException
Gets an option by name in the highest priority segment the given user belongs to and returns its value as a boolean.

Parameters:
pProfile - The user to find the highest priority segment to be used to lookup the value.
pOptionName - The name of option to find.
Returns:
A boolean representation of the value.
Throws:
ObjectNotFoundException - If the default option is not found for the given name.
javax.ejb.FinderException - If the underlying finder call to get the list of segments fails.

getIntegerValue

public int getIntegerValue(atg.repository.RepositoryItem pProfile,
                           java.lang.String pOptionName)
                    throws javax.ejb.FinderException,
                           ObjectNotFoundException
Gets an option by name in the highest priority segment the given user belongs to and returns its value as a int.

Parameters:
pProfile - The user to find the highest priority segment to be used to lookup the value.
pOptionName - The name of option to find.
Returns:
A int representation of the value.
Throws:
ObjectNotFoundException - If the default option is not found for the given name.
javax.ejb.FinderException - If the underlying finder call to get the list of segments fails.

getArrayValue

public java.lang.String[] getArrayValue(atg.repository.RepositoryItem pProfile,
                                        java.lang.String pOptionName)
                                 throws javax.ejb.FinderException,
                                        ObjectNotFoundException
Gets an option by name in the highest priority segment the given user belongs to and returns its value as a String.

Parameters:
pProfile - The user to find the highest priority segment to be used to lookup the value.
pOptionName - The name of the option.
Returns:
The array of String values for the Segmented option.
Throws:
ObjectNotFoundException - If the SegmentedOption is not found by the given name in the given segment.
javax.ejb.FinderException - If the underlying finder call to get the list of segments fails.

getStringValue

public java.lang.String getStringValue(java.lang.String pSegment,
                                       java.lang.String pOptionName)
                                throws ObjectNotFoundException
Gets a Segmented option by name and returns its value as a String.

Parameters:
pSegment - The segment name of option to find.
pOptionName - The name of option to find.
Returns:
A string representation of the value.
Throws:
ObjectNotFoundException - If the SegmentedOption is not found by the given name in the given segment.
java.lang.IllegalArgumentException - If the pSegment or pOptionName arguments are empty.

getBooleanValue

public boolean getBooleanValue(java.lang.String pSegment,
                               java.lang.String pOptionName)
                        throws ObjectNotFoundException
Gets a Segmented option by name and returns its value as a boolean.

Parameters:
pSegment - The segment name of option to find.
pOptionName - The name of option to find.
Returns:
A boolean representation of the value.
Throws:
ObjectNotFoundException - If the default option is not found for the given name.
java.lang.IllegalArgumentException - If the pSegment or pOptionName arguments are empty.

getIntegerValue

public int getIntegerValue(java.lang.String pSegment,
                           java.lang.String pOptionName)
                    throws ObjectNotFoundException
Gets a Segmented option by name and returns its value as an int.

Parameters:
pSegment - The segment name of option to find.
pOptionName - The name of option to find.
Returns:
A int representation of the value.
Throws:
ObjectNotFoundException - If the default option is not found for the given name.
java.lang.IllegalArgumentException - If the pSegment or pOptionName arguments are empty.

getArrayValue

public java.lang.String[] getArrayValue(java.lang.String pSegment,
                                        java.lang.String pOptionName)
                                 throws ObjectNotFoundException
Gets a Segmented option by name and returns its value as an array of Strings.

Parameters:
pSegment - The segment name of option to find.
pOptionName - The name of the option.
Returns:
The array of String values for the Segmented option.
Throws:
ObjectNotFoundException - If the SegmentedOption is not found by the given name in the given segment.
java.lang.IllegalArgumentException - If the pSegment or pOptionName arguments are empty.

getHighestPriorityOptionSegmentForCurrentUser

public java.lang.String getHighestPriorityOptionSegmentForCurrentUser()
                                                               throws javax.ejb.FinderException
Gets the highest priority segment the current user belongs to. The segments are the one configured in the OptionSegment segments list. Each one is tested against the current user and the highest priority on the user belongs to is the one that is returned.

Developer's note: this could be an expensive operation. It might be best to cache this value in the current request if using it for multiple get*Value calls above. It cannot be cached in the session because the value is dynamic and could change if the user's profile changes.

Returns:
The segment name.
Throws:
javax.ejb.FinderException

getHighestPriorityOptionSegment

public java.lang.String getHighestPriorityOptionSegment(atg.repository.RepositoryItem pProfile)
                                                 throws javax.ejb.FinderException
Gets the highest priority segment the given user belongs to. The segments are the one configured in the OptionSegment segments list. Each one is tested against the current user and the highest priority on the user belongs to is the one that is returned.

Developer's note: this could be an expensive operation. It might be best to cache this value in the current request if using it for multiple get*Value calls above. It cannot be cached in the session because the value is dynamic and could change if the user's profile changes.

Parameters:
pProfile - The user to get the segment for.
Returns:
The segment name.
Throws:
javax.ejb.FinderException - If the finder for getting the segments fails.

findOptionBySegmentAndName

public atg.svc.repository.beans.SegmentedOption findOptionBySegmentAndName(java.lang.String pSegment,
                                                                           java.lang.String pOptionName)
                                                                    throws ObjectNotFoundException
Finds a single SegmentedOption given the segment and option name.

Parameters:
pSegment - The non-empty name of the segment (profile group).
pOptionName - The non-empty name of the option.
Returns:
The SegmentedOption with the given segment and name.
Throws:
ObjectNotFoundException - If no SegmentedOption is found with the given segment and name.
java.lang.IllegalArgumentException - If either argument is empty.

findOptionsBySegment

public java.util.Collection findOptionsBySegment(java.lang.String pSegment)
                                          throws javax.ejb.FinderException
Gets the collection of SegmentedOption objects given the segment.

Parameters:
pSegment - The segment to get the options for.
Returns:
The collection of options. If none then an empty ArrayList is returned.
Throws:
javax.ejb.FinderException - If the finder fails.

createOptionsSegment

public void createOptionsSegment(java.lang.String pApplicationId,
                                 java.lang.String pSrcSegmentName,
                                 java.lang.String pDstSegmentName)
                          throws DuplicateRecordException,
                                 javax.ejb.CreateException,
                                 javax.ejb.FinderException,
                                 ObjectNotFoundException,
                                 PersistenceException
Creates a new options segment, copies the set of SegmentedOption from the source segment to the new one and sets the new segment priority to the beginning of the list.

Parameters:
pApplicationId - The app id for framework, e.g. "workspace" or "selfService", can be null to ignore framework objects and copy only options
pSrcSegmentName - The repository id of the existing segment to copy the options from (the source).
pDstSegmentName - The name of the new segment which is also the name of the profile group.
Throws:
javax.ejb.CreateException - If a creating the new OptionSegment or a SegmentedOption fails
javax.ejb.FinderException - If the finder that gets all the source SegmentedOption objects fails.
ObjectNotFoundException - If source OptionSegment cannot be found by the given id.
PersistenceException - If the write of the new OptionSegment or a copied SegmentedOption fails
DuplicateRecordException

removeOptionsSegment

public void removeOptionsSegment(java.lang.String pApplicationId,
                                 java.lang.String pId)
                          throws javax.ejb.FinderException,
                                 ObjectNotFoundException,
                                 PersistenceException
Removes all options associated with the given segment and the option segment as well.

Parameters:
pApplicationId - The app id for framework, e.g. "workspace" or "selfService", can be null to ignore framework objects and remove only options
pId - The repository id of the segment.
Throws:
javax.ejb.FinderException - If the finder to get all the options by segment fails.
ObjectNotFoundException - If not segment is found with the given name.
PersistenceException - If the remove of the segment or one of the SegmentedOption objects fails.

swapOptionSegmentPriorities

public void swapOptionSegmentPriorities(java.lang.String pId1,
                                        java.lang.String pId2)
                                 throws ObjectNotFoundException,
                                        PersistenceException
Swaps the priority of the two given OptionSegment objects given their ids and commits the changed to the repository.

Parameters:
pId1 - The repository id of an existing OptionSegment
pId2 - The repository id of another existing OptionSegment
Throws:
ObjectNotFoundException - If either of the two segments cannot be found by id.
PersistenceException - If the commit to the repository fails.
java.lang.IllegalArgumentException - If the given arguments are the same id.

saveOptionSegment

public void saveOptionSegment(atg.svc.repository.beans.OptionSegment pOptionSegment)
                       throws DuplicateRecordException,
                              PersistenceException
Commits changes in the given OptionSegment to the repository.

Parameters:
pOptionSegment - The OptionSegment to commit.
Throws:
PersistenceException - If the commit operation fails.
DuplicateRecordException

findOptionSegmentByName

public atg.svc.repository.beans.OptionSegment findOptionSegmentByName(java.lang.String pSegment)
                                                               throws ObjectNotFoundException
Gets an option segment given the name of the segment.

Parameters:
pSegment - The name of the segment.
Returns:
The OptionSegment object.
Throws:
ObjectNotFoundException - If the OptionSegment is not found by the given name.

getAllOptionSegments

public java.util.List getAllOptionSegments()
                                    throws javax.ejb.FinderException
Gets the list of options segments in priority order.

Returns:
The list of segments (as OptionSegment) configured for segmented options.
Throws:
javax.ejb.FinderException - If the finder call fails.

findOptionSegmentById

public atg.svc.repository.beans.OptionSegment findOptionSegmentById(java.lang.String pId)
                                                             throws ObjectNotFoundException
Finds an OptionSegment object by the given id.

Parameters:
pId - The id of the OptionSegment to find.
Returns:
The OptionSegment.
Throws:
ObjectNotFoundException - If the OptionSegment is not found by the given id.

getSegmentService

public SegmentService getSegmentService()
Gets the SegmentService business component.

Returns:
The SegmentService business component.

setSegmentService

public void setSegmentService(SegmentService pSegmentService)
Sets the SegmentService business component.

Parameters:
pSegmentService - The SegmentService business component.

getUiService

public UIService getUiService()
Gets the UIService business component.

Returns:
The UIService business component.

setUiService

public void setUiService(UIService pUIService)
Sets the UIService business component.

Parameters:
pUIService - The UIService business component.

validateSegmentedOptionIsUnique

public void validateSegmentedOptionIsUnique(atg.svc.repository.beans.SegmentedOption pSegmentedOption)
                                     throws DuplicateRecordException,
                                            PersistenceException
Looks for another checked-in SegmentedOption with the same segment name and option name. Throws a DuplicateRecordException if another segemented option exists.

Parameters:
pSegmentedOption - the Self Serivce option we wish to validate
Throws:
DuplicateRecordException - thrown if a segmented option already exists with the same option name and segment name.
PersistenceException - thrown if an unexpected error occurred while performing this function.

validateOptionSegmentIsUnique

public void validateOptionSegmentIsUnique(atg.svc.repository.beans.OptionSegment pOptionSegment)
                                   throws DuplicateRecordException,
                                          PersistenceException
Looks for another checked-in OptionSegment with the same segment name. Throws a DuplicateRecordException if another option segment exists.

Parameters:
pOptionSegment - The object that represents a self service site - this is the object we're validating to make the name is unique
Throws:
DuplicateRecordException - thrown if a OptionSegment already exists with the same name.
PersistenceException - thrown if an unexpected error occurred while performing this function.