Class QueryUtil

java.lang.Object
com.almis.awe.config.ServiceConfig
com.almis.awe.model.util.data.QueryUtil
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware

public class QueryUtil extends ServiceConfig
Abstract query builder
  • Constructor Details

    • QueryUtil

      public QueryUtil(BaseConfigProperties baseConfigProperties, DatabaseConfigProperties databaseConfigProperties)
      QueryUtil constructor
      Parameters:
      baseConfigProperties - Base config properties
      databaseConfigProperties - Database config properties
  • Method Details

    • getSortList

      public List<SortColumn> getSortList(com.fasterxml.jackson.databind.node.ArrayNode sortArrayNode)
      Generate sort list
      Parameters:
      sortArrayNode - Sort parameter
      Returns:
      Query parameter map
    • getDefaultVariableMap

      public Map<String,QueryParameter> getDefaultVariableMap(com.fasterxml.jackson.databind.node.ObjectNode parameters)
      Prepare query variables if not defined previously
      Parameters:
      parameters - Parameter list
      Returns:
      Query parameter map
    • getVariableMap

      public Map<String,QueryParameter> getVariableMap(List<Variable> variables, com.fasterxml.jackson.databind.node.ObjectNode parameters, Integer index) throws AWException
      Prepare query variables if not defined previously
      Parameters:
      variables - Variable map
      parameters - Parameter list
      index - Index
      Returns:
      Query parameter map
      Throws:
      AWException - Error generating variables
    • getVariableMap

      public Map<String,QueryParameter> getVariableMap(Query query, com.fasterxml.jackson.databind.node.ObjectNode parameters) throws AWException
      Prepare query variables if not defined previously
      Parameters:
      query - Query
      parameters - Parameter list
      Returns:
      Query parameter map
      Throws:
      AWException - Error generating variables
    • addToVariableMap

      public void addToVariableMap(Map<String,QueryParameter> variableMap, Query query, com.fasterxml.jackson.databind.node.ObjectNode parameters) throws AWException
      Prepare query variables if not defined previously
      Parameters:
      variableMap - Variable map
      query - Query
      Throws:
      AWException - Error generating variables
    • addDataListToRequestParameters

      public void addDataListToRequestParameters(DataList dataList, com.fasterxml.jackson.databind.node.ObjectNode parameters)
      Prepare query variables if not defined previously
      Parameters:
      dataList - DataList
    • getVariableMap

      public Map<String,QueryParameter> getVariableMap(MaintainQuery query, com.fasterxml.jackson.databind.node.ObjectNode parameters) throws AWException
      Get variable map for a single index without lists
      Parameters:
      query - Query
      parameters - Parameter map
      Returns:
      Query parameter map
      Throws:
      AWException - Error generating variables
    • getVariableMap

      public Map<String,QueryParameter> getVariableMap(Query query, String page, String max) throws AWException
      Prepare query variables if not defined previously
      Parameters:
      query - Query
      page - Page number
      max - Max elements per page
      Returns:
      Query parameter map
      Throws:
      AWException - Error generating variables
    • getParameters

      public com.fasterxml.jackson.databind.node.ObjectNode getParameters()
      Prepare query variables if not defined previously
      Returns:
      Query parameter map
    • getParameters

      public com.fasterxml.jackson.databind.node.ObjectNode getParameters(com.fasterxml.jackson.databind.node.ObjectNode parameters)
      Prepare query variables if not defined previously
      Parameters:
      parameters - Parameters
      Returns:
      Query parameter map
    • getParameters

      public com.fasterxml.jackson.databind.node.ObjectNode getParameters(String alias, String page, String max)
      Prepare query variables if not defined previously
      Parameters:
      alias - Database alias
      page - Page number
      max - Max elements per page
      Returns:
      Query parameter map
    • getParameters

      public com.fasterxml.jackson.databind.node.ObjectNode getParameters(String alias)
      Prepare query variables if not defined previously
      Parameters:
      alias - Database alias
      Returns:
      Query parameter map
    • getParameters

      public com.fasterxml.jackson.databind.node.ObjectNode getParameters(@NonNull @NonNull com.fasterxml.jackson.databind.node.ObjectNode parameters, String alias, String page, String max)
      Prepare query variables if not defined previously
      Parameters:
      parameters - Parameters
      alias - Query alias
      page - Page number
      max - Max elements per page
      Returns:
      Query parameter map
    • getVariableMap

      public Map<String,QueryParameter> getVariableMap(String page, String max) throws AWException
      Prepare query variables if not defined previously
      Parameters:
      page - Page number
      max - Max elements per page
      Returns:
      Query parameter map
      Throws:
      AWException - Error generating variables
    • getParameter

      public com.fasterxml.jackson.databind.JsonNode getParameter(Variable variable, com.fasterxml.jackson.databind.node.ObjectNode parameters) throws AWException
      Retrieve parameter
      Parameters:
      variable - Variable
      parameters - Parameters
      Returns:
      Parameter
      Throws:
      AWException - Error retrieving variable value
    • getParameter

      public com.fasterxml.jackson.databind.JsonNode getParameter(String stringValue, com.fasterxml.jackson.databind.JsonNode parameter, ParameterType type, String variableId) throws AWException
      Retrieve parameter as Json
      Parameters:
      stringValue - String value
      parameter - Parameter
      type - Type
      variableId - Variable id
      Returns:
      Parameter as JSON
      Throws:
      AWException - Error retrieving variable value
    • getRequestParameter

      public com.fasterxml.jackson.databind.JsonNode getRequestParameter(String name, com.fasterxml.jackson.databind.node.ObjectNode parameters)
      Retrieve parameter from request
      Parameters:
      name - Parameter name
      parameters - Parameters list
      Returns:
      Parameter
    • getRequestParameter

      public com.fasterxml.jackson.databind.JsonNode getRequestParameter(String name)
      Retrieve parameter from request
      Parameters:
      name - Parameter name
      Returns:
      Parameter
    • variableIsList

      public boolean variableIsList(@NonNull @NonNull Variable variable, com.fasterxml.jackson.databind.node.ObjectNode parameters) throws AWException
      Finds out if a variable value is a list
      Parameters:
      variable - Variable
      parameters - Parameters
      Returns:
      isList
      Throws:
      AWException - AWE exception
    • isEmptyString

      public boolean isEmptyString(String value)
      Check if a string variable is empty or not
      Parameters:
      value - String value
      Returns:
      String is null or empty
    • isNullString

      public boolean isNullString(String value)
      Check if a string variable is null or not
      Parameters:
      value - String value
      Returns:
      String is null or empty
    • isEmptyVariable

      public boolean isEmptyVariable(com.fasterxml.jackson.databind.JsonNode variable)
      Check if a json node variable is empty or not
      Parameters:
      variable - Variable as json
      Returns:
      Variable is empty
    • isNullVariable

      public boolean isNullVariable(com.fasterxml.jackson.databind.JsonNode variable)
      Check if a json node variable is null or not
      Parameters:
      variable - Variable as json
      Returns:
      Variable is null
    • isEmptyParameter

      public boolean isEmptyParameter(QueryParameter parameter)
      Check if a parameter variable is empty or not
      Parameters:
      parameter - Variable as json
      Returns:
      Variable is empty
    • getDatabaseAlias

      public String getDatabaseAlias(Map<String,QueryParameter> parameters)
      Retrieve database alias
      Parameters:
      parameters - Query parameters
      Returns:
      Database alias
    • getFullSQL

      public String getFullSQL(String sql, List<Object> parameters)
      Retrieve full sql statement as string
      Parameters:
      sql - SQL Statement
      parameters - Parameter list
      Returns:
      SQL statement