Class ConfigurationsBC

  • All Implemented Interfaces:
    BusinessComponent, IConfigurationsBC

    public class ConfigurationsBC
    extends Object
    implements BusinessComponent, IConfigurationsBC
    Will handle a VKEYED config file that will store and provide configurations. This is currently used in the configuration widget plugin. It ill handle a config file that will store and provide configurations for different users, setting and programs. The BC will not create the VKEYED config file. the key fields are -REALM: where the configuration is being used -KEYX: program name -USERID: username of the configuration owner -SETTING: name of the configuration. a user can have multiple settings
    Author:
    jcorea
    • Constructor Detail

      • ConfigurationsBC

        public ConfigurationsBC()
      • ConfigurationsBC

        public ConfigurationsBC​(String pathConfigFile)
      • ConfigurationsBC

        public ConfigurationsBC​(String pathConfigFile,
                                String userName)
    • Method Detail

      • setUserName

        public void setUserName​(String userName)
        Description copied from interface: IConfigurationsBC
        set a new username. username will be used to determine the visible configurations and permissions. empty String "" as username enables admin mode
        Specified by:
        setUserName in interface IConfigurationsBC
      • setTemplateConfigFile

        public void setTemplateConfigFile​(String template)
        sets the string template for the config file (and resets the attributes record)
        Specified by:
        setTemplateConfigFile in interface IConfigurationsBC
        Parameters:
        template - new string template
      • getAttributesRecord

        public DataRow getAttributesRecord()
        Description copied from interface: BusinessComponent
        Returns an empty DataRow including all field attributes (like field name, editable, label etc.), which the retrieve method could return.
        Specified by:
        getAttributesRecord in interface BusinessComponent
        Returns:
        an empty DataRow with field attributes.
      • setFieldLengthAttribute

        protected void setFieldLengthAttribute​(DataRow attributes)
        sets the field length for each attribute in a 'LENGTH' attribute. length is defined in the templated string.
        Parameters:
        attributes -
      • setFilter

        public void setFilter​(DataRow filter)
        Description copied from interface: BusinessComponent
        Set a filter for the search result.
        If the filter is set it will be used in the retrieve method.
        If no filter is set, the retrieve method will return all data.
        Specified by:
        setFilter in interface BusinessComponent
        Parameters:
        filter - a DataRow including field names and values to filter for. Filters are AND combined.
        See Also:
        BusinessComponent.retrieve()
      • getAdminUser

        public String getAdminUser()
        returns admin user. user with permission to edit all entries. other users can only modify their configuration
        Specified by:
        getAdminUser in interface IConfigurationsBC
        Returns:
      • setAdminUser

        public void setAdminUser​(String adminUser)
        sets admin user. user with permission to edit all entries. other users can only modify their configuration
        Specified by:
        setAdminUser in interface IConfigurationsBC
        Parameters:
        adminUser -
      • setFieldSelection

        public void setFieldSelection​(DataRow fieldSelection)
        Description copied from interface: BusinessComponent
        Set a field selection to retrieve a custom set of fields.
        All fields will be returned if no field selection is set.
        Specified by:
        setFieldSelection in interface BusinessComponent
        Parameters:
        fieldSelection - a DataRow containing the field names for retrieving. Only the field names in the DataRow are used.
      • setFieldSelection

        public void setFieldSelection​(Collection<String> fieldSelection)
        Description copied from interface: BusinessComponent
        Set a field selection to retrieve a custom set of fields.
        The default scope will be used if no field selection is set.
        Specified by:
        setFieldSelection in interface BusinessComponent
        Parameters:
        fieldSelection - a String Collection containing the field names for retrieving.
      • setScope

        public void setScope​(String scope)
        Description copied from interface: BusinessComponent
        Set a field selection scope (A, B, C, etc.).
        If no or a wrong scope is set then all fields will be returned.
        Specified by:
        setScope in interface BusinessComponent
        Parameters:
        scope - the scope to set.
      • getKNUMValue

        protected DataRow getKNUMValue​(int knumIndex)
                                throws ParseException
        returns the modified filter where all key fields are removed and instead 2 fields are added
        -FILTER_VALUE
        -FILTER_KNUM
        FILTER_VALUE is the concatination of the key fields in the knum order, so the DataFileHandler can use it to query the file
        All key fields must be provided in the filter, otherwise an unmodified filter is returned.
        Parameters:
        knumIndex -
        Returns:
        Throws:
        ParseException
      • getKNUMString

        protected String getKNUMString​(int knumIndex,
                                       DataRow dr)
        concatenates the knum key and puts it in the right order. Used by getKNUMValue().
        Parameters:
        knumIndex -
        dr -
        Returns:
        See Also:
        getKNUMValue()
      • containsAllKNUMKeys

        protected boolean containsAllKNUMKeys​(DataRow dr)
        returns whether or not all key fields are provided in the data row
        Parameters:
        dr -
        Returns:
      • retrieve

        public ResultSet retrieve()
                           throws Exception
        Description copied from interface: BusinessComponent
        Retrieves a ResultSet with DataRow's.
        If a filter is set, this will be applied to filter the result.
        If a scope and/or a field selection is set, it will be used to retrieve the desired fields.
        Specified by:
        retrieve in interface BusinessComponent
        Returns:
        a ResultSet with DataRow's (may be empty).
        Throws:
        Exception - may occur during reading.
      • retrieve

        public ResultSet retrieve​(int first,
                                  int last)
                           throws Exception
        Description copied from interface: BusinessComponent
        Retrieves a ResultSet containing a subset of DataRow's (for pagination f.g.).
        If a filter is set, this will be applied to filter the result.
        If a scope and/or a field selection is set, it will be used to retrieve the desired fields.
        Specified by:
        retrieve in interface BusinessComponent
        Parameters:
        first - the index to start from (0 based).
        last - the index of the last element in the subset.
        Returns:
        a ResultSet with DataRow's (may be empty).
        Throws:
        Exception - may occur during reading.
      • validationErrorMessage

        protected DataRow validationErrorMessage​(String fieldName,
                                                 String type,
                                                 String message)
        generates error message for validation methods.
        Parameters:
        fieldName -
        type -
        message -
        Returns:
      • checkDataRowMustContainField

        protected void checkDataRowMustContainField​(DataRow dr,
                                                    ResultSet errorRS,
                                                    String fieldName)
        checks if the field is contained in the datarow, otherwise an error is added to the resultset
        Parameters:
        dr -
        errorRS -
        fieldName -
        See Also:
        checkEditableFieldsInDataRow()
      • checkDataRowMustNotContainField

        protected void checkDataRowMustNotContainField​(DataRow dr,
                                                       ResultSet errorRS,
                                                       String fieldName)
        checks if the field is NOT contained in the datarow, otherwise an error is added to the resultset
        Parameters:
        dr -
        errorRS -
        fieldName -
        See Also:
        checkEditableFieldsInDataRow()
      • checkEditableFieldsInDataRow

        protected void checkEditableFieldsInDataRow​(DataRow dr,
                                                    ResultSet errorRS,
                                                    boolean checkKeysOnly)
                                             throws Exception
        checks a data row if it violates the requirements as defined in the attributesRecord.
        For example if a field is a key, the dataRow must contain it.
        If it is read only, the dataRow must not contain it (That is, if 'checkKeysOnly' is false. In case of violation, an error is added in the error result set.
        Parameters:
        dr -
        errorRS -
        checkKeysOnly -
        Throws:
        Exception
      • validateWrite

        public ResultSet validateWrite​(DataRow dr)
        Validates a DataRow object before it can be written.
        This method is internally used by the write method.
        But it can also be called from the frontend to check for required or missing data.
        Specified by:
        validateWrite in interface BusinessComponent
        Parameters:
        dr - a DataRow to validated.
        Returns:
        a ResultSet with validation messages (empty ResultSet means no validation errors).
        Each DataRow in the ResultSet should have following fields: FIELD_NAME, TYPE and MESSAGE.
        FIELD_NAME: the name of the validated field
        TYPE: INFO, WARNING or ERROR
        MESSAGE: the validation message
      • throwValidation

        protected void throwValidation​(ResultSet validation)
                                throws Exception
        throws a validation error if the validation has failed. Does only affect methods where validation is called (e.g. write(), remove() etc.). The validate methods will instead return Boolean.FALSE
        Parameters:
        validation -
        Throws:
        Exception
      • find

        protected DataRow find​(DataRow dr)
                        throws ParseException
        Parameters:
        dr - dataRow containing knum fields
        Returns:
        returns empty dataRow if entry was not found, or the entry as dataRow if found
        Throws:
        ParseException
      • validateRemove

        public ResultSet validateRemove​(DataRow dr)
        validates datarow before removal. Does only check if main keys are provided, and NOT if record exists in the file.
        Specified by:
        validateRemove in interface BusinessComponent
        Parameters:
        dr - the DataRow that should be removed.
        Returns:
        a ResultSet with validation messages (empty ResultSet means no validation errors).
        Each DataRow in the ResultSet should have following fields: FIELD_NAME, TYPE and MESSAGE.
        FIELD_NAME: the name of the validated field
        TYPE: INFO, WARNING or ERROR
        MESSAGE: the validation message
      • canModify

        public Boolean canModify​(DataRow dr)
        returns true if this datarow can be modified. checks the username which is set with setUserName(). if the username does not equal the userid field in the datarow, this returns false, unless the adminuser is set. The admin user can modify all configurations.
        Specified by:
        canModify in interface IConfigurationsBC
        Parameters:
        dr -
        Returns:
      • getNewObjectTemplate

        public DataRow getNewObjectTemplate​(DataRow conditions)
        Description copied from interface: BusinessComponent
        Returns a new (predefined) DataRow including all field attributes (like field name, editable, label etc.).
        Specified by:
        getNewObjectTemplate in interface BusinessComponent
        Parameters:
        conditions - a DataRow with predefined fields.
        Returns:
        a new predefined DataRow with the field attributes.
      • getKeyFieldsOnly

        protected DataRow getKeyFieldsOnly​(DataRow dr)
                                    throws ParseException
        returns a DataRow with only the knum key fields from a given dataRow. if not all keys are present, adds them with empty value
        Parameters:
        dr -
        Returns:
        Throws:
        ParseException
      • getEffectiveConfiguration

        public ResultSet getEffectiveConfiguration()
        gets the effective configuration for a user. This means, if a configuration for a given user with given settings exist (as specified by the filter), then this configuration will be returned, otherwise a default configuration will be returned.
        Specified by:
        getEffectiveConfiguration in interface IConfigurationsBC
        Returns:
        ResultSet with the effective Configuration
      • printDebug

        protected void printDebug​(String s)
      • getAvailableConfigurations

        public ResultSet getAvailableConfigurations()
                                             throws Exception
        returns the available configurations the user can access with the current filter. conditions are: -only filtered realm -only filtered keyx -only when match with set userid OR default userid -ignore settings filter (all settings should be shown)
        Specified by:
        getAvailableConfigurations in interface IConfigurationsBC
        Returns:
        ResultSet with available Configurations
        Throws:
        Exception
      • getSharedConfigs

        public ResultSet getSharedConfigs()
                                   throws Exception
        returns the shared configurations the user can access with the current filter. conditions are: -only filtered realm -only filtered keyx -only configs NOT owned by user -shared with user via '*' -ignore settings filter (all settings should be shown)
        Specified by:
        getSharedConfigs in interface IConfigurationsBC
        Returns:
        ResultSet with available Configurations
        Throws:
        Exception
      • mergeResultSetsOnKeys

        protected ResultSet mergeResultSetsOnKeys​(ResultSet rs1,
                                                  ResultSet rs2)
        merges 2 resultsets
        Parameters:
        rs1 -
        rs2 -
        Returns:
      • main

        public static void main​(String[] args)
      • getScope

        public DataRow getScope()
      • getLookup

        public BusinessComponent getLookup​(String fieldName,
                                           DataRow dr)
        Description copied from interface: BusinessComponent
        returns a bc that contains data providing predefined values for a field. for example a lookup for a field "country" could return a countryBC which can retrieve values to fill a ListButton with. other fields are ignored.
        Specified by:
        getLookup in interface BusinessComponent
        Parameters:
        fieldName - the field to retrieve the Lookup for
        dr - current datarow
        Returns:
        the lookup BC
      • getLookupData

        public ResultSet getLookupData​(String fieldName,
                                       DataRow dr)
        Description copied from interface: BusinessComponent
        like getLookup, but instead returns a resultset containg the lookup data.
        Specified by:
        getLookupData in interface BusinessComponent
        Parameters:
        fieldName - the field to retrieve the Lookup for
        dr - current datarow
        Returns:
        the retrieved resultset from the lookup