com.endeca.portal.attributes
Class SemanticViewManager

java.lang.Object
  extended by com.endeca.portal.attributes.SemanticViewManager

public class SemanticViewManager
extends java.lang.Object

Author:
Endeca Technologies, Inc

Nested Class Summary
static class SemanticViewManager.GroupAllFilter
          Nested class implementation of a filter that removes group named 'all'
 
Field Summary
static java.lang.String AVAILABLE_AGGRAGATIONS_DELIMITER
           
static java.lang.String DEFAULT_AGG_ORD
           
static java.lang.String DEFAULT_AVAIL_AGG_BOOL
           
static java.lang.String DEFAULT_AVAIL_AGG_DATETIME
           
static java.lang.String DEFAULT_AVAIL_AGG_DURATION
           
static java.lang.String DEFAULT_AVAIL_AGG_GEO
           
static java.lang.String DEFAULT_AVAIL_AGG_NUM
           
static java.lang.String DEFAULT_AVAIL_AGG_STRING
           
static java.lang.String DEFAULT_AVAIL_AGG_TIME
           
static java.lang.String DEFAULT_SEMANTIC_VIEW_KEY
           
static java.lang.String EID_PROPERTY_PREFIX
           
static java.lang.String GROUP_PROPERTY_PREFIX
           
static java.lang.String INCL_DETAILS_PROPERTY_DEFAULT_VALUE
           
static java.lang.String INCL_NAV_PROPERTY_DEFAULT_VALUE
           
static java.lang.String MDEX_TYPE_BOOL
           
static java.lang.String MDEX_TYPE_DATETIME
           
static java.lang.String MDEX_TYPE_DOUBLE
           
static java.lang.String MDEX_TYPE_DURATION
           
static java.lang.String MDEX_TYPE_GEO
           
static java.lang.String MDEX_TYPE_INTEGER
           
static java.lang.String MDEX_TYPE_LONG
           
static java.lang.String MDEX_TYPE_STRING
           
static java.lang.String MDEX_TYPE_TIME
           
static java.lang.String SYSTEM_AVAILABLE_AGGREGATIONS
           
static java.lang.String SYSTEM_DEFAULT_AGGREGATION
           
static java.lang.String SYSTEM_DESCRIPTION
           
static java.lang.String SYSTEM_FORMAT_SETTINGS
           
static java.lang.String SYSTEM_IS_DIMENSION
           
static java.lang.String SYSTEM_LOCALIZED_DN_SETTINGS
           
 
Constructor Summary
SemanticViewManager()
           
 
Method Summary
static SemanticView createEmptySemanticView()
          Convenience method that creates a new empty instance of the SemanticView model.
static SemanticView createEmptySemanticView(int attrSize, int groupSize)
          Convenience method that creates a new empty instance of the SemanticView model with predefined collection sizes.
static SemanticView deserializeSemanticView(java.lang.String semanticViewJson)
          Deserializes an attribute settings model using Jackson.
static SemanticView filter(SemanticView semanticView, BPCFilter groupFilter, BPCFilter attributeFilter, boolean removeUngroupedAttributes)
          This method allows an SemanticView model object to be filtered in accordance with the specified filters.
static PrefinedMetric genPredefinedMetricInstance(com.endeca.mdex.sconfig._2010.types.Metric met, java.util.Locale locale)
          Create predefined metric instance
static ViewMetadata genViewMetadataInstance(com.endeca.mdex.sconfig._2010.types.SemanticEntity entity, java.util.Locale locale)
          Create view metadata instance
static java.lang.String getLocalized(java.util.Locale locale, java.lang.String localizedStr, java.lang.String defaultStr)
          Get localized string.
static java.lang.String getLocalizedDisplayName(com.endeca.mdex.sconfig._2010.types.SemanticAttribute attribute, java.util.Locale locale)
          Get localized display name from semantic attribute
static SemanticView getSemanticViewFromDatasource(DataSource datasource)
          Get semantic view object from datasource by base-view
static SemanticView getSemanticViewFromDatasource(DataSource datasource, java.util.Locale locale)
          Get semantic view object from datasource by base-view
static SemanticView getSemanticViewFromDatasource(DataSource datasource, java.lang.String semanticKey)
          Get semantic view object
static SemanticView getSemanticViewFromDatasource(DataSource datasource, java.lang.String semanticKey, java.util.Locale locale)
          Get semantic view object from datasource
