Package org.openbravo.service.datasource
Class TreeDatasourceService
- java.lang.Object
-
- org.openbravo.service.datasource.BaseDataSourceService
-
- org.openbravo.service.datasource.DefaultDataSourceService
-
- org.openbravo.service.datasource.TreeDatasourceService
-
- All Implemented Interfaces:
DataSourceService
- Direct Known Subclasses:
ADTreeDatasourceService
,LinkToParentTreeDatasourceService
public abstract class TreeDatasourceService extends DefaultDataSourceService
The TreeDatasourceService is an abstract class that provides a simple way of returning data in the correct format for a OBTreeGrid client side component using a datasource.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
TreeDatasourceService.CycleInHierarchyException
Exception thrown when the a cycle is detected in the data to be returned by the datasourceprotected class
TreeDatasourceService.MultipleParentsException
Exception thrown when an operation can not be done upon a node that has several parentsprotected class
TreeDatasourceService.TooManyTreeNodesException
Exception thrown when the number of records returned by the datasource is higher than the defined limit
-
Field Summary
Fields Modifier and Type Field Description protected static String
ROOT_NODE_CLIENT
protected static String
ROOT_NODE_DB
-
Constructor Summary
Constructors Constructor Description TreeDatasourceService()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description String
add(Map<String,String> parameters, String content)
This method is called when a new record is created in a tree table.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 tableprotected 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 implementationvoid
checkEditDatasourceAccess(Map<String,String> parameter)
This method allows to implement a security access to a DataSource when it is used add(), update() or remove() methods.void
checkFetchDatasourceAccess(Map<String,String> parameter)
This method allows to implement a security access to a DataSource when it is used fetch() method.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 tableString
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 userprotected abstract org.codehaus.jettison.json.JSONArray
fetchFilteredNodesForTreesWithMultiParentNodes(Map<String,String> parameters, Map<String,Object> datasourceParameters, TableTree tableTree, List<String> filteredNodes, String hqlTreeWhereClause, String hqlTreeWhereClauseRootNodes, boolean allowNotApplyingWhereClauseToChildren)
protected abstract org.codehaus.jettison.json.JSONArray
fetchNodeChildren(Map<String,String> parameters, Map<String,Object> datasourceParameters, String parentId, String hqlWhereClause, String hqlWhereClauseRootNodes)
protected abstract Map<String,Object>
getDatasourceSpecificParams(Map<String,String> parameters)
protected Entity
getEntity(org.codehaus.jettison.json.JSONObject bobProperties)
protected abstract org.codehaus.jettison.json.JSONObject
getJSONObjectByNodeId(Map<String,String> parameters, Map<String,Object> datasourceParameters, String nodeId)
protected abstract org.codehaus.jettison.json.JSONObject
getJSONObjectByRecordId(Map<String,String> parameters, Map<String,Object> datasourceParameters, String nodeId)
protected 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 criteriaprotected abstract org.codehaus.jettison.json.JSONObject
moveNode(Map<String,String> parameters, String nodeId, String newParentId, String prevNodeId, String nextNodeId)
protected abstract boolean
nodeConformsToWhereClause(TableTree tableTree, String nodeId, String hqlWhereClause)
Method that checks if a node conforms to a hqlWhereClauseprotected 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 tableString
remove(Map<String,String> parameters)
This method is called when a new record is deleted in a tree table.protected String
substituteParameters(String hqlTreeWhereClause, Map<String,String> parameters)
If a where clause contains parameters, substitute the parameter with the actual valueString
update(Map<String,String> parameters, String content)
Execute an update action.-
Methods inherited from class org.openbravo.service.datasource.DefaultDataSourceService
add, addFetchParameters, fetch, fetch, getDataSourceProperties, getInitialProperties, remove
-
Methods inherited from class org.openbravo.service.datasource.BaseDataSourceService
getDataSource, getDataUrl, getEntity, getName, getTemplate, getWhereAndFilterClause, getWhereClause, handleExceptionUnsecuredDSAccess, setDataSource, setDataUrl, setEntity, setName, setWhereClause
-
-
-
-
Field Detail
-
ROOT_NODE_DB
protected static final String ROOT_NODE_DB
- See Also:
- Constant Field Values
-
ROOT_NODE_CLIENT
protected static final String ROOT_NODE_CLIENT
- See Also:
- Constant Field Values
-
-
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 interfaceDataSourceService
- Overrides:
add
in classDefaultDataSourceService
- Parameters:
parameters
- the parameters often coming from the HTTP requestcontent
- , 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 interfaceDataSourceService
- Overrides:
remove
in classDefaultDataSourceService
- Parameters:
parameters
- the parameters often coming from the HTTP request- Returns:
- the result message as a json string
-
checkEditDatasourceAccess
public void checkEditDatasourceAccess(Map<String,String> parameter)
Description copied from interface:DataSourceService
This method allows to implement a security access to a DataSource when it is used add(), update() or remove() methods. It can be overridden in specific DataSources to apply a particular security mechanism.- Specified by:
checkEditDatasourceAccess
in interfaceDataSourceService
- Overrides:
checkEditDatasourceAccess
in classBaseDataSourceService
-
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 interfaceDataSourceService
- Overrides:
fetch
in classDefaultDataSourceService
- Parameters:
parameters
- the parameters often coming from the HTTP request- Returns:
- the json result string
-
checkFetchDatasourceAccess
public void checkFetchDatasourceAccess(Map<String,String> parameter)
Description copied from interface:DataSourceService
This method allows to implement a security access to a DataSource when it is used fetch() method. It can be overridden in specific DataSources to apply a particular security mechanism.- Specified by:
checkFetchDatasourceAccess
in interfaceDataSourceService
- Overrides:
checkFetchDatasourceAccess
in classBaseDataSourceService
-
getDatasourceSpecificParams
protected abstract Map<String,Object> getDatasourceSpecificParams(Map<String,String> parameters)
-
fetchFilteredNodesForTreesWithMultiParentNodes
protected abstract org.codehaus.jettison.json.JSONArray fetchFilteredNodesForTreesWithMultiParentNodes(Map<String,String> parameters, Map<String,Object> datasourceParameters, TableTree tableTree, List<String> filteredNodes, String hqlTreeWhereClause, String hqlTreeWhereClauseRootNodes, boolean allowNotApplyingWhereClauseToChildren) throws TreeDatasourceService.MultipleParentsException, TreeDatasourceService.TooManyTreeNodesException
-
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 treenodeId
- id of the node to be checkedhqlWhereClause
- 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/selectorparameters
-- 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 requestdatasourceParameters
- specific datasource parameters obtained using methodgetDatasourceSpecificParams(Map)
nodeId
- id of the tree node- Returns:
- returns a json object with the definition of a node give its record id
-
getJSONObjectByNodeId
protected abstract org.codehaus.jettison.json.JSONObject getJSONObjectByNodeId(Map<String,String> parameters, Map<String,Object> datasourceParameters, String nodeId) throws TreeDatasourceService.MultipleParentsException
- Parameters:
parameters
- a map with the parameters of the requestdatasourceParameters
- specific datasource parameters obtained using methodgetDatasourceSpecificParams(Map)
nodeId
- id of the tree node- Returns:
- returns a json object with the definition of a node give its node id
- Throws:
TreeDatasourceService.MultipleParentsException
-
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 requestdatasourceParameters
- specific datasource parametersparentId
- id of the node whose children are to be retrievedhqlWhereClause
- hql where clase of the tab/selectorhqlWhereClauseRootNodes
- 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
-
update
public final String update(Map<String,String> parameters, String content)
Description copied from interface:DataSourceService
Execute an update action.- Specified by:
update
in interfaceDataSourceService
- Overrides:
update
in classDefaultDataSourceService
- Parameters:
parameters
- the parameters often coming from the HTTP requestcontent
- , the request content, is assumed to be a json string- Returns:
- the result message as a json string
-
moveNode
protected abstract org.codehaus.jettison.json.JSONObject moveNode(Map<String,String> parameters, String nodeId, String newParentId, String prevNodeId, String nextNodeId) throws Exception
- Throws:
Exception
-
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 treebob
- BaseOBObject representation of the nodenode
- 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 propertyparentPropertyName
- 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
-
-