@Test public void getStatisticsWorksWithModifiedLimits() { WorkflowInstance i1 = constructWorkflowInstanceBuilder().setNextActivation(null).build(); instanceDao.insertWorkflowInstance(i1); Map<String, Map<String, WorkflowDefinitionStatistics>> stats = statisticsDao.getWorkflowDefinitionStatistics(i1.type, null, null, now().plusDays(1), now().plusDays(2)); assertThat(stats.size(), is(0)); }
public Map<String, Map<String, WorkflowDefinitionStatistics>> getWorkflowDefinitionStatistics(String type, DateTime createdAfter, DateTime createdBefore, DateTime modifiedAfter, DateTime modifiedBefore) { String executorGroup = executorInfo.getExecutorGroup(); List<Object> argsList = new ArrayList<>(); argsList.addAll(asList(executorGroup, type)); StringBuilder whereBuilder = new StringBuilder(); if (createdAfter != null) { whereBuilder.append(" and created >= ?"); argsList.add(createdAfter.toDate()); } if (createdBefore != null) { whereBuilder.append(" and created < ?"); argsList.add(createdBefore.toDate()); } if (modifiedAfter != null) { whereBuilder.append(" and modified >= ?"); argsList.add(modifiedAfter.toDate()); } if (modifiedBefore != null) { whereBuilder.append(" and modified < ?"); argsList.add(modifiedBefore.toDate()); } String where = whereBuilder.toString(); StringBuilder sqlBuilder = new StringBuilder("select state, status, count(*) all_instances,") .append(" count(case when next_activation < current_timestamp then 1 else null end) queued_instances") .append(" from nflow_workflow where executor_group = ? and type = ?").append(where).append(" group by state, status"); String query = sqlBuilder.toString(); Object[] argsArray = argsList.toArray(new Object[argsList.size()]); final Map<String, Map<String, WorkflowDefinitionStatistics>> stats = new LinkedHashMap<>(); jdbc.query(query, argsArray, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { String state = rs.getString("state"); Map<String, WorkflowDefinitionStatistics> stateStats = stats.get(state); if (stateStats == null) { stateStats = new LinkedHashMap<>(); stats.put(state, stateStats); } String status = rs.getString("status"); WorkflowDefinitionStatistics statusStats = new WorkflowDefinitionStatistics(); statusStats.allInstances = rs.getLong("all_instances"); statusStats.queuedInstances = rs.getLong("queued_instances"); stateStats.put(status, statusStats); } }); return stats; }
StatisticsDao { public Map<String, Map<String, WorkflowDefinitionStatistics>> getWorkflowDefinitionStatistics(String type, DateTime createdAfter, DateTime createdBefore, DateTime modifiedAfter, DateTime modifiedBefore) { String executorGroup = executorInfo.getExecutorGroup(); List<Object> argsList = new ArrayList<>(); argsList.addAll(asList(executorGroup, type)); StringBuilder whereBuilder = new StringBuilder(); if (createdAfter != null) { whereBuilder.append(" and created >= ?"); argsList.add(createdAfter.toDate()); } if (createdBefore != null) { whereBuilder.append(" and created < ?"); argsList.add(createdBefore.toDate()); } if (modifiedAfter != null) { whereBuilder.append(" and modified >= ?"); argsList.add(modifiedAfter.toDate()); } if (modifiedBefore != null) { whereBuilder.append(" and modified < ?"); argsList.add(modifiedBefore.toDate()); } String where = whereBuilder.toString(); StringBuilder sqlBuilder = new StringBuilder("select state, status, count(*) all_instances,") .append(" count(case when next_activation < current_timestamp then 1 else null end) queued_instances") .append(" from nflow_workflow where executor_group = ? and type = ?").append(where).append(" group by state, status"); String query = sqlBuilder.toString(); Object[] argsArray = argsList.toArray(new Object[argsList.size()]); final Map<String, Map<String, WorkflowDefinitionStatistics>> stats = new LinkedHashMap<>(); jdbc.query(query, argsArray, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { String state = rs.getString("state"); Map<String, WorkflowDefinitionStatistics> stateStats = stats.get(state); if (stateStats == null) { stateStats = new LinkedHashMap<>(); stats.put(state, stateStats); } String status = rs.getString("status"); WorkflowDefinitionStatistics statusStats = new WorkflowDefinitionStatistics(); statusStats.allInstances = rs.getLong("all_instances"); statusStats.queuedInstances = rs.getLong("queued_instances"); stateStats.put(status, statusStats); } }); return stats; } }
StatisticsDao { public Map<String, Map<String, WorkflowDefinitionStatistics>> getWorkflowDefinitionStatistics(String type, DateTime createdAfter, DateTime createdBefore, DateTime modifiedAfter, DateTime modifiedBefore) { String executorGroup = executorInfo.getExecutorGroup(); List<Object> argsList = new ArrayList<>(); argsList.addAll(asList(executorGroup, type)); StringBuilder whereBuilder = new StringBuilder(); if (createdAfter != null) { whereBuilder.append(" and created >= ?"); argsList.add(createdAfter.toDate()); } if (createdBefore != null) { whereBuilder.append(" and created < ?"); argsList.add(createdBefore.toDate()); } if (modifiedAfter != null) { whereBuilder.append(" and modified >= ?"); argsList.add(modifiedAfter.toDate()); } if (modifiedBefore != null) { whereBuilder.append(" and modified < ?"); argsList.add(modifiedBefore.toDate()); } String where = whereBuilder.toString(); StringBuilder sqlBuilder = new StringBuilder("select state, status, count(*) all_instances,") .append(" count(case when next_activation < current_timestamp then 1 else null end) queued_instances") .append(" from nflow_workflow where executor_group = ? and type = ?").append(where).append(" group by state, status"); String query = sqlBuilder.toString(); Object[] argsArray = argsList.toArray(new Object[argsList.size()]); final Map<String, Map<String, WorkflowDefinitionStatistics>> stats = new LinkedHashMap<>(); jdbc.query(query, argsArray, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { String state = rs.getString("state"); Map<String, WorkflowDefinitionStatistics> stateStats = stats.get(state); if (stateStats == null) { stateStats = new LinkedHashMap<>(); stats.put(state, stateStats); } String status = rs.getString("status"); WorkflowDefinitionStatistics statusStats = new WorkflowDefinitionStatistics(); statusStats.allInstances = rs.getLong("all_instances"); statusStats.queuedInstances = rs.getLong("queued_instances"); stateStats.put(status, statusStats); } }); return stats; } @Inject  StatisticsDao(@NFlow JdbcTemplate jdbcTemplate, ExecutorDao executorDao); }
StatisticsDao { public Map<String, Map<String, WorkflowDefinitionStatistics>> getWorkflowDefinitionStatistics(String type, DateTime createdAfter, DateTime createdBefore, DateTime modifiedAfter, DateTime modifiedBefore) { String executorGroup = executorInfo.getExecutorGroup(); List<Object> argsList = new ArrayList<>(); argsList.addAll(asList(executorGroup, type)); StringBuilder whereBuilder = new StringBuilder(); if (createdAfter != null) { whereBuilder.append(" and created >= ?"); argsList.add(createdAfter.toDate()); } if (createdBefore != null) { whereBuilder.append(" and created < ?"); argsList.add(createdBefore.toDate()); } if (modifiedAfter != null) { whereBuilder.append(" and modified >= ?"); argsList.add(modifiedAfter.toDate()); } if (modifiedBefore != null) { whereBuilder.append(" and modified < ?"); argsList.add(modifiedBefore.toDate()); } String where = whereBuilder.toString(); StringBuilder sqlBuilder = new StringBuilder("select state, status, count(*) all_instances,") .append(" count(case when next_activation < current_timestamp then 1 else null end) queued_instances") .append(" from nflow_workflow where executor_group = ? and type = ?").append(where).append(" group by state, status"); String query = sqlBuilder.toString(); Object[] argsArray = argsList.toArray(new Object[argsList.size()]); final Map<String, Map<String, WorkflowDefinitionStatistics>> stats = new LinkedHashMap<>(); jdbc.query(query, argsArray, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { String state = rs.getString("state"); Map<String, WorkflowDefinitionStatistics> stateStats = stats.get(state); if (stateStats == null) { stateStats = new LinkedHashMap<>(); stats.put(state, stateStats); } String status = rs.getString("status"); WorkflowDefinitionStatistics statusStats = new WorkflowDefinitionStatistics(); statusStats.allInstances = rs.getLong("all_instances"); statusStats.queuedInstances = rs.getLong("queued_instances"); stateStats.put(status, statusStats); } }); return stats; } @Inject  StatisticsDao(@NFlow JdbcTemplate jdbcTemplate, ExecutorDao executorDao); Statistics getQueueStatistics(); Map<String, Map<String, WorkflowDefinitionStatistics>> getWorkflowDefinitionStatistics(String type,
      DateTime createdAfter, DateTime createdBefore, DateTime modifiedAfter, DateTime modifiedBefore); }