static SemanticView mergeTwoPartials(DataSource datasource, java.lang.String semanticKey, SemanticView base, SemanticView changes)
          This method merges two attribute sets with each other, and adds filters for the datasource's global groups and attributes.
static SemanticView mergeTwoPartials(SemanticView base, SemanticView changes, BPCFilter groupFilter, BPCFilter attributeFilter, boolean allowCleanup, boolean doUnion)
          Merges two attribute settings model structures.
static SemanticView mergeWithGlobal(DataSource datasource, java.lang.String semanticKey, SemanticView changes)
          This method merges the submitted changes with the global attribute settings associated with the datasource.
static SemanticView mergeWithGlobal(DataSource datasource, java.lang.String semanticKey, SemanticView changes, BPCFilter groupFilter, BPCFilter attributeFilter, boolean doUnion)
          oes a join between the global model associated with the datasource, and the given attribute settings object.
static SemanticView mergeWithGlobal(DataSource datasource, java.lang.String semanticKey, SemanticView changes, BPCFilter groupFilter, BPCFilter attributeFilter, boolean doUnion, java.util.Locale locale)
          Does a join between the global model associated with the datasource, and the given attribute settings object.
static SemanticView mergeWithGlobal(DataSource datasource, java.lang.String semanticKey, SemanticView changes, java.util.Locale locale)
          This method merges the submitted changes with the global attribute settings associated with the datasource.
static void saveSemanticViewGroups(DataSource datasource, java.lang.String semanticKey, SemanticView viewData)
          Save groups of semantic view.
static java.lang.String serializeSemanticView(SemanticView semanticView)
          Serialize a given SemanticView object into a JSON model
static java.lang.String serializeSemanticViewPrettyPrint(SemanticView semanticView)
          Same as serializeSemanticView(SemanticView) except it uses pretty-print format for output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SEMANTIC_VIEW_KEY

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

EID_PROPERTY_PREFIX

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

GROUP_PROPERTY_PREFIX

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

SYSTEM_AVAILABLE_AGGREGATIONS

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

SYSTEM_DEFAULT_AGGREGATION

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

SYSTEM_DESCRIPTION

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

SYSTEM_LOCALIZED_DN_SETTINGS

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

SYSTEM_FORMAT_SETTINGS

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

SYSTEM_IS_DIMENSION

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

MDEX_TYPE_INTEGER

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

MDEX_TYPE_LONG

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

MDEX_TYPE_DOUBLE

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

MDEX_TYPE_STRING

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

MDEX_TYPE_DATETIME

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

MDEX_TYPE_TIME

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

MDEX_TYPE_DURATION

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

MDEX_TYPE_BOOL

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

MDEX_TYPE_GEO

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

AVAILABLE_AGGRAGATIONS_DELIMITER

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

DEFAULT_AGG_ORD

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

DEFAULT_AVAIL_AGG_NUM

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

DEFAULT_AVAIL_AGG_STRING

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

DEFAULT_AVAIL_AGG_DATETIME

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

DEFAULT_AVAIL_AGG_TIME

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

DEFAULT_AVAIL_AGG_DURATION

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

DEFAULT_AVAIL_AGG_GEO

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

DEFAULT_AVAIL_AGG_BOOL

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

INCL_NAV_PROPERTY_DEFAULT_VALUE

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

INCL_DETAILS_PROPERTY_DEFAULT_VALUE

public static final java.lang.String INCL_DETAILS_PROPERTY_DEFAULT_VALUE
See Also:
Constant Field Values
Constructor Detail

SemanticViewManager

public SemanticViewManager()
Method Detail

deserializeSemanticView

public static SemanticView deserializeSemanticView(java.lang.String semanticViewJson)
                                            throws org.codehaus.jackson.JsonParseException,
                                                   org.codehaus.jackson.map.JsonMappingException,
                                                   java.io.IOException
Deserializes an attribute settings model using Jackson.

Parameters:
semanticViewJson - - a serialized JSON representation of the SemanticView model.
Returns:
a newly constructed SemanticView object based on the serialized input String.
Throws:
org.codehaus.jackson.JsonParseException
org.codehaus.jackson.map.JsonMappingException
java.io.IOException

serializeSemanticView

