Esempio n. 1
0
  public String execute() throws Exception {
    int monthDays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

    navigationString = "Dashboard";
    orgUnitList = new ArrayList<OrganisationUnit>();

    if (aggOption == null || aggOption.trim().equals("")) {
      aggOption = AlertUtility.USEEXISTINGAGGDATA;
    }

    // Period Info

    Date toDay = new Date();
    Calendar endCal = Calendar.getInstance();
    endCal.setTime(toDay);
    endCal.add(Calendar.MONTH, -1);
    endCal.set(Calendar.DATE, 1);

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    // String periodId = "Monthly_"+simpleDateFormat.format( cal.getTime() )+"_";

    if ((endCal.get(Calendar.YEAR) % 400 == 0 || endCal.get(Calendar.YEAR) % 4 == 0)
        && endCal.get(Calendar.MONTH) == 1) {
      endCal.set(Calendar.DATE, monthDays[Calendar.MONTH] + 1);
    } else {
      endCal.set(Calendar.DATE, monthDays[Calendar.MONTH]);
    }
    Date eDate = endCal.getTime();

    if (endCal.get(Calendar.MONTH) < Calendar.APRIL) {
      endCal.roll(Calendar.YEAR, -1);
    }
    endCal.set(Calendar.MONTH, Calendar.APRIL);
    endCal.set(Calendar.DATE, 1);

    // periodId += simpleDateFormat.format( cal.getTime() );
    Date sDate = endCal.getTime();

    List<Period> periodList =
        new ArrayList<Period>(periodService.getIntersectingPeriods(sDate, eDate));

    Collection<Integer> periodIds =
        new ArrayList<Integer>(getIdentifiers(Period.class, periodList));

    String periodIdsByComma = getCommaDelimitedString(periodIds);

    // Period selectedPeriod = periodService.getPeriodByExternalId( periodId );

    DataSet selectedDataSet = dataSetService.getDataSetByCode(DASHBOARD_DATASET);

    List<OrganisationUnit> rootOrgUnitList = new ArrayList<OrganisationUnit>();
    rootOrgUnitList.addAll(currentUserService.getCurrentUser().getOrganisationUnits());

    if (drillDownOrgUnitId == null) {
      if (rootOrgUnitList != null && rootOrgUnitList.size() > 0) {
        navigationString += " -> " + rootOrgUnitList.get(0).getName();
        selOrgUnit = rootOrgUnitList.get(0);
      } else {
        navigationString += " -> NO FACILITY";
      }
    } else {
      selOrgUnit =
          organisationUnitService.getOrganisationUnit(Integer.parseInt(drillDownOrgUnitId));
      navigationString += " -> " + selOrgUnit.getName();
    }

    navigationString +=
        " ( " + simpleDateFormat.format(sDate) + " TO " + simpleDateFormat.format(eDate) + " )";

    for (OrganisationUnit orgUnit : rootOrgUnitList) {
      List<OrganisationUnit> tempOuList = new ArrayList<OrganisationUnit>(orgUnit.getChildren());
      Collections.sort(tempOuList, new IdentifiableObjectNameComparator());

      orgUnitList.add(orgUnit);
      orgUnitList.addAll(tempOuList);
    }

    if (selectedDataSet == null || selOrgUnit == null || periodIdsByComma == null) {
      customDataEntryFormCode = " ";
    } else {
      customDataEntryFormCode =
          alertUtility.getCustomDataSetReport(
              selectedDataSet, selOrgUnit, periodIdsByComma, aggOption, format);
    }

    return SUCCESS;
  }