Class TreeDatasourceService

    • Constructor Detail

      • TreeDatasourceService

        public TreeDatasourceService()
    • Method Detail

      • add

        public final String add​(Map<String,​String> parameters,
                                String content)
        This method is called when a new record is created in a tree table. It calls the addNewNode abstract method, which is implemented in the classes that extend TreeDatasourceService
        Specified by:
        add in interface DataSourceService
        Overrides:
        add in class DefaultDataSourceService
        Parameters:
        parameters - the parameters often coming from the HTTP request
        content - , the request content, is assumed to be a json string
        Returns:
        the result message as a json string
      • addNewNode

        protected abstract void addNewNode​(org.codehaus.jettison.json.JSONObject bobProperties)
        Classes that extend TreeDatasourceService this method must implement this method to handle the creation of a node in a tree table
      • remove

        public final String remove​(Map<String,​String> parameters)
        This method is called when a new record is deleted in a tree table. It calls the deleteNode abstract method, which is implemented in the classes that extend TreeDatasourceService
        Specified by:
        remove in interface DataSourceService
        Overrides:
        remove in class DefaultDataSourceService
        Parameters:
        parameters - the parameters often coming from the HTTP request
        Returns:
        the result message as a json string
      • deleteNode

        protected abstract void deleteNode​(org.codehaus.jettison.json.JSONObject bobProperties)
        Classes that extend TreeDatasourceService this method must implement this method to handle the deletion of a node in a tree table
      • nodeHasChildren

        protected boolean nodeHasChildren​(Entity entity,
                                          String nodeId,
                                          String hqlWhereClause)
        Classes that extend TreeDatasourceService this method must implement this method to handle the check if a node has children in a tree table
      • fetch

        public final String fetch​(Map<String,​String> parameters)
        Fetches some tree nodes Two operation modes: - If a criteria is included in the parameters, this method will return the nodes that conform to the criteria plus all its parent until reaching the root nodes - Otherwise, the child nodes of a given node (its node id included in the parameters) are returned Either the tabId (when it is called from a tree window) or the treeReferenceId (when called from a tree reference) must be included in the parameters If the datasource were to return a number of nodes higher than the limit (defined in the TreeDatasourceFetchLimit preference), an empty data is returned and an error is shown to the user
        Specified by:
        fetch in interface DataSourceService
        Overrides:
        fetch in class DefaultDataSourceService
        Parameters:
        parameters - the parameters often coming from the HTTP request
        Returns:
        the json result string
      • nodeConformsToWhereClause

        protected abstract boolean nodeConformsToWhereClause​(TableTree tableTree,
                                                             String nodeId,
                                                             String hqlWhereClause)
        Method that checks if a node conforms to a hqlWhereClause
        Parameters:
        tableTree - tableTree that defines the tree category that defines the tree
        nodeId - id of the node to be checked
        hqlWhereClause - hql where clause to be applied
      • substituteParameters

        protected String substituteParameters​(String hqlTreeWhereClause,
                                              Map<String,​String> parameters)
        If a where clause contains parameters, substitute the parameter with the actual value
        Parameters:
        hqlTreeWhereClause - the original where clause as defined in the tab/selector
        parameters -
        Returns:
        the updated where clause, having replaced the parameters with their actual values
      • getJSONObjectByRecordId

        protected abstract org.codehaus.jettison.json.JSONObject getJSONObjectByRecordId​(Map<String,​String> parameters,
                                                                                         Map<String,​Object> datasourceParameters,
                                                                                         String nodeId)
        Parameters:
        parameters - a map with the parameters of the request
        datasourceParameters - specific datasource parameters obtained using method getDatasourceSpecificParams(Map)
        nodeId - id of the tree node
        Returns:
        returns a json object with the definition of a node give its record id
      • fetchNodeChildren

        protected abstract org.codehaus.jettison.json.JSONArray fetchNodeChildren​(Map<String,​String> parameters,
                                                                                  Map<String,​Object> datasourceParameters,
                                                                                  String parentId,
                                                                                  String hqlWhereClause,
                                                                                  String hqlWhereClauseRootNodes)
                                                                           throws org.codehaus.jettison.json.JSONException,
                                                                                  TreeDatasourceService.TooManyTreeNodesException
        Parameters:
        parameters - a map with the parameters of the request
        datasourceParameters - specific datasource parameters
        parentId - id of the node whose children are to be retrieved
        hqlWhereClause - hql where clase of the tab/selector
        hqlWhereClauseRootNodes - hql where clause that define what nodes are roots
        Throws:
        org.codehaus.jettison.json.JSONException
        TreeDatasourceService.TooManyTreeNodesException - if the number of returned nodes were to be too high
      • getEntity

        protected Entity getEntity​(org.codehaus.jettison.json.JSONObject bobProperties)
                            throws org.codehaus.jettison.json.JSONException
        Throws:
        org.codehaus.jettison.json.JSONException
      • addNodeCommonAttributes

        protected final void addNodeCommonAttributes​(Entity entity,
                                                     BaseOBObject bob,
                                                     org.codehaus.jettison.json.JSONObject node)
        Adds to a json representation of a node some attributes that are common to all trees regardless of its particular implementation
        Parameters:
        entity - entity of the table associated with the tree
        bob - BaseOBObject representation of the node
        node - JSONObject representation of the node. The common attributes will be added to this object
      • getParentRecordIdFromCriteria

        protected final String getParentRecordIdFromCriteria​(org.codehaus.jettison.json.JSONArray criteria,
                                                             String parentPropertyName)
        Given a criteria and the name of a property, returns the value of that property in the criteria
        Parameters:
        criteria - the criteria that might contain a value for the provided property
        parentPropertyName - the property whose value might be contained in the criteria
        Returns:
        the value of the property in the criteria, or null if it is not found