public static java.lang.String serializeSemanticView(SemanticView semanticView)
                                              throws org.codehaus.jackson.JsonGenerationException,
                                                     org.codehaus.jackson.map.JsonMappingException,
                                                     java.io.IOException
Serialize a given SemanticView object into a JSON model

Parameters:
semanticView -
Returns:
a string serialized JSON model
Throws:
org.codehaus.jackson.JsonGenerationException
org.codehaus.jackson.map.JsonMappingException
java.io.IOException

serializeSemanticViewPrettyPrint

public static java.lang.String serializeSemanticViewPrettyPrint(SemanticView semanticView)
                                                         throws org.codehaus.jackson.JsonGenerationException,
                                                                org.codehaus.jackson.map.JsonMappingException,
                                                                java.io.IOException
Same as serializeSemanticView(SemanticView) except it uses pretty-print format for output. NOTE: Do not use this except for debug/test as it is somewhat slower than serializeSemanticView

Parameters:
semanticView -
Returns:
a pretty-printed string serialized JSON model
Throws:
org.codehaus.jackson.JsonGenerationException
org.codehaus.jackson.map.JsonMappingException
java.io.IOException

mergeWithGlobal

public static SemanticView mergeWithGlobal(DataSource datasource,
                                           java.lang.String semanticKey,
                                           SemanticView changes)
                                    throws DataSourceException
This method merges the submitted changes with the global attribute settings associated with the datasource. It does a left join of the global attributes with the submitted changes.

Parameters:
datasource -
semanticKey -
changes -
Returns:
mergedAttributeSettings
Throws:
DataSourceException

mergeWithGlobal

public static SemanticView mergeWithGlobal(DataSource datasource,
                                           java.lang.String semanticKey,
                                           SemanticView changes,
                                           java.util.Locale locale)
                                    throws DataSourceException
This method merges the submitted changes with the global attribute settings associated with the datasource. It does a left join of the global attributes with the submitted changes.

Parameters:
datasource -
semanticKey -
changes -
locale -
Returns:
mergedAttributeSettings
Throws:
DataSourceException

mergeWithGlobal

public static SemanticView mergeWithGlobal(DataSource datasource,
                                           java.lang.String semanticKey,
                                           SemanticView changes,
                                           BPCFilter groupFilter,
                                           BPCFilter attributeFilter,
                                           boolean doUnion,
                                           java.util.Locale locale)
                                    throws DataSourceException
Does a join between the global model associated with the datasource, and the given attribute settings object. Anything contained in the global set should be considered immutable, therefore we should not try to apply removal indicators to it (i.e. allowCleanup will always be false). This method also takes additional parameters that define whether or not the merged Attribute Groups should be filtered.

Parameters:
datasource - - the left hand side of the merge operation is the global attribute settings object associated with this datasource. Required.
semanticKey - - the semantic view key. Required.
changes - - the right hand side of the merge operation. This should be an instance of an attribute settings model that contains changes that should be applied to the global attribute settings. Required.
groupFilter - - optional BPC Filter object that is used to filter the groups in the final result of the merge operation before it is returned. If this parameter is set to null, no filtering occurs. Otherwise, only the groups that pass the filter test will be included in the results. This filter will also be applied to the groupOrder list. However, this filter will NOT prevent ungrouped attributes from appearing in the result.
attributeFilter - - a BPC Filter object that is used to filter the attributes portion of the merge operation before it is returned. If this parameter is set to null, no filtering occurs. Otherwise, only the attributes that pass the filter test will be included in the results.
doUnion - - when true, this merge will be a union of the two maps with some special handling surrounding null values. If this parameter is false, this merge will be a left join, with global attributes on the left side of the join (objects only appearing on the right hand side will not be included in the results).
locale - - Localized group/attribute/metric display name and view display name, description
Returns:
A merged SemanticView model. Note that the returned model may contain references to the cached objects from the global model or the "changes" model if those objects are taken verbatim.
Throws:
DataSourceException

mergeWithGlobal

public static SemanticView mergeWithGlobal(DataSource datasource,
                                           java.lang.String semanticKey,
                                           SemanticView changes,
                                           BPCFilter groupFilter,
                                           BPCFilter attributeFilter,
                                           boolean doUnion)
                                    throws DataSourceException
oes a join between the global model associated with the datasource, and the given attribute settings object.

Parameters:
datasource -
semanticKey -
changes -
groupFilter -
attributeFilter -
doUnion -
Returns:
Throws:
DataSourceException

