@PostConstruct
  protected void registerDataSetDefinitions() {
    String jbpmDataSource = JpaSettings.get().getDataSourceJndiName();

    DataSetDef humanTasksDef =
        DataSetDefFactory.newSQLDataSetDef()
            .uuid(HUMAN_TASKS_DATASET)
            .name("Human tasks")
            .dataSource(jbpmDataSource)
            .dbTable("AuditTaskImpl", false)
            .date(COLUMN_ACTIVATIONTIME)
            .label(COLUMN_ACTUALOWNER)
            .label(COLUMN_CREATEDBY)
            .date(COLUMN_CREATEDON)
            .label(COLUMN_DEPLOYMENTID)
            .text(COLUMN_DESCRIPTION)
            .date(COLUMN_DUEDATE)
            .label(COLUMN_NAME)
            .number(COLUMN_PARENTID)
            .number(COLUMN_PRIORITY)
            .label(COLUMN_PROCESSID)
            .number(COLUMN_PROCESSINSTANCEID)
            .number(COLUMN_PROCESSSESSIONID)
            .label(COLUMN_STATUS)
            .number(COLUMN_TASKID)
            .number(COLUMN_WORKITEMID)
            .buildDef();

    DataSetDef humanTasksWithUserDef =
        DataSetDefFactory.newSQLDataSetDef()
            .uuid(HUMAN_TASKS_WITH_USER_DATASET)
            .name("Human tasks and users")
            .dataSource(jbpmDataSource)
            .dbSQL(
                "select  t.activationTime, t.actualOwner, t.createdBy, "
                    + "t.createdOn, t.deploymentId, t.description, t.dueDate, "
                    + "t.name, t.parentId, t.priority, t.processId, t.processInstanceId, "
                    + "t.processSessionId, t.status, t.taskId, t.workItemId, oe.id oeid "
                    + "from AuditTaskImpl t, "
                    + "PeopleAssignments_PotOwners po, "
                    + "OrganizationalEntity oe "
                    + "where t.taskId = po.task_id and po.entity_id = oe.id",
                false)
            .date(COLUMN_ACTIVATIONTIME)
            .label(COLUMN_ACTUALOWNER)
            .label(COLUMN_CREATEDBY)
            .date(COLUMN_CREATEDON)
            .label(COLUMN_DEPLOYMENTID)
            .text(COLUMN_DESCRIPTION)
            .date(COLUMN_DUEDATE)
            .label(COLUMN_NAME)
            .number(COLUMN_PARENTID)
            .number(COLUMN_PRIORITY)
            .label(COLUMN_PROCESSID)
            .number(COLUMN_PROCESSINSTANCEID)
            .number(COLUMN_PROCESSSESSIONID)
            .label(COLUMN_STATUS)
            .label(
                COLUMN_TASKID) // declaring as label(even though it's numeric) because needs apply
                               // groupby and  Group by number not supported
            .number(COLUMN_WORKITEMID)
            .label(COLUMN_ORGANIZATIONAL_ENTITY)
            .buildDef();

    DataSetDef humanTaskWithAdminDef =
        DataSetDefFactory.newSQLDataSetDef()
            .uuid(HUMAN_TASKS_WITH_ADMIN_DATASET)
            .name("Human tasks and admins")
            .dataSource(jbpmDataSource)
            .dbSQL(
                "select t.activationTime, t.actualOwner, t.createdBy, "
                    + "t.createdOn, t.deploymentId, t.description, t.dueDate, "
                    + "t.name, t.parentId, t.priority, t.processId, t.processInstanceId, "
                    + "t.processSessionId, t.status, t.taskId, t.workItemId, oe.id oeid "
                    + "from AuditTaskImpl t, "
                    + "PeopleAssignments_BAs bas, "
                    + "OrganizationalEntity oe "
                    + "where t.taskId = bas.task_id and bas.entity_id = oe.id",
                false)
            .date(COLUMN_ACTIVATIONTIME)
            .label(COLUMN_ACTUALOWNER)
            .label(COLUMN_CREATEDBY)
            .date(COLUMN_CREATEDON)
            .label(COLUMN_DEPLOYMENTID)
            .text(COLUMN_DESCRIPTION)
            .date(COLUMN_DUEDATE)
            .label(COLUMN_NAME)
            .number(COLUMN_PARENTID)
            .number(COLUMN_PRIORITY)
            .label(COLUMN_PROCESSID)
            .number(COLUMN_PROCESSINSTANCEID)
            .number(COLUMN_PROCESSSESSIONID)
            .label(COLUMN_STATUS)
            .label(
                COLUMN_TASKID) // declaring as label(even though it's numeric) because needs apply
                               // groupby and  Group by number not supported
            .number(COLUMN_WORKITEMID)
            .label(COLUMN_ORGANIZATIONAL_ENTITY)
            .buildDef();

    DataSetDef humanTasksWithUserDomainDef =
        DataSetDefFactory
            .newSQLDataSetDef() // Add to this dataset TaskName? to apply with the specified filter
            .uuid(HUMAN_TASKS_WITH_VARIABLES_DATASET)
            .name("Domain Specific Task")
            .dataSource(jbpmDataSource)
            .dbSQL(
                "select  tvi.taskId taskId ,\n"
                    + "       at.name name,\n"
                    + "       tvi.name varname,\n"
                    + "       tvi.value varvalue\n"
                    + " from TaskVariableImpl tvi,AuditTaskImpl at "
                    + " where tvi.taskId = at.taskId "
                    + " order by tvi.taskId, tvi.name ",
                false)
            .number(COLUMN_TASK_VARIABLE_TASKID)
            .label(COLUMN_TASK_VARIABLE_TASKNAME)
            .label(COLUMN_TASK_VARIABLE_NAME)
            .label(COLUMN_TASK_VARIABLE_VALUE)
            .buildDef();

    // Hide all these internal data set from end user view
    humanTasksDef.setPublic(false);
    humanTasksWithUserDef.setPublic(false);
    humanTaskWithAdminDef.setPublic(false);
    humanTasksWithUserDomainDef.setPublic(false);

    // Register the data set definitions
    dataSetDefRegistry.registerDataSetDef(humanTasksDef);
    dataSetDefRegistry.registerDataSetDef(humanTasksWithUserDef);
    dataSetDefRegistry.registerDataSetDef(humanTaskWithAdminDef);
    dataSetDefRegistry.registerDataSetDef(humanTasksWithUserDomainDef);
    logger.info("Human task datasets registered");
  }
  protected void registerDataSetDefinitions() {

    DataSetDef humanTasksDef =
        DataSetFactory.newSQLDataSetDef()
            .uuid(HUMAN_TASKS_DATASET)
            .name("Human tasks")
            .dataSource(jbpmDatasource)
            .dbTable(HUMAN_TASKS_TABLE, false)
            .date(DataSetTasksListGridViewImpl.COLUMN_ACTIVATIONTIME)
            .label(DataSetTasksListGridViewImpl.COLUMN_ACTUALOWNER)
            .label(DataSetTasksListGridViewImpl.COLUMN_CREATEDBY)
            .date(DataSetTasksListGridViewImpl.COLUMN_CREATEDON)
            .label(DataSetTasksListGridViewImpl.COLUMN_DEPLOYMENTID)
            .text(DataSetTasksListGridViewImpl.COLUMN_DESCRIPTION)
            .date(DataSetTasksListGridViewImpl.COLUMN_DUEDATE)
            .label(DataSetTasksListGridViewImpl.COLUMN_NAME)
            .number(DataSetTasksListGridViewImpl.COLUMN_PARENTID)
            .number(DataSetTasksListGridViewImpl.COLUMN_PRIORITY)
            .label(DataSetTasksListGridViewImpl.COLUMN_PROCESSID)
            .number(DataSetTasksListGridViewImpl.COLUMN_PROCESSINSTANCEID)
            .number(DataSetTasksListGridViewImpl.COLUMN_PROCESSSESSIONID)
            .label(DataSetTasksListGridViewImpl.COLUMN_STATUS)
            .number(DataSetTasksListGridViewImpl.COLUMN_TASKID)
            .number(DataSetTasksListGridViewImpl.COLUMN_WORKITEMID)
            .buildDef();

    DataSetDef humanTasksWithUserDef =
        DataSetFactory.newSQLDataSetDef()
            .uuid(HUMAN_TASKS_WITH_USER_DATASET)
            .name("Human tasks and users")
            .dataSource(jbpmDatasource)
            .dbSQL(
                "select  t.activationtime, t.actualowner, t.createdby, "
                    + "t.createdon, t.deploymentid, t.description, t.duedate, "
                    + "t.name, t.parentid, t.priority, t.processid, t.processinstanceid, "
                    + "t.processsessionid, t.status, t.taskid, t.workitemid, oe.id oeid "
                    + "from AuditTaskImpl t, "
                    + "peopleassignments_potowners po, "
                    + "organizationalentity oe "
                    + "where t.id = po.task_id and po.entity_id = oe.id",
                false)
            .date(DataSetTasksListGridViewImpl.COLUMN_ACTIVATIONTIME)
            .label(DataSetTasksListGridViewImpl.COLUMN_ACTUALOWNER)
            .label(DataSetTasksListGridViewImpl.COLUMN_CREATEDBY)
            .date(DataSetTasksListGridViewImpl.COLUMN_CREATEDON)
            .label(DataSetTasksListGridViewImpl.COLUMN_DEPLOYMENTID)
            .text(DataSetTasksListGridViewImpl.COLUMN_DESCRIPTION)
            .date(DataSetTasksListGridViewImpl.COLUMN_DUEDATE)
            .label(DataSetTasksListGridViewImpl.COLUMN_NAME)
            .number(DataSetTasksListGridViewImpl.COLUMN_PARENTID)
            .number(DataSetTasksListGridViewImpl.COLUMN_PRIORITY)
            .label(DataSetTasksListGridViewImpl.COLUMN_PROCESSID)
            .number(DataSetTasksListGridViewImpl.COLUMN_PROCESSINSTANCEID)
            .number(DataSetTasksListGridViewImpl.COLUMN_PROCESSSESSIONID)
            .label(DataSetTasksListGridViewImpl.COLUMN_STATUS)
            .label(
                DataSetTasksListGridViewImpl
                    .COLUMN_TASKID) // declaring as label(even though it's numeric) because needs
                                    // apply groupby and  Group by number not supported
            .number(DataSetTasksListGridViewImpl.COLUMN_WORKITEMID)
            .label(DataSetTasksListGridViewImpl.COLUMN_ORGANIZATIONAL_ENTITY)
            .buildDef();

    DataSetDef humanTaskWithAdminDef =
        DataSetFactory.newSQLDataSetDef()
            .uuid(HUMAN_TASKS_WITH_ADMIN_DATASET)
            .name("Human tasks and admins")
            .dataSource(jbpmDatasource)
            .dbSQL(
                "select t.activationtime, t.actualowner, t.createdby, "
                    + "t.createdon, t.deploymentid, t.description, t.duedate, "
                    + "t.name, t.parentid, t.priority, t.processid, t.processinstanceid, "
                    + "t.processsessionid, t.status, t.taskid, t.workitemid, oe.id oeid "
                    + "from AuditTaskImpl t, "
                    + "peopleassignments_bas bas, "
                    + "organizationalentity oe "
                    + "where t.id = bas.task_id and bas.entity_id = oe.id",
                false)
            .date(DataSetTasksListGridViewImpl.COLUMN_ACTIVATIONTIME)
            .label(DataSetTasksListGridViewImpl.COLUMN_ACTUALOWNER)
            .label(DataSetTasksListGridViewImpl.COLUMN_CREATEDBY)
            .date(DataSetTasksListGridViewImpl.COLUMN_CREATEDON)
            .label(DataSetTasksListGridViewImpl.COLUMN_DEPLOYMENTID)
            .text(DataSetTasksListGridViewImpl.COLUMN_DESCRIPTION)
            .date(DataSetTasksListGridViewImpl.COLUMN_DUEDATE)
            .label(DataSetTasksListGridViewImpl.COLUMN_NAME)
            .number(DataSetTasksListGridViewImpl.COLUMN_PARENTID)
            .number(DataSetTasksListGridViewImpl.COLUMN_PRIORITY)
            .label(DataSetTasksListGridViewImpl.COLUMN_PROCESSID)
            .number(DataSetTasksListGridViewImpl.COLUMN_PROCESSINSTANCEID)
            .number(DataSetTasksListGridViewImpl.COLUMN_PROCESSSESSIONID)
            .label(DataSetTasksListGridViewImpl.COLUMN_STATUS)
            .label(
                DataSetTasksListGridViewImpl
                    .COLUMN_TASKID) // declaring as label(even though it's numeric) because needs
                                    // apply groupby and  Group by number not supported
            .number(DataSetTasksListGridViewImpl.COLUMN_WORKITEMID)
            .label(DataSetTasksListGridViewImpl.COLUMN_ORGANIZATIONAL_ENTITY)
            .buildDef();

    DataSetDef processesWithVariablesDef =
        DataSetFactory.newSQLDataSetDef()
            .uuid(PROCESS_INSTANCE_WITH_VARIABLES_DATASET)
            .name("Domain Specific Process Instances")
            .dataSource(jbpmDatasource)
            .dbSQL(
                "select pil.processInstanceId pid,\n"
                    + "       pil.processId pname,\n"
                    + "       v.id varid,\n"
                    + "       v.variableId varname,\n"
                    + "       v.value varvalue\n"
                    + "from ProcessInstancelog pil\n"
                    + "  inner join (select vil.processInstanceId ,vil.variableId, MAX(vil.ID) maxvilid  FROM VariableInstanceLog vil\n"
                    + "  GROUP BY vil.processInstanceId, vil.variableId)  x\n"
                    + "    on (x.processInstanceId =pil.processInstanceId)\n"
                    + "  INNER JOIN VariableInstanceLog v\n"
                    + "    ON (v.variableId = x.variableId  AND v.id = x.maxvilid )",
                false)
            .number("pid")
            .label("pname")
            .number("varid")
            .label("varname")
            .label("varvalue")
            .buildDef();

    // Hide all these internal data set from end user view
    humanTasksDef.setPublic(false);
    humanTasksWithUserDef.setPublic(false);
    humanTaskWithAdminDef.setPublic(false);
    processesWithVariablesDef.setPublic(false);

    // Register the data set definitions
    dataSetDefRegistry.registerDataSetDef(humanTasksDef);
    dataSetDefRegistry.registerDataSetDef(humanTasksWithUserDef);
    dataSetDefRegistry.registerDataSetDef(humanTaskWithAdminDef);
    dataSetDefRegistry.registerDataSetDef(processesWithVariablesDef);
  }