StatisticsDao { public Map<String, Map<String, WorkflowDefinitionStatistics>> getWorkflowDefinitionStatistics(String type, DateTime createdAfter, DateTime createdBefore, DateTime modifiedAfter, DateTime modifiedBefore) { String executorGroup = executorInfo.getExecutorGroup(); List<Object> argsList = new ArrayList<>(); argsList.addAll(asList(executorGroup, type)); StringBuilder whereBuilder = new StringBuilder(); if (createdAfter != null) { whereBuilder.append(" and created >= ?"); argsList.add(createdAfter.toDate()); } if (createdBefore != null) { whereBuilder.append(" and created < ?"); argsList.add(createdBefore.toDate()); } if (modifiedAfter != null) { whereBuilder.append(" and modified >= ?"); argsList.add(modifiedAfter.toDate()); } if (modifiedBefore != null) { whereBuilder.append(" and modified < ?"); argsList.add(modifiedBefore.toDate()); } String where = whereBuilder.toString(); StringBuilder sqlBuilder = new StringBuilder("select state, status, count(*) all_instances,") .append(" count(case when next_activation < current_timestamp then 1 else null end) queued_instances") .append(" from nflow_workflow where executor_group = ? and type = ?").append(where).append(" group by state, status"); String query = sqlBuilder.toString(); Object[] argsArray = argsList.toArray(new Object[argsList.size()]); final Map<String, Map<String, WorkflowDefinitionStatistics>> stats = new LinkedHashMap<>(); jdbc.query(query, argsArray, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { String state = rs.getString("state"); Map<String, WorkflowDefinitionStatistics> stateStats = stats.get(state); if (stateStats == null) { stateStats = new LinkedHashMap<>(); stats.put(state, stateStats); } String status = rs.getString("status"); WorkflowDefinitionStatistics statusStats = new WorkflowDefinitionStatistics(); statusStats.allInstances = rs.getLong("all_instances"); statusStats.queuedInstances = rs.getLong("queued_instances"); stateStats.put(status, statusStats); } }); return stats; } @Inject  StatisticsDao(@NFlow JdbcTemplate jdbcTemplate, ExecutorDao executorDao); Statistics getQueueStatistics(); Map<String, Map<String, WorkflowDefinitionStatistics>> getWorkflowDefinitionStatistics(String type,
      DateTime createdAfter, DateTime createdBefore, DateTime modifiedAfter, DateTime modifiedBefore);  }