mergeTwoPartials

public static SemanticView mergeTwoPartials(DataSource datasource,
                                            java.lang.String semanticKey,
                                            SemanticView base,
                                            SemanticView changes)
                                     throws DataSourceException
This method merges two attribute sets with each other, and adds filters for the datasource's global groups and attributes. It does allow cleanup, and does a union merge. Calling this convenience method is the same as calling SemanticViewManager#mergeTwoPartials(SemanticView base, SemanticView changes, datasource.getGlobalAttributeSettings().getGroupFilter(), datasource.getGlobalAttributeSettings().getAttributeFilter(), true, true)

Parameters:
base -
changes -
Returns:
mergedAttributeSet
Throws:
DataSourceException

mergeTwoPartials

public static SemanticView mergeTwoPartials(SemanticView base,
                                            SemanticView changes,
                                            BPCFilter groupFilter,
                                            BPCFilter attributeFilter,
                                            boolean allowCleanup,
                                            boolean doUnion)
Merges two attribute settings model structures. This method is designed to merge an older partial model (previous preferences) with updates to that model. The "changes" model may indicate that certain properties or whole BPCs should be removed and allowCleanup should be set to true in that case. This method can also be used to merge global attributes with local saved preferences, as long as the global group filter and global attribute filters are passed into the merge to ensure that BPCs that no longer exist in the MDEX Engine are excluded from the results of the merge, and allowCleanup is set to false (anything contained in the global set should be considered immutable, so do not try to edit it). When merging global attribute settings, the use of SemanticViewManager#mergeWithGlobal(DataSource, SemanticView) is recommended. This method also takes additional parameters that define whether or not empty value cleanup is allowed, whether to do a union style merge or a left join, and whether the Attribute Groups should be filtered.

Parameters:
base - - the Left-Hand Side of the merge operation. This should be an instance of an attribute settings model, to which the changes should be applied. Required.
changes - - the Right-Hand Side of the merge operation. This should be an instance of an attribute settings model that contains changes that should be applied to the "base". Required.
groupFilter - - a BPC Filter object that is used to filter the final result of the merge operation before it is returned. This parameter provides a filtering mechanism that allows the resulting SemanticView model to only contain information limited to the specified groups. If this parameter is set to null, no filtering occurs. Otherwise, only the groups that pass the filter test will be included in the results. This filter will also be applied to the groupOrder list. However, this filter will NOT prevent ungrouped attributes from appearing in the result.
attributeFilter - - a BPC Filter object that is used to filter the attributes portion of the merge operation before it is returned. If this parameter is set to null, no filtering occurs. Otherwise, only the attributes that pass the filter test will be included in the results.
allowCleanup - - when true allows individual properties or whole attributes/groups to be removed from the result of the merge. Generally, this should be set to true when merging to partial models and false when merging a global model with the partial diff. The removal works as follows. If a property is specified in the changes but its value is set to null, that property is removed from the merged attribute/group. If an attribute/group key is specified in the "changes" but the corresponding value is set to null, that attribute/group is excluded from the model. If after all properties for a given attribute/group have been merged that attribute/group ends up being empty (as defined by the isEmpty() method), that attribute/group is excluded from the merged model.
doUnion - - when true, this merge will be a union of the two maps with some special handling surrounding null values. If this parameter is false, this merge will be a left join on the base map. In general, this value should be set to false when doing global merges, and true when doing partial diff merges.
Returns:
A merged SemanticView model. Note that the returned model may contain references to the cached objects from the global model or the "changes" model if those objects are taken verbatim.

filter

public static SemanticView filter(SemanticView semanticView,
                                  BPCFilter groupFilter,
                                  BPCFilter attributeFilter,
                                  boolean removeUngroupedAttributes)
This method allows an SemanticView model object to be filtered in accordance with the specified filters. Separate filters can be specified for attributes and groups. Note that this method will never modify the original model and will always return a new instance of the SemanticView. However, the filtered model may reference individual objects from the original.

