public WorkflowRollupOverview calculateRollupBase(WorkflowInstance instance) {
    // if this is a fresh run no need to calculate the base
    // since all steps will be reset anyway
    // if aggregated info is not present - there would be no results
    if (instance == null
        || instance.isFreshRun()
        || instance.getRunConfig().getPolicy().equals(RunPolicy.RESTART_FROM_BEGINNING)
        || instance.getAggregatedInfo() == null
        || instance.getAggregatedInfo().getStepAggregatedViews() == null) {
      return null;
    }

    Map<String, Long> stepIdRunIdForeachSubworkflowPrevious =
        RollupAggregationHelper.getStepIdToRunIdForForeachAndSubworkflowFromPreviousRuns(instance);

    WorkflowRollupOverview aggregatedBaseRollup =
        getAggregatedForeachAndSubworkflowStepRollup(
            instance.getWorkflowId(),
            instance.getWorkflowInstanceId(),
            stepIdRunIdForeachSubworkflowPrevious);

    WorkflowRollupOverview regularStepsPrevRunRollupAggregated =
        RollupAggregationHelper.getAggregatedRollupForStepsFromPreviousRuns(
            instance.getWorkflowId(),
            instance.getWorkflowInstanceId(),
            instance,
            stepIdRunIdForeachSubworkflowPrevious != null
                ? stepIdRunIdForeachSubworkflowPrevious.keySet()
                : null);

    if (aggregatedBaseRollup == null) {
      return regularStepsPrevRunRollupAggregated;
    }

    if (regularStepsPrevRunRollupAggregated != null) {
      aggregatedBaseRollup.aggregate(regularStepsPrevRunRollupAggregated);
    }

    return aggregatedBaseRollup;
  }
@Test
  public void testCalculateBaseRollup() throws IOException {
    WorkflowInstance sampleInstance =
        loadObject(
            "fixtures/instances/sample-workflow-instance-created-foreach-subworkflow-1.json",
            WorkflowInstance.class);
    sampleInstance.setRunConfig(new RunConfig());
    sampleInstance.getRunConfig().setPolicy(RunPolicy.RESTART_FROM_INCOMPLETE);
    WorkflowRollupOverview rollupBase = rollupAggregationHelper.calculateRollupBase(sampleInstance);
    assertNotNull(rollupBase.getOverview().get(StepInstance.Status.SUCCEEDED));
    assertEquals(1, rollupBase.getOverview().get(StepInstance.Status.SUCCEEDED).getCnt());

    rollupBase = rollupAggregationHelper.calculateRollupBase(null);
    assertNull(rollupBase);

    WorkflowInstance wi = new WorkflowInstance();
    rollupBase = rollupAggregationHelper.calculateRollupBase(wi);
    assertNull(rollupBase);
  }