Parameters:
semanticView - - the SemanticView model to be filtered
groupFilter - - a filter to be applied to the groups collection and the groupOrder list. Only the groups that pass the filter test will be included. This filter can also be applied to attributes indirectly depending on the value of the removeUngroupedProperties flag
attributeFilter - - a filter to be applied to the attributes collection. Only the attributes that pass the filter test will be included. This filter can also be indirectly combined with the groupFilter depending on the value of the removeUngroupedProperties flag. Additionally, if this filter is specified, the Groups will be checked to make sure that they only reference valid attributes. This will always be done to preserve referential integrity of the model.
removeUngroupedAttributes - - this is a rather confusing setting that controls whether or not the attributes not contained in the groups that remain after filtering should also be removed from the model. In other words, when this parameter is set to true, an additional ExclusiveSetFilter will be created to represent only the attributes contained by the remaining groups. This new filter will be and-chained with the attributeFilter if necessary.
Returns:
a new instance of the SemanticView class.

createEmptySemanticView

public static SemanticView createEmptySemanticView()
Convenience method that creates a new empty instance of the SemanticView model. A note on performance. This method assumes the typical size of 100 for the attributes collection and 10 for groups collection. If these sizes are known ahead of time you should use #createEmptyAttributeSettings(int, int) method instead.

Returns:
a new instance of SemanticView with empty (but initialized) attributes, groups, and groupOrder collections.

createEmptySemanticView

public static SemanticView createEmptySemanticView(int attrSize,
                                                   int groupSize)
Convenience method that creates a new empty instance of the SemanticView model with predefined collection sizes. Use this method if the size of the SemanticView model is known in advance and is not expected to change over time.

Parameters:
attrSize - - expected size of the attributes collection. This is used to calculate the initial capacity of the HashMap that contains attributes.
groupSize - - expected size of the groups collection. This is used to calculate the initial capacity of the HashMap that contains groups.
Returns:
a new instance of SemanticView with empty (but initialized) attributes, groups, and groupOrder collections.

saveSemanticViewGroups

public static void saveSemanticViewGroups(DataSource datasource,
                                          java.lang.String semanticKey,
                                          SemanticView viewData)
                                   throws DataSourceException,
                                          javax.xml.parsers.ParserConfigurationException
Save groups of semantic view.

Parameters:
datasource -
semanticKey -
viewData -
Throws:
DataSourceException
javax.xml.parsers.ParserConfigurationException

genPredefinedMetricInstance

public static PrefinedMetric genPredefinedMetricInstance(com.endeca.mdex.sconfig._2010.types.Metric met,
                                                         java.util.Locale locale)
Create predefined metric instance

Parameters:
met -
Returns:

genViewMetadataInstance

public static ViewMetadata genViewMetadataInstance(com.endeca.mdex.sconfig._2010.types.SemanticEntity entity,
                                                   java.util.Locale locale)
Create view metadata instance

Parameters:
entity -
Returns:

getSemanticViewFromDatasource

public static SemanticView getSemanticViewFromDatasource(DataSource datasource,
                                                         java.lang.String semanticKey,
                                                         java.util.Locale locale)
                                                  throws DataSourceException
Get semantic view object from datasource

Parameters:
datasource -
semanticKey -
Returns:
Throws:
DataSourceException

getSemanticViewFromDatasource

public static SemanticView getSemanticViewFromDatasource(DataSource datasource)
                                                  throws DataSourceException
Get semantic view object from datasource by base-view

Parameters:
datasource -
Returns:
Throws:
DataSourceException

getSemanticViewFromDatasource

public static SemanticView getSemanticViewFromDatasource(DataSource datasource,
                                                         java.util.Locale locale)
                                                  throws DataSourceException
Get semantic view object from datasource by base-view

Parameters:
datasource -
locale -
Returns:
Throws:
DataSourceException

getSemanticViewFromDatasource

public static SemanticView getSemanticViewFromDatasource(DataSource datasource,
                                                         java.lang.String semanticKey)
                                                  throws DataSourceException
Get semantic view object

Parameters:
datasource -
semanticKey -
Returns:
Throws:
DataSourceException

getLocalized

public static java.lang.String getLocalized(java.util.Locale locale,
                                            java.lang.String localizedStr,
                                            java.lang.String defaultStr)
Get localized string.

Parameters:
locale - locale object
localizedStr - A string contains localized information, the syntax is '{"zh_CN":"Test"}'
defaultStr - The default string
Returns:

getLocalizedDisplayName

public static java.lang.String getLocalizedDisplayName(com.endeca.mdex.sconfig._2010.types.SemanticAttribute attribute,
                                                       java.util.Locale locale)
Get localized display name from semantic attribute

Parameters:
attribute -
locale -
